ODE STYLE Formating gulliver/system/class.database_mssql.php
Change format files in gulliver/system/class.database_mssql.php
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* class.database_mssql.php
|
* class.database_mssql.php
|
||||||
|
*
|
||||||
* @package gulliver.system
|
* @package gulliver.system
|
||||||
*
|
*
|
||||||
* ProcessMaker Open Source Edition
|
* ProcessMaker Open Source Edition
|
||||||
@@ -25,16 +26,19 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @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 = MSSQL_ASSOC;
|
public $iFetchType = MSSQL_ASSOC;
|
||||||
|
|
||||||
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;
|
||||||
@@ -47,9 +51,8 @@ class database extends database_base {
|
|||||||
$this->sQuoteCharacterEnd = ']';
|
$this->sQuoteCharacterEnd = ']';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function generateCreateTableSQL ($sTable, $aColumns)
|
||||||
|
{
|
||||||
public function generateCreateTableSQL($sTable, $aColumns) {
|
|
||||||
$sKeys = '';
|
$sKeys = '';
|
||||||
$sSQL = 'CREATE TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . '(';
|
$sSQL = 'CREATE TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . '(';
|
||||||
|
|
||||||
@@ -85,45 +88,48 @@ class database extends database_base {
|
|||||||
return $sSQL;
|
return $sSQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateDropColumnSQL($sTable, $sColumn) {
|
public function generateDropColumnSQL ($sTable, $sColumn)
|
||||||
|
{
|
||||||
// SQL Server first should remove the restriction before the Elimination of the field
|
// SQL Server first should remove the restriction before the Elimination of the field
|
||||||
$oConstraint = $this->dropFieldConstraint( $sTable, $sColumn );
|
$oConstraint = $this->dropFieldConstraint( $sTable, $sColumn );
|
||||||
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter .
|
$sSQL = 'ALTER TABLE ' . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . ' DROP COLUMN ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . $this->sEndLine;
|
||||||
' DROP COLUMN ' . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . $this->sEndLine;
|
|
||||||
return $sSQL;
|
return $sSQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateAddColumnSQL($sTable, $sColumn, $aParameters) {
|
public function generateAddColumnSQL ($sTable, $sColumn, $aParameters)
|
||||||
|
{
|
||||||
if (isset( $aParameters['Type'] ) && isset( $aParameters['Null'] )) {
|
if (isset( $aParameters['Type'] ) && isset( $aParameters['Null'] )) {
|
||||||
$sDefault = "";
|
$sDefault = "";
|
||||||
$sType = $aParameters['Type'];
|
$sType = $aParameters['Type'];
|
||||||
$sDataType = $aParameters['Type'];
|
$sDataType = $aParameters['Type'];
|
||||||
if(! in_array($sDataType, array("TEXT", "DATE") )) {
|
if (! in_array( $sDataType, array ("TEXT","DATE"
|
||||||
|
) )) {
|
||||||
$sType = substr( $sType, 0, strpos( $sType, '(' ) );
|
$sType = substr( $sType, 0, strpos( $sType, '(' ) );
|
||||||
}
|
}
|
||||||
switch ($sType) {
|
switch ($sType) {
|
||||||
case 'VARCHAR':
|
case 'VARCHAR':
|
||||||
case 'TEXT' : $sDefault = " DEFAULT '' ";
|
case 'TEXT':
|
||||||
|
$sDefault = " DEFAULT '' ";
|
||||||
break;
|
break;
|
||||||
case 'DATE' : $sDataType = " CHAR(19) ";
|
case 'DATE':
|
||||||
|
$sDataType = " CHAR(19) ";
|
||||||
$sDefault = " DEFAULT '0000-00-00' "; // The date data type to use char (19)
|
$sDefault = " DEFAULT '0000-00-00' "; // The date data type to use char (19)
|
||||||
break;
|
break;
|
||||||
case 'INT':
|
case 'INT':
|
||||||
case 'FLOAT' : $sDataType = $sType;
|
case 'FLOAT':
|
||||||
|
$sDataType = $sType;
|
||||||
$sDefault = " DEFAULT 0 ";
|
$sDefault = " DEFAULT 0 ";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$sSQL = "ALTER TABLE " . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter .
|
$sSQL = "ALTER TABLE " . $this->sQuoteCharacter . $sTable . $this->sQuoteCharacter . " ADD " . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter . " " . $aParameters['Type'];
|
||||||
" ADD " . $this->sQuoteCharacter . $sColumn . $this->sQuoteCharacter .
|
|
||||||
" " . $aParameters['Type'];
|
|
||||||
if ($aParameters['Null'] == 'YES') {
|
if ($aParameters['Null'] == 'YES') {
|
||||||
$sSQL .= " NULL";
|
$sSQL .= " NULL";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$sSQL .= " NOT NULL " . $sDefault;
|
$sSQL .= " NOT NULL " . $sDefault;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -135,14 +141,12 @@ class database extends database_base {
|
|||||||
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'] ) && $aParameters['Default'] != '') {
|
if (isset( $aParameters['Default'] ) && $aParameters['Default'] != '') {
|
||||||
$sSQL .= " DEFAULT '" . $aParameters['Default'] . "'";
|
$sSQL .= " DEFAULT '" . $aParameters['Default'] . "'";
|
||||||
}
|
}
|
||||||
@@ -151,18 +155,16 @@ class database extends database_base {
|
|||||||
return $sSQL;
|
return $sSQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
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';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -182,8 +184,7 @@ class database extends database_base {
|
|||||||
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'] . "'";
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
@@ -195,33 +196,28 @@ class database extends database_base {
|
|||||||
return $sSQL;
|
return $sSQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get primary key
|
* Get primary key
|
||||||
|
*
|
||||||
* @param eter string $sTable
|
* @param eter string $sTable
|
||||||
* @return string $sPrimaryKey
|
* @return string $sPrimaryKey
|
||||||
*/
|
*/
|
||||||
public function getPrimaryKey ($sTable)
|
public function getPrimaryKey ($sTable)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$sSQL = " SELECT c.COLUMN_NAME " .
|
$sSQL = " SELECT c.COLUMN_NAME " . " FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS pk , " . " INFORMATION_SCHEMA.KEY_COLUMN_USAGE c " . " WHERE pk.TABLE_NAME = '" . trim( $sTable ) . "' " . " AND CONSTRAINT_TYPE = 'PRIMARY KEY' " . " AND c.TABLE_NAME = pk.TABLE_NAME " . " AND c.CONSTRAINT_NAME = pk.CONSTRAINT_NAME ";
|
||||||
" FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS pk , " .
|
|
||||||
" INFORMATION_SCHEMA.KEY_COLUMN_USAGE c " .
|
|
||||||
" WHERE pk.TABLE_NAME = '" . trim($sTable) . "' " .
|
|
||||||
" AND CONSTRAINT_TYPE = 'PRIMARY KEY' " .
|
|
||||||
" AND c.TABLE_NAME = pk.TABLE_NAME " .
|
|
||||||
" AND c.CONSTRAINT_NAME = pk.CONSTRAINT_NAME ";
|
|
||||||
$oPrimaryKey = $this->executeQuery( $sSQL );
|
$oPrimaryKey = $this->executeQuery( $sSQL );
|
||||||
$aPrimaryKey = mssql_fetch_array( $oPrimaryKey );
|
$aPrimaryKey = mssql_fetch_array( $oPrimaryKey );
|
||||||
mssql_free_result( $oPrimaryKey );
|
mssql_free_result( $oPrimaryKey );
|
||||||
@@ -233,6 +229,7 @@ class database extends database_base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Field Constraint
|
* Get Field Constraint
|
||||||
|
*
|
||||||
* @param eter string $sTable
|
* @param eter string $sTable
|
||||||
* @param eter string $sField
|
* @param eter string $sField
|
||||||
* @return string $sFieldConstraint
|
* @return string $sFieldConstraint
|
||||||
@@ -240,12 +237,7 @@ class database extends database_base {
|
|||||||
public function getFieldConstraint ($sTable, $sField)
|
public function getFieldConstraint ($sTable, $sField)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$sSQL = " select a.name " .
|
$sSQL = " select a.name " . " from sysobjects a " . " inner join syscolumns b on a.id = b.cdefault " . " where a.xtype = 'D' " . " and a.parent_obj = (select id from sysobjects where xtype = 'U' and name = '" . trim( $sTable ) . "') " . " and b.name = '" . trim( $sField ) . "' ";
|
||||||
" from sysobjects a " .
|
|
||||||
" inner join syscolumns b on a.id = b.cdefault " .
|
|
||||||
" where a.xtype = 'D' " .
|
|
||||||
" and a.parent_obj = (select id from sysobjects where xtype = 'U' and name = '" . trim($sTable) . "') " .
|
|
||||||
" and b.name = '" . trim($sField) . "' ";
|
|
||||||
|
|
||||||
$oFieldConstraint = $this->executeQuery( $sSQL );
|
$oFieldConstraint = $this->executeQuery( $sSQL );
|
||||||
$aFieldConstraint = mssql_fetch_array( $oFieldConstraint );
|
$aFieldConstraint = mssql_fetch_array( $oFieldConstraint );
|
||||||
@@ -256,9 +248,9 @@ class database extends database_base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* drop Field Constraint
|
* drop Field Constraint
|
||||||
|
*
|
||||||
* @param eter string $sTable
|
* @param eter string $sTable
|
||||||
* @param eter string $sField
|
* @param eter string $sField
|
||||||
* @return object $oFieldConstraint
|
* @return object $oFieldConstraint
|
||||||
@@ -275,8 +267,8 @@ class database extends database_base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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!' );
|
||||||
@@ -284,31 +276,30 @@ class database extends database_base {
|
|||||||
$sPrimayKey = $this->getPrimaryKey( $sTable );
|
$sPrimayKey = $this->getPrimaryKey( $sTable );
|
||||||
|
|
||||||
return ' ALTER TABLE ' . $sTable . ' DROP CONSTRAINT ' . $sPrimayKey . $this->sEndLine;
|
return ' ALTER TABLE ' . $sTable . ' DROP CONSTRAINT ' . $sPrimayKey . $this->sEndLine;
|
||||||
}
|
} catch (Exception $oException) {
|
||||||
catch (Exception $oException) {
|
|
||||||
throw $oException;
|
throw $oException;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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!' );
|
||||||
@@ -317,13 +308,13 @@ class database extends database_base {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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') {
|
||||||
@@ -337,62 +328,70 @@ class database extends database_base {
|
|||||||
$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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateShowTablesSQL() {
|
public function generateShowTablesSQL ()
|
||||||
|
{
|
||||||
return 'SHOW TABLES' . $this->sEndLine;
|
return 'SHOW TABLES' . $this->sEndLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateShowTablesLikeSQL($sTable) {
|
public function generateShowTablesLikeSQL ($sTable)
|
||||||
|
{
|
||||||
return "SHOW TABLES LIKE '" . $sTable . "'" . $this->sEndLine;
|
return "SHOW TABLES LIKE '" . $sTable . "'" . $this->sEndLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (substr( $sQuery, 0, 4 ) == 'DESC')
|
||||||
|
$found = true;
|
||||||
|
if (substr( $sQuery, 0, 4 ) == 'USE ')
|
||||||
|
$found = true;
|
||||||
if (! $found) {
|
if (! $found) {
|
||||||
$logFile = PATH_DATA . 'log' . PATH_SEP . 'query.log';
|
$logFile = PATH_DATA . 'log' . PATH_SEP . 'query.log';
|
||||||
$fp = fopen( $logFile, 'a+' );
|
$fp = fopen( $logFile, 'a+' );
|
||||||
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) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function executeQuery($sQuery) {
|
public function executeQuery ($sQuery)
|
||||||
|
{
|
||||||
$this->logQuery( $sQuery );
|
$this->logQuery( $sQuery );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -400,30 +399,32 @@ class database extends database_base {
|
|||||||
@mssql_select_db( $this->sDataBase );
|
@mssql_select_db( $this->sDataBase );
|
||||||
|
|
||||||
return @mssql_query( $sQuery );
|
return @mssql_query( $sQuery );
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw new Exception( 'invalid connection to database ' . $this->sDataBase );
|
throw new Exception( 'invalid connection to database ' . $this->sDataBase );
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception $oException) {
|
||||||
catch (Exception $oException) {
|
|
||||||
$this->logQuery( $oException->getMessage() );
|
$this->logQuery( $oException->getMessage() );
|
||||||
throw $oException;
|
throw $oException;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function countResults($oDataset) {
|
public function countResults ($oDataset)
|
||||||
|
{
|
||||||
return @mssql_num_rows( $oDataset );
|
return @mssql_num_rows( $oDataset );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRegistry($oDataset) {
|
public function getRegistry ($oDataset)
|
||||||
|
{
|
||||||
return @mssql_fetch_array( $oDataset, $this->iFetchType );
|
return @mssql_fetch_array( $oDataset, $this->iFetchType );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close() {
|
public function close ()
|
||||||
|
{
|
||||||
@mssql_close( $this->oConnection );
|
@mssql_close( $this->oConnection );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateInsertSQL($table, $data) {
|
public function generateInsertSQL ($table, $data)
|
||||||
|
{
|
||||||
$fields = array ();
|
$fields = array ();
|
||||||
$values = array ();
|
$values = array ();
|
||||||
foreach ($data as $field) {
|
foreach ($data as $field) {
|
||||||
@@ -439,17 +440,18 @@ class database extends database_base {
|
|||||||
$values[] = addslashes( $field['value'] );
|
$values[] = addslashes( $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'
|
||||||
|
), $fields );
|
||||||
$sql = sprintf( "INSERT INTO %s (%s) VALUES (%s)", $this->putQuotes( $table ), implode( ', ', $fields ), implode( ', ', $values ) );
|
$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 ();
|
$fields = array ();
|
||||||
$where = array ();
|
$where = array ();
|
||||||
foreach ($data as $field) {
|
foreach ($data as $field) {
|
||||||
@@ -464,8 +466,7 @@ class database extends database_base {
|
|||||||
$fields[] = $this->putQuotes( $field['field'] ) . " = " . addslashes( $field['value'] );
|
$fields[] = $this->putQuotes( $field['field'] ) . " = " . addslashes( $field['value'] );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$values[] = $this->nullString;
|
$values[] = $this->nullString;
|
||||||
}
|
}
|
||||||
if (in_array( $field['field'], $keys )) {
|
if (in_array( $field['field'], $keys )) {
|
||||||
@@ -476,7 +477,8 @@ class database extends database_base {
|
|||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateDeleteSQL($table, $keys, $data) {
|
public function generateDeleteSQL ($table, $keys, $data)
|
||||||
|
{
|
||||||
$fields = array ();
|
$fields = array ();
|
||||||
$where = array ();
|
$where = array ();
|
||||||
foreach ($data as $field) {
|
foreach ($data as $field) {
|
||||||
@@ -492,8 +494,7 @@ class database extends database_base {
|
|||||||
$where[] = $this->putQuotes( $field['field'] ) . " = " . addslashes( $field['value'] );
|
$where[] = $this->putQuotes( $field['field'] ) . " = " . addslashes( $field['value'] );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$values[] = $this->nullString;
|
$values[] = $this->nullString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -502,7 +503,8 @@ class database extends database_base {
|
|||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateSelectSQL($table, $keys, $data) {
|
public function generateSelectSQL ($table, $keys, $data)
|
||||||
|
{
|
||||||
$fields = array ();
|
$fields = array ();
|
||||||
$where = array ();
|
$where = array ();
|
||||||
foreach ($data as $field) {
|
foreach ($data as $field) {
|
||||||
@@ -518,8 +520,7 @@ class database extends database_base {
|
|||||||
$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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -528,7 +529,8 @@ class database extends database_base {
|
|||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function putQuotes($element) {
|
private function putQuotes ($element)
|
||||||
|
{
|
||||||
return $this->sQuoteCharacterBegin . $element . $this->sQuoteCharacterEnd;
|
return $this->sQuoteCharacterBegin . $element . $this->sQuoteCharacterEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -620,8 +622,7 @@ class database extends database_base {
|
|||||||
$sqlConcat = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME AS [USER] ";
|
$sqlConcat = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME AS [USER] ";
|
||||||
$sqlGroupBy = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME ";
|
$sqlGroupBy = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME ";
|
||||||
|
|
||||||
$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,
|
||||||
@@ -649,8 +650,7 @@ class database extends database_base {
|
|||||||
$sqlConcat = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME AS [USER] ";
|
$sqlConcat = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME AS [USER] ";
|
||||||
$sqlGroupBy = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME ";
|
$sqlGroupBy = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME ";
|
||||||
|
|
||||||
$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,
|
||||||
@@ -679,8 +679,7 @@ class database extends database_base {
|
|||||||
$sqlConcat = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME AS [USER] ";
|
$sqlConcat = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME AS [USER] ";
|
||||||
$sqlGroupBy = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME ";
|
$sqlGroupBy = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME ";
|
||||||
|
|
||||||
$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,
|
||||||
@@ -709,8 +708,7 @@ class database extends database_base {
|
|||||||
$sqlConcat = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME AS [USER] ";
|
$sqlConcat = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME AS [USER] ";
|
||||||
$sqlGroupBy = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME ";
|
$sqlGroupBy = " U.USR_LASTNAME + ' ' + USR_FIRSTNAME ";
|
||||||
|
|
||||||
$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,
|
||||||
@@ -746,19 +744,16 @@ class database extends database_base {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* query functions for class class.net.php
|
* query functions for class class.net.php
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function getDropTable($sTableName)
|
function getDropTable($sTableName)
|
||||||
{
|
{
|
||||||
$sql = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='" . $sTableName . "' AND xtype='U') " .
|
$sql = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='" . $sTableName . "' AND xtype='U') " . "DROP TABLE ['" . $sTableName . "']";
|
||||||
"DROP TABLE ['" . $sTableName . "']";
|
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getTableDescription($sTableName)
|
function getTableDescription($sTableName)
|
||||||
{
|
{
|
||||||
$sql = " select column_name as Field,
|
$sql = " select column_name as Field,
|
||||||
@@ -777,8 +772,7 @@ class database extends database_base {
|
|||||||
when 'No' then 'NO' else 'YES' END) AS AsNull,
|
when 'No' then 'NO' else 'YES' END) AS AsNull,
|
||||||
COLUMN_DEFAULT as [Default]
|
COLUMN_DEFAULT as [Default]
|
||||||
FROM information_schema.columns
|
FROM information_schema.columns
|
||||||
WHERE table_name = '" . trim($sTableName) . "'" .
|
WHERE table_name = '" . trim( $sTableName ) . "'" . " Order by Ordinal_Position asc ";
|
||||||
" Order by Ordinal_Position asc ";
|
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -820,7 +814,8 @@ class database extends database_base {
|
|||||||
/**
|
/**
|
||||||
* Determining the existence of a table
|
* Determining the existence of a table
|
||||||
*/
|
*/
|
||||||
function tableExists ($table, $db) {
|
function tableExists($table, $db)
|
||||||
|
{
|
||||||
$sql = "SELECT * FROM sysobjects WHERE name='" . $table . "' AND type='u'";
|
$sql = "SELECT * FROM sysobjects WHERE name='" . $table . "' AND type='u'";
|
||||||
$bExists = true;
|
$bExists = true;
|
||||||
$oConnection = mssql_connect( DB_HOST, DB_USER, DB_PASS );
|
$oConnection = mssql_connect( DB_HOST, DB_USER, DB_PASS );
|
||||||
@@ -828,5 +823,5 @@ class database extends database_base {
|
|||||||
$oDataset = mssql_query( $sql ) || ($bExists = false);
|
$oDataset = mssql_query( $sql ) || ($bExists = false);
|
||||||
return $bExists;
|
return $bExists;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user