Merge pull request #773 from norahmollo/master
CODE STYLE Formating gulliver/system
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* class.database_mysql.php
|
||||
*
|
||||
* @package gulliver.system
|
||||
*
|
||||
* ProcessMaker Open Source Edition
|
||||
@@ -25,24 +26,29 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package gulliver.system
|
||||
*
|
||||
*/
|
||||
|
||||
G::LoadSystem( 'database_base' );
|
||||
|
||||
class database extends database_base {
|
||||
class database extends database_base
|
||||
{
|
||||
|
||||
public $iFetchType = MYSQL_ASSOC;
|
||||
|
||||
/**
|
||||
* class database constructor
|
||||
*
|
||||
* @param $sType adapter type
|
||||
* @param $sServer server
|
||||
* @param $sUser db user
|
||||
* @param $sPass db user password
|
||||
* @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->sServer = $sServer;
|
||||
$this->sUser = $sUser;
|
||||
@@ -55,11 +61,13 @@ class database extends database_base {
|
||||
|
||||
/**
|
||||
* generate the sql sentence to create a table
|
||||
*
|
||||
* @param $sTable table name
|
||||
* @param $aColumns array of columns
|
||||
* @return $sSql the sql sentence
|
||||
*/
|
||||
public function generateCreateTableSQL($sTable, $aColumns) {
|
||||
public function generateCreateTableSQL ($sTable, $aColumns)
|
||||
{
|
||||
$sKeys = '';
|
||||
$sSQL = 'CREATE TABLE IF NOT EXISTS ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . '(';
|
||||
|
||||
@@ -97,41 +105,43 @@ class database extends database_base {
|
||||
|
||||
/**
|
||||
* generate a drop table sentence
|
||||
*
|
||||
* @param $sTable table name
|
||||
* @return sql sentence string
|
||||
*/
|
||||
public function generateDropTableSQL($sTable) {
|
||||
public function generateDropTableSQL ($sTable)
|
||||
{
|
||||
return 'DROP TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . $this->sEndLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate drop column sentence
|
||||
*
|
||||
* @param $sTable table name
|
||||
* @param $sColumn column name
|
||||
* @return $sSql sql sentence
|
||||
*/
|
||||
public function generateDropColumnSQL($sTable, $sColumn) {
|
||||
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter .
|
||||
' DROP COLUMN ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . $this->sEndLine;
|
||||
public function generateDropColumnSQL ($sTable, $sColumn)
|
||||
{
|
||||
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP COLUMN ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . $this->sEndLine;
|
||||
return $sSQL;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate an add column sentence
|
||||
*
|
||||
* @param $sTable table name
|
||||
* @param $sColumn column name
|
||||
* @param $aParameters parameters of field like typo or if it can be null
|
||||
* @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 .
|
||||
' ADD COLUMN ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter .
|
||||
' ' . $aParameters['Type'];
|
||||
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' ADD COLUMN ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . ' ' . $aParameters['Type'];
|
||||
if ($aParameters['Null'] == 'YES') {
|
||||
$sSQL .= ' NULL';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$sSQL .= ' NOT NULL';
|
||||
}
|
||||
}
|
||||
@@ -142,14 +152,12 @@ class database extends database_base {
|
||||
if (isset( $aParameters['AI'] )) {
|
||||
if ($aParameters['AI'] == 1) {
|
||||
$sSQL .= ' AUTO_INCREMENT';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if ($aParameters['Default'] != '') {
|
||||
$sSQL .= " DEFAULT '" . $aParameters['Default'] . "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (isset( $aParameters['Default'] )) {
|
||||
$sSQL .= " DEFAULT '" . $aParameters['Default'] . "'";
|
||||
}
|
||||
@@ -160,24 +168,23 @@ class database extends database_base {
|
||||
|
||||
/**
|
||||
* generate a change column sentence
|
||||
*
|
||||
* @param $sTable table name
|
||||
* @param $sColumn column name
|
||||
* @param $aParameters parameters of field like typo or if it can be null
|
||||
* @param $sColumnNewName column new name
|
||||
* @return $sSql sql sentence
|
||||
*/
|
||||
public function generateChangeColumnSQL($sTable, $sColumn, $aParameters, $sColumnNewName = '') {
|
||||
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter .
|
||||
' CHANGE COLUMN ' . $this->sQuoteCharacter . ($sColumnNewName != '' ? $sColumnNewName : $sColumn) . $this->sQuoteCharacter .
|
||||
' ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter;
|
||||
public function generateChangeColumnSQL ($sTable, $sColumn, $aParameters, $sColumnNewName = '')
|
||||
{
|
||||
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' CHANGE COLUMN ' . $this->sQuoteCharacter . ($sColumnNewName != '' ? $sColumnNewName : $sColumn) . $this->sQuoteCharacter . ' ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter;
|
||||
if (isset( $aParameters['Type'] )) {
|
||||
$sSQL .= ' ' . $aParameters['Type'];
|
||||
}
|
||||
if (isset( $aParameters['Null'] )) {
|
||||
if ($aParameters['Null'] == 'YES') {
|
||||
$sSQL .= ' NULL';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$sSQL .= ' NOT NULL';
|
||||
}
|
||||
}
|
||||
@@ -197,8 +204,7 @@ class database extends database_base {
|
||||
if (isset( $aParameters['Default'] )) {
|
||||
if (trim( $aParameters['Default'] ) == '' && $aParameters['Type'] == 'datetime') {
|
||||
//do nothing
|
||||
}
|
||||
else
|
||||
} else
|
||||
$sSQL .= " DEFAULT '" . $aParameters['Default'] . "'";
|
||||
//}
|
||||
}
|
||||
@@ -212,69 +218,73 @@ class database extends database_base {
|
||||
|
||||
/**
|
||||
* Generate and get the primary key in a sentence
|
||||
*
|
||||
* @param $sTable table name
|
||||
* @return $sSql sql sentence
|
||||
*/
|
||||
public function generateGetPrimaryKeysSQL($sTable) {
|
||||
public function generateGetPrimaryKeysSQL ($sTable)
|
||||
{
|
||||
try {
|
||||
if ($sTable == '') {
|
||||
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;
|
||||
}
|
||||
catch (Exception $oException) {
|
||||
} catch (Exception $oException) {
|
||||
throw $oException;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a sentence to drop the primary key
|
||||
*
|
||||
* @param $sTable table name
|
||||
* @return sql sentence
|
||||
*/
|
||||
public function generateDropPrimaryKeysSQL($sTable) {
|
||||
public function generateDropPrimaryKeysSQL ($sTable)
|
||||
{
|
||||
try {
|
||||
if ($sTable == '') {
|
||||
throw new Exception( 'The table name cannot be empty!' );
|
||||
}
|
||||
return 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP PRIMARY KEY' . $this->sEndLine;
|
||||
}
|
||||
catch (Exception $oException) {
|
||||
} catch (Exception $oException) {
|
||||
throw $oException;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a sentence to add multiple primary keys
|
||||
*
|
||||
* @param $sTable table name
|
||||
* @param $aPrimaryKeys array of primary keys
|
||||
* @return sql sentence
|
||||
*/
|
||||
public function generateAddPrimaryKeysSQL($sTable, $aPrimaryKeys) {
|
||||
public function generateAddPrimaryKeysSQL ($sTable, $aPrimaryKeys)
|
||||
{
|
||||
try {
|
||||
if ($sTable == '') {
|
||||
throw new Exception( 'The table name cannot be empty!' );
|
||||
}
|
||||
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter .
|
||||
' ADD PRIMARY KEY (';
|
||||
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' ADD PRIMARY KEY (';
|
||||
foreach ($aPrimaryKeys as $sKey) {
|
||||
$sSQL .= $this->sQuoteCharacter . $sKey . $this->sQuoteCharacter . ',';
|
||||
}
|
||||
$sSQL = substr( $sSQL, 0, - 1 ) . ')' . $this->sEndLine;
|
||||
return $sSQL;
|
||||
}
|
||||
catch (Exception $oException) {
|
||||
} catch (Exception $oException) {
|
||||
throw $oException;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a sentence to drop an index
|
||||
*
|
||||
* @param $sTable table name
|
||||
* @param $sIndexName index name
|
||||
* @return sql sentence
|
||||
*/
|
||||
public function generateDropKeySQL($sTable, $sIndexName) {
|
||||
public function generateDropKeySQL ($sTable, $sIndexName)
|
||||
{
|
||||
try {
|
||||
if ($sTable == '') {
|
||||
throw new Exception( 'The table name cannot be empty!' );
|
||||
@@ -283,21 +293,22 @@ class database extends database_base {
|
||||
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;
|
||||
}
|
||||
catch (Exception $oException) {
|
||||
} catch (Exception $oException) {
|
||||
throw $oException;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a sentence to add indexes or primary keys
|
||||
*
|
||||
* @param $sTable table name
|
||||
* @param $indexName index name
|
||||
* @param $aKeys array of keys
|
||||
* @return sql sentence
|
||||
*/
|
||||
|
||||
public function generateAddKeysSQL($sTable, $indexName, $aKeys) {
|
||||
public function generateAddKeysSQL ($sTable, $indexName, $aKeys)
|
||||
{
|
||||
try {
|
||||
$indexType = 'INDEX';
|
||||
if ($indexName == 'primaryKey' || $indexName == 'PRIMARY') {
|
||||
@@ -311,60 +322,68 @@ class database extends database_base {
|
||||
$sSQL = substr( $sSQL, 0, - 2 );
|
||||
$sSQL .= ')' . $this->sEndLine;
|
||||
return $sSQL;
|
||||
}
|
||||
catch (Exception $oException) {
|
||||
} catch (Exception $oException) {
|
||||
throw $oException;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a sentence to show the tables
|
||||
*
|
||||
* @return sql sentence
|
||||
*/
|
||||
public function generateShowTablesSQL() {
|
||||
public function generateShowTablesSQL ()
|
||||
{
|
||||
return 'SHOW TABLES' . $this->sEndLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a sentence to show the tables with a like sentence
|
||||
*
|
||||
* @return sql sentence
|
||||
*/
|
||||
public function generateShowTablesLikeSQL($sTable) {
|
||||
public function generateShowTablesLikeSQL ($sTable)
|
||||
{
|
||||
return "SHOW TABLES LIKE '" . $sTable . "'" . $this->sEndLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a sentence to show the tables with a like sentence
|
||||
*
|
||||
* @param $sTable table name
|
||||
* @return sql sentence
|
||||
*/
|
||||
public function generateDescTableSQL($sTable) {
|
||||
public function generateDescTableSQL ($sTable)
|
||||
{
|
||||
try {
|
||||
if ($sTable == '') {
|
||||
throw new Exception( 'The table name cannot be empty!' );
|
||||
}
|
||||
return 'DESC ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . $this->sEndLine;
|
||||
}
|
||||
catch (Exception $oException) {
|
||||
} catch (Exception $oException) {
|
||||
throw $oException;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a sentence to show some table indexes
|
||||
*
|
||||
* @param $sTable table name
|
||||
* @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 . " WHERE Key_name <> 'PRIMARY'" . $this->sEndLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* execute a sentence to check if there is connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function isConnected() {
|
||||
public function isConnected ()
|
||||
{
|
||||
if (! $this->oConnection)
|
||||
return false;
|
||||
return $this->executeQuery( 'USE ' . $this->sDataBase );
|
||||
@@ -372,16 +391,22 @@ class database extends database_base {
|
||||
|
||||
/**
|
||||
* generate a sentence to show the tables with a like sentence
|
||||
*
|
||||
* @param $sQuery sql query string
|
||||
* @return void
|
||||
*/
|
||||
public function logQuery($sQuery ) {
|
||||
public function logQuery ($sQuery)
|
||||
{
|
||||
try {
|
||||
$found = false;
|
||||
if ( substr($sQuery,0, 6) == 'SELECT' ) $found = true;
|
||||
if ( substr($sQuery,0, 4) == 'SHOW' ) $found = true;
|
||||
if ( substr($sQuery,0, 4) == 'DESC' ) $found = true;
|
||||
if ( substr($sQuery,0, 4) == 'USE ' ) $found = true;
|
||||
if (substr( $sQuery, 0, 6 ) == 'SELECT')
|
||||
$found = true;
|
||||
if (substr( $sQuery, 0, 4 ) == 'SHOW')
|
||||
$found = true;
|
||||
if (substr( $sQuery, 0, 4 ) == 'DESC')
|
||||
$found = true;
|
||||
if (substr( $sQuery, 0, 4 ) == 'USE ')
|
||||
$found = true;
|
||||
if (! $found) {
|
||||
$logDir = PATH_DATA . 'log';
|
||||
if (! file_exists( $logDir ))
|
||||
@@ -394,17 +419,18 @@ class database extends database_base {
|
||||
fclose( $fp );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception $oException) {
|
||||
} catch (Exception $oException) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* execute a sql query
|
||||
*
|
||||
* @param $sQuery table name
|
||||
* @return void
|
||||
*/
|
||||
public function executeQuery($sQuery) {
|
||||
public function executeQuery ($sQuery)
|
||||
{
|
||||
$this->logQuery( $sQuery );
|
||||
|
||||
try {
|
||||
@@ -412,12 +438,10 @@ class database extends database_base {
|
||||
@mysql_select_db( $this->sDataBase );
|
||||
|
||||
return @mysql_query( $sQuery );
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new Exception( 'invalid connection to database ' . $this->sDataBase );
|
||||
}
|
||||
}
|
||||
catch (Exception $oException) {
|
||||
} catch (Exception $oException) {
|
||||
$this->logQuery( $oException->getMessage() );
|
||||
throw $oException;
|
||||
}
|
||||
@@ -425,31 +449,38 @@ class database extends database_base {
|
||||
|
||||
/**
|
||||
* count the rows of a dataset
|
||||
*
|
||||
* @param $oDataset
|
||||
* @return the number of rows
|
||||
*/
|
||||
public function countResults($oDataset) {
|
||||
public function countResults ($oDataset)
|
||||
{
|
||||
return @mysql_num_rows( $oDataset );
|
||||
}
|
||||
|
||||
/**
|
||||
* count an array of the registry from a dataset
|
||||
*
|
||||
* @param $oDataset
|
||||
* @return the registry
|
||||
*/
|
||||
public function getRegistry($oDataset) {
|
||||
public function getRegistry ($oDataset)
|
||||
{
|
||||
return @mysql_fetch_array( $oDataset, $this->iFetchType );
|
||||
}
|
||||
|
||||
/**
|
||||
* close the current connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function close() {
|
||||
public function close ()
|
||||
{
|
||||
@mysql_close( $this->oConnection );
|
||||
}
|
||||
|
||||
public function generateInsertSQL($table, $data) {
|
||||
public function generateInsertSQL ($table, $data)
|
||||
{
|
||||
$fields = array ();
|
||||
$values = array ();
|
||||
foreach ($data as $field) {
|
||||
@@ -465,17 +496,18 @@ class database extends database_base {
|
||||
$values[] = mysql_real_escape_string( $field['value'] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$values[] = $this->nullString;
|
||||
}
|
||||
}
|
||||
$fields = array_map(array($this, 'putQuotes'), $fields);
|
||||
$fields = array_map( array ($this,'putQuotes'
|
||||
), $fields );
|
||||
$sql = sprintf( "INSERT INTO %s (%s) VALUES (%s)", $this->putQuotes( $table ), implode( ', ', $fields ), implode( ', ', $values ) );
|
||||
return $sql;
|
||||
}
|
||||
|
||||
public function generateUpdateSQL($table, $keys, $data) {
|
||||
public function generateUpdateSQL ($table, $keys, $data)
|
||||
{
|
||||
$fields = array ();
|
||||
$where = array ();
|
||||
foreach ($data as $field) {
|
||||
@@ -490,8 +522,7 @@ class database extends database_base {
|
||||
$fields[] = $this->putQuotes( $field['field'] ) . " = " . mysql_real_escape_string( $field['value'] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$values[] = $this->nullString;
|
||||
}
|
||||
if (in_array( $field['field'], $keys )) {
|
||||
@@ -502,7 +533,8 @@ class database extends database_base {
|
||||
return $sql;
|
||||
}
|
||||
|
||||
public function generateDeleteSQL($table, $keys, $data) {
|
||||
public function generateDeleteSQL ($table, $keys, $data)
|
||||
{
|
||||
$fields = array ();
|
||||
$where = array ();
|
||||
foreach ($data as $field) {
|
||||
@@ -518,8 +550,7 @@ class database extends database_base {
|
||||
$where[] = $this->putQuotes( $field['field'] ) . " = " . mysql_real_escape_string( $field['value'] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$values[] = $this->nullString;
|
||||
}
|
||||
}
|
||||
@@ -528,7 +559,8 @@ class database extends database_base {
|
||||
return $sql;
|
||||
}
|
||||
|
||||
public function generateSelectSQL($table, $keys, $data) {
|
||||
public function generateSelectSQL ($table, $keys, $data)
|
||||
{
|
||||
$fields = array ();
|
||||
$where = array ();
|
||||
foreach ($data as $field) {
|
||||
@@ -544,8 +576,7 @@ class database extends database_base {
|
||||
$where[] = $this->putQuotes( $field['field'] ) . " = " . mysql_real_escape_string( $field['value'] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$values[] = $this->nullString;
|
||||
}
|
||||
}
|
||||
@@ -554,7 +585,8 @@ class database extends database_base {
|
||||
return $sql;
|
||||
}
|
||||
|
||||
private function putQuotes($element) {
|
||||
private function putQuotes ($element)
|
||||
{
|
||||
return $this->sQuoteCharacter . $element . $this->sQuoteCharacter;
|
||||
}
|
||||
|
||||
@@ -651,8 +683,7 @@ class database extends database_base {
|
||||
$sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER ";
|
||||
$sqlGroupBy = " USER ";
|
||||
|
||||
$sql = "SELECT " . $sqlConcat . ", " .
|
||||
" COUNT(*) AS CANTCASES,
|
||||
$sql = "SELECT " . $sqlConcat . ", " . " COUNT(*) AS CANTCASES,
|
||||
MIN(AD.DEL_DURATION) AS MIN,
|
||||
MAX(AD.DEL_DURATION) AS MAX,
|
||||
SUM(AD.DEL_DURATION) AS TOTALDUR,
|
||||
@@ -680,8 +711,7 @@ class database extends database_base {
|
||||
$sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER ";
|
||||
$sqlGroupBy = " USER ";
|
||||
|
||||
$sql = " SELECT " . $sqlConcat . ", " .
|
||||
" COUNT(*) AS CANTCASES,
|
||||
$sql = " SELECT " . $sqlConcat . ", " . " COUNT(*) AS CANTCASES,
|
||||
MIN(AD.DEL_DURATION) AS MIN,
|
||||
MAX(AD.DEL_DURATION) AS MAX,
|
||||
SUM(AD.DEL_DURATION) AS TOTALDUR,
|
||||
@@ -709,8 +739,7 @@ class database extends database_base {
|
||||
$sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER ";
|
||||
$sqlGroupBy = " USER ";
|
||||
|
||||
$sql = " SELECT " . $sqlConcat . ", " .
|
||||
" COUNT(*) AS CANTCASES,
|
||||
$sql = " SELECT " . $sqlConcat . ", " . " COUNT(*) AS CANTCASES,
|
||||
MIN(AD.DEL_DURATION) AS MIN,
|
||||
MAX(AD.DEL_DURATION) AS MAX,
|
||||
SUM(AD.DEL_DURATION) AS TOTALDUR,
|
||||
@@ -739,8 +768,7 @@ class database extends database_base {
|
||||
$sqlConcat = " CONCAT(U.USR_LASTNAME,' ',USR_FIRSTNAME) AS USER ";
|
||||
$sqlGroupBy = " USER ";
|
||||
|
||||
$sql = "SELECT " . $sqlConcat . ", " .
|
||||
" COUNT(*) AS CANTCASES,
|
||||
$sql = "SELECT " . $sqlConcat . ", " . " COUNT(*) AS CANTCASES,
|
||||
MIN(AD.DEL_DURATION) AS MIN,
|
||||
MAX(AD.DEL_DURATION) AS MAX,
|
||||
SUM(AD.DEL_DURATION) AS TOTALDUR,
|
||||
@@ -770,7 +798,6 @@ class database extends database_base {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* query functions for class class.net.php, class.reportTables.php
|
||||
*
|
||||
@@ -781,7 +808,6 @@ class database extends database_base {
|
||||
return $sql;
|
||||
}
|
||||
|
||||
|
||||
function getTableDescription ($sTableName)
|
||||
{
|
||||
$sql = "DESC " . $sTableName;
|
||||
@@ -831,7 +857,8 @@ class database extends database_base {
|
||||
@mysql_select_db( $database );
|
||||
$tables = array ();
|
||||
$tablesResult = mysql_query( "SHOW TABLES FROM $database;" );
|
||||
while ($row = @mysql_fetch_row($tablesResult)) $tables[] = $row[0];
|
||||
while ($row = @mysql_fetch_row( $tablesResult ))
|
||||
$tables[] = $row[0];
|
||||
if (in_array( $tableName, $tables )) {
|
||||
return TRUE;
|
||||
}
|
||||
@@ -850,5 +877,5 @@ class database extends database_base {
|
||||
// }
|
||||
// return FALSE;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* class.dbconnection.php
|
||||
*
|
||||
* @package gulliver.system
|
||||
*
|
||||
* ProcessMaker Open Source Edition
|
||||
@@ -25,7 +26,9 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package gulliver.system
|
||||
*
|
||||
*/
|
||||
|
||||
require_once ("DB.php");
|
||||
@@ -39,6 +42,7 @@ define ( 'DB_ERROR_SHOWALL_AND_CONTINUE', 4);
|
||||
/**
|
||||
* DBConnection class definition
|
||||
* It is useful to stablish a connection
|
||||
*
|
||||
* @package gulliver.system
|
||||
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
||||
* @copyright (C) 2002 by Colosa Development Team.
|
||||
@@ -50,30 +54,33 @@ class DBConnection
|
||||
var $errorLevel;
|
||||
var $type;
|
||||
|
||||
/*****************************************************************
|
||||
/* Error types:
|
||||
/* -1 Fatal error ( clase no instanced )
|
||||
/* -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.
|
||||
/* 1 display small box with error information and die.
|
||||
/* 2 display small box with error information and continue
|
||||
/* 3 display complete error information and die.
|
||||
/* 4 display complete error information and continue.
|
||||
/*
|
||||
/* Error Structure
|
||||
/* int error code
|
||||
/* string error message
|
||||
/* string error detailed message
|
||||
/*
|
||||
/* In all cases, the error will be saved in the apache log file
|
||||
/*
|
||||
/* */
|
||||
/**
|
||||
* ***************************************************************
|
||||
* /* Error types:
|
||||
* /* -1 Fatal error ( clase no instanced )
|
||||
* /* -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.
|
||||
* /* 1 display small box with error information and die.
|
||||
* /* 2 display small box with error information and continue
|
||||
* /* 3 display complete error information and die.
|
||||
* /* 4 display complete error information and continue.
|
||||
* /*
|
||||
* /* Error Structure
|
||||
* /* int error code
|
||||
* /* string error message
|
||||
* /* string error detailed message
|
||||
* /*
|
||||
* /* In all cases, the error will be saved in the apache log file
|
||||
* /*
|
||||
* /*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Starts DB connection with default values
|
||||
*
|
||||
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
||||
* @access public
|
||||
* @param const $strServer Host Name
|
||||
@@ -89,7 +96,8 @@ class DBConnection
|
||||
function DBConnection ($strServer = DB_HOST, $strUser = DB_USER, $strPwd = DB_PASS, $strDB = DB_NAME, $type = DB_ADAPTER, $strPort = 0, $errorLevel = 2)
|
||||
{
|
||||
$this->errorLevel = $errorLevel;
|
||||
if ($type == null ) $type = 'mysql';
|
||||
if ($type == null)
|
||||
$type = 'mysql';
|
||||
$this->type = $type;
|
||||
//print "<hr>$type $strServer, $strUser, $strPwd, $strDB <hr>";
|
||||
if ($type == "mysql")
|
||||
@@ -110,7 +118,7 @@ class DBConnection
|
||||
if ($type == "oracle") {
|
||||
$dsn = "oci8://$strUser:$strPwd@$strServer/$strDB";
|
||||
}
|
||||
$this->db_error = NULL;
|
||||
$this->db_error = null;
|
||||
if ($type === 'myxml') {
|
||||
$this->db = XMLDB::connect( $strServer );
|
||||
} else {
|
||||
@@ -118,13 +126,14 @@ class DBConnection
|
||||
}
|
||||
if (DB::isError( $this->db )) {
|
||||
$this->db_error = $this->db;
|
||||
$this->db = NULL;
|
||||
$this->db = null;
|
||||
$this->logError( $this->db_error );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close Connection and Generate Log Message
|
||||
*
|
||||
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
||||
* @access public
|
||||
* @return void
|
||||
@@ -134,11 +143,12 @@ class DBConnection
|
||||
if ($this->db) {
|
||||
$this->db->disconnect();
|
||||
}
|
||||
$this->db = NULL;
|
||||
$this->db = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect from Data base
|
||||
*
|
||||
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
||||
* @access public
|
||||
* @return void
|
||||
@@ -150,6 +160,7 @@ class DBConnection
|
||||
|
||||
/**
|
||||
* Close Connection
|
||||
*
|
||||
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
||||
* @access public
|
||||
* @return void
|
||||
@@ -161,6 +172,7 @@ class DBConnection
|
||||
|
||||
/**
|
||||
* log Errors
|
||||
*
|
||||
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
||||
* @access public
|
||||
* @param db_error $obj
|
||||
@@ -172,12 +184,13 @@ class DBConnection
|
||||
global $_SESSION;
|
||||
global $_SERVER;
|
||||
if (is_null( $errorLevel ))
|
||||
if ( isset ( $this->errorLevel) )
|
||||
if (isset( $this->errorLevel )) {
|
||||
$errorLevel = $this->errorLevel;
|
||||
else
|
||||
} else {
|
||||
$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 "<tr><td><b>" . $obj->code . ' ' . $obj->message . "</b></td></tr>";
|
||||
if ($errorLevel == DB_ERROR_SHOWALL_AND_STOP || $errorLevel == DB_ERROR_SHOWALL_AND_CONTINUE) {
|
||||
@@ -193,12 +206,13 @@ class DBConnection
|
||||
//G::setErrorHandler ( );
|
||||
G::customErrorLog( 'DB_Error', $obj->code . ' ' . $obj->message . '-' . $obj->userinfo, '', '' );
|
||||
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).
|
||||
*
|
||||
* @author David Callizaya
|
||||
* @param string $tts
|
||||
* @param string $limit
|
||||
@@ -212,18 +226,19 @@ class DBConnection
|
||||
if ($tts > 0) {
|
||||
$tts --;
|
||||
} else {
|
||||
$out .= '['.basename($step['file']).': '.$step['line'].'] : ' . $step['function'] .'(' .
|
||||
DBConnection::printArgs($step['args']). ")\n";
|
||||
$out .= '[' . basename( $step['file'] ) . ': ' . $step['line'] . '] : ' . $step['function'] . '(' . DBConnection::printArgs( $step['args'] ) . ")\n";
|
||||
$limit --;
|
||||
if ($limit===0)
|
||||
if ($limit === 0) {
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the arguments of a function
|
||||
*
|
||||
* @author David Callizaya
|
||||
* @param string $args
|
||||
* @return string
|
||||
@@ -233,30 +248,34 @@ class DBConnection
|
||||
$out = '';
|
||||
if (is_array( $args )) {
|
||||
foreach ($args as $arg) {
|
||||
if ($out!=='')
|
||||
if ($out !== '') {
|
||||
$out .= ' ,';
|
||||
if (is_string($arg))
|
||||
}
|
||||
if (is_string( $arg )) {
|
||||
$out .= "'" . ($arg) . "'";
|
||||
elseif (is_array($arg) )
|
||||
} elseif (is_array( $arg )) {
|
||||
$out .= print_r( $arg, 1 );
|
||||
elseif (is_object($arg))
|
||||
} elseif (is_object( $arg )) {
|
||||
$out .= get_class( $arg ); // print_r ( $arg ,1 );
|
||||
elseif (!isset($arg))
|
||||
} elseif (! isset( $arg )) {
|
||||
$out .= 'NULL';
|
||||
else
|
||||
} else {
|
||||
$out .= sprintf( "%s", $arg );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!isset($args))
|
||||
if (! isset( $args )) {
|
||||
$out = 'NULL';
|
||||
else
|
||||
} else {
|
||||
$out = print_r( $args, 1 );
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets last autoincrement value inserted
|
||||
*
|
||||
* @author Fernando Ontiveros Lira <fernando@colosa.com>
|
||||
* @access public
|
||||
* @return void
|
||||
@@ -265,14 +284,12 @@ class DBConnection
|
||||
{
|
||||
if (PEAR_DATABASE == "mysql") {
|
||||
return mysql_insert_id();
|
||||
}
|
||||
else {
|
||||
$dberror = PEAR::raiseError(null, DB_ERROR_FEATURE_NOT_AVAILABLE, null, 'null',
|
||||
"getLastID with " . PEAR_DATABASE . ' database.',
|
||||
'G_Error', true);
|
||||
} else {
|
||||
$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!!
|
||||
return $dberror;
|
||||
}
|
||||
return mysql_insert_id();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user