Merge pull request #773 from norahmollo/master
CODE STYLE Formating gulliver/system
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* class.database_mysql.php
|
* class.database_mysql.php
|
||||||
|
*
|
||||||
* @package gulliver.system
|
* @package gulliver.system
|
||||||
*
|
*
|
||||||
* ProcessMaker Open Source Edition
|
* ProcessMaker Open Source Edition
|
||||||
@@ -25,60 +26,67 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @package gulliver.system
|
* @package gulliver.system
|
||||||
*/
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
G::LoadSystem('database_base');
|
G::LoadSystem( 'database_base' );
|
||||||
|
|
||||||
class database extends database_base {
|
class database extends database_base
|
||||||
|
{
|
||||||
|
|
||||||
public $iFetchType = MYSQL_ASSOC;
|
public $iFetchType = MYSQL_ASSOC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class database constructor
|
* class database constructor
|
||||||
|
*
|
||||||
* @param $sType adapter type
|
* @param $sType adapter type
|
||||||
* @param $sServer server
|
* @param $sServer server
|
||||||
* @param $sUser db user
|
* @param $sUser db user
|
||||||
* @param $sPass db user password
|
* @param $sPass db user password
|
||||||
* @param $sDataBase Database name
|
* @param $sDataBase Database name
|
||||||
*/
|
*/
|
||||||
public function __construct($sType = DB_ADAPTER, $sServer = DB_HOST, $sUser = DB_USER, $sPass = DB_PASS, $sDataBase = DB_NAME) {
|
public function __construct ($sType = DB_ADAPTER, $sServer = DB_HOST, $sUser = DB_USER, $sPass = DB_PASS, $sDataBase = DB_NAME)
|
||||||
|
{
|
||||||
$this->sType = $sType;
|
$this->sType = $sType;
|
||||||
$this->sServer = $sServer;
|
$this->sServer = $sServer;
|
||||||
$this->sUser = $sUser;
|
$this->sUser = $sUser;
|
||||||
$this->sPass = $sPass;
|
$this->sPass = $sPass;
|
||||||
$this->sDataBase = $sDataBase;
|
$this->sDataBase = $sDataBase;
|
||||||
$this->oConnection = @mysql_connect($sServer, $sUser, $sPass) || null;
|
$this->oConnection = @mysql_connect( $sServer, $sUser, $sPass ) || null;
|
||||||
$this->sQuoteCharacter = '`';
|
$this->sQuoteCharacter = '`';
|
||||||
$this->nullString = 'null';
|
$this->nullString = 'null';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generate the sql sentence to create a table
|
* generate the sql sentence to create a table
|
||||||
|
*
|
||||||
* @param $sTable table name
|
* @param $sTable table name
|
||||||
* @param $aColumns array of columns
|
* @param $aColumns array of columns
|
||||||
* @return $sSql the sql sentence
|
* @return $sSql the sql sentence
|
||||||
*/
|
*/
|
||||||
public function generateCreateTableSQL($sTable, $aColumns) {
|
public function generateCreateTableSQL ($sTable, $aColumns)
|
||||||
|
{
|
||||||
$sKeys = '';
|
$sKeys = '';
|
||||||
$sSQL = 'CREATE TABLE IF NOT EXISTS ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . '(';
|
$sSQL = 'CREATE TABLE IF NOT EXISTS ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . '(';
|
||||||
|
|
||||||
foreach ($aColumns as $sColumnName => $aParameters) {
|
foreach ($aColumns as $sColumnName => $aParameters) {
|
||||||
if ($sColumnName != 'INDEXES') {
|
if ($sColumnName != 'INDEXES') {
|
||||||
|
|
||||||
if ( $sColumnName != '' && isset($aParameters['Type']) && $aParameters['Type'] != '' ){
|
if ($sColumnName != '' && isset( $aParameters['Type'] ) && $aParameters['Type'] != '') {
|
||||||
$sSQL .= $this->sQuoteCharacter . $sColumnName . $this->sQuoteCharacter . ' ' . $aParameters['Type'];
|
$sSQL .= $this->sQuoteCharacter . $sColumnName . $this->sQuoteCharacter . ' ' . $aParameters['Type'];
|
||||||
|
|
||||||
if ( isset($aParameters['Null']) && $aParameters['Null'] == 'YES') {
|
if (isset( $aParameters['Null'] ) && $aParameters['Null'] == 'YES') {
|
||||||
$sSQL .= ' NULL';
|
$sSQL .= ' NULL';
|
||||||
} else {
|
} else {
|
||||||
$sSQL .= ' NOT NULL';
|
$sSQL .= ' NOT NULL';
|
||||||
}
|
}
|
||||||
if ( isset($aParameters['Key']) && $aParameters['Key'] == 'PRI') {
|
if (isset( $aParameters['Key'] ) && $aParameters['Key'] == 'PRI') {
|
||||||
$sKeys .= $this->sQuoteCharacter . $sColumnName . $this->sQuoteCharacter . ',';
|
$sKeys .= $this->sQuoteCharacter . $sColumnName . $this->sQuoteCharacter . ',';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset($aParameters['Default']) && $aParameters['Default'] != '' ) {
|
if (isset( $aParameters['Default'] ) && $aParameters['Default'] != '') {
|
||||||
$sSQL .= " DEFAULT '" . $aParameters['Default'] . "'";
|
$sSQL .= " DEFAULT '" . $aParameters['Default'] . "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,9 +94,9 @@ class database extends database_base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sSQL = substr($sSQL, 0, -1);
|
$sSQL = substr( $sSQL, 0, - 1 );
|
||||||
if ($sKeys != '') {
|
if ($sKeys != '') {
|
||||||
$sSQL .= ',PRIMARY KEY(' . substr($sKeys, 0, -1) . ')';
|
$sSQL .= ',PRIMARY KEY(' . substr( $sKeys, 0, - 1 ) . ')';
|
||||||
}
|
}
|
||||||
$sSQL .= ')' . $this->sEndLine;
|
$sSQL .= ')' . $this->sEndLine;
|
||||||
|
|
||||||
@@ -97,41 +105,43 @@ class database extends database_base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* generate a drop table sentence
|
* generate a drop table sentence
|
||||||
|
*
|
||||||
* @param $sTable table name
|
* @param $sTable table name
|
||||||
* @return sql sentence string
|
* @return sql sentence string
|
||||||
*/
|
*/
|
||||||
public function generateDropTableSQL($sTable) {
|
public function generateDropTableSQL ($sTable)
|
||||||
|
{
|
||||||
return 'DROP TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . $this->sEndLine;
|
return 'DROP TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . $this->sEndLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generate drop column sentence
|
* generate drop column sentence
|
||||||
|
*
|
||||||
* @param $sTable table name
|
* @param $sTable table name
|
||||||
* @param $sColumn column name
|
* @param $sColumn column name
|
||||||
* @return $sSql sql sentence
|
* @return $sSql sql sentence
|
||||||
*/
|
*/
|
||||||
public function generateDropColumnSQL($sTable, $sColumn) {
|
public function generateDropColumnSQL ($sTable, $sColumn)
|
||||||
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter .
|
{
|
||||||
' DROP COLUMN ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . $this->sEndLine;
|
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP COLUMN ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . $this->sEndLine;
|
||||||
return $sSQL;
|
return $sSQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generate an add column sentence
|
* generate an add column sentence
|
||||||
|
*
|
||||||
* @param $sTable table name
|
* @param $sTable table name
|
||||||
* @param $sColumn column name
|
* @param $sColumn column name
|
||||||
* @param $aParameters parameters of field like typo or if it can be null
|
* @param $aParameters parameters of field like typo or if it can be null
|
||||||
* @return $sSql sql sentence
|
* @return $sSql sql sentence
|
||||||
*/
|
*/
|
||||||
public function generateAddColumnSQL($sTable, $sColumn, $aParameters) {
|
public function generateAddColumnSQL ($sTable, $sColumn, $aParameters)
|
||||||
if ( isset($aParameters['Type']) && isset($aParameters['Null']) ) {
|
{
|
||||||
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter .
|
if (isset( $aParameters['Type'] ) && isset( $aParameters['Null'] )) {
|
||||||
' ADD COLUMN ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter .
|
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' ADD COLUMN ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . ' ' . $aParameters['Type'];
|
||||||
' ' . $aParameters['Type'];
|
|
||||||
if ($aParameters['Null'] == 'YES') {
|
if ($aParameters['Null'] == 'YES') {
|
||||||
$sSQL .= ' NULL';
|
$sSQL .= ' NULL';
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$sSQL .= ' NOT NULL';
|
$sSQL .= ' NOT NULL';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,18 +149,16 @@ class database extends database_base {
|
|||||||
$sKeys .= 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter .
|
$sKeys .= 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter .
|
||||||
' ADD PRIMARY KEY (' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . ')' . $this->sEndLine;
|
' ADD PRIMARY KEY (' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . ')' . $this->sEndLine;
|
||||||
}*/
|
}*/
|
||||||
if (isset($aParameters['AI'])) {
|
if (isset( $aParameters['AI'] )) {
|
||||||
if ($aParameters['AI'] == 1) {
|
if ($aParameters['AI'] == 1) {
|
||||||
$sSQL .= ' AUTO_INCREMENT';
|
$sSQL .= ' AUTO_INCREMENT';
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if ($aParameters['Default'] != '') {
|
if ($aParameters['Default'] != '') {
|
||||||
$sSQL .= " DEFAULT '" . $aParameters['Default'] . "'";
|
$sSQL .= " DEFAULT '" . $aParameters['Default'] . "'";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
if (isset( $aParameters['Default'] )) {
|
||||||
if (isset($aParameters['Default'])) {
|
|
||||||
$sSQL .= " DEFAULT '" . $aParameters['Default'] . "'";
|
$sSQL .= " DEFAULT '" . $aParameters['Default'] . "'";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -160,24 +168,23 @@ class database extends database_base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* generate a change column sentence
|
* generate a change column sentence
|
||||||
|
*
|
||||||
* @param $sTable table name
|
* @param $sTable table name
|
||||||
* @param $sColumn column name
|
* @param $sColumn column name
|
||||||
* @param $aParameters parameters of field like typo or if it can be null
|
* @param $aParameters parameters of field like typo or if it can be null
|
||||||
* @param $sColumnNewName column new name
|
* @param $sColumnNewName column new name
|
||||||
* @return $sSql sql sentence
|
* @return $sSql sql sentence
|
||||||
*/
|
*/
|
||||||
public function generateChangeColumnSQL($sTable, $sColumn, $aParameters, $sColumnNewName = '') {
|
public function generateChangeColumnSQL ($sTable, $sColumn, $aParameters, $sColumnNewName = '')
|
||||||
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter .
|
{
|
||||||
' CHANGE COLUMN ' . $this->sQuoteCharacter . ($sColumnNewName != '' ? $sColumnNewName : $sColumn) . $this->sQuoteCharacter .
|
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' CHANGE COLUMN ' . $this->sQuoteCharacter . ($sColumnNewName != '' ? $sColumnNewName : $sColumn) . $this->sQuoteCharacter . ' ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter;
|
||||||
' ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter;
|
if (isset( $aParameters['Type'] )) {
|
||||||
if (isset($aParameters['Type'])) {
|
|
||||||
$sSQL .= ' ' . $aParameters['Type'];
|
$sSQL .= ' ' . $aParameters['Type'];
|
||||||
}
|
}
|
||||||
if (isset($aParameters['Null'])) {
|
if (isset( $aParameters['Null'] )) {
|
||||||
if ($aParameters['Null'] == 'YES') {
|
if ($aParameters['Null'] == 'YES') {
|
||||||
$sSQL .= ' NULL';
|
$sSQL .= ' NULL';
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$sSQL .= ' NOT NULL';
|
$sSQL .= ' NOT NULL';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -194,15 +201,14 @@ class database extends database_base {
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
//else {
|
//else {
|
||||||
if (isset($aParameters['Default'])) {
|
if (isset( $aParameters['Default'] )) {
|
||||||
if ( trim($aParameters['Default']) == '' && $aParameters['Type'] == 'datetime' ) {
|
if (trim( $aParameters['Default'] ) == '' && $aParameters['Type'] == 'datetime') {
|
||||||
//do nothing
|
//do nothing
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
$sSQL .= " DEFAULT '" . $aParameters['Default'] . "'";
|
$sSQL .= " DEFAULT '" . $aParameters['Default'] . "'";
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
if (!isset($aParameters['Default']) && isset($aParameters['Null']) && $aParameters['Null'] == 'YES') {
|
if (! isset( $aParameters['Default'] ) && isset( $aParameters['Null'] ) && $aParameters['Null'] == 'YES') {
|
||||||
$sSQL .= " DEFAULT NULL ";
|
$sSQL .= " DEFAULT NULL ";
|
||||||
}
|
}
|
||||||
//}
|
//}
|
||||||
@@ -212,95 +218,100 @@ class database extends database_base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate and get the primary key in a sentence
|
* Generate and get the primary key in a sentence
|
||||||
|
*
|
||||||
* @param $sTable table name
|
* @param $sTable table name
|
||||||
* @return $sSql sql sentence
|
* @return $sSql sql sentence
|
||||||
*/
|
*/
|
||||||
public function generateGetPrimaryKeysSQL($sTable) {
|
public function generateGetPrimaryKeysSQL ($sTable)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
if ($sTable == '') {
|
if ($sTable == '') {
|
||||||
throw new Exception('The table name cannot be empty!');
|
throw new Exception( 'The table name cannot be empty!' );
|
||||||
}
|
}
|
||||||
return 'SHOW INDEX FROM ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' WHERE Seq_in_index = 1' . $this->sEndLine;
|
return 'SHOW INDEX FROM ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' WHERE Seq_in_index = 1' . $this->sEndLine;
|
||||||
}
|
} catch (Exception $oException) {
|
||||||
catch (Exception $oException) {
|
|
||||||
throw $oException;
|
throw $oException;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generate a sentence to drop the primary key
|
* generate a sentence to drop the primary key
|
||||||
|
*
|
||||||
* @param $sTable table name
|
* @param $sTable table name
|
||||||
* @return sql sentence
|
* @return sql sentence
|
||||||
*/
|
*/
|
||||||
public function generateDropPrimaryKeysSQL($sTable) {
|
public function generateDropPrimaryKeysSQL ($sTable)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
if ($sTable == '') {
|
if ($sTable == '') {
|
||||||
throw new Exception('The table name cannot be empty!');
|
throw new Exception( 'The table name cannot be empty!' );
|
||||||
}
|
}
|
||||||
return 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP PRIMARY KEY' . $this->sEndLine;
|
return 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP PRIMARY KEY' . $this->sEndLine;
|
||||||
}
|
} catch (Exception $oException) {
|
||||||
catch (Exception $oException) {
|
|
||||||
throw $oException;
|
throw $oException;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generate a sentence to add multiple primary keys
|
* generate a sentence to add multiple primary keys
|
||||||
|
*
|
||||||
* @param $sTable table name
|
* @param $sTable table name
|
||||||
* @param $aPrimaryKeys array of primary keys
|
* @param $aPrimaryKeys array of primary keys
|
||||||
* @return sql sentence
|
* @return sql sentence
|
||||||
*/
|
*/
|
||||||
public function generateAddPrimaryKeysSQL($sTable, $aPrimaryKeys) {
|
public function generateAddPrimaryKeysSQL ($sTable, $aPrimaryKeys)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
if ($sTable == '') {
|
if ($sTable == '') {
|
||||||
throw new Exception('The table name cannot be empty!');
|
throw new Exception( 'The table name cannot be empty!' );
|
||||||
}
|
}
|
||||||
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter .
|
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' ADD PRIMARY KEY (';
|
||||||
' ADD PRIMARY KEY (';
|
|
||||||
foreach ($aPrimaryKeys as $sKey) {
|
foreach ($aPrimaryKeys as $sKey) {
|
||||||
$sSQL .= $this->sQuoteCharacter . $sKey . $this->sQuoteCharacter . ',';
|
$sSQL .= $this->sQuoteCharacter . $sKey . $this->sQuoteCharacter . ',';
|
||||||
}
|
}
|
||||||
$sSQL = substr($sSQL, 0, -1) . ')' . $this->sEndLine;
|
$sSQL = substr( $sSQL, 0, - 1 ) . ')' . $this->sEndLine;
|
||||||
return $sSQL;
|
return $sSQL;
|
||||||
}
|
} catch (Exception $oException) {
|
||||||
catch (Exception $oException) {
|
|
||||||
throw $oException;
|
throw $oException;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generate a sentence to drop an index
|
* generate a sentence to drop an index
|
||||||
|
*
|
||||||
* @param $sTable table name
|
* @param $sTable table name
|
||||||
* @param $sIndexName index name
|
* @param $sIndexName index name
|
||||||
* @return sql sentence
|
* @return sql sentence
|
||||||
*/
|
*/
|
||||||
public function generateDropKeySQL($sTable, $sIndexName) {
|
public function generateDropKeySQL ($sTable, $sIndexName)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
if ($sTable == '') {
|
if ($sTable == '') {
|
||||||
throw new Exception('The table name cannot be empty!');
|
throw new Exception( 'The table name cannot be empty!' );
|
||||||
}
|
}
|
||||||
if ($sIndexName == '') {
|
if ($sIndexName == '') {
|
||||||
throw new Exception('The column name cannot be empty!');
|
throw new Exception( 'The column name cannot be empty!' );
|
||||||
}
|
}
|
||||||
return 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP INDEX ' . $this->sQuoteCharacter . $sIndexName . $this->sQuoteCharacter . $this->sEndLine;
|
return 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP INDEX ' . $this->sQuoteCharacter . $sIndexName . $this->sQuoteCharacter . $this->sEndLine;
|
||||||
}
|
} catch (Exception $oException) {
|
||||||
catch (Exception $oException) {
|
|
||||||
throw $oException;
|
throw $oException;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generate a sentence to add indexes or primary keys
|
* generate a sentence to add indexes or primary keys
|
||||||
|
*
|
||||||
* @param $sTable table name
|
* @param $sTable table name
|
||||||
* @param $indexName index name
|
* @param $indexName index name
|
||||||
* @param $aKeys array of keys
|
* @param $aKeys array of keys
|
||||||
* @return sql sentence
|
* @return sql sentence
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function generateAddKeysSQL($sTable, $indexName, $aKeys) {
|
public function generateAddKeysSQL ($sTable, $indexName, $aKeys)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
$indexType = 'INDEX';
|
$indexType = 'INDEX';
|
||||||
if ( $indexName == 'primaryKey' || $indexName == 'PRIMARY' ) {
|
if ($indexName == 'primaryKey' || $indexName == 'PRIMARY') {
|
||||||
$indexType = 'PRIMARY';
|
$indexType = 'PRIMARY';
|
||||||
$indexName = 'KEY';
|
$indexName = 'KEY';
|
||||||
}
|
}
|
||||||
@@ -308,116 +319,129 @@ class database extends database_base {
|
|||||||
foreach ($aKeys as $sKey) {
|
foreach ($aKeys as $sKey) {
|
||||||
$sSQL .= $this->sQuoteCharacter . $sKey . $this->sQuoteCharacter . ', ';
|
$sSQL .= $this->sQuoteCharacter . $sKey . $this->sQuoteCharacter . ', ';
|
||||||
}
|
}
|
||||||
$sSQL = substr($sSQL, 0, -2);
|
$sSQL = substr( $sSQL, 0, - 2 );
|
||||||
$sSQL .= ')' . $this->sEndLine;
|
$sSQL .= ')' . $this->sEndLine;
|
||||||
return $sSQL;
|
return $sSQL;
|
||||||
}
|
} catch (Exception $oException) {
|
||||||
catch (Exception $oException) {
|
|
||||||
throw $oException;
|
throw $oException;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generate a sentence to show the tables
|
* generate a sentence to show the tables
|
||||||
|
*
|
||||||
* @return sql sentence
|
* @return sql sentence
|
||||||
*/
|
*/
|
||||||
public function generateShowTablesSQL() {
|
public function generateShowTablesSQL ()
|
||||||
|
{
|
||||||
return 'SHOW TABLES' . $this->sEndLine;
|
return 'SHOW TABLES' . $this->sEndLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generate a sentence to show the tables with a like sentence
|
* generate a sentence to show the tables with a like sentence
|
||||||
|
*
|
||||||
* @return sql sentence
|
* @return sql sentence
|
||||||
*/
|
*/
|
||||||
public function generateShowTablesLikeSQL($sTable) {
|
public function generateShowTablesLikeSQL ($sTable)
|
||||||
|
{
|
||||||
return "SHOW TABLES LIKE '" . $sTable . "'" . $this->sEndLine;
|
return "SHOW TABLES LIKE '" . $sTable . "'" . $this->sEndLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generate a sentence to show the tables with a like sentence
|
* generate a sentence to show the tables with a like sentence
|
||||||
|
*
|
||||||
* @param $sTable table name
|
* @param $sTable table name
|
||||||
* @return sql sentence
|
* @return sql sentence
|
||||||
*/
|
*/
|
||||||
public function generateDescTableSQL($sTable) {
|
public function generateDescTableSQL ($sTable)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
if ($sTable == '') {
|
if ($sTable == '') {
|
||||||
throw new Exception('The table name cannot be empty!');
|
throw new Exception( 'The table name cannot be empty!' );
|
||||||
}
|
}
|
||||||
return 'DESC ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . $this->sEndLine;
|
return 'DESC ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . $this->sEndLine;
|
||||||
}
|
} catch (Exception $oException) {
|
||||||
catch (Exception $oException) {
|
|
||||||
throw $oException;
|
throw $oException;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generate a sentence to show some table indexes
|
* generate a sentence to show some table indexes
|
||||||
|
*
|
||||||
* @param $sTable table name
|
* @param $sTable table name
|
||||||
* @return sql sentence
|
* @return sql sentence
|
||||||
*/
|
*/
|
||||||
public function generateTableIndexSQL($sTable) {
|
public function generateTableIndexSQL ($sTable)
|
||||||
|
{
|
||||||
return 'SHOW INDEX FROM ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . " " . $this->sEndLine;
|
return 'SHOW INDEX FROM ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . " " . $this->sEndLine;
|
||||||
//return 'SHOW INDEX FROM ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . " WHERE Key_name <> 'PRIMARY'" . $this->sEndLine;
|
//return 'SHOW INDEX FROM ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . " WHERE Key_name <> 'PRIMARY'" . $this->sEndLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* execute a sentence to check if there is connection
|
* execute a sentence to check if there is connection
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function isConnected() {
|
public function isConnected ()
|
||||||
if ( !$this->oConnection )
|
{
|
||||||
|
if (! $this->oConnection)
|
||||||
return false;
|
return false;
|
||||||
return $this->executeQuery( 'USE ' . $this->sDataBase );
|
return $this->executeQuery( 'USE ' . $this->sDataBase );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generate a sentence to show the tables with a like sentence
|
* generate a sentence to show the tables with a like sentence
|
||||||
|
*
|
||||||
* @param $sQuery sql query string
|
* @param $sQuery sql query string
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function logQuery($sQuery ) {
|
public function logQuery ($sQuery)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
$found = false;
|
$found = false;
|
||||||
if ( substr($sQuery,0, 6) == 'SELECT' ) $found = true;
|
if (substr( $sQuery, 0, 6 ) == 'SELECT')
|
||||||
if ( substr($sQuery,0, 4) == 'SHOW' ) $found = true;
|
$found = true;
|
||||||
if ( substr($sQuery,0, 4) == 'DESC' ) $found = true;
|
if (substr( $sQuery, 0, 4 ) == 'SHOW')
|
||||||
if ( substr($sQuery,0, 4) == 'USE ' ) $found = true;
|
$found = true;
|
||||||
if ( ! $found ) {
|
if (substr( $sQuery, 0, 4 ) == 'DESC')
|
||||||
|
$found = true;
|
||||||
|
if (substr( $sQuery, 0, 4 ) == 'USE ')
|
||||||
|
$found = true;
|
||||||
|
if (! $found) {
|
||||||
$logDir = PATH_DATA . 'log';
|
$logDir = PATH_DATA . 'log';
|
||||||
if (!file_exists($logDir))
|
if (! file_exists( $logDir ))
|
||||||
if (!mkdir($logDir))
|
if (! mkdir( $logDir ))
|
||||||
return;
|
return;
|
||||||
$logFile = "$logDir/query.log";
|
$logFile = "$logDir/query.log";
|
||||||
$fp = fopen ( $logFile, 'a+' );
|
$fp = fopen( $logFile, 'a+' );
|
||||||
if ($fp !== false) {
|
if ($fp !== false) {
|
||||||
fwrite ( $fp, date("Y-m-d H:i:s") . " " . $this->sDataBase . " " . $sQuery . "\n" );
|
fwrite( $fp, date( "Y-m-d H:i:s" ) . " " . $this->sDataBase . " " . $sQuery . "\n" );
|
||||||
fclose ( $fp );
|
fclose( $fp );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception $oException) {
|
||||||
catch (Exception $oException) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* execute a sql query
|
* execute a sql query
|
||||||
|
*
|
||||||
* @param $sQuery table name
|
* @param $sQuery table name
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function executeQuery($sQuery) {
|
public function executeQuery ($sQuery)
|
||||||
$this->logQuery( $sQuery);
|
{
|
||||||
|
$this->logQuery( $sQuery );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($this->oConnection) {
|
if ($this->oConnection) {
|
||||||
@mysql_select_db($this->sDataBase);
|
@mysql_select_db( $this->sDataBase );
|
||||||
|
|
||||||
return @mysql_query($sQuery);
|
return @mysql_query( $sQuery );
|
||||||
|
} else {
|
||||||
|
throw new Exception( 'invalid connection to database ' . $this->sDataBase );
|
||||||
}
|
}
|
||||||
else {
|
} catch (Exception $oException) {
|
||||||
throw new Exception('invalid connection to database ' . $this->sDataBase );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception $oException) {
|
|
||||||
$this->logQuery( $oException->getMessage() );
|
$this->logQuery( $oException->getMessage() );
|
||||||
throw $oException;
|
throw $oException;
|
||||||
}
|
}
|
||||||
@@ -425,136 +449,144 @@ class database extends database_base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* count the rows of a dataset
|
* count the rows of a dataset
|
||||||
|
*
|
||||||
* @param $oDataset
|
* @param $oDataset
|
||||||
* @return the number of rows
|
* @return the number of rows
|
||||||
*/
|
*/
|
||||||
public function countResults($oDataset) {
|
public function countResults ($oDataset)
|
||||||
return @mysql_num_rows($oDataset);
|
{
|
||||||
|
return @mysql_num_rows( $oDataset );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* count an array of the registry from a dataset
|
* count an array of the registry from a dataset
|
||||||
|
*
|
||||||
* @param $oDataset
|
* @param $oDataset
|
||||||
* @return the registry
|
* @return the registry
|
||||||
*/
|
*/
|
||||||
public function getRegistry($oDataset) {
|
public function getRegistry ($oDataset)
|
||||||
return @mysql_fetch_array($oDataset, $this->iFetchType);
|
{
|
||||||
|
return @mysql_fetch_array( $oDataset, $this->iFetchType );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* close the current connection
|
* close the current connection
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function close() {
|
public function close ()
|
||||||
@mysql_close($this->oConnection);
|
{
|
||||||
|
@mysql_close( $this->oConnection );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateInsertSQL($table, $data) {
|
public function generateInsertSQL ($table, $data)
|
||||||
$fields = array();
|
{
|
||||||
$values = array();
|
$fields = array ();
|
||||||
|
$values = array ();
|
||||||
foreach ($data as $field) {
|
foreach ($data as $field) {
|
||||||
$fields[] = $field['field'];
|
$fields[] = $field['field'];
|
||||||
if (!is_null($field['value'])) {
|
if (! is_null( $field['value'] )) {
|
||||||
switch ($field['type']) {
|
switch ($field['type']) {
|
||||||
case 'text':
|
case 'text':
|
||||||
case 'date':
|
case 'date':
|
||||||
$values[] = "'" . mysql_real_escape_string($field['value']) . "'";
|
$values[] = "'" . mysql_real_escape_string( $field['value'] ) . "'";
|
||||||
break;
|
break;
|
||||||
case 'int':
|
case 'int':
|
||||||
default:
|
default:
|
||||||
$values[] = mysql_real_escape_string($field['value']);
|
$values[] = mysql_real_escape_string( $field['value'] );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$values[] = $this->nullString;
|
$values[] = $this->nullString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$fields = array_map(array($this, 'putQuotes'), $fields);
|
$fields = array_map( array ($this,'putQuotes'
|
||||||
$sql = sprintf("INSERT INTO %s (%s) VALUES (%s)", $this->putQuotes($table), implode(', ', $fields), implode(', ', $values));
|
), $fields );
|
||||||
|
$sql = sprintf( "INSERT INTO %s (%s) VALUES (%s)", $this->putQuotes( $table ), implode( ', ', $fields ), implode( ', ', $values ) );
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateUpdateSQL($table, $keys, $data) {
|
public function generateUpdateSQL ($table, $keys, $data)
|
||||||
$fields = array();
|
{
|
||||||
$where = array();
|
$fields = array ();
|
||||||
|
$where = array ();
|
||||||
foreach ($data as $field) {
|
foreach ($data as $field) {
|
||||||
if (!is_null($field['value'])) {
|
if (! is_null( $field['value'] )) {
|
||||||
switch ($field['type']) {
|
switch ($field['type']) {
|
||||||
case 'text':
|
case 'text':
|
||||||
case 'date':
|
case 'date':
|
||||||
$fields[] = $this->putQuotes($field['field']) . " = '" . mysql_real_escape_string($field['value']) . "'";
|
$fields[] = $this->putQuotes( $field['field'] ) . " = '" . mysql_real_escape_string( $field['value'] ) . "'";
|
||||||
break;
|
break;
|
||||||
case 'int':
|
case 'int':
|
||||||
default:
|
default:
|
||||||
$fields[] = $this->putQuotes($field['field']) . " = " . mysql_real_escape_string($field['value']);
|
$fields[] = $this->putQuotes( $field['field'] ) . " = " . mysql_real_escape_string( $field['value'] );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$values[] = $this->nullString;
|
$values[] = $this->nullString;
|
||||||
}
|
}
|
||||||
if (in_array($field['field'], $keys)) {
|
if (in_array( $field['field'], $keys )) {
|
||||||
$where[] = $fields[count($fields) - 1];
|
$where[] = $fields[count( $fields ) - 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sql = sprintf("UPDATE %s SET %s WHERE %s", $this->putQuotes($table), implode(', ', $fields), implode(', ', $where));
|
$sql = sprintf( "UPDATE %s SET %s WHERE %s", $this->putQuotes( $table ), implode( ', ', $fields ), implode( ', ', $where ) );
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateDeleteSQL($table, $keys, $data) {
|
public function generateDeleteSQL ($table, $keys, $data)
|
||||||
$fields = array();
|
{
|
||||||
$where = array();
|
$fields = array ();
|
||||||
|
$where = array ();
|
||||||
foreach ($data as $field) {
|
foreach ($data as $field) {
|
||||||
if (in_array($field['field'], $keys)) {
|
if (in_array( $field['field'], $keys )) {
|
||||||
if (!is_null($field['value'])) {
|
if (! is_null( $field['value'] )) {
|
||||||
switch ($field['type']) {
|
switch ($field['type']) {
|
||||||
case 'text':
|
case 'text':
|
||||||
case 'date':
|
case 'date':
|
||||||
$where[] = $this->putQuotes($field['field']) . " = '" . mysql_real_escape_string($field['value']) . "'";
|
$where[] = $this->putQuotes( $field['field'] ) . " = '" . mysql_real_escape_string( $field['value'] ) . "'";
|
||||||
break;
|
break;
|
||||||
case 'int':
|
case 'int':
|
||||||
default:
|
default:
|
||||||
$where[] = $this->putQuotes($field['field']) . " = " . mysql_real_escape_string($field['value']);
|
$where[] = $this->putQuotes( $field['field'] ) . " = " . mysql_real_escape_string( $field['value'] );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$values[] = $this->nullString;
|
$values[] = $this->nullString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sql = sprintf("DELETE FROM %s WHERE %s", $this->putQuotes($table), implode(', ', $where));
|
$sql = sprintf( "DELETE FROM %s WHERE %s", $this->putQuotes( $table ), implode( ', ', $where ) );
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateSelectSQL($table, $keys, $data) {
|
public function generateSelectSQL ($table, $keys, $data)
|
||||||
$fields = array();
|
{
|
||||||
$where = array();
|
$fields = array ();
|
||||||
|
$where = array ();
|
||||||
foreach ($data as $field) {
|
foreach ($data as $field) {
|
||||||
if (in_array($field['field'], $keys)) {
|
if (in_array( $field['field'], $keys )) {
|
||||||
if (!is_null($field['value'])) {
|
if (! is_null( $field['value'] )) {
|
||||||
switch ($field['type']) {
|
switch ($field['type']) {
|
||||||
case 'text':
|
case 'text':
|
||||||
case 'date':
|
case 'date':
|
||||||
$where[] = $this->putQuotes($field['field']) . " = '" . mysql_real_escape_string($field['value']) . "'";
|
$where[] = $this->putQuotes( $field['field'] ) . " = '" . mysql_real_escape_string( $field['value'] ) . "'";
|
||||||
break;
|
break;
|
||||||
case 'int':
|
case 'int':
|
||||||
default:
|
default:
|
||||||
$where[] = $this->putQuotes($field['field']) . " = " . mysql_real_escape_string($field['value']);
|
$where[] = $this->putQuotes( $field['field'] ) . " = " . mysql_real_escape_string( $field['value'] );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$values[] = $this->nullString;
|
$values[] = $this->nullString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sql = sprintf("SELECT * FROM %s WHERE %s", $this->putQuotes($table), implode(', ', $where));
|
$sql = sprintf( "SELECT * FROM %s WHERE %s", $this->putQuotes( $table ), implode( ', ', $where ) );
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function putQuotes($element) {
|
private function putQuotes ($element)
|
||||||
|
{
|
||||||
return $this->sQuoteCharacter . $element . $this->sQuoteCharacter;
|
return $this->sQuoteCharacter . $element . $this->sQuoteCharacter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -568,16 +600,16 @@ class database extends database_base {
|
|||||||
*
|
*
|
||||||
* @return string $sConcat
|
* @return string $sConcat
|
||||||
*/
|
*/
|
||||||
function concatString()
|
function concatString ()
|
||||||
{
|
{
|
||||||
$nums = func_num_args();
|
$nums = func_num_args();
|
||||||
$vars = func_get_args();
|
$vars = func_get_args();
|
||||||
|
|
||||||
$sConcat = " CONCAT(";
|
$sConcat = " CONCAT(";
|
||||||
for($i = 0;$i < $nums; $i++) {
|
for ($i = 0; $i < $nums; $i ++) {
|
||||||
if(isset($vars[$i])) {
|
if (isset( $vars[$i] )) {
|
||||||
$sConcat .= $vars[$i];
|
$sConcat .= $vars[$i];
|
||||||
if(($i+1) < $nums)
|
if (($i + 1) < $nums)
|
||||||
$sConcat .= ", ";
|
$sConcat .= ", ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -600,7 +632,7 @@ class database extends database_base {
|
|||||||
*
|
*
|
||||||
* @return string $sCompare
|
* @return string $sCompare
|
||||||
*/
|
*/
|
||||||
function getCaseWhen($compareValue, $trueResult, $falseResult)
|
function getCaseWhen ($compareValue, $trueResult, $falseResult)
|
||||||
{
|
{
|
||||||
$sCompare = "IF(" . $compareValue . ", " . $trueResult . ", " . $falseResult . ") ";
|
$sCompare = "IF(" . $compareValue . ", " . $trueResult . ", " . $falseResult . ") ";
|
||||||
return $sCompare;
|
return $sCompare;
|
||||||
@@ -615,7 +647,7 @@ class database extends database_base {
|
|||||||
*
|
*
|
||||||
* @return string $sql
|
* @return string $sql
|
||||||
*/
|
*/
|
||||||
function createTableObjectPermission()
|
function createTableObjectPermission ()
|
||||||
{
|
{
|
||||||
$sql = "CREATE TABLE IF NOT EXISTS `OBJECT_PERMISSION` (
|
$sql = "CREATE TABLE IF NOT EXISTS `OBJECT_PERMISSION` (
|
||||||
`OP_UID` varchar(32) NOT NULL,
|
`OP_UID` varchar(32) NOT NULL,
|
||||||
@@ -645,14 +677,13 @@ class database extends database_base {
|
|||||||
*
|
*
|
||||||
* @return string $sql
|
* @return string $sql
|
||||||
*/
|
*/
|
||||||
function getSelectReport4()
|
function getSelectReport4 ()
|
||||||
{
|
{
|
||||||
|
|
||||||
$sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER ";
|
$sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER ";
|
||||||
$sqlGroupBy = " USER ";
|
$sqlGroupBy = " USER ";
|
||||||
|
|
||||||
$sql = "SELECT " . $sqlConcat . ", " .
|
$sql = "SELECT " . $sqlConcat . ", " . " COUNT(*) AS CANTCASES,
|
||||||
" COUNT(*) AS CANTCASES,
|
|
||||||
MIN(AD.DEL_DURATION) AS MIN,
|
MIN(AD.DEL_DURATION) AS MIN,
|
||||||
MAX(AD.DEL_DURATION) AS MAX,
|
MAX(AD.DEL_DURATION) AS MAX,
|
||||||
SUM(AD.DEL_DURATION) AS TOTALDUR,
|
SUM(AD.DEL_DURATION) AS TOTALDUR,
|
||||||
@@ -675,13 +706,12 @@ class database extends database_base {
|
|||||||
*
|
*
|
||||||
* @return string $sql
|
* @return string $sql
|
||||||
*/
|
*/
|
||||||
function getSelectReport4Filter($var)
|
function getSelectReport4Filter ($var)
|
||||||
{
|
{
|
||||||
$sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER ";
|
$sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER ";
|
||||||
$sqlGroupBy = " USER ";
|
$sqlGroupBy = " USER ";
|
||||||
|
|
||||||
$sql = " SELECT " . $sqlConcat . ", " .
|
$sql = " SELECT " . $sqlConcat . ", " . " COUNT(*) AS CANTCASES,
|
||||||
" COUNT(*) AS CANTCASES,
|
|
||||||
MIN(AD.DEL_DURATION) AS MIN,
|
MIN(AD.DEL_DURATION) AS MIN,
|
||||||
MAX(AD.DEL_DURATION) AS MAX,
|
MAX(AD.DEL_DURATION) AS MAX,
|
||||||
SUM(AD.DEL_DURATION) AS TOTALDUR,
|
SUM(AD.DEL_DURATION) AS TOTALDUR,
|
||||||
@@ -689,7 +719,7 @@ class database extends database_base {
|
|||||||
FROM APPLICATION AS A
|
FROM APPLICATION AS A
|
||||||
LEFT JOIN APP_DELEGATION AS AD ON(A.APP_UID = AD.APP_UID AND AD.DEL_INDEX=1)
|
LEFT JOIN APP_DELEGATION AS AD ON(A.APP_UID = AD.APP_UID AND AD.DEL_INDEX=1)
|
||||||
LEFT JOIN USERS AS U ON(U.USR_UID = A.APP_INIT_USER)
|
LEFT JOIN USERS AS U ON(U.USR_UID = A.APP_INIT_USER)
|
||||||
".$var."
|
" . $var . "
|
||||||
GROUP BY " . $sqlGroupBy;
|
GROUP BY " . $sqlGroupBy;
|
||||||
|
|
||||||
return $sql;
|
return $sql;
|
||||||
@@ -704,13 +734,12 @@ class database extends database_base {
|
|||||||
*
|
*
|
||||||
* @return string $sql
|
* @return string $sql
|
||||||
*/
|
*/
|
||||||
function getSelectReport5()
|
function getSelectReport5 ()
|
||||||
{
|
{
|
||||||
$sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER ";
|
$sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER ";
|
||||||
$sqlGroupBy = " USER ";
|
$sqlGroupBy = " USER ";
|
||||||
|
|
||||||
$sql = " SELECT " . $sqlConcat . ", " .
|
$sql = " SELECT " . $sqlConcat . ", " . " COUNT(*) AS CANTCASES,
|
||||||
" COUNT(*) AS CANTCASES,
|
|
||||||
MIN(AD.DEL_DURATION) AS MIN,
|
MIN(AD.DEL_DURATION) AS MIN,
|
||||||
MAX(AD.DEL_DURATION) AS MAX,
|
MAX(AD.DEL_DURATION) AS MAX,
|
||||||
SUM(AD.DEL_DURATION) AS TOTALDUR,
|
SUM(AD.DEL_DURATION) AS TOTALDUR,
|
||||||
@@ -733,14 +762,13 @@ class database extends database_base {
|
|||||||
*
|
*
|
||||||
* @return string $sql
|
* @return string $sql
|
||||||
*/
|
*/
|
||||||
function getSelectReport5Filter($var)
|
function getSelectReport5Filter ($var)
|
||||||
{
|
{
|
||||||
|
|
||||||
$sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER ";
|
$sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER ";
|
||||||
$sqlGroupBy = " USER ";
|
$sqlGroupBy = " USER ";
|
||||||
|
|
||||||
$sql = "SELECT " . $sqlConcat . ", " .
|
$sql = "SELECT " . $sqlConcat . ", " . " COUNT(*) AS CANTCASES,
|
||||||
" COUNT(*) AS CANTCASES,
|
|
||||||
MIN(AD.DEL_DURATION) AS MIN,
|
MIN(AD.DEL_DURATION) AS MIN,
|
||||||
MAX(AD.DEL_DURATION) AS MAX,
|
MAX(AD.DEL_DURATION) AS MAX,
|
||||||
SUM(AD.DEL_DURATION) AS TOTALDUR,
|
SUM(AD.DEL_DURATION) AS TOTALDUR,
|
||||||
@@ -748,7 +776,7 @@ class database extends database_base {
|
|||||||
FROM APP_DELEGATION AS AD
|
FROM APP_DELEGATION AS AD
|
||||||
LEFT JOIN PROCESS AS P ON (P.PRO_UID = AD.PRO_UID)
|
LEFT JOIN PROCESS AS P ON (P.PRO_UID = AD.PRO_UID)
|
||||||
LEFT JOIN USERS AS U ON(U.USR_UID = AD.USR_UID)
|
LEFT JOIN USERS AS U ON(U.USR_UID = AD.USR_UID)
|
||||||
".$var."
|
" . $var . "
|
||||||
GROUP BY " . $sqlGroupBy;
|
GROUP BY " . $sqlGroupBy;
|
||||||
|
|
||||||
return $sql;
|
return $sql;
|
||||||
@@ -758,43 +786,41 @@ class database extends database_base {
|
|||||||
* query functions for class class.net.php
|
* query functions for class class.net.php
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function getServerVersion($driver, $dbIP, $dbPort, $dbUser, $dbPasswd, $dbSourcename)
|
function getServerVersion ($driver, $dbIP, $dbPort, $dbUser, $dbPasswd, $dbSourcename)
|
||||||
{
|
{
|
||||||
|
|
||||||
if($link = @mysql_connect($dbIP, $dbUser, $dbPasswd)){
|
if ($link = @mysql_connect( $dbIP, $dbUser, $dbPasswd )) {
|
||||||
$v = @mysql_get_server_info();
|
$v = @mysql_get_server_info();
|
||||||
} else {
|
} else {
|
||||||
throw new Exception(@mysql_error($link));
|
throw new Exception( @mysql_error( $link ) );
|
||||||
}
|
}
|
||||||
return (isset($v))?$v:'none';
|
return (isset( $v )) ? $v : 'none';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* query functions for class class.net.php, class.reportTables.php
|
* query functions for class class.net.php, class.reportTables.php
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function getDropTable($sTableName)
|
function getDropTable ($sTableName)
|
||||||
{
|
{
|
||||||
$sql = 'DROP TABLE IF EXISTS `' . $sTableName . '`';
|
$sql = 'DROP TABLE IF EXISTS `' . $sTableName . '`';
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTableDescription ($sTableName)
|
||||||
function getTableDescription($sTableName)
|
|
||||||
{
|
{
|
||||||
$sql = "DESC ".$sTableName;
|
$sql = "DESC " . $sTableName;
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFieldNull()
|
function getFieldNull ()
|
||||||
{
|
{
|
||||||
$fieldName = "Null";
|
$fieldName = "Null";
|
||||||
return $fieldName;
|
return $fieldName;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getValidate($validate)
|
function getValidate ($validate)
|
||||||
{
|
{
|
||||||
$oValidate = $validate;
|
$oValidate = $validate;
|
||||||
return $oValidate;
|
return $oValidate;
|
||||||
@@ -804,12 +830,12 @@ class database extends database_base {
|
|||||||
* Determines whether a table exists
|
* Determines whether a table exists
|
||||||
* It is part of class.reportTables.php
|
* It is part of class.reportTables.php
|
||||||
*/
|
*/
|
||||||
function reportTableExist()
|
function reportTableExist ()
|
||||||
{
|
{
|
||||||
$bExists = true;
|
$bExists = true;
|
||||||
$oConnection = mysql_connect(DB_HOST, DB_USER, DB_PASS);
|
$oConnection = mysql_connect( DB_HOST, DB_USER, DB_PASS );
|
||||||
mysql_select_db(DB_NAME);
|
mysql_select_db( DB_NAME );
|
||||||
$oDataset = mysql_query('SELECT COUNT(*) FROM REPORT_TABLE') || ($bExists = false);
|
$oDataset = mysql_query( 'SELECT COUNT(*) FROM REPORT_TABLE' ) || ($bExists = false);
|
||||||
|
|
||||||
return $bExists;
|
return $bExists;
|
||||||
}
|
}
|
||||||
@@ -817,38 +843,39 @@ class database extends database_base {
|
|||||||
/**
|
/**
|
||||||
* It is part of class.pagedTable.php
|
* It is part of class.pagedTable.php
|
||||||
*/
|
*/
|
||||||
function getLimitRenderTable($nCurrentPage, $nRowsPerPage)
|
function getLimitRenderTable ($nCurrentPage, $nRowsPerPage)
|
||||||
{
|
{
|
||||||
$sql = ' LIMIT '.(($nCurrentPage-1)*$nRowsPerPage).', '.$nRowsPerPage;
|
$sql = ' LIMIT ' . (($nCurrentPage - 1) * $nRowsPerPage) . ', ' . $nRowsPerPage;
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determining the existence of a table
|
* Determining the existence of a table
|
||||||
*/
|
*/
|
||||||
function tableExists($tableName, $database)
|
function tableExists ($tableName, $database)
|
||||||
{
|
{
|
||||||
@mysql_select_db($database);
|
@mysql_select_db( $database );
|
||||||
$tables = array();
|
$tables = array ();
|
||||||
$tablesResult = mysql_query("SHOW TABLES FROM $database;");
|
$tablesResult = mysql_query( "SHOW TABLES FROM $database;" );
|
||||||
while ($row = @mysql_fetch_row($tablesResult)) $tables[] = $row[0];
|
while ($row = @mysql_fetch_row( $tablesResult ))
|
||||||
if(in_array($tableName, $tables)) {
|
$tables[] = $row[0];
|
||||||
|
if (in_array( $tableName, $tables )) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determining the existence of a table (Depricated)
|
* Determining the existence of a table (Depricated)
|
||||||
*/
|
*/
|
||||||
// function tableExists ($table, $db) {
|
// function tableExists ($table, $db) {
|
||||||
// $tables = mysql_list_tables ($db);
|
// $tables = mysql_list_tables ($db);
|
||||||
// while (list ($temp) = @mysql_fetch_array ($tables)) {
|
// while (list ($temp) = @mysql_fetch_array ($tables)) {
|
||||||
// if ($temp == $table) {
|
// if ($temp == $table) {
|
||||||
// return TRUE;
|
// return TRUE;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// return FALSE;
|
// return FALSE;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* class.dbconnection.php
|
* class.dbconnection.php
|
||||||
|
*
|
||||||
* @package gulliver.system
|
* @package gulliver.system
|
||||||
*
|
*
|
||||||
* ProcessMaker Open Source Edition
|
* ProcessMaker Open Source Edition
|
||||||
@@ -25,20 +26,23 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @package gulliver.system
|
* @package gulliver.system
|
||||||
*/
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
require_once ("DB.php");
|
require_once ("DB.php");
|
||||||
|
|
||||||
define ( 'DB_ERROR_NO_SHOW_AND_CONTINUE', 0);
|
define( 'DB_ERROR_NO_SHOW_AND_CONTINUE', 0 );
|
||||||
define ( 'DB_ERROR_SHOW_AND_STOP', 1);
|
define( 'DB_ERROR_SHOW_AND_STOP', 1 );
|
||||||
define ( 'DB_ERROR_SHOW_AND_CONTINUE', 2);
|
define( 'DB_ERROR_SHOW_AND_CONTINUE', 2 );
|
||||||
define ( 'DB_ERROR_SHOWALL_AND_STOP', 3);
|
define( 'DB_ERROR_SHOWALL_AND_STOP', 3 );
|
||||||
define ( 'DB_ERROR_SHOWALL_AND_CONTINUE', 4);
|
define( 'DB_ERROR_SHOWALL_AND_CONTINUE', 4 );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DBConnection class definition
|
* DBConnection class definition
|
||||||
* It is useful to stablish a connection
|
* It is useful to stablish a connection
|
||||||
|
*
|
||||||
* @package gulliver.system
|
* @package gulliver.system
|
||||||
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
||||||
* @copyright (C) 2002 by Colosa Development Team.
|
* @copyright (C) 2002 by Colosa Development Team.
|
||||||
@@ -50,30 +54,33 @@ class DBConnection
|
|||||||
var $errorLevel;
|
var $errorLevel;
|
||||||
var $type;
|
var $type;
|
||||||
|
|
||||||
/*****************************************************************
|
/**
|
||||||
/* Error types:
|
* ***************************************************************
|
||||||
/* -1 Fatal error ( clase no instanced )
|
* /* Error types:
|
||||||
/* -2 Syntax error ( session missing, query malformed, etc )
|
* /* -1 Fatal error ( clase no instanced )
|
||||||
/* -3 warning ( when the engine build a dangerous query, i.e delete without where clause )
|
* /* -2 Syntax error ( session missing, query malformed, etc )
|
||||||
/*
|
* /* -3 warning ( when the engine build a dangerous query, i.e delete without where clause )
|
||||||
/* Error level:
|
* /*
|
||||||
/* 0 don't display any error information and continue.
|
* /* Error level:
|
||||||
/* 1 display small box with error information and die.
|
* /* 0 don't display any error information and continue.
|
||||||
/* 2 display small box with error information and continue
|
* /* 1 display small box with error information and die.
|
||||||
/* 3 display complete error information and die.
|
* /* 2 display small box with error information and continue
|
||||||
/* 4 display complete error information and continue.
|
* /* 3 display complete error information and die.
|
||||||
/*
|
* /* 4 display complete error information and continue.
|
||||||
/* Error Structure
|
* /*
|
||||||
/* int error code
|
* /* Error Structure
|
||||||
/* string error message
|
* /* int error code
|
||||||
/* string error detailed message
|
* /* string error message
|
||||||
/*
|
* /* string error detailed message
|
||||||
/* In all cases, the error will be saved in the apache log file
|
* /*
|
||||||
/*
|
* /* In all cases, the error will be saved in the apache log file
|
||||||
/* */
|
* /*
|
||||||
|
* /*
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts DB connection with default values
|
* Starts DB connection with default values
|
||||||
|
*
|
||||||
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
||||||
* @access public
|
* @access public
|
||||||
* @param const $strServer Host Name
|
* @param const $strServer Host Name
|
||||||
@@ -86,193 +93,203 @@ class DBConnection
|
|||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function DBConnection( $strServer = DB_HOST, $strUser = DB_USER, $strPwd = DB_PASS, $strDB = DB_NAME , $type = DB_ADAPTER, $strPort = 0, $errorLevel = 2 )
|
function DBConnection ($strServer = DB_HOST, $strUser = DB_USER, $strPwd = DB_PASS, $strDB = DB_NAME, $type = DB_ADAPTER, $strPort = 0, $errorLevel = 2)
|
||||||
{
|
{
|
||||||
$this->errorLevel = $errorLevel;
|
$this->errorLevel = $errorLevel;
|
||||||
if ($type == null ) $type = 'mysql';
|
if ($type == null)
|
||||||
|
$type = 'mysql';
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
//print "<hr>$type $strServer, $strUser, $strPwd, $strDB <hr>";
|
//print "<hr>$type $strServer, $strUser, $strPwd, $strDB <hr>";
|
||||||
if ( $type == "mysql" )
|
if ($type == "mysql")
|
||||||
$dsn = "mysql://$strUser:$strPwd@$strServer/$strDB";
|
$dsn = "mysql://$strUser:$strPwd@$strServer/$strDB";
|
||||||
if ( $type == "pgsql" ) {
|
if ($type == "pgsql") {
|
||||||
//$dsn = "pgsql://postgres@$strServer/$strDB";
|
//$dsn = "pgsql://postgres@$strServer/$strDB";
|
||||||
$prt = ( $strPort == 0 || $strPort == 5432 ? '' : ":$strPort" );
|
$prt = ($strPort == 0 || $strPort == 5432 ? '' : ":$strPort");
|
||||||
$dsn = "pgsql://$strUser:$strPwd@$strServer$prt/$strDB";
|
$dsn = "pgsql://$strUser:$strPwd@$strServer$prt/$strDB";
|
||||||
}
|
}
|
||||||
if ( $type == "odbc" )
|
if ($type == "odbc")
|
||||||
$dsn = "odbc://$strUser:$strPwd@$strServer/$strDB";
|
$dsn = "odbc://$strUser:$strPwd@$strServer/$strDB";
|
||||||
if ( $type == "mssql" ) {
|
if ($type == "mssql") {
|
||||||
$strServer = substr($strServer, 0, strpos($strServer,':'));
|
$strServer = substr( $strServer, 0, strpos( $strServer, ':' ) );
|
||||||
$prt = ( $strPort == 0 || $strPort == 1433 ? '' : ":$strPort" );
|
$prt = ($strPort == 0 || $strPort == 1433 ? '' : ":$strPort");
|
||||||
$dsn = "mssql://$strUser:$strPwd@$strServer$prt/$strDB";
|
$dsn = "mssql://$strUser:$strPwd@$strServer$prt/$strDB";
|
||||||
///--) $dsn = "mssql://$strUser:$strPwd@$strServer/$strDB";
|
///--) $dsn = "mssql://$strUser:$strPwd@$strServer/$strDB";
|
||||||
}
|
}
|
||||||
if ( $type == "oracle" ) {
|
if ($type == "oracle") {
|
||||||
$dsn = "oci8://$strUser:$strPwd@$strServer/$strDB";
|
$dsn = "oci8://$strUser:$strPwd@$strServer/$strDB";
|
||||||
}
|
}
|
||||||
$this->db_error = NULL;
|
$this->db_error = null;
|
||||||
if ( $type === 'myxml' ) {
|
if ($type === 'myxml') {
|
||||||
$this->db = XMLDB::connect ( $strServer );
|
$this->db = XMLDB::connect( $strServer );
|
||||||
} else {
|
} else {
|
||||||
$this->db = DB::connect ( $dsn );
|
$this->db = DB::connect( $dsn );
|
||||||
}
|
}
|
||||||
if ( DB::isError ($this->db) ) {
|
if (DB::isError( $this->db )) {
|
||||||
$this->db_error = $this->db;
|
$this->db_error = $this->db;
|
||||||
$this->db = NULL;
|
$this->db = null;
|
||||||
$this->logError( $this->db_error );
|
$this->logError( $this->db_error );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close Connection and Generate Log Message
|
* Close Connection and Generate Log Message
|
||||||
|
*
|
||||||
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
||||||
* @access public
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function Reset()
|
function Reset ()
|
||||||
{
|
{
|
||||||
if ( $this->db ){
|
if ($this->db) {
|
||||||
$this->db->disconnect();
|
$this->db->disconnect();
|
||||||
}
|
}
|
||||||
$this->db = NULL;
|
$this->db = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disconnect from Data base
|
* Disconnect from Data base
|
||||||
|
*
|
||||||
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
||||||
* @access public
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function Free()
|
function Free ()
|
||||||
{
|
{
|
||||||
$this->Reset();
|
$this->Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close Connection
|
* Close Connection
|
||||||
|
*
|
||||||
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
||||||
* @access public
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function Close()
|
function Close ()
|
||||||
{
|
{
|
||||||
$this->Reset();
|
$this->Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* log Errors
|
* log Errors
|
||||||
|
*
|
||||||
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
||||||
* @access public
|
* @access public
|
||||||
* @param db_error $obj
|
* @param db_error $obj
|
||||||
* @param string $errorLevel
|
* @param string $errorLevel
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function logError( $obj, $errorLevel = NULL )
|
function logError ($obj, $errorLevel = NULL)
|
||||||
{
|
{
|
||||||
global $_SESSION;
|
global $_SESSION;
|
||||||
global $_SERVER;
|
global $_SERVER;
|
||||||
if ( is_null( $errorLevel ) )
|
if (is_null( $errorLevel ))
|
||||||
if ( isset ( $this->errorLevel) )
|
if (isset( $this->errorLevel )) {
|
||||||
$errorLevel = $this->errorLevel;
|
$errorLevel = $this->errorLevel;
|
||||||
else
|
} else {
|
||||||
$errorLevel = DB_ERROR_SHOWALL_AND_STOP; //for fatal errors the default is 3, show detailed and die.
|
$errorLevel = DB_ERROR_SHOWALL_AND_STOP; //for fatal errors the default is 3, show detailed and die.
|
||||||
if ($errorLevel == DB_ERROR_SHOW_AND_STOP || $errorLevel == DB_ERROR_SHOW_AND_CONTINUE ||
|
}
|
||||||
$errorLevel == DB_ERROR_SHOWALL_AND_STOP || $errorLevel == DB_ERROR_SHOWALL_AND_CONTINUE ) {
|
|
||||||
|
if ($errorLevel == DB_ERROR_SHOW_AND_STOP || $errorLevel == DB_ERROR_SHOW_AND_CONTINUE || $errorLevel == DB_ERROR_SHOWALL_AND_STOP || $errorLevel == DB_ERROR_SHOWALL_AND_CONTINUE) {
|
||||||
print "<table border=1 style='font-family:Arial' cellspacing=1 cellpadding = 0 width=400 class= 'tableError' >";
|
print "<table border=1 style='font-family:Arial' cellspacing=1 cellpadding = 0 width=400 class= 'tableError' >";
|
||||||
print "<tr><td><b>" . $obj->code . ' '. $obj->message . "</b></td></tr>";
|
print "<tr><td><b>" . $obj->code . ' ' . $obj->message . "</b></td></tr>";
|
||||||
if ($errorLevel == DB_ERROR_SHOWALL_AND_STOP || $errorLevel == DB_ERROR_SHOWALL_AND_CONTINUE ) {
|
if ($errorLevel == DB_ERROR_SHOWALL_AND_STOP || $errorLevel == DB_ERROR_SHOWALL_AND_CONTINUE) {
|
||||||
print "<tr><td>" . $obj->userinfo . "</td></tr>";
|
print "<tr><td>" . $obj->userinfo . "</td></tr>";
|
||||||
}
|
}
|
||||||
print "</table>";
|
print "</table>";
|
||||||
}
|
}
|
||||||
if (defined('DB_ERROR_BACKTRACE') && DB_ERROR_BACKTRACE) {
|
if (defined( 'DB_ERROR_BACKTRACE' ) && DB_ERROR_BACKTRACE) {
|
||||||
print "<table border = 1 width=400 class= 'sendMsgRojo'><tr><td><textarea rows='12' cols='180' style='width:100%;font-family:courier;white-space:pre-line;overflow:auto;border:none;'>";
|
print "<table border = 1 width=400 class= 'sendMsgRojo'><tr><td><textarea rows='12' cols='180' style='width:100%;font-family:courier;white-space:pre-line;overflow:auto;border:none;'>";
|
||||||
print((htmlentities(DBConnection::traceError())));
|
print ((htmlentities( DBConnection::traceError() ))) ;
|
||||||
print "</textarea></td></tr></table>";
|
print "</textarea></td></tr></table>";
|
||||||
}
|
}
|
||||||
//G::setErrorHandler ( );
|
//G::setErrorHandler ( );
|
||||||
G::customErrorLog ('DB_Error', $obj->code . ' '. $obj->message .'-' . $obj->userinfo, '', '');
|
G::customErrorLog( 'DB_Error', $obj->code . ' ' . $obj->message . '-' . $obj->userinfo, '', '' );
|
||||||
if ($errorLevel == DB_ERROR_SHOW_AND_STOP || $errorLevel == DB_ERROR_SHOWALL_AND_STOP ) {
|
if ($errorLevel == DB_ERROR_SHOW_AND_STOP || $errorLevel == DB_ERROR_SHOWALL_AND_STOP) {
|
||||||
die; //stop
|
die(); //stop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the trace of the current execution (debug_backtrace).
|
* Get the trace of the current execution (debug_backtrace).
|
||||||
|
*
|
||||||
* @author David Callizaya
|
* @author David Callizaya
|
||||||
* @param string $tts
|
* @param string $tts
|
||||||
* @param string $limit
|
* @param string $limit
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function traceError( $tts=2 , $limit=-1 )
|
function traceError ($tts = 2, $limit = -1)
|
||||||
{
|
{
|
||||||
$trace = debug_backtrace();
|
$trace = debug_backtrace();
|
||||||
$out='';
|
$out = '';
|
||||||
foreach($trace as $step) {
|
foreach ($trace as $step) {
|
||||||
if ($tts>0) {
|
if ($tts > 0) {
|
||||||
$tts--;
|
$tts --;
|
||||||
} else {
|
} else {
|
||||||
$out .= '['.basename($step['file']).': '.$step['line'].'] : ' . $step['function'] .'(' .
|
$out .= '[' . basename( $step['file'] ) . ': ' . $step['line'] . '] : ' . $step['function'] . '(' . DBConnection::printArgs( $step['args'] ) . ")\n";
|
||||||
DBConnection::printArgs($step['args']). ")\n";
|
$limit --;
|
||||||
$limit--;
|
if ($limit === 0) {
|
||||||
if ($limit===0)
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print the arguments of a function
|
* Print the arguments of a function
|
||||||
|
*
|
||||||
* @author David Callizaya
|
* @author David Callizaya
|
||||||
* @param string $args
|
* @param string $args
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function printArgs( $args )
|
function printArgs ($args)
|
||||||
{
|
{
|
||||||
$out = '';
|
$out = '';
|
||||||
if (is_array($args)){
|
if (is_array( $args )) {
|
||||||
foreach($args as $arg) {
|
foreach ($args as $arg) {
|
||||||
if ($out!=='')
|
if ($out !== '') {
|
||||||
$out .= ' ,';
|
$out .= ' ,';
|
||||||
if (is_string($arg))
|
}
|
||||||
$out .= "'".($arg)."'";
|
if (is_string( $arg )) {
|
||||||
elseif (is_array($arg) )
|
$out .= "'" . ($arg) . "'";
|
||||||
$out .= print_r ( $arg ,1 );
|
} elseif (is_array( $arg )) {
|
||||||
elseif (is_object($arg))
|
$out .= print_r( $arg, 1 );
|
||||||
$out .= get_class($arg);// print_r ( $arg ,1 );
|
} elseif (is_object( $arg )) {
|
||||||
elseif (!isset($arg))
|
$out .= get_class( $arg ); // print_r ( $arg ,1 );
|
||||||
|
} elseif (! isset( $arg )) {
|
||||||
$out .= 'NULL';
|
$out .= 'NULL';
|
||||||
else
|
} else {
|
||||||
$out .= sprintf ( "%s" ,$arg );
|
$out .= sprintf( "%s", $arg );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!isset($args))
|
if (! isset( $args )) {
|
||||||
$out = 'NULL';
|
$out = 'NULL';
|
||||||
else
|
} else {
|
||||||
$out = print_r($args,1);
|
$out = print_r( $args, 1 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets last autoincrement value inserted
|
* Gets last autoincrement value inserted
|
||||||
|
*
|
||||||
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
||||||
* @access public
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function GetLastID()
|
function GetLastID ()
|
||||||
{
|
{
|
||||||
if ( PEAR_DATABASE == "mysql" ){
|
if (PEAR_DATABASE == "mysql") {
|
||||||
return mysql_insert_id();
|
return mysql_insert_id();
|
||||||
}
|
} else {
|
||||||
else {
|
$dberror = PEAR::raiseError( null, DB_ERROR_FEATURE_NOT_AVAILABLE, null, 'null', "getLastID with " . PEAR_DATABASE . ' database.', 'G_Error', true );
|
||||||
$dberror = PEAR::raiseError(null, DB_ERROR_FEATURE_NOT_AVAILABLE, null, 'null',
|
|
||||||
"getLastID with " . PEAR_DATABASE . ' database.',
|
|
||||||
'G_Error', true);
|
|
||||||
DBconnection::logError( $dberror, DB_ERROR_SHOWALL_AND_STOP ); //this error will stop the execution, until we add this feature!!
|
DBconnection::logError( $dberror, DB_ERROR_SHOWALL_AND_STOP ); //this error will stop the execution, until we add this feature!!
|
||||||
return $dberror;
|
return $dberror;
|
||||||
}
|
}
|
||||||
return mysql_insert_id();
|
return mysql_insert_id();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user