sd
Browse files- connections/ADOConnection.php +0 -310
- connections/Connection.php +0 -764
- connections/ConnectionManager.php +0 -206
- connections/ConnectionManager_base.php +0 -303
- connections/DB2Connection.php +0 -178
- connections/InformixConnection.php +0 -197
- connections/MSSQLSrvConnection.php +0 -295
- connections/MSSQLUnixConnection.php +0 -164
- connections/MSSQLWinConnection.php +0 -320
- connections/MySQLConnection.php +0 -277
- connections/MySQLiConnection.php +0 -331
- connections/ODBCConnection.php +0 -187
- connections/OracleConnection.php +0 -326
- connections/PDOConnection.php +0 -206
- connections/PostgreConnection.php +0 -250
- connections/QueryResult.php +0 -209
- connections/SQLite3Connection.php +0 -172
- connections/apis.php +0 -66
- connections/dbfunctions/DB2Functions.php +0 -127
- connections/dbfunctions/DBFunctions.php +0 -364
- connections/dbfunctions/GenericFunctions.php +0 -19
- connections/dbfunctions/InformixFunctions.php +0 -86
- connections/dbfunctions/MSSQLFunctions.php +0 -174
- connections/dbfunctions/MySQLFunctions.php +0 -183
- connections/dbfunctions/ODBCFunctions.php +0 -155
- connections/dbfunctions/OracleFunctions.php +0 -147
- connections/dbfunctions/PostgreFunctions.php +0 -155
- connections/dbfunctions/SQLite3Functions.php +0 -95
- connections/dbfunctions_legacy.php +0 -156
- connections/dbinfo/ADOInfo.php +0 -40
- connections/dbinfo/DB2Info.php +0 -83
- connections/dbinfo/DBInfo.php +0 -19
- connections/dbinfo/InformixInfo.php +0 -94
- connections/dbinfo/MSSQLInfo.php +0 -43
- connections/dbinfo/MySQLInfo.php +0 -114
- connections/dbinfo/MySQLiInfo.php +0 -120
- connections/dbinfo/ODBCInfo.php +0 -86
- connections/dbinfo/OracleInfo.php +0 -80
- connections/dbinfo/PostgreInfo.php +0 -84
- connections/dbinfo/SQLLite3Info.php +0 -37
- connections/rest.php +0 -444
connections/ADOConnection.php
DELETED
|
@@ -1,310 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class ADOConnection extends Connection
|
| 3 |
-
{
|
| 4 |
-
/**
|
| 5 |
-
* A date format string
|
| 6 |
-
* @type String
|
| 7 |
-
*/
|
| 8 |
-
protected $access_dmy;
|
| 9 |
-
|
| 10 |
-
protected $ODBCString;
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
protected $errExeprionMess = "";
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
function __construct( $params )
|
| 17 |
-
{
|
| 18 |
-
parent::__construct( $params );
|
| 19 |
-
}
|
| 20 |
-
|
| 21 |
-
/**
|
| 22 |
-
* Set db connection's properties
|
| 23 |
-
* @param Array params
|
| 24 |
-
*/
|
| 25 |
-
protected function assignConnectionParams( $params )
|
| 26 |
-
{
|
| 27 |
-
parent::assignConnectionParams( $params );
|
| 28 |
-
|
| 29 |
-
$this->ODBCString = $params["ODBCString"];
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
/**
|
| 33 |
-
* Open a connection to db
|
| 34 |
-
*/
|
| 35 |
-
public function connect()
|
| 36 |
-
{
|
| 37 |
-
global $cCodepage;
|
| 38 |
-
|
| 39 |
-
try
|
| 40 |
-
{
|
| 41 |
-
$this->conn = new COM("ADODB.Connection", NULL, $cCodepage);
|
| 42 |
-
$this->conn->Open( $this->ODBCString );
|
| 43 |
-
|
| 44 |
-
if( $this->dbType == nDATABASE_Access )
|
| 45 |
-
{
|
| 46 |
-
$rs = $this->conn->Execute("select datevalue('2000-11-22') as qw");
|
| 47 |
-
$str = $rs->Fields[0]->Value;
|
| 48 |
-
|
| 49 |
-
$this->access_dmy = "mdy";
|
| 50 |
-
$y = strpos($str,"2000");
|
| 51 |
-
$m = strpos($str,"11");
|
| 52 |
-
$d = strpos($str,"22");
|
| 53 |
-
if( $y < $m && $m < $d )
|
| 54 |
-
$this->access_dmy = "ymd";
|
| 55 |
-
|
| 56 |
-
if( $d < $m && $m < $y )
|
| 57 |
-
$this->access_dmy = "dmy";
|
| 58 |
-
}
|
| 59 |
-
}
|
| 60 |
-
catch(Exception $e)
|
| 61 |
-
{
|
| 62 |
-
$this->triggerError( $e->getMessage() );
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
return $this->conn;
|
| 66 |
-
}
|
| 67 |
-
|
| 68 |
-
/**
|
| 69 |
-
* Close the db connection
|
| 70 |
-
*/
|
| 71 |
-
public function close()
|
| 72 |
-
{
|
| 73 |
-
$this->conn->Close();
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
/**
|
| 77 |
-
* Send an SQL query
|
| 78 |
-
* @param String sql
|
| 79 |
-
* @return Mixed
|
| 80 |
-
*/
|
| 81 |
-
public function query( $sql )
|
| 82 |
-
{
|
| 83 |
-
global $cCodepage;
|
| 84 |
-
|
| 85 |
-
$this->debugInfo($sql);
|
| 86 |
-
|
| 87 |
-
try
|
| 88 |
-
{
|
| 89 |
-
$recordset = new COM("ADODB.recordset", NULL, $cCodepage);
|
| 90 |
-
$recordset->Open($sql, $this->conn, 2);
|
| 91 |
-
|
| 92 |
-
return new QueryResult( $this, $recordset );
|
| 93 |
-
}
|
| 94 |
-
catch(com_exception $e)
|
| 95 |
-
{
|
| 96 |
-
$this->triggerError($e->getMessage());
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
return FALSE;
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
/**
|
| 103 |
-
* Execute an SQL query
|
| 104 |
-
* @param String sql
|
| 105 |
-
*/
|
| 106 |
-
public function exec( $sql )
|
| 107 |
-
{
|
| 108 |
-
$qResult = $this->query( $sql );
|
| 109 |
-
if( $qResult )
|
| 110 |
-
return $qResult->getQueryHandle();
|
| 111 |
-
|
| 112 |
-
return FALSE;
|
| 113 |
-
}
|
| 114 |
-
|
| 115 |
-
/**
|
| 116 |
-
* Get a description of the last error
|
| 117 |
-
* @return String
|
| 118 |
-
*/
|
| 119 |
-
public function lastError()
|
| 120 |
-
{
|
| 121 |
-
if( $this->conn->Errors->Count )
|
| 122 |
-
{
|
| 123 |
-
$description = $this->errExeprionMess;
|
| 124 |
-
$this->errExeprionMess = "";
|
| 125 |
-
|
| 126 |
-
return $description." ".$this->conn->Errors[ $this->conn->Errors->Count - 1 ]->Description;
|
| 127 |
-
}
|
| 128 |
-
|
| 129 |
-
return '';
|
| 130 |
-
}
|
| 131 |
-
|
| 132 |
-
/**
|
| 133 |
-
* The stub openSchema method overrided in the ADO connection class
|
| 134 |
-
* @param Number
|
| 135 |
-
* @return Mixed
|
| 136 |
-
*/
|
| 137 |
-
public function openSchema( $querytype )
|
| 138 |
-
{
|
| 139 |
-
$recordset = $this->conn->OpenSchema( $querytype );
|
| 140 |
-
return new QueryResult( $this, $recordset );
|
| 141 |
-
}
|
| 142 |
-
|
| 143 |
-
/**
|
| 144 |
-
* Fetch a result row as an array
|
| 145 |
-
* @param Mixed qHanle The query handle
|
| 146 |
-
* @param Number assoc (optional)
|
| 147 |
-
* @return Array
|
| 148 |
-
*/
|
| 149 |
-
protected function _fetch_array( $qHandle, $assoc = 1 )
|
| 150 |
-
{
|
| 151 |
-
$ret = array();
|
| 152 |
-
|
| 153 |
-
if( $qHandle->EOF() )
|
| 154 |
-
return false;
|
| 155 |
-
|
| 156 |
-
try {
|
| 157 |
-
for( $i = 0; $i < $this->num_fields( $qHandle ); $i++ )
|
| 158 |
-
{
|
| 159 |
-
if( IsBinaryType( $qHandle->Fields[$i]->Type ) && $qHandle->Fields[$i]->Type != 128 || $qHandle->Fields[$i]->Type == 203 )
|
| 160 |
-
{
|
| 161 |
-
$str = "";
|
| 162 |
-
if( $qHandle->Fields[$i]->ActualSize > 0 )
|
| 163 |
-
{
|
| 164 |
-
$size = $qHandle->Fields[$i]->ActualSize;
|
| 165 |
-
$val = $qHandle->Fields[$i]->GetChunk( $size );
|
| 166 |
-
|
| 167 |
-
if( is_array($val) || is_object($val) )
|
| 168 |
-
{
|
| 169 |
-
$str = str_pad("", $size);
|
| 170 |
-
$j = 0;
|
| 171 |
-
foreach($val as $byte)
|
| 172 |
-
{
|
| 173 |
-
$str[ $j++ ] = chr($byte);
|
| 174 |
-
}
|
| 175 |
-
}
|
| 176 |
-
else
|
| 177 |
-
$str = $val;
|
| 178 |
-
}
|
| 179 |
-
|
| 180 |
-
if( $assoc )
|
| 181 |
-
$ret[ $qHandle->Fields[$i]->Name ] = $str;
|
| 182 |
-
else
|
| 183 |
-
$ret[ $i ] = $str;
|
| 184 |
-
}
|
| 185 |
-
else
|
| 186 |
-
{
|
| 187 |
-
$value = $qHandle->Fields[$i]->Value;
|
| 188 |
-
|
| 189 |
-
if( is_null($value) )
|
| 190 |
-
$val = NULL;
|
| 191 |
-
else
|
| 192 |
-
{
|
| 193 |
-
if( isdatefieldtype( $qHandle->Fields[$i]->Type ) )
|
| 194 |
-
$value = localdatetime2db( (string)$qHandle->Fields[$i]->Value, $this->access_dmy );
|
| 195 |
-
if( IsNumberType( $qHandle->Fields[$i]->Type ) )
|
| 196 |
-
$val = floatval($value);
|
| 197 |
-
else
|
| 198 |
-
$val = strval($value);
|
| 199 |
-
}
|
| 200 |
-
|
| 201 |
-
if( $assoc )
|
| 202 |
-
$ret[ $qHandle->Fields[$i]->Name ] = $val;
|
| 203 |
-
else
|
| 204 |
-
$ret[ $i ] = $val;
|
| 205 |
-
}
|
| 206 |
-
}
|
| 207 |
-
|
| 208 |
-
$qHandle->MoveNext();
|
| 209 |
-
}
|
| 210 |
-
catch(com_exception $e)
|
| 211 |
-
{
|
| 212 |
-
$this->triggerError($e->getMessage() );
|
| 213 |
-
}
|
| 214 |
-
|
| 215 |
-
return $ret;
|
| 216 |
-
}
|
| 217 |
-
|
| 218 |
-
/**
|
| 219 |
-
* Fetch a result row as an associative array
|
| 220 |
-
* @param Mixed qHanle The query handle
|
| 221 |
-
* @return Array | Boolean
|
| 222 |
-
*/
|
| 223 |
-
public function fetch_array( $qHandle )
|
| 224 |
-
{
|
| 225 |
-
return $this->_fetch_array($qHandle, 1);
|
| 226 |
-
}
|
| 227 |
-
|
| 228 |
-
/**
|
| 229 |
-
* Fetch a result row as a numeric array
|
| 230 |
-
* @param Mixed qHanle The query handle
|
| 231 |
-
* @return Array | Boolean
|
| 232 |
-
*/
|
| 233 |
-
public function fetch_numarray( $qHandle )
|
| 234 |
-
{
|
| 235 |
-
return $this->_fetch_array($qHandle, 0);
|
| 236 |
-
}
|
| 237 |
-
|
| 238 |
-
/**
|
| 239 |
-
* Free resources associated with a query result set
|
| 240 |
-
* @param Mixed qHanle The query handle
|
| 241 |
-
*/
|
| 242 |
-
public function closeQuery( $qHandle )
|
| 243 |
-
{
|
| 244 |
-
$qHandle->Close();
|
| 245 |
-
}
|
| 246 |
-
|
| 247 |
-
/**
|
| 248 |
-
* Get number of fields in a result
|
| 249 |
-
* @param Mixed qHanle The query handle
|
| 250 |
-
* @return Number
|
| 251 |
-
*/
|
| 252 |
-
public function num_fields( $qHandle )
|
| 253 |
-
{
|
| 254 |
-
return $qHandle->Fields->Count;
|
| 255 |
-
}
|
| 256 |
-
|
| 257 |
-
/**
|
| 258 |
-
* Get the name of the specified field in a result
|
| 259 |
-
* @param Mixed qHanle The query handle
|
| 260 |
-
* @param Number offset
|
| 261 |
-
* @return String
|
| 262 |
-
*/
|
| 263 |
-
public function field_name( $qHandle, $offset )
|
| 264 |
-
{
|
| 265 |
-
return $qHandle->Fields( $offset )->Name;
|
| 266 |
-
}
|
| 267 |
-
|
| 268 |
-
/**
|
| 269 |
-
* @param Mixed qHandle
|
| 270 |
-
* @param Number pageSize
|
| 271 |
-
* @param Number page
|
| 272 |
-
*/
|
| 273 |
-
public function seekRecord($qHandle, $n )
|
| 274 |
-
{
|
| 275 |
-
if( $page == 1 )
|
| 276 |
-
return;
|
| 277 |
-
|
| 278 |
-
if( $qHandle->EOF() )
|
| 279 |
-
return;
|
| 280 |
-
|
| 281 |
-
$qHandle->Move( $n );
|
| 282 |
-
}
|
| 283 |
-
|
| 284 |
-
/**
|
| 285 |
-
* Execute an SQL query with blob fields processing
|
| 286 |
-
* @param String sql
|
| 287 |
-
* @param Array blobs
|
| 288 |
-
* @param Array blobTypes
|
| 289 |
-
* @return Boolean
|
| 290 |
-
*/
|
| 291 |
-
public function execWithBlobProcessing( $sql, $blobs, $blobTypes = array(), $autoincField = null )
|
| 292 |
-
{
|
| 293 |
-
global $cCodepage;
|
| 294 |
-
|
| 295 |
-
$this->debugInfo($sql);
|
| 296 |
-
|
| 297 |
-
try
|
| 298 |
-
{
|
| 299 |
-
$recordset = new COM("ADODB.recordset", NULL, $cCodepage);
|
| 300 |
-
$recordset->Open($sql, $this->conn, 2);
|
| 301 |
-
return true;
|
| 302 |
-
}
|
| 303 |
-
catch(com_exception $e)
|
| 304 |
-
{
|
| 305 |
-
$this->errExeprionMess = $e->getMessage();
|
| 306 |
-
return false;
|
| 307 |
-
}
|
| 308 |
-
}
|
| 309 |
-
}
|
| 310 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/Connection.php
DELETED
|
@@ -1,764 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class Connection
|
| 3 |
-
{
|
| 4 |
-
/**
|
| 5 |
-
* The db connection link identifier
|
| 6 |
-
* @type Mixed
|
| 7 |
-
*/
|
| 8 |
-
public $conn = null;
|
| 9 |
-
|
| 10 |
-
/**
|
| 11 |
-
* The database type identifier
|
| 12 |
-
* @type Number
|
| 13 |
-
*/
|
| 14 |
-
public $dbType;
|
| 15 |
-
|
| 16 |
-
/**
|
| 17 |
-
* The db connection id
|
| 18 |
-
* @type Number
|
| 19 |
-
*/
|
| 20 |
-
public $connId;
|
| 21 |
-
|
| 22 |
-
/**
|
| 23 |
-
* @type DBInfo
|
| 24 |
-
*/
|
| 25 |
-
public $_encryptInfo;
|
| 26 |
-
|
| 27 |
-
/**
|
| 28 |
-
* @type DBFunctions
|
| 29 |
-
*/
|
| 30 |
-
protected $_functions;
|
| 31 |
-
|
| 32 |
-
/**
|
| 33 |
-
* @type DBInfo
|
| 34 |
-
*/
|
| 35 |
-
protected $_info;
|
| 36 |
-
|
| 37 |
-
/**
|
| 38 |
-
* asp compatibility
|
| 39 |
-
*/
|
| 40 |
-
public $SQLUpdateMode;
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
/**
|
| 44 |
-
* @type boolean
|
| 45 |
-
*/
|
| 46 |
-
protected $silentMode;
|
| 47 |
-
|
| 48 |
-
protected static $lastInsertedId;
|
| 49 |
-
|
| 50 |
-
function __construct( $params )
|
| 51 |
-
{
|
| 52 |
-
include_once getabspath("connections/QueryResult.php");
|
| 53 |
-
|
| 54 |
-
$this->assignConnectionParams( $params );
|
| 55 |
-
|
| 56 |
-
// set the db connection
|
| 57 |
-
$this->connect();
|
| 58 |
-
|
| 59 |
-
$this->setDbFunctions( $params );
|
| 60 |
-
$this->setDbInfo( $params["ODBCString"] );
|
| 61 |
-
|
| 62 |
-
$this->_encryptInfo = $params["EncryptInfo"];
|
| 63 |
-
|
| 64 |
-
$initSQLList = $this->_functions->initializationSQL();
|
| 65 |
-
foreach( $initSQLList as $query ) {
|
| 66 |
-
$this->exec( $query );
|
| 67 |
-
}
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
/**
|
| 71 |
-
* @return Boolean
|
| 72 |
-
*/
|
| 73 |
-
function isEncryptionByPHPEnabled()
|
| 74 |
-
{
|
| 75 |
-
return isset( $this->_encryptInfo["mode"] ) && $this->_encryptInfo["mode"] == ENCRYPTION_PHP;
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
/**
|
| 79 |
-
* @param String sql
|
| 80 |
-
*/
|
| 81 |
-
function setInitializingSQL( $sql )
|
| 82 |
-
{
|
| 83 |
-
// in PHP just exec the initialization SQL right away.
|
| 84 |
-
$this->exec( $sql );
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
/**
|
| 89 |
-
* Set db connection's properties
|
| 90 |
-
* @param Array params
|
| 91 |
-
*/
|
| 92 |
-
protected function assignConnectionParams( $params )
|
| 93 |
-
{
|
| 94 |
-
$this->dbType = $params["dbType"];
|
| 95 |
-
$this->connId = $params["connId"];
|
| 96 |
-
}
|
| 97 |
-
|
| 98 |
-
/**
|
| 99 |
-
* Set the DBFunction object
|
| 100 |
-
* @param String leftWrapper
|
| 101 |
-
* @param String rightWrapper
|
| 102 |
-
*/
|
| 103 |
-
protected function setDbFunctions( $params )
|
| 104 |
-
{
|
| 105 |
-
include_once getabspath("connections/dbfunctions/DBFunctions.php");
|
| 106 |
-
|
| 107 |
-
$extraParams = array_merge($this->getDbFunctionsExtraParams(), $params);
|
| 108 |
-
|
| 109 |
-
switch( $this->dbType )
|
| 110 |
-
{
|
| 111 |
-
case nDATABASE_MySQL:
|
| 112 |
-
include_once getabspath("connections/dbfunctions/MySQLFunctions.php");
|
| 113 |
-
$this->_functions = new MySQLFunctions( $extraParams );
|
| 114 |
-
break;
|
| 115 |
-
case nDATABASE_Oracle:
|
| 116 |
-
include_once getabspath("connections/dbfunctions/OracleFunctions.php");
|
| 117 |
-
$this->_functions = new OracleFunctions( $extraParams );
|
| 118 |
-
break;
|
| 119 |
-
case nDATABASE_MSSQLServer:
|
| 120 |
-
include_once getabspath("connections/dbfunctions/MSSQLFunctions.php");
|
| 121 |
-
$this->_functions = new MSSQLFunctions( $extraParams );
|
| 122 |
-
break;
|
| 123 |
-
case nDATABASE_Access:
|
| 124 |
-
include_once getabspath("connections/dbfunctions/ODBCFunctions.php");
|
| 125 |
-
$this->_functions = new ODBCFunctions( $extraParams );
|
| 126 |
-
break;
|
| 127 |
-
case nDATABASE_PostgreSQL:
|
| 128 |
-
include_once getabspath("connections/dbfunctions/PostgreFunctions.php");
|
| 129 |
-
$this->_functions = new PostgreFunctions( $extraParams );
|
| 130 |
-
break;
|
| 131 |
-
case nDATABASE_Informix:
|
| 132 |
-
include_once getabspath("connections/dbfunctions/InformixFunctions.php");
|
| 133 |
-
$this->_functions = new InformixFunctions( $extraParams );
|
| 134 |
-
break;
|
| 135 |
-
case nDATABASE_SQLite3:
|
| 136 |
-
include_once getabspath("connections/dbfunctions/SQLite3Functions.php");
|
| 137 |
-
$this->_functions = new SQLite3Functions( $extraParams );
|
| 138 |
-
break;
|
| 139 |
-
case nDATABASE_DB2:
|
| 140 |
-
case 18: // iSeries
|
| 141 |
-
include_once getabspath("connections/dbfunctions/DB2Functions.php");
|
| 142 |
-
$this->_functions = new DB2Functions( $extraParams );
|
| 143 |
-
break;
|
| 144 |
-
default:
|
| 145 |
-
include_once getabspath("connections/dbfunctions/GenericFunctions.php");
|
| 146 |
-
$this->_functions = new GenericFunctions( $extraParams );
|
| 147 |
-
}
|
| 148 |
-
}
|
| 149 |
-
|
| 150 |
-
/**
|
| 151 |
-
* Get extra connection params that may be connected
|
| 152 |
-
* with the db connection link directly
|
| 153 |
-
* @return Array
|
| 154 |
-
*/
|
| 155 |
-
protected function getDbFunctionsExtraParams()
|
| 156 |
-
{
|
| 157 |
-
return array();
|
| 158 |
-
}
|
| 159 |
-
|
| 160 |
-
/**
|
| 161 |
-
* Set the DbInfo object
|
| 162 |
-
* @param String ODBCString
|
| 163 |
-
*/
|
| 164 |
-
protected function setDbInfo( $ODBCString )
|
| 165 |
-
{
|
| 166 |
-
include_once getabspath("connections/dbinfo/DBInfo.php");
|
| 167 |
-
switch( $this->dbType )
|
| 168 |
-
{
|
| 169 |
-
case nDATABASE_MySQL:
|
| 170 |
-
if( useMySQLiLib() )
|
| 171 |
-
{
|
| 172 |
-
include_once getabspath("connections/dbinfo/MySQLiInfo.php");
|
| 173 |
-
$this->_info = new MySQLiInfo( $this );
|
| 174 |
-
}
|
| 175 |
-
else
|
| 176 |
-
{
|
| 177 |
-
include_once getabspath("connections/dbinfo/MySQLInfo.php");
|
| 178 |
-
$this->_info = new MySQLInfo( $this );
|
| 179 |
-
}
|
| 180 |
-
break;
|
| 181 |
-
case nDATABASE_Oracle:
|
| 182 |
-
include_once getabspath("connections/dbinfo/OracleInfo.php");
|
| 183 |
-
$this->_info = new OracleInfo( $this );
|
| 184 |
-
break;
|
| 185 |
-
case nDATABASE_MSSQLServer:
|
| 186 |
-
include_once getabspath("connections/dbinfo/MSSQLInfo.php");
|
| 187 |
-
$this->_info = new MSSQLInfo( $this );
|
| 188 |
-
break;
|
| 189 |
-
case nDATABASE_Access:
|
| 190 |
-
if( stripos($ODBCString, 'Provider=') !== false )
|
| 191 |
-
{
|
| 192 |
-
include_once getabspath("connections/dbinfo/ADOInfo.php");
|
| 193 |
-
$this->_info = new ADOInfo( $this );
|
| 194 |
-
}
|
| 195 |
-
else
|
| 196 |
-
{
|
| 197 |
-
include_once getabspath("connections/dbinfo/ODBCInfo.php");
|
| 198 |
-
$this->_info = new ODBCInfo( $this );
|
| 199 |
-
}
|
| 200 |
-
break;
|
| 201 |
-
case nDATABASE_PostgreSQL:
|
| 202 |
-
include_once getabspath("connections/dbinfo/PostgreInfo.php");
|
| 203 |
-
$this->_info = new PostgreInfo( $this );
|
| 204 |
-
break;
|
| 205 |
-
case nDATABASE_Informix:
|
| 206 |
-
include_once getabspath("connections/dbinfo/InformixInfo.php");
|
| 207 |
-
$this->_info = new InformixInfo( $this );
|
| 208 |
-
break;
|
| 209 |
-
case nDATABASE_SQLite3:
|
| 210 |
-
include_once getabspath("connections/dbinfo/SQLLite3Info.php");
|
| 211 |
-
$this->_info = new SQLLite3Info( $this );
|
| 212 |
-
break;
|
| 213 |
-
case nDATABASE_DB2:
|
| 214 |
-
include_once getabspath("connections/dbinfo/DB2Info.php");
|
| 215 |
-
$this->_info = new DB2Info( $this );
|
| 216 |
-
}
|
| 217 |
-
}
|
| 218 |
-
|
| 219 |
-
/**
|
| 220 |
-
* An interface stub.
|
| 221 |
-
* Open a connection to db
|
| 222 |
-
*/
|
| 223 |
-
public function connect()
|
| 224 |
-
{
|
| 225 |
-
//db_connect
|
| 226 |
-
}
|
| 227 |
-
|
| 228 |
-
/**
|
| 229 |
-
* An interface stub
|
| 230 |
-
* Close the db connection
|
| 231 |
-
*/
|
| 232 |
-
public function close()
|
| 233 |
-
{
|
| 234 |
-
//db_close
|
| 235 |
-
}
|
| 236 |
-
|
| 237 |
-
/**
|
| 238 |
-
* An interface stub
|
| 239 |
-
* Send an SQL query
|
| 240 |
-
* @param String sql
|
| 241 |
-
* @return QueryResult
|
| 242 |
-
*/
|
| 243 |
-
public function query( $sql )
|
| 244 |
-
{
|
| 245 |
-
//db_query
|
| 246 |
-
//return new QueryResult( $this, $qHandle );
|
| 247 |
-
}
|
| 248 |
-
|
| 249 |
-
/**
|
| 250 |
-
* An interface stub
|
| 251 |
-
* Execute an SQL query
|
| 252 |
-
* @param String sql
|
| 253 |
-
*/
|
| 254 |
-
public function exec( $sql )
|
| 255 |
-
{
|
| 256 |
-
//db_exec
|
| 257 |
-
}
|
| 258 |
-
|
| 259 |
-
/**
|
| 260 |
-
* An interface stub
|
| 261 |
-
* Get a description of the last error
|
| 262 |
-
* @return String
|
| 263 |
-
*/
|
| 264 |
-
public function lastError()
|
| 265 |
-
{
|
| 266 |
-
//db_error
|
| 267 |
-
}
|
| 268 |
-
|
| 269 |
-
/**
|
| 270 |
-
* Get the auto generated id used in the last query
|
| 271 |
-
* @param String key (optional)
|
| 272 |
-
* @param String table (optional)
|
| 273 |
-
* @return Number
|
| 274 |
-
*/
|
| 275 |
-
public function getInsertedId( $key = null, $table = null )
|
| 276 |
-
{
|
| 277 |
-
$insertedIdSQL = $this->_functions->getInsertedIdSQL( $key, $table );
|
| 278 |
-
|
| 279 |
-
if ( $insertedIdSQL )
|
| 280 |
-
{
|
| 281 |
-
$qResult = $this->query( $insertedIdSQL );
|
| 282 |
-
if( $qResult )
|
| 283 |
-
{
|
| 284 |
-
$lastId = $qResult->fetchNumeric();
|
| 285 |
-
return $lastId[0];
|
| 286 |
-
}
|
| 287 |
-
}
|
| 288 |
-
|
| 289 |
-
return 0;
|
| 290 |
-
}
|
| 291 |
-
|
| 292 |
-
/**
|
| 293 |
-
*
|
| 294 |
-
*/
|
| 295 |
-
public static function getAutoincField($tableInfo)
|
| 296 |
-
{
|
| 297 |
-
if (!$tableInfo)
|
| 298 |
-
return null;
|
| 299 |
-
|
| 300 |
-
if (!is_array($tableInfo["fields"]))
|
| 301 |
-
return null;
|
| 302 |
-
|
| 303 |
-
$keys = array();
|
| 304 |
-
$autoincField = null;
|
| 305 |
-
foreach ($tableInfo["fields"] as $f) {
|
| 306 |
-
if ($f["key"]) {
|
| 307 |
-
$keys[$f["name"]] = $f["type"];
|
| 308 |
-
|
| 309 |
-
if ($f["autoInc"]) {
|
| 310 |
-
$autoincField = $f["name"];
|
| 311 |
-
break;
|
| 312 |
-
}
|
| 313 |
-
}
|
| 314 |
-
}
|
| 315 |
-
|
| 316 |
-
if ($autoincField == null && count($keys) == 1) {
|
| 317 |
-
foreach ($keys as $key => $type) {
|
| 318 |
-
if (IsNumberType($type)) {
|
| 319 |
-
$autoincField = $key;
|
| 320 |
-
}
|
| 321 |
-
}
|
| 322 |
-
}
|
| 323 |
-
|
| 324 |
-
return $autoincField;
|
| 325 |
-
}
|
| 326 |
-
|
| 327 |
-
/**
|
| 328 |
-
* The stub openSchema method overrided in the ADO connection class
|
| 329 |
-
* @param Number querytype
|
| 330 |
-
* @return Mixed
|
| 331 |
-
*/
|
| 332 |
-
public function openSchema( $querytype )
|
| 333 |
-
{
|
| 334 |
-
return null;
|
| 335 |
-
}
|
| 336 |
-
|
| 337 |
-
/**
|
| 338 |
-
* An interface stub
|
| 339 |
-
* Fetch a result row as an associative array
|
| 340 |
-
* @param Mixed qHanle The query handle
|
| 341 |
-
* @return Array | Boolean
|
| 342 |
-
*/
|
| 343 |
-
public function fetch_array( $qHandle )
|
| 344 |
-
{
|
| 345 |
-
//db_fetch_array
|
| 346 |
-
}
|
| 347 |
-
|
| 348 |
-
/**
|
| 349 |
-
* An interface stub
|
| 350 |
-
* Fetch a result row as a numeric array
|
| 351 |
-
* @param Mixed qHanle The query handle
|
| 352 |
-
* @return Array | Boolean
|
| 353 |
-
*/
|
| 354 |
-
public function fetch_numarray( $qHandle )
|
| 355 |
-
{
|
| 356 |
-
//db_fetch_numarray
|
| 357 |
-
}
|
| 358 |
-
|
| 359 |
-
/**
|
| 360 |
-
* An interface stub
|
| 361 |
-
* Free resources associated with a query result set
|
| 362 |
-
* @param Mixed qHanle The query handle
|
| 363 |
-
*/
|
| 364 |
-
public function closeQuery( $qHandle )
|
| 365 |
-
{
|
| 366 |
-
//db_closequery
|
| 367 |
-
}
|
| 368 |
-
|
| 369 |
-
/**
|
| 370 |
-
* An interface stub.
|
| 371 |
-
* Get number of fields in a result
|
| 372 |
-
* @param Mixed qHanle The query handle
|
| 373 |
-
* @return Number
|
| 374 |
-
*/
|
| 375 |
-
public function num_fields( $qHandle )
|
| 376 |
-
{
|
| 377 |
-
//db_numfields
|
| 378 |
-
}
|
| 379 |
-
|
| 380 |
-
/**
|
| 381 |
-
* An interface stub.
|
| 382 |
-
* Get the name of the specified field in a result
|
| 383 |
-
* @param Mixed qHanle The query handle
|
| 384 |
-
* @param Number offset
|
| 385 |
-
* @return String
|
| 386 |
-
*/
|
| 387 |
-
public function field_name( $qHandle, $offset )
|
| 388 |
-
{
|
| 389 |
-
//db_fieldname
|
| 390 |
-
}
|
| 391 |
-
|
| 392 |
-
/**
|
| 393 |
-
* An interface stub
|
| 394 |
-
* @param Mixed qHandle
|
| 395 |
-
* @param Number pageSize
|
| 396 |
-
* @param Number page
|
| 397 |
-
*/
|
| 398 |
-
public function seekRecord($qHandle, $n)
|
| 399 |
-
{
|
| 400 |
-
for($i = 0; $i < $n; $i++)
|
| 401 |
-
{
|
| 402 |
-
$this->fetch_array( $qHandle );
|
| 403 |
-
}
|
| 404 |
-
}
|
| 405 |
-
|
| 406 |
-
/**
|
| 407 |
-
* @param String str
|
| 408 |
-
* @return String
|
| 409 |
-
*/
|
| 410 |
-
public function escapeLIKEpattern( $str )
|
| 411 |
-
{
|
| 412 |
-
return $this->_functions->escapeLIKEpattern( $str );
|
| 413 |
-
}
|
| 414 |
-
|
| 415 |
-
/**
|
| 416 |
-
* Returns SQL statement like 'val1 = val2'
|
| 417 |
-
* Use this only for strings!
|
| 418 |
-
*/
|
| 419 |
-
public function comparisonSQL( $val1, $val2, $ignoreCase ) {
|
| 420 |
-
return $ignoreCase
|
| 421 |
-
? $this->caseInsensitiveComparison( $val1, $val2 )
|
| 422 |
-
: $this->caseSensitiveComparison( $val1, $val2 );
|
| 423 |
-
}
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
public function caseSensitiveComparison( $val1, $val2 )
|
| 427 |
-
{
|
| 428 |
-
return $this->_functions->caseSensitiveComparison( $val1, $val2 );
|
| 429 |
-
}
|
| 430 |
-
|
| 431 |
-
public function caseInsensitiveComparison( $val1, $val2 )
|
| 432 |
-
{
|
| 433 |
-
return $this->_functions->caseInsensitiveComparison( $val1, $val2 );
|
| 434 |
-
}
|
| 435 |
-
|
| 436 |
-
/**
|
| 437 |
-
* Checks if character at position $pos in SQL string is inside quotes.
|
| 438 |
-
* Example:
|
| 439 |
-
* select 'aaa\' 1', ' ' 2
|
| 440 |
-
* Character 1 is on quotes, 2 - not
|
| 441 |
-
* @return Boolean
|
| 442 |
-
*/
|
| 443 |
-
public function positionQuoted( $sql, $pos )
|
| 444 |
-
{
|
| 445 |
-
return $this->_functions->positionQuoted( $sql, $pos );
|
| 446 |
-
}
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
/**
|
| 450 |
-
* @param String str
|
| 451 |
-
* @return String
|
| 452 |
-
*/
|
| 453 |
-
public function prepareString( $str )
|
| 454 |
-
{
|
| 455 |
-
return $this->_functions->prepareString( $str );
|
| 456 |
-
}
|
| 457 |
-
|
| 458 |
-
/**
|
| 459 |
-
* @param String str
|
| 460 |
-
* @return String
|
| 461 |
-
*/
|
| 462 |
-
public function addSlashes( $str )
|
| 463 |
-
{
|
| 464 |
-
return $this->_functions->addslashes( $str );
|
| 465 |
-
}
|
| 466 |
-
|
| 467 |
-
/**
|
| 468 |
-
* @param String str
|
| 469 |
-
* @return String
|
| 470 |
-
*/
|
| 471 |
-
public function addSlashesBinary( $str )
|
| 472 |
-
{
|
| 473 |
-
return $this->_functions->addSlashesBinary( $str );
|
| 474 |
-
}
|
| 475 |
-
|
| 476 |
-
/**
|
| 477 |
-
* @param String str
|
| 478 |
-
* @return String
|
| 479 |
-
*/
|
| 480 |
-
public function stripSlashesBinary( $str )
|
| 481 |
-
{
|
| 482 |
-
return $this->_functions->stripSlashesBinary( $str );
|
| 483 |
-
}
|
| 484 |
-
|
| 485 |
-
/**
|
| 486 |
-
* @param String fName
|
| 487 |
-
* @return String
|
| 488 |
-
*/
|
| 489 |
-
public function addFieldWrappers( $fName )
|
| 490 |
-
{
|
| 491 |
-
return $this->_functions->addFieldWrappers( $fName );
|
| 492 |
-
}
|
| 493 |
-
|
| 494 |
-
/**
|
| 495 |
-
* @param String tName
|
| 496 |
-
* @return String
|
| 497 |
-
*/
|
| 498 |
-
public function addTableWrappers( $tName )
|
| 499 |
-
{
|
| 500 |
-
return $this->_functions->addTableWrappers( $tName );
|
| 501 |
-
}
|
| 502 |
-
|
| 503 |
-
/**
|
| 504 |
-
* Resolves the table name and schema name (if any).
|
| 505 |
-
* @param string $name the table name
|
| 506 |
-
* @return Array
|
| 507 |
-
*/
|
| 508 |
-
public function getTableNameComponents( $name )
|
| 509 |
-
{
|
| 510 |
-
return $this->_functions->getTableNameComponents( $name );
|
| 511 |
-
}
|
| 512 |
-
|
| 513 |
-
/**
|
| 514 |
-
* @param String str
|
| 515 |
-
* @return String
|
| 516 |
-
*/
|
| 517 |
-
public function upper( $str )
|
| 518 |
-
{
|
| 519 |
-
return $this->_functions->upper( $str );
|
| 520 |
-
}
|
| 521 |
-
|
| 522 |
-
/**
|
| 523 |
-
* @param Mixed value
|
| 524 |
-
* @return String
|
| 525 |
-
*/
|
| 526 |
-
public function addDateQuotes( $value )
|
| 527 |
-
{
|
| 528 |
-
return $this->_functions->addDateQuotes( $value );
|
| 529 |
-
}
|
| 530 |
-
|
| 531 |
-
/**
|
| 532 |
-
* @param Mixed value
|
| 533 |
-
* @param Number type ( optional )
|
| 534 |
-
* @return String
|
| 535 |
-
*/
|
| 536 |
-
public function field2char( $value, $type = 3 )
|
| 537 |
-
{
|
| 538 |
-
return $this->_functions->field2char( $value, $type );
|
| 539 |
-
}
|
| 540 |
-
|
| 541 |
-
/**
|
| 542 |
-
* It's invoked when search is running on the 'View as:Time' field
|
| 543 |
-
* @param Mixed value
|
| 544 |
-
* @param Number type
|
| 545 |
-
* @return String
|
| 546 |
-
*/
|
| 547 |
-
public function field2time( $value, $type )
|
| 548 |
-
{
|
| 549 |
-
return $this->_functions->field2time( $value, $type );
|
| 550 |
-
}
|
| 551 |
-
|
| 552 |
-
/**
|
| 553 |
-
* @param String tName
|
| 554 |
-
* @return String
|
| 555 |
-
*/
|
| 556 |
-
public function timeToSecWrapper( $tName )
|
| 557 |
-
{
|
| 558 |
-
return $this->_functions->timeToSecWrapper( $tName );
|
| 559 |
-
}
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
/**
|
| 563 |
-
* @return Array
|
| 564 |
-
*/
|
| 565 |
-
public function getTableList()
|
| 566 |
-
{
|
| 567 |
-
return $this->_info->db_gettablelist();
|
| 568 |
-
}
|
| 569 |
-
|
| 570 |
-
/**
|
| 571 |
-
* @param String
|
| 572 |
-
* @return Array
|
| 573 |
-
*/
|
| 574 |
-
public function getFieldsList( $sql )
|
| 575 |
-
{
|
| 576 |
-
return $this->_info->db_getfieldslist( $sql );
|
| 577 |
-
}
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
/**
|
| 581 |
-
* Check if the db supports subqueries
|
| 582 |
-
* @return Boolean
|
| 583 |
-
*/
|
| 584 |
-
public function checkDBSubqueriesSupport()
|
| 585 |
-
{
|
| 586 |
-
return true;
|
| 587 |
-
}
|
| 588 |
-
|
| 589 |
-
/**
|
| 590 |
-
* @param String sql
|
| 591 |
-
* @param Number pageStart 1-based page number
|
| 592 |
-
* @param Number pageSize
|
| 593 |
-
* @param Boolean applyLimit
|
| 594 |
-
*/
|
| 595 |
-
public function queryPage($strSQL, $pageStart, $pageSize, $applyLimit)
|
| 596 |
-
{
|
| 597 |
-
return $this->limitedQuery( $strSQL, ($pageStart - 1) * $pageSize, $pageSize, $applyLimit );
|
| 598 |
-
}
|
| 599 |
-
|
| 600 |
-
/**
|
| 601 |
-
* @param String sql
|
| 602 |
-
* @param Number skip - how many records to skip
|
| 603 |
-
* @param Number total - how many records to return
|
| 604 |
-
* @param Boolean applyLimit - modify SQL to accomodate for skip & total
|
| 605 |
-
*/
|
| 606 |
-
public function limitedQuery($strSQL, $skip, $total, $applyLimit)
|
| 607 |
-
{
|
| 608 |
-
return $this->_functions->limitedQuery( $this, $strSQL, $skip, $total, $applyLimit );
|
| 609 |
-
}
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
/**
|
| 613 |
-
* An interface stub
|
| 614 |
-
* Execute an SQL query with blob fields processing
|
| 615 |
-
* @param String sql
|
| 616 |
-
* @param Array blobs
|
| 617 |
-
* @param Array blobTypes
|
| 618 |
-
* @return Boolean
|
| 619 |
-
*/
|
| 620 |
-
public function execWithBlobProcessing( $sql, $blobs, $blobTypes = array(), $autoincField = null )
|
| 621 |
-
{
|
| 622 |
-
return $this->exec( $sql );
|
| 623 |
-
}
|
| 624 |
-
|
| 625 |
-
/**
|
| 626 |
-
* Get the number of rows fetched by an SQL query
|
| 627 |
-
* @param String sql A part of an SQL query or a full SQL query
|
| 628 |
-
* @param Boolean The flag indicating if the full SQL query (that can be used as a subquery)
|
| 629 |
-
* or the part of an sql query ( from + where clauses ) is passed as the first param
|
| 630 |
-
*/
|
| 631 |
-
public function getFetchedRowsNumber( $sql )
|
| 632 |
-
{
|
| 633 |
-
$countSql = "select count(*) from (".$sql.") a";
|
| 634 |
-
|
| 635 |
-
$countdata = $this->query( $countSql )->fetchNumeric();
|
| 636 |
-
return $countdata[0];
|
| 637 |
-
}
|
| 638 |
-
|
| 639 |
-
/**
|
| 640 |
-
* Check if SQL queries containing joined subquery are optimized
|
| 641 |
-
* @return Boolean
|
| 642 |
-
*/
|
| 643 |
-
public function checkIfJoinSubqueriesOptimized()
|
| 644 |
-
{
|
| 645 |
-
return true;
|
| 646 |
-
}
|
| 647 |
-
|
| 648 |
-
/**
|
| 649 |
-
* Set and print debug information
|
| 650 |
-
* @param String sql
|
| 651 |
-
*/
|
| 652 |
-
function debugInfo( $sql )
|
| 653 |
-
{
|
| 654 |
-
global $strLastSQL, $dDebug;
|
| 655 |
-
|
| 656 |
-
$strLastSQL = $sql;
|
| 657 |
-
|
| 658 |
-
if( $dDebug === true )
|
| 659 |
-
echo $sql."<br>";
|
| 660 |
-
}
|
| 661 |
-
|
| 662 |
-
/**
|
| 663 |
-
* @param String message
|
| 664 |
-
*/
|
| 665 |
-
function triggerError( $message )
|
| 666 |
-
{
|
| 667 |
-
if( !$this->silentMode )
|
| 668 |
-
trigger_error( $message, E_USER_ERROR );
|
| 669 |
-
}
|
| 670 |
-
|
| 671 |
-
/**
|
| 672 |
-
* Enables or disables Silent Mode, when no SQL errors are displayed.
|
| 673 |
-
* @param Boolean silent
|
| 674 |
-
* @return Boolean - previous Silent mode
|
| 675 |
-
*/
|
| 676 |
-
public function setSilentMode( $silent )
|
| 677 |
-
{
|
| 678 |
-
$oldMode = $this->silentMode;
|
| 679 |
-
$this->silentMode = $silent;
|
| 680 |
-
return $oldMode;
|
| 681 |
-
}
|
| 682 |
-
|
| 683 |
-
/**
|
| 684 |
-
* query, silent mode
|
| 685 |
-
* @param String sql
|
| 686 |
-
* @return QueryResult
|
| 687 |
-
*/
|
| 688 |
-
public function querySilent( $sql )
|
| 689 |
-
{
|
| 690 |
-
$silent = $this->setSilentMode( true );
|
| 691 |
-
$ret = $this->query( $sql );
|
| 692 |
-
$this->setSilentMode( $silent );
|
| 693 |
-
return $ret;
|
| 694 |
-
}
|
| 695 |
-
|
| 696 |
-
/**
|
| 697 |
-
* exec, silent mode
|
| 698 |
-
* @param String sql
|
| 699 |
-
* @return Mixed
|
| 700 |
-
*/
|
| 701 |
-
public function execSilent( $sql )
|
| 702 |
-
{
|
| 703 |
-
$silent = $this->setSilentMode( true );
|
| 704 |
-
$ret = $this->exec( $sql );
|
| 705 |
-
$this->setSilentMode( $silent );
|
| 706 |
-
return $ret;
|
| 707 |
-
}
|
| 708 |
-
|
| 709 |
-
/**
|
| 710 |
-
* Execute an SQL query with blob fields processing, silent mode
|
| 711 |
-
* @param String sql
|
| 712 |
-
* @param Array blobs
|
| 713 |
-
* @param Array blobTypes
|
| 714 |
-
* @return Mixed
|
| 715 |
-
*/
|
| 716 |
-
public function execSilentWithBlobProcessing( $sql, $blobs, $blobTypes = array(), $autoincField = null )
|
| 717 |
-
{
|
| 718 |
-
$silent = $this->setSilentMode( true );
|
| 719 |
-
$ret = $this->execWithBlobProcessing( $sql, $blobs, $blobTypes, $autoincField );
|
| 720 |
-
$this->setSilentMode( $silent );
|
| 721 |
-
return $ret;
|
| 722 |
-
}
|
| 723 |
-
|
| 724 |
-
public function intervalExpressionString( $expr, $interval )
|
| 725 |
-
{
|
| 726 |
-
return $this->_functions->intervalExpressionString( $expr, $interval );
|
| 727 |
-
}
|
| 728 |
-
|
| 729 |
-
public function intervalExpressionNumber( $expr, $interval )
|
| 730 |
-
{
|
| 731 |
-
return $this->_functions->intervalExpressionNumber( $expr, $interval );
|
| 732 |
-
}
|
| 733 |
-
|
| 734 |
-
public function intervalExpressionDate( $expr, $interval )
|
| 735 |
-
{
|
| 736 |
-
return $this->_functions->intervalExpressionDate( $expr, $interval );
|
| 737 |
-
}
|
| 738 |
-
|
| 739 |
-
public function execMultiple( $sqls )
|
| 740 |
-
{
|
| 741 |
-
foreach( $sqls as $sql ) {
|
| 742 |
-
if( !$this->execSilent( $sql ) ) {
|
| 743 |
-
return false;
|
| 744 |
-
}
|
| 745 |
-
}
|
| 746 |
-
return true;
|
| 747 |
-
}
|
| 748 |
-
|
| 749 |
-
public function dbBased() {
|
| 750 |
-
return true;
|
| 751 |
-
}
|
| 752 |
-
|
| 753 |
-
public function clearResultBuffer() {
|
| 754 |
-
}
|
| 755 |
-
|
| 756 |
-
/**
|
| 757 |
-
* @return String
|
| 758 |
-
*/
|
| 759 |
-
public function getVersion() {
|
| 760 |
-
return "";
|
| 761 |
-
}
|
| 762 |
-
|
| 763 |
-
}
|
| 764 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/ConnectionManager.php
DELETED
|
@@ -1,206 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
include_once(getabspath("connections/ConnectionManager_base.php"));
|
| 4 |
-
|
| 5 |
-
class ConnectionManager extends ConnectionManager_Base
|
| 6 |
-
{
|
| 7 |
-
/**
|
| 8 |
-
* @param String connId
|
| 9 |
-
* @return Connection
|
| 10 |
-
*/
|
| 11 |
-
protected function getConnection( $connId )
|
| 12 |
-
{
|
| 13 |
-
include_once getabspath("connections/Connection.php");
|
| 14 |
-
|
| 15 |
-
$data = $this->_connectionsData[ $connId ];
|
| 16 |
-
switch( $data["connStringType"] )
|
| 17 |
-
{
|
| 18 |
-
case "mysql":
|
| 19 |
-
if( useMySQLiLib() )
|
| 20 |
-
{
|
| 21 |
-
include_once getabspath("connections/MySQLiConnection.php");
|
| 22 |
-
return new MySQLiConnection( $data );
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
include_once getabspath("connections/MySQLConnection.php");
|
| 26 |
-
return new MySQLConnection( $data );
|
| 27 |
-
|
| 28 |
-
case "mssql":
|
| 29 |
-
case "compact":
|
| 30 |
-
if( useMSSQLWinConnect() )
|
| 31 |
-
{
|
| 32 |
-
include_once getabspath("connections/MSSQLWinConnection.php");
|
| 33 |
-
return new MSSQLWinConnection( $data );
|
| 34 |
-
}
|
| 35 |
-
if( isSqlsrvExtLoaded() )
|
| 36 |
-
{
|
| 37 |
-
include_once getabspath("connections/MSSQLSrvConnection.php");
|
| 38 |
-
return new MSSQLSrvConnection( $data );
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
if( function_exists("mssql_connect") ) {
|
| 42 |
-
include_once getabspath("connections/MSSQLUnixConnection.php");
|
| 43 |
-
return new MSSQLUnixConnection( $data );
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
if( class_exists("PDO") ) {
|
| 47 |
-
include_once getabspath("connections/PDOConnection.php");
|
| 48 |
-
$drivers = pdo_drivers();
|
| 49 |
-
if( in_array( "sqlsrv", $drivers) )
|
| 50 |
-
{
|
| 51 |
-
$data["PDOString"] = "sqlsrv:Server=" . $data["connInfo"][0] . ";Database=" . $data["connInfo"][3];
|
| 52 |
-
$data["PDOUser"] = $data["connInfo"][1];
|
| 53 |
-
$data["PDOPass"] = $data["connInfo"][2];
|
| 54 |
-
return new PDOConnection( $data );
|
| 55 |
-
}
|
| 56 |
-
if( in_array( "dblib", $drivers) )
|
| 57 |
-
{
|
| 58 |
-
$data["PDOString"] = "dblib:host=" . $data["connInfo"][0] . ";dbname=" . $data["connInfo"][3];
|
| 59 |
-
$data["PDOUser"] = $data["connInfo"][1];
|
| 60 |
-
$data["PDOPass"] = $data["connInfo"][2];
|
| 61 |
-
return new PDOConnection( $data );
|
| 62 |
-
}
|
| 63 |
-
}
|
| 64 |
-
echo "No SQL Server driver found in your PHP settings.";
|
| 65 |
-
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
| 66 |
-
echo "<br>To enable SQL Server support add the following line to php.ini file:";
|
| 67 |
-
echo "<br>extension=php_com_dotnet.dll";
|
| 68 |
-
}
|
| 69 |
-
exit();
|
| 70 |
-
|
| 71 |
-
case "msaccess":
|
| 72 |
-
case "odbc":
|
| 73 |
-
case "odbcdsn":
|
| 74 |
-
case "custom":
|
| 75 |
-
case "file":
|
| 76 |
-
if( stripos($data["ODBCString"], 'Provider=') !== false )
|
| 77 |
-
{
|
| 78 |
-
include_once getabspath("connections/ADOConnection.php");
|
| 79 |
-
return new ADOConnection( $data );
|
| 80 |
-
}
|
| 81 |
-
|
| 82 |
-
include_once getabspath("connections/ODBCConnection.php");
|
| 83 |
-
return new ODBCConnection( $data );
|
| 84 |
-
|
| 85 |
-
case "oracle":
|
| 86 |
-
include_once getabspath("connections/OracleConnection.php");
|
| 87 |
-
return new OracleConnection( $data );
|
| 88 |
-
|
| 89 |
-
case "postgre":
|
| 90 |
-
include_once getabspath("connections/PostgreConnection.php");
|
| 91 |
-
return new PostgreConnection( $data );
|
| 92 |
-
|
| 93 |
-
case "db2":
|
| 94 |
-
include_once getabspath("connections/DB2Connection.php");
|
| 95 |
-
return new DB2Connection( $data );
|
| 96 |
-
|
| 97 |
-
case "informix":
|
| 98 |
-
include_once getabspath("connections/InformixConnection.php");
|
| 99 |
-
return new InformixConnection( $data );
|
| 100 |
-
|
| 101 |
-
case "sqlite":
|
| 102 |
-
include_once getabspath("connections/SQLite3Connection.php");
|
| 103 |
-
return new SQLite3Connection( $data );
|
| 104 |
-
case "pdo":
|
| 105 |
-
include_once getabspath("connections/PDOConnection.php");
|
| 106 |
-
return new PDOConnection( $data );
|
| 107 |
-
}
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
-
/**
|
| 111 |
-
* Set the data representing the project's
|
| 112 |
-
* db connection properties
|
| 113 |
-
*/
|
| 114 |
-
protected function _setConnectionsData()
|
| 115 |
-
{
|
| 116 |
-
// content of this function can be modified on demo account
|
| 117 |
-
// variable names $data and $connectionsData are important
|
| 118 |
-
|
| 119 |
-
$connectionsData = array();
|
| 120 |
-
|
| 121 |
-
$data = array();
|
| 122 |
-
$data["dbType"] = 4;
|
| 123 |
-
$data["connId"] = "KnowledgeBase2_at_localhost";
|
| 124 |
-
$data["connName"] = "KnowledgeBase2 at localhost";
|
| 125 |
-
$data["connStringType"] = "postgre";
|
| 126 |
-
$postgre_url = getenv("postgre_url");
|
| 127 |
-
$data["connectionString"] = $postgre_url; //currently unused
|
| 128 |
-
|
| 129 |
-
$this->_connectionsIdByName["KnowledgeBase2 at localhost"] = "KnowledgeBase2_at_localhost";
|
| 130 |
-
|
| 131 |
-
$data["connInfo"] = array();
|
| 132 |
-
$data["ODBCUID"] = "miyataken999";
|
| 133 |
-
$data["ODBCPWD"] = "";
|
| 134 |
-
$data["leftWrap"] = "\"";
|
| 135 |
-
$data["rightWrap"] = "\"";
|
| 136 |
-
|
| 137 |
-
$data["DBPath"] = "db"; //currently unused
|
| 138 |
-
$data["useServerMapPath"] = 1; //currently unused
|
| 139 |
-
|
| 140 |
-
$host="ep-odd-mode-93794521.us-east-2.aws.neon.tech";
|
| 141 |
-
$user="miyataken999";
|
| 142 |
-
$password="yz1wPf4KrWTm";
|
| 143 |
-
$options="options=endpoint=ep-odd-mode-93794521 port=5432";
|
| 144 |
-
$dbname="neondb";
|
| 145 |
-
$data["connInfo"][0] = $host;
|
| 146 |
-
$data["connInfo"][1] = $user;
|
| 147 |
-
$data["connInfo"][2] = $password;
|
| 148 |
-
$data["connInfo"][3] = $options;
|
| 149 |
-
$data["connInfo"][4] = $dbname;
|
| 150 |
-
;
|
| 151 |
-
// encription set
|
| 152 |
-
$data["EncryptInfo"] = array();
|
| 153 |
-
$data["EncryptInfo"]["mode"] = 0;
|
| 154 |
-
$data["EncryptInfo"]["alg"] = 128;
|
| 155 |
-
$data["EncryptInfo"]["key"] = "";
|
| 156 |
-
|
| 157 |
-
$connectionsData["KnowledgeBase2_at_localhost"] = $data;
|
| 158 |
-
$data = array();
|
| 159 |
-
$data["dbType"] = 4;
|
| 160 |
-
$data["connId"] = "neondbatuseast2awsneontech";
|
| 161 |
-
$data["connName"] = "neondb at us-east-2.aws.neon.t";
|
| 162 |
-
$data["connStringType"] = "postgre";
|
| 163 |
-
$data["connectionString"] = $postgre_url; //currently unused
|
| 164 |
-
|
| 165 |
-
$this->_connectionsIdByName["neondb at us-east-2.aws.neon.t"] = "neondbatuseast2awsneontech";
|
| 166 |
-
|
| 167 |
-
$data["connInfo"] = array();
|
| 168 |
-
$data["ODBCUID"] = "miyataken999";
|
| 169 |
-
$data["ODBCPWD"] = "";
|
| 170 |
-
$data["leftWrap"] = "\"";
|
| 171 |
-
$data["rightWrap"] = "\"";
|
| 172 |
-
|
| 173 |
-
$data["DBPath"] = "db"; //currently unused
|
| 174 |
-
$data["useServerMapPath"] = 1; //currently unused
|
| 175 |
-
|
| 176 |
-
$host="ep-odd-mode-93794521.us-east-2.aws.neon.tech";
|
| 177 |
-
$user="miyataken999";
|
| 178 |
-
$password="yz1wPf4KrWTm";
|
| 179 |
-
$options="options=endpoint=ep-odd-mode-93794521 port=5432";
|
| 180 |
-
$dbname="neondb";
|
| 181 |
-
$data["connInfo"][0] = $host;
|
| 182 |
-
$data["connInfo"][1] = $user;
|
| 183 |
-
$data["connInfo"][2] = $password;
|
| 184 |
-
$data["connInfo"][3] = $options;
|
| 185 |
-
$data["connInfo"][4] = $dbname;
|
| 186 |
-
;
|
| 187 |
-
// encription set
|
| 188 |
-
$data["EncryptInfo"] = array();
|
| 189 |
-
$data["EncryptInfo"]["mode"] = 0;
|
| 190 |
-
$data["EncryptInfo"]["alg"] = 256;
|
| 191 |
-
$data["EncryptInfo"]["key"] = "";
|
| 192 |
-
|
| 193 |
-
$connectionsData["neondbatuseast2awsneontech"] = $data;
|
| 194 |
-
$this->_connectionsData = &$connectionsData;
|
| 195 |
-
}
|
| 196 |
-
|
| 197 |
-
/**
|
| 198 |
-
* Close db connections
|
| 199 |
-
* @destructor
|
| 200 |
-
*/
|
| 201 |
-
function __desctruct()
|
| 202 |
-
{
|
| 203 |
-
$this->CloseConnections();
|
| 204 |
-
}
|
| 205 |
-
}
|
| 206 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/ConnectionManager_base.php
DELETED
|
@@ -1,303 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class ConnectionManager_Base
|
| 3 |
-
{
|
| 4 |
-
/**
|
| 5 |
-
* Cached Connection objects
|
| 6 |
-
* @type Array
|
| 7 |
-
*/
|
| 8 |
-
protected $cache = array();
|
| 9 |
-
|
| 10 |
-
/**
|
| 11 |
-
* Project connections data
|
| 12 |
-
* @type Array
|
| 13 |
-
*/
|
| 14 |
-
protected $_connectionsData;
|
| 15 |
-
|
| 16 |
-
/**
|
| 17 |
-
* Project connections data
|
| 18 |
-
* @type Array
|
| 19 |
-
*/
|
| 20 |
-
protected $_connectionsIdByName = array();
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
/**
|
| 24 |
-
* An array storing the correspondence between project
|
| 25 |
-
* datasource tables names and connections ids
|
| 26 |
-
* @type Array
|
| 27 |
-
*/
|
| 28 |
-
protected $_tablesConnectionIds;
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
/**
|
| 32 |
-
* @constructor
|
| 33 |
-
*/
|
| 34 |
-
function __construct()
|
| 35 |
-
{
|
| 36 |
-
$this->_setConnectionsData();
|
| 37 |
-
$this->_setTablesConnectionIds();
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
/**
|
| 41 |
-
* Get connection id by the table name
|
| 42 |
-
* @param String tName
|
| 43 |
-
* @return Connection
|
| 44 |
-
*/
|
| 45 |
-
public function getTableConnId( $tName )
|
| 46 |
-
{
|
| 47 |
-
return $this->_tablesConnectionIds[ $tName ];
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
/**
|
| 52 |
-
* Get connection object by the table name
|
| 53 |
-
* @param String tName
|
| 54 |
-
* @return Connection
|
| 55 |
-
*/
|
| 56 |
-
public function byTable( $tName )
|
| 57 |
-
{
|
| 58 |
-
$connId = $this->_tablesConnectionIds[ $tName ];
|
| 59 |
-
if( !$connId )
|
| 60 |
-
return $this->getDefault();
|
| 61 |
-
return $this->byId( $connId );
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
/**
|
| 65 |
-
* Get connection object by the connection name
|
| 66 |
-
* @param String connName
|
| 67 |
-
* @return Connection
|
| 68 |
-
*/
|
| 69 |
-
public function byName( $connName )
|
| 70 |
-
{
|
| 71 |
-
$connId = $this->getIdByName( $connName );
|
| 72 |
-
if( !$connId )
|
| 73 |
-
return $this->getDefault();
|
| 74 |
-
return $this->byId( $connId );
|
| 75 |
-
}
|
| 76 |
-
|
| 77 |
-
/**
|
| 78 |
-
* Get connection id by the connection name
|
| 79 |
-
* @param String connName
|
| 80 |
-
* @return String
|
| 81 |
-
*/
|
| 82 |
-
protected function getIdByName( $connName )
|
| 83 |
-
{
|
| 84 |
-
return $this->_connectionsIdByName[ $connName ];
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
/**
|
| 88 |
-
* Get connection object by the connection id
|
| 89 |
-
* @param String connId
|
| 90 |
-
* @return Connection
|
| 91 |
-
*/
|
| 92 |
-
public function byId( $connId )
|
| 93 |
-
{
|
| 94 |
-
if( !isset( $this->cache[ $connId ] ) ) {
|
| 95 |
-
$conn = $this->getConnection( $connId );
|
| 96 |
-
if( !$conn ) {
|
| 97 |
-
global $restApis;
|
| 98 |
-
$conn = $restApis->getConnection( $connId );
|
| 99 |
-
}
|
| 100 |
-
if( !$conn ) {
|
| 101 |
-
$conn = $this->getDefault();
|
| 102 |
-
}
|
| 103 |
-
$this->cache[ $connId ] = $conn;
|
| 104 |
-
}
|
| 105 |
-
|
| 106 |
-
return $this->cache[ $connId ];
|
| 107 |
-
}
|
| 108 |
-
|
| 109 |
-
/**
|
| 110 |
-
* Get the default db connection class
|
| 111 |
-
* @return Connection
|
| 112 |
-
*/
|
| 113 |
-
public function getDefault()
|
| 114 |
-
{
|
| 115 |
-
return $this->byId( "KnowledgeBase2_at_localhost" );
|
| 116 |
-
}
|
| 117 |
-
|
| 118 |
-
/**
|
| 119 |
-
* Get the default db connection id
|
| 120 |
-
* @return String
|
| 121 |
-
*/
|
| 122 |
-
public function getDefaultConnId()
|
| 123 |
-
{
|
| 124 |
-
return "KnowledgeBase2_at_localhost";
|
| 125 |
-
}
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
/**
|
| 130 |
-
* Get the users table db connection
|
| 131 |
-
* @return Connection
|
| 132 |
-
*/
|
| 133 |
-
public function getForLogin() {
|
| 134 |
-
return $this->byId( $this->getLoginConnId() );
|
| 135 |
-
}
|
| 136 |
-
|
| 137 |
-
public function getLoginConnId() {
|
| 138 |
-
$db = &Security::dbProvider();
|
| 139 |
-
if( $db ) {
|
| 140 |
-
return $db["table"]["connId"];
|
| 141 |
-
}
|
| 142 |
-
return "";
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
/**
|
| 147 |
-
* Get the log table db connection
|
| 148 |
-
* @return Connection
|
| 149 |
-
*/
|
| 150 |
-
public function getForAudit()
|
| 151 |
-
{
|
| 152 |
-
return $this->byId( "KnowledgeBase2_at_localhost" );
|
| 153 |
-
}
|
| 154 |
-
|
| 155 |
-
/**
|
| 156 |
-
* Get the locking table db connection
|
| 157 |
-
* @return Connection
|
| 158 |
-
*/
|
| 159 |
-
public function getForLocking()
|
| 160 |
-
{
|
| 161 |
-
return $this->byId( "KnowledgeBase2_at_localhost" );
|
| 162 |
-
}
|
| 163 |
-
|
| 164 |
-
/**
|
| 165 |
-
* Get the 'ug_groups' table db connection
|
| 166 |
-
* @return Connection
|
| 167 |
-
*/
|
| 168 |
-
public function getForUserGroups() {
|
| 169 |
-
return $this->byId( $this->getUserGroupsConnId() );
|
| 170 |
-
}
|
| 171 |
-
|
| 172 |
-
public function getUserGroupsConnId() {
|
| 173 |
-
return "KnowledgeBase2_at_localhost";
|
| 174 |
-
}
|
| 175 |
-
|
| 176 |
-
/**
|
| 177 |
-
* Get the saved searches table db connection
|
| 178 |
-
* @return Connection
|
| 179 |
-
*/
|
| 180 |
-
public function getForSavedSearches()
|
| 181 |
-
{
|
| 182 |
-
return $this->byId( $this->getSavedSearchesConnId() );
|
| 183 |
-
}
|
| 184 |
-
|
| 185 |
-
/**
|
| 186 |
-
* Get the saved searches table db connection
|
| 187 |
-
* @return Connection
|
| 188 |
-
*/
|
| 189 |
-
public function getSavedSearchesConnId()
|
| 190 |
-
{
|
| 191 |
-
return "KnowledgeBase2_at_localhost";
|
| 192 |
-
}
|
| 193 |
-
|
| 194 |
-
/**
|
| 195 |
-
* Get the webreports tables db connection
|
| 196 |
-
* @return Connection
|
| 197 |
-
*/
|
| 198 |
-
public function getForWebReports()
|
| 199 |
-
{
|
| 200 |
-
return $this->byId( $this->getSavedSearchesConnId() );
|
| 201 |
-
}
|
| 202 |
-
|
| 203 |
-
/**
|
| 204 |
-
* Get the webreports tables db connection id
|
| 205 |
-
* @return String
|
| 206 |
-
*/
|
| 207 |
-
public function getWebReportsConnId() {
|
| 208 |
-
return "KnowledgeBase2_at_localhost";
|
| 209 |
-
}
|
| 210 |
-
|
| 211 |
-
/**
|
| 212 |
-
* @param String connId
|
| 213 |
-
* @return Connection
|
| 214 |
-
*/
|
| 215 |
-
protected function getConnection( $connId )
|
| 216 |
-
{
|
| 217 |
-
return false;
|
| 218 |
-
}
|
| 219 |
-
|
| 220 |
-
public function getConectionsIds()
|
| 221 |
-
{
|
| 222 |
-
$connectionsIds = array();
|
| 223 |
-
foreach ($this->_connectionsData as $connId => $data) {
|
| 224 |
-
$connectionsIds[] = $connId;
|
| 225 |
-
}
|
| 226 |
-
|
| 227 |
-
return $connectionsIds;
|
| 228 |
-
}
|
| 229 |
-
|
| 230 |
-
/**
|
| 231 |
-
* Set the data representing the project's
|
| 232 |
-
* db connection properties
|
| 233 |
-
*/
|
| 234 |
-
protected function _setConnectionsData()
|
| 235 |
-
{
|
| 236 |
-
return null;
|
| 237 |
-
}
|
| 238 |
-
|
| 239 |
-
/**
|
| 240 |
-
* Set the data representing the correspondence between
|
| 241 |
-
* the project's table names and db connections
|
| 242 |
-
*/
|
| 243 |
-
protected function _setTablesConnectionIds()
|
| 244 |
-
{
|
| 245 |
-
$connectionsIds = array();
|
| 246 |
-
$connectionsIds["kbarticles"] = "KnowledgeBase2_at_localhost";
|
| 247 |
-
$connectionsIds["kbcategories"] = "KnowledgeBase2_at_localhost";
|
| 248 |
-
$connectionsIds["kbcomments"] = "KnowledgeBase2_at_localhost";
|
| 249 |
-
$connectionsIds["public.kbusers"] = "KnowledgeBase2_at_localhost";
|
| 250 |
-
$connectionsIds["main"] = "KnowledgeBase2_at_localhost";
|
| 251 |
-
$connectionsIds["faicons"] = "KnowledgeBase2_at_localhost";
|
| 252 |
-
$connectionsIds["admin_comments"] = "KnowledgeBase2_at_localhost";
|
| 253 |
-
$connectionsIds["public.fasis_chat_history"] = "KnowledgeBase2_at_localhost";
|
| 254 |
-
$connectionsIds["public.diamondprice"] = "KnowledgeBase2_at_localhost";
|
| 255 |
-
$connectionsIds["public.products"] = "KnowledgeBase2_at_localhost";
|
| 256 |
-
$connectionsIds["public.items"] = "KnowledgeBase2_at_localhost";
|
| 257 |
-
$connectionsIds["public.appointments"] = "KnowledgeBase2_at_localhost";
|
| 258 |
-
$connectionsIds["chat_history"] = "KnowledgeBase2_at_localhost";
|
| 259 |
-
$connectionsIds["chat_users"] = "KnowledgeBase2_at_localhost";
|
| 260 |
-
$connectionsIds["chat_settings"] = "KnowledgeBase2_at_localhost";
|
| 261 |
-
$connectionsIds["chat_files"] = "KnowledgeBase2_at_localhost";
|
| 262 |
-
$connectionsIds["chat_groups"] = "KnowledgeBase2_at_localhost";
|
| 263 |
-
$connectionsIds["chat_peopletype"] = "KnowledgeBase2_at_localhost";
|
| 264 |
-
$connectionsIds["chat_timezone"] = "KnowledgeBase2_at_localhost";
|
| 265 |
-
|
| 266 |
-
$this->_tablesConnectionIds = &$connectionsIds;
|
| 267 |
-
}
|
| 268 |
-
|
| 269 |
-
/**
|
| 270 |
-
* Check if It's possible to add to one table's sql query
|
| 271 |
-
* an sql subquery to another table.
|
| 272 |
-
* Access doesn't support subqueries from the same table as main.
|
| 273 |
-
* @param String dataSourceTName1
|
| 274 |
-
* @param String dataSourceTName2
|
| 275 |
-
* @return Boolean
|
| 276 |
-
*/
|
| 277 |
-
public function checkTablesSubqueriesSupport( $dataSourceTName1, $dataSourceTName2 )
|
| 278 |
-
{
|
| 279 |
-
$connId1 = $this->_tablesConnectionIds[ $dataSourceTName1 ];
|
| 280 |
-
$connId2 = $this->_tablesConnectionIds[ $dataSourceTName2 ];
|
| 281 |
-
|
| 282 |
-
if( $connId1 != $connId2 )
|
| 283 |
-
return false;
|
| 284 |
-
|
| 285 |
-
if( $this->_connectionsData[ $connId1 ]["dbType"] == nDATABASE_Access && $dataSourceTName1 == $dataSourceTName2 )
|
| 286 |
-
return false;
|
| 287 |
-
|
| 288 |
-
return true;
|
| 289 |
-
}
|
| 290 |
-
|
| 291 |
-
/**
|
| 292 |
-
* Close db connections
|
| 293 |
-
*/
|
| 294 |
-
function CloseConnections()
|
| 295 |
-
{
|
| 296 |
-
foreach( $this->cache as $connection )
|
| 297 |
-
{
|
| 298 |
-
if( $connection )
|
| 299 |
-
$connection->close();
|
| 300 |
-
}
|
| 301 |
-
}
|
| 302 |
-
}
|
| 303 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/DB2Connection.php
DELETED
|
@@ -1,178 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class DB2Connection extends Connection
|
| 3 |
-
{
|
| 4 |
-
protected $host;
|
| 5 |
-
|
| 6 |
-
protected $user;
|
| 7 |
-
|
| 8 |
-
protected $pwd;
|
| 9 |
-
|
| 10 |
-
protected $port;
|
| 11 |
-
|
| 12 |
-
protected $dbname;
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
function __construct( $params )
|
| 16 |
-
{
|
| 17 |
-
parent::__construct( $params );
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
/**
|
| 21 |
-
* Set db connection's properties
|
| 22 |
-
* @param Array params
|
| 23 |
-
*/
|
| 24 |
-
protected function assignConnectionParams( $params )
|
| 25 |
-
{
|
| 26 |
-
parent::assignConnectionParams( $params );
|
| 27 |
-
|
| 28 |
-
$this->host = $params["connInfo"][0]; //strConnectInfo1
|
| 29 |
-
$this->port = $params["connInfo"][1]; //strConnectInfo2
|
| 30 |
-
$this->user = $params["connInfo"][2]; //strConnectInfo3
|
| 31 |
-
$this->pwd = $params["connInfo"][3]; //strConnectInfo4
|
| 32 |
-
$this->dbname = $params["connInfo"][4]; //strConnectInfo5
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
/**
|
| 36 |
-
* Open a connection to db
|
| 37 |
-
*/
|
| 38 |
-
public function connect()
|
| 39 |
-
{
|
| 40 |
-
$conn_string = "DATABASE=".$this->dbname.";HOSTNAME=".$this->host.";PORT=".$this->port.";PROTOCOL=TCPIP;UID=".$this->user.";PWD=".$this->pwd.";";
|
| 41 |
-
$this->conn = db2_connect($conn_string, '', '');
|
| 42 |
-
|
| 43 |
-
if( !$this->conn )
|
| 44 |
-
$this->triggerError( db2_conn_errormsg() );
|
| 45 |
-
|
| 46 |
-
return $this->conn;
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
/**
|
| 50 |
-
* Close the db connection
|
| 51 |
-
*/
|
| 52 |
-
public function close()
|
| 53 |
-
{
|
| 54 |
-
return db2_close( $this->conn );
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
/**
|
| 58 |
-
* Send an SQL query
|
| 59 |
-
* @param String sql
|
| 60 |
-
* @return Mixed
|
| 61 |
-
*/
|
| 62 |
-
public function query( $sql )
|
| 63 |
-
{
|
| 64 |
-
$this->debugInfo($sql);
|
| 65 |
-
|
| 66 |
-
$ret = db2_exec( $this->conn, $sql );
|
| 67 |
-
if( !$ret )
|
| 68 |
-
{
|
| 69 |
-
$this->triggerError(db2_stmt_errormsg());
|
| 70 |
-
return FALSE;
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
return new QueryResult( $this, $ret );
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
/**
|
| 77 |
-
* Execute an SQL query
|
| 78 |
-
* @param String sql
|
| 79 |
-
*/
|
| 80 |
-
public function exec( $sql )
|
| 81 |
-
{
|
| 82 |
-
$this->debugInfo($sql);
|
| 83 |
-
return db2_exec($this->conn, $sql);
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
-
/**
|
| 87 |
-
* Get a description of the last error
|
| 88 |
-
* @return String
|
| 89 |
-
*/
|
| 90 |
-
public function lastError()
|
| 91 |
-
{
|
| 92 |
-
return @db2_stmt_errormsg();
|
| 93 |
-
}
|
| 94 |
-
|
| 95 |
-
/**
|
| 96 |
-
* Get the auto generated id used in the last query
|
| 97 |
-
* @return Number
|
| 98 |
-
*/
|
| 99 |
-
public function getInsertedId($key = null, $table = null )
|
| 100 |
-
{
|
| 101 |
-
db2_last_insert_id( $this->conn );
|
| 102 |
-
}
|
| 103 |
-
|
| 104 |
-
/**
|
| 105 |
-
* Fetch a result row as an associative array
|
| 106 |
-
* @param Mixed qHanle The query handle
|
| 107 |
-
* @return Array
|
| 108 |
-
*/
|
| 109 |
-
public function fetch_array( $qHandle )
|
| 110 |
-
{
|
| 111 |
-
return db2_fetch_assoc($qHandle);
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
/**
|
| 115 |
-
* Fetch a result row as a numeric array
|
| 116 |
-
* @param Mixed qHanle The query handle
|
| 117 |
-
* @return Array
|
| 118 |
-
*/
|
| 119 |
-
public function fetch_numarray( $qHandle )
|
| 120 |
-
{
|
| 121 |
-
return db2_fetch_array($qHandle);
|
| 122 |
-
}
|
| 123 |
-
|
| 124 |
-
/**
|
| 125 |
-
* Free resources associated with a query result set
|
| 126 |
-
* @param Mixed qHanle The query handle
|
| 127 |
-
*/
|
| 128 |
-
public function closeQuery( $qHandle )
|
| 129 |
-
{
|
| 130 |
-
@db2_free_result($qHandle);
|
| 131 |
-
}
|
| 132 |
-
|
| 133 |
-
/**
|
| 134 |
-
* Get number of fields in a result
|
| 135 |
-
* @param Mixed qHanle The query handle
|
| 136 |
-
* @return Number
|
| 137 |
-
*/
|
| 138 |
-
public function num_fields( $qHandle )
|
| 139 |
-
{
|
| 140 |
-
return num_fields($qHandle);
|
| 141 |
-
}
|
| 142 |
-
|
| 143 |
-
/**
|
| 144 |
-
* Get the name of the specified field in a result
|
| 145 |
-
* @param Mixed qHanle The query handle
|
| 146 |
-
* @param Number offset
|
| 147 |
-
* @return String
|
| 148 |
-
*/
|
| 149 |
-
public function field_name( $qHandle, $offset )
|
| 150 |
-
{
|
| 151 |
-
return db2_field_name($qHandle, $offset);
|
| 152 |
-
}
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
/**
|
| 156 |
-
* Execute an SQL query with blob fields processing
|
| 157 |
-
* @param String sql
|
| 158 |
-
* @param Array blobs
|
| 159 |
-
* @param Array blobTypes
|
| 160 |
-
* @return Boolean
|
| 161 |
-
*/
|
| 162 |
-
public function execWithBlobProcessing( $sql, $blobs, $blobTypes = array(), $autoincField = null )
|
| 163 |
-
{
|
| 164 |
-
$stml = db2_prepare($this->conn, $sql);
|
| 165 |
-
|
| 166 |
-
$numblobs = 1;
|
| 167 |
-
foreach($blobs as $bfield)
|
| 168 |
-
{
|
| 169 |
-
db2_bind_param($stml, $numblobs, "bfield", DB2_BINARY, DB2_PARAM_IN);
|
| 170 |
-
$numblobs += 1;
|
| 171 |
-
}
|
| 172 |
-
|
| 173 |
-
$ret = @db2_execute( $stml );
|
| 174 |
-
db2_commit( $this->conn );
|
| 175 |
-
return $ret;
|
| 176 |
-
}
|
| 177 |
-
}
|
| 178 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/InformixConnection.php
DELETED
|
@@ -1,197 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class InformixConnection extends Connection
|
| 3 |
-
{
|
| 4 |
-
protected $host;
|
| 5 |
-
|
| 6 |
-
protected $user;
|
| 7 |
-
|
| 8 |
-
protected $pwd;
|
| 9 |
-
|
| 10 |
-
protected $dbname;
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
function __construct( $params )
|
| 14 |
-
{
|
| 15 |
-
parent::__construct( $params );
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
/**
|
| 19 |
-
* Set db connection's properties
|
| 20 |
-
* @param Array params
|
| 21 |
-
*/
|
| 22 |
-
protected function assignConnectionParams( $params )
|
| 23 |
-
{
|
| 24 |
-
parent::assignConnectionParams( $params );
|
| 25 |
-
|
| 26 |
-
$this->host = $params["connInfo"][0]; //strConnectInfo1
|
| 27 |
-
$this->user = $params["connInfo"][1]; //strConnectInfo2
|
| 28 |
-
$this->pwd = $params["connInfo"][2]; //strConnectInfo3
|
| 29 |
-
$this->dbname =$params["connInfo"][3] ; //strConnectInfo4
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
/**
|
| 33 |
-
* Open a connection to db
|
| 34 |
-
*/
|
| 35 |
-
public function connect()
|
| 36 |
-
{
|
| 37 |
-
$this->conn = ifx_connect($this->dbname."@".$this->host, $this->user, $this->pwd);
|
| 38 |
-
if( !$this->conn )
|
| 39 |
-
$this->triggerError(ifx_errormsg());
|
| 40 |
-
|
| 41 |
-
ifx_blobinfile_mode(0);
|
| 42 |
-
ifx_textasvarchar(1);
|
| 43 |
-
ifx_byteasvarchar(1);
|
| 44 |
-
return $this->conn;
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
/**
|
| 48 |
-
* Close the db connection
|
| 49 |
-
*/
|
| 50 |
-
public function close()
|
| 51 |
-
{
|
| 52 |
-
return ifx_close( $this->conn );
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
/**
|
| 56 |
-
* Send an SQL query
|
| 57 |
-
* @param String sql
|
| 58 |
-
* @return Mixed
|
| 59 |
-
*/
|
| 60 |
-
public function query( $sql )
|
| 61 |
-
{
|
| 62 |
-
$this->debugInfo($sql);
|
| 63 |
-
|
| 64 |
-
$ret = ifx_query($sql, $this->conn);
|
| 65 |
-
if( !$ret )
|
| 66 |
-
{
|
| 67 |
-
$this->triggerError(ifx_errormsg());
|
| 68 |
-
return FALSE;
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
return new QueryResult( $this, $ret );
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
/**
|
| 75 |
-
* Execute an SQL query
|
| 76 |
-
* @param String sql
|
| 77 |
-
*/
|
| 78 |
-
public function exec( $sql )
|
| 79 |
-
{
|
| 80 |
-
$this->debugInfo($sql);
|
| 81 |
-
return ifx_query($sql, $this->conn);
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
/**
|
| 85 |
-
* Get a description of the last error
|
| 86 |
-
* @return String
|
| 87 |
-
*/
|
| 88 |
-
public function lastError()
|
| 89 |
-
{
|
| 90 |
-
return @ifx_errormsg();
|
| 91 |
-
}
|
| 92 |
-
|
| 93 |
-
/**
|
| 94 |
-
* Get the auto generated id used in the last query
|
| 95 |
-
* @return Number
|
| 96 |
-
*/
|
| 97 |
-
public function getInsertedId($key = null, $table = null )
|
| 98 |
-
{
|
| 99 |
-
return 0;
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
/**
|
| 103 |
-
* Fetch a result row as an associative array
|
| 104 |
-
* @param Mixed qHanle The query handle
|
| 105 |
-
* @return Array
|
| 106 |
-
*/
|
| 107 |
-
public function fetch_array( $qHandle )
|
| 108 |
-
{
|
| 109 |
-
return ifx_fetch_row( $qHandle );
|
| 110 |
-
}
|
| 111 |
-
|
| 112 |
-
/**
|
| 113 |
-
* Fetch a result row as a numeric array
|
| 114 |
-
* @param Mixed qHanle The query handle
|
| 115 |
-
* @return Array
|
| 116 |
-
*/
|
| 117 |
-
public function fetch_numarray( $qHandle )
|
| 118 |
-
{
|
| 119 |
-
$res = array();
|
| 120 |
-
$col = 0;
|
| 121 |
-
foreach( ifx_fetch_row($qHandle) as $val )
|
| 122 |
-
{
|
| 123 |
-
$res[ $col ] = $val;
|
| 124 |
-
$col += $col;
|
| 125 |
-
}
|
| 126 |
-
return $res;
|
| 127 |
-
}
|
| 128 |
-
|
| 129 |
-
/**
|
| 130 |
-
* Free resources associated with a query result set
|
| 131 |
-
* @param Mixed qHanle The query handle
|
| 132 |
-
*/
|
| 133 |
-
public function closeQuery( $qHandle )
|
| 134 |
-
{
|
| 135 |
-
@ifx_free_result($qHandle);
|
| 136 |
-
}
|
| 137 |
-
|
| 138 |
-
/**
|
| 139 |
-
* Get number of fields in a result
|
| 140 |
-
* @param Mixed qHanle The query handle
|
| 141 |
-
* @return Number
|
| 142 |
-
*/
|
| 143 |
-
public function num_fields( $qHandle )
|
| 144 |
-
{
|
| 145 |
-
return ifx_num_fields($qHandle);
|
| 146 |
-
}
|
| 147 |
-
|
| 148 |
-
/**
|
| 149 |
-
* Get the name of the specified field in a result
|
| 150 |
-
* @param Mixed qHanle The query handle
|
| 151 |
-
* @param Number offset
|
| 152 |
-
* @return String
|
| 153 |
-
*/
|
| 154 |
-
public function field_name( $qHandle, $offset )
|
| 155 |
-
{
|
| 156 |
-
$count = 1;
|
| 157 |
-
foreach( ifx_fetch_row($qHandle) as $fname => $val )
|
| 158 |
-
{
|
| 159 |
-
if($count == $offset)
|
| 160 |
-
return $fname;
|
| 161 |
-
|
| 162 |
-
$count += $count; // ?
|
| 163 |
-
}
|
| 164 |
-
return "";
|
| 165 |
-
}
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
/**
|
| 169 |
-
* Execute an SQL query with blob fields processing
|
| 170 |
-
* @param String sql
|
| 171 |
-
* @param Array blobs
|
| 172 |
-
* @param Array blobTypes
|
| 173 |
-
* @return Boolean
|
| 174 |
-
*/
|
| 175 |
-
public function execWithBlobProcessing( $sql, $blobs, $blobTypes = array(), $autoincField = null )
|
| 176 |
-
{
|
| 177 |
-
if( !$blobs )
|
| 178 |
-
{
|
| 179 |
-
$this->exec( $sql );
|
| 180 |
-
return;
|
| 181 |
-
}
|
| 182 |
-
|
| 183 |
-
$blobidarray = array();
|
| 184 |
-
foreach($blobs as $fname => $fvalue)
|
| 185 |
-
{
|
| 186 |
-
if( IsTextType( $blobTypes[ $fname ] ) )
|
| 187 |
-
$blob_type = 1;
|
| 188 |
-
else
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/MSSQLSrvConnection.php
DELETED
|
@@ -1,295 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class MSSQLSrvConnection extends Connection
|
| 3 |
-
{
|
| 4 |
-
protected $host;
|
| 5 |
-
|
| 6 |
-
protected $user;
|
| 7 |
-
|
| 8 |
-
protected $pwd;
|
| 9 |
-
|
| 10 |
-
protected $dbname;
|
| 11 |
-
|
| 12 |
-
protected $options;
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
function __construct( $params )
|
| 16 |
-
{
|
| 17 |
-
parent::__construct( $params );
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
/**
|
| 21 |
-
* Set db connection's properties
|
| 22 |
-
* @param Array params
|
| 23 |
-
*/
|
| 24 |
-
protected function assignConnectionParams( $params )
|
| 25 |
-
{
|
| 26 |
-
parent::assignConnectionParams( $params );
|
| 27 |
-
|
| 28 |
-
$this->host = $params["connInfo"][0]; //strConnectInfo1
|
| 29 |
-
|
| 30 |
-
if( $params["connInfo"][2] == "SSPI" )
|
| 31 |
-
{
|
| 32 |
-
$this->dbname = $params["connInfo"][1]; //strConnectInfo2
|
| 33 |
-
$this->options = $params["connInfo"][2]; //strConnectInfo3
|
| 34 |
-
}
|
| 35 |
-
else
|
| 36 |
-
{
|
| 37 |
-
$this->user = $params["connInfo"][1]; //strConnectInfo2
|
| 38 |
-
$this->pwd = $params["connInfo"][2]; //strConnectInfo3
|
| 39 |
-
$this->dbname = $params["connInfo"][3]; //strConnectInfo4
|
| 40 |
-
}
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
/**
|
| 44 |
-
* handling errors
|
| 45 |
-
*/
|
| 46 |
-
protected function triggerErrorMSSQL()
|
| 47 |
-
{
|
| 48 |
-
$error = $this->lastError();
|
| 49 |
-
if( !strlen($error) )
|
| 50 |
-
$this->triggerError("Udefined MSSQL Server Error");
|
| 51 |
-
else
|
| 52 |
-
$this->triggerError($error);
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
/**
|
| 56 |
-
* Open a connection to db
|
| 57 |
-
*/
|
| 58 |
-
public function connect()
|
| 59 |
-
{
|
| 60 |
-
$connectionInfo = array("Database" => $this->dbname, "PWD" => $this->pwd, "UID" => $this->user);
|
| 61 |
-
if( $this->options == "SSPI" )
|
| 62 |
-
$connectionInfo = array("Database" => $this->dbname );
|
| 63 |
-
$connectionInfo["TrustServerCertificate"] = true;
|
| 64 |
-
$this->conn = sqlsrv_connect($this->host, $connectionInfo);
|
| 65 |
-
|
| 66 |
-
if( !$this->conn )
|
| 67 |
-
$this->triggerErrorMSSQL();
|
| 68 |
-
|
| 69 |
-
return $this->conn;
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
/**
|
| 73 |
-
* Close the db connection
|
| 74 |
-
*/
|
| 75 |
-
public function close()
|
| 76 |
-
{
|
| 77 |
-
return sqlsrv_close( $this->conn );
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
/**
|
| 81 |
-
* Send an SQL query
|
| 82 |
-
* @param String sql
|
| 83 |
-
* @return Mixed
|
| 84 |
-
*/
|
| 85 |
-
public function query( $sql )
|
| 86 |
-
{
|
| 87 |
-
$this->debugInfo($sql);
|
| 88 |
-
$ret = sqlsrv_query($this->conn, $sql);
|
| 89 |
-
|
| 90 |
-
if( !$ret )
|
| 91 |
-
{
|
| 92 |
-
$this->triggerErrorMSSQL();
|
| 93 |
-
return FALSE;
|
| 94 |
-
}
|
| 95 |
-
|
| 96 |
-
return new QueryResult( $this, $ret );
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
/**
|
| 100 |
-
* Execute an SQL query
|
| 101 |
-
* @param String sql
|
| 102 |
-
*/
|
| 103 |
-
public function exec( $sql )
|
| 104 |
-
{
|
| 105 |
-
$this->debugInfo($sql);
|
| 106 |
-
$ret = sqlsrv_query($this->conn, $sql);
|
| 107 |
-
|
| 108 |
-
if( $ret === false )
|
| 109 |
-
$this->triggerErrorMSSQL();
|
| 110 |
-
return $ret;
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
/**
|
| 114 |
-
* Get the auto generated id used in the last query
|
| 115 |
-
* @return Number
|
| 116 |
-
*/
|
| 117 |
-
public function getInsertedId($key = null, $table = null )
|
| 118 |
-
{
|
| 119 |
-
$qResult = $this->query( "select SCOPE_IDENTITY() as indent" );
|
| 120 |
-
if( $qResult )
|
| 121 |
-
{
|
| 122 |
-
$row = $qResult->fetchAssoc();
|
| 123 |
-
return $row["indent"];
|
| 124 |
-
}
|
| 125 |
-
return 0;
|
| 126 |
-
}
|
| 127 |
-
|
| 128 |
-
/**
|
| 129 |
-
* Fetch a result row as an associative array
|
| 130 |
-
* @param Mixed qHanle The query handle
|
| 131 |
-
* @return Array
|
| 132 |
-
*/
|
| 133 |
-
public function fetch_array( $qHandle )
|
| 134 |
-
{
|
| 135 |
-
$rowArray = array();
|
| 136 |
-
$metaData = sqlsrv_field_metadata($qHandle);
|
| 137 |
-
$fetchRes = sqlsrv_fetch($qHandle);
|
| 138 |
-
|
| 139 |
-
if( $fetchRes === false )
|
| 140 |
-
{
|
| 141 |
-
$this->triggerErrorMSSQL();
|
| 142 |
-
return $rowArray;
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
-
if( is_null($fetchRes) )
|
| 146 |
-
return $rowArray;
|
| 147 |
-
|
| 148 |
-
$j = 0;
|
| 149 |
-
foreach($metaData as $fieldMetadata)
|
| 150 |
-
{
|
| 151 |
-
$rowArray[ $fieldMetadata['Name'] ] = $this->processFieldValue( $qHandle, $j, $fieldMetadata );
|
| 152 |
-
$j++;
|
| 153 |
-
}
|
| 154 |
-
return $rowArray;
|
| 155 |
-
}
|
| 156 |
-
|
| 157 |
-
/**
|
| 158 |
-
* return $j-number field value from the current record of the recordset
|
| 159 |
-
*/
|
| 160 |
-
function processFieldValue( $qHandle, $j, $fieldMetadata ) {
|
| 161 |
-
switch( $fieldMetadata['Type'] )
|
| 162 |
-
{
|
| 163 |
-
//dateTime
|
| 164 |
-
// Date
|
| 165 |
-
case 93:
|
| 166 |
-
case 91:
|
| 167 |
-
case -154: // for type Time
|
| 168 |
-
$fieldVal = sqlsrv_get_field( $qHandle, $j, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR) );
|
| 169 |
-
$pointPosition = strrpos($fieldVal, ".");
|
| 170 |
-
if ( $pointPosition ) {
|
| 171 |
-
$fieldVal = substr( $fieldVal, 0, $pointPosition );
|
| 172 |
-
}
|
| 173 |
-
return $fieldVal;
|
| 174 |
-
break;
|
| 175 |
-
// image
|
| 176 |
-
case -4:
|
| 177 |
-
case -3:
|
| 178 |
-
$fieldVal = sqlsrv_get_field( $qHandle, $j, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY) );
|
| 179 |
-
$buffer = null;
|
| 180 |
-
while( !feof($fieldVal) ) {
|
| 181 |
-
$buffer.= fgets($fieldVal, 4096);
|
| 182 |
-
}
|
| 183 |
-
fclose($fieldVal);
|
| 184 |
-
return $buffer;
|
| 185 |
-
break;
|
| 186 |
-
// ntext
|
| 187 |
-
case -10:
|
| 188 |
-
case -9:
|
| 189 |
-
// text
|
| 190 |
-
case -1:
|
| 191 |
-
$fieldVal = sqlsrv_get_field( $qHandle, $j, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR) );
|
| 192 |
-
$buffer = null;
|
| 193 |
-
while( !feof($fieldVal) ) {
|
| 194 |
-
$buffer.= fgets($fieldVal, 4096);
|
| 195 |
-
}
|
| 196 |
-
fclose($fieldVal);
|
| 197 |
-
return $buffer;
|
| 198 |
-
break;
|
| 199 |
-
// need to check, maybe int data should be retrieved in another type
|
| 200 |
-
default:
|
| 201 |
-
return sqlsrv_get_field( $qHandle, $j );
|
| 202 |
-
}
|
| 203 |
-
|
| 204 |
-
}
|
| 205 |
-
|
| 206 |
-
/**
|
| 207 |
-
* Fetch a result row as a numeric array
|
| 208 |
-
* @param Mixed qHanle The query handle
|
| 209 |
-
* @return Array
|
| 210 |
-
*/
|
| 211 |
-
public function fetch_numarray( $qHandle )
|
| 212 |
-
{
|
| 213 |
-
$rowArray = array();
|
| 214 |
-
$metaData = sqlsrv_field_metadata($qHandle);
|
| 215 |
-
$fetchRes = sqlsrv_fetch($qHandle);
|
| 216 |
-
|
| 217 |
-
if( $fetchRes === false )
|
| 218 |
-
{
|
| 219 |
-
$this->triggerErrorMSSQL();
|
| 220 |
-
return $rowArray;
|
| 221 |
-
}
|
| 222 |
-
|
| 223 |
-
if( is_null($fetchRes) )
|
| 224 |
-
return $rowArray;
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
$j = 0;
|
| 228 |
-
foreach($metaData as $fieldMetadata)
|
| 229 |
-
{
|
| 230 |
-
$rowArray[] = $this->processFieldValue( $qHandle, $j, $fieldMetadata );
|
| 231 |
-
$j++;
|
| 232 |
-
}
|
| 233 |
-
|
| 234 |
-
return $rowArray;
|
| 235 |
-
}
|
| 236 |
-
|
| 237 |
-
/**
|
| 238 |
-
* Free resources associated with a query result set
|
| 239 |
-
* @param Mixed qHanle The query handle
|
| 240 |
-
*/
|
| 241 |
-
public function closeQuery( $qHandle )
|
| 242 |
-
{
|
| 243 |
-
@sqlsrv_free_stmt($qHandle);
|
| 244 |
-
}
|
| 245 |
-
|
| 246 |
-
/**
|
| 247 |
-
* Get number of fields in a result
|
| 248 |
-
* @param Mixed qHanle The query handle
|
| 249 |
-
* @return Number
|
| 250 |
-
*/
|
| 251 |
-
public function num_fields( $qHandle )
|
| 252 |
-
{
|
| 253 |
-
return @sqlsrv_num_fields($qHandle);
|
| 254 |
-
}
|
| 255 |
-
|
| 256 |
-
/**
|
| 257 |
-
* Get the name of the specified field in a result
|
| 258 |
-
* @param Mixed qHanle The query handle
|
| 259 |
-
* @param Number offset
|
| 260 |
-
* @return String
|
| 261 |
-
*/
|
| 262 |
-
public function field_name( $qHandle, $offset )
|
| 263 |
-
{
|
| 264 |
-
$metaData = @sqlsrv_field_metadata($qHandle);
|
| 265 |
-
|
| 266 |
-
if( $metaData !== false )
|
| 267 |
-
return $metaData[ $offset ]['Name'];
|
| 268 |
-
return "";
|
| 269 |
-
}
|
| 270 |
-
|
| 271 |
-
/**
|
| 272 |
-
* Execute an SQL query with blob fields processing
|
| 273 |
-
* @param String sql
|
| 274 |
-
* @param Array blobs
|
| 275 |
-
* @param Array blobTypes
|
| 276 |
-
* @return Boolean
|
| 277 |
-
*/
|
| 278 |
-
public function execWithBlobProcessing( $sql, $blobs, $blobTypes = array(), $autoincField = null )
|
| 279 |
-
{
|
| 280 |
-
$this->debugInfo($sql);
|
| 281 |
-
return @sqlsrv_query($this->conn, $sql);
|
| 282 |
-
}
|
| 283 |
-
|
| 284 |
-
function lastError() {
|
| 285 |
-
$errors = @sqlsrv_errors( SQLSRV_ERR_ERRORS );
|
| 286 |
-
if( !$errors )
|
| 287 |
-
return "";
|
| 288 |
-
$message = "";
|
| 289 |
-
foreach( $errors as $error ) {
|
| 290 |
-
$message .= @$error["code"] . " " . @$error["message"] . "<br>";
|
| 291 |
-
}
|
| 292 |
-
return $message;
|
| 293 |
-
}
|
| 294 |
-
}
|
| 295 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/MSSQLUnixConnection.php
DELETED
|
@@ -1,164 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class MSSQLUnixConnection extends Connection
|
| 3 |
-
{
|
| 4 |
-
protected $host;
|
| 5 |
-
|
| 6 |
-
protected $user;
|
| 7 |
-
|
| 8 |
-
protected $pwd;
|
| 9 |
-
|
| 10 |
-
protected $dbname;
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
function __construct( $params )
|
| 14 |
-
{
|
| 15 |
-
parent::__construct( $params );
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
/**
|
| 19 |
-
* Set db connection's properties
|
| 20 |
-
* @param Array params
|
| 21 |
-
*/
|
| 22 |
-
protected function assignConnectionParams( $params )
|
| 23 |
-
{
|
| 24 |
-
parent::assignConnectionParams( $params );
|
| 25 |
-
|
| 26 |
-
$this->host = $params["connInfo"][0]; //strConnectInfo1
|
| 27 |
-
$this->user = $params["connInfo"][1]; //strConnectInfo2
|
| 28 |
-
$this->pwd = $params["connInfo"][2]; //strConnectInfo3
|
| 29 |
-
$this->dbname = $params["connInfo"][3]; //strConnectInfo4
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
/**
|
| 33 |
-
* Open a connection to db
|
| 34 |
-
*/
|
| 35 |
-
public function connect()
|
| 36 |
-
{
|
| 37 |
-
$this->conn = mssql_connect( $this->host, $this->user, $this->pwd );
|
| 38 |
-
if( !$this->conn )
|
| 39 |
-
$this->triggerError( $this->lastError() );
|
| 40 |
-
|
| 41 |
-
mssql_select_db( $this->dbname, $this->conn );
|
| 42 |
-
return $this->conn;
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
/**
|
| 46 |
-
* Close the db connection
|
| 47 |
-
*/
|
| 48 |
-
public function close()
|
| 49 |
-
{
|
| 50 |
-
return mssql_close( $this->conn );
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
/**
|
| 54 |
-
* Send an SQL query
|
| 55 |
-
* @param String sql
|
| 56 |
-
* @return Mixed
|
| 57 |
-
*/
|
| 58 |
-
public function query( $sql )
|
| 59 |
-
{
|
| 60 |
-
$this->debugInfo($sql);
|
| 61 |
-
$ret = mssql_query( $sql, $this->conn );
|
| 62 |
-
if( !$ret )
|
| 63 |
-
{
|
| 64 |
-
$this->triggerError($this->lastError());
|
| 65 |
-
return FALSE;
|
| 66 |
-
}
|
| 67 |
-
|
| 68 |
-
return new QueryResult( $this, $ret );
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
/**
|
| 72 |
-
* Execute an SQL query
|
| 73 |
-
* @param String sql
|
| 74 |
-
*/
|
| 75 |
-
public function exec( $sql )
|
| 76 |
-
{
|
| 77 |
-
$this->debugInfo($sql);
|
| 78 |
-
return mssql_query( $sql, $this->conn );
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
/**
|
| 82 |
-
* Get a description of the last error
|
| 83 |
-
* @return String
|
| 84 |
-
*/
|
| 85 |
-
public function lastError()
|
| 86 |
-
{
|
| 87 |
-
return @mssql_get_last_message();
|
| 88 |
-
}
|
| 89 |
-
|
| 90 |
-
/**
|
| 91 |
-
* Fetch a result row as an associative array
|
| 92 |
-
* @param Mixed qHanle The query handle
|
| 93 |
-
* @return Array
|
| 94 |
-
*/
|
| 95 |
-
public function fetch_array( $qHandle )
|
| 96 |
-
{
|
| 97 |
-
return @mssql_fetch_array($qHandle, MSSQL_ASSOC);
|
| 98 |
-
}
|
| 99 |
-
|
| 100 |
-
/**
|
| 101 |
-
* Fetch a result row as a numeric array
|
| 102 |
-
* @param Mixed qHanle The query handle
|
| 103 |
-
* @return Array
|
| 104 |
-
*/
|
| 105 |
-
public function fetch_numarray( $qHandle )
|
| 106 |
-
{
|
| 107 |
-
return @mssql_fetch_array($qHandle, MSSQL_NUM);
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
-
/**
|
| 111 |
-
* Free resources associated with a query result set
|
| 112 |
-
* @param Mixed qHanle The query handle
|
| 113 |
-
*/
|
| 114 |
-
public function closeQuery( $qHandle )
|
| 115 |
-
{
|
| 116 |
-
@mssql_free_result($qHandle);
|
| 117 |
-
}
|
| 118 |
-
|
| 119 |
-
/**
|
| 120 |
-
* Get number of fields in a result
|
| 121 |
-
* @param Mixed qHanle The query handle
|
| 122 |
-
* @return Number
|
| 123 |
-
*/
|
| 124 |
-
public function num_fields( $qHandle )
|
| 125 |
-
{
|
| 126 |
-
return @mssql_num_fields( $qHandle );
|
| 127 |
-
}
|
| 128 |
-
|
| 129 |
-
/**
|
| 130 |
-
* Get the name of the specified field in a result
|
| 131 |
-
* @param Mixed qHanle The query handle
|
| 132 |
-
* @param Number offset
|
| 133 |
-
* @return String
|
| 134 |
-
*/
|
| 135 |
-
public function field_name( $qHandle, $offset )
|
| 136 |
-
{
|
| 137 |
-
return @mssql_field_name($qHandle, $offset);
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
/**
|
| 141 |
-
* @param Mixed qHandle
|
| 142 |
-
* @param Number pageSize
|
| 143 |
-
* @param Number page
|
| 144 |
-
*/
|
| 145 |
-
public function seekRecord($qHandle, $n)
|
| 146 |
-
{
|
| 147 |
-
if( $n > 0 )
|
| 148 |
-
mssql_data_seek( $qHandle, $n );
|
| 149 |
-
}
|
| 150 |
-
|
| 151 |
-
/**
|
| 152 |
-
* Execute an SQL query with blob fields processing
|
| 153 |
-
* @param String sql
|
| 154 |
-
* @param Array blobs
|
| 155 |
-
* @param Array blobTypes
|
| 156 |
-
* @return Boolean
|
| 157 |
-
*/
|
| 158 |
-
public function execWithBlobProcessing( $sql, $blobs, $blobTypes = array(), $autoincField = null )
|
| 159 |
-
{
|
| 160 |
-
$this->debugInfo($sql);
|
| 161 |
-
return @mssql_query( $sql, $this->conn );
|
| 162 |
-
}
|
| 163 |
-
}
|
| 164 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/MSSQLWinConnection.php
DELETED
|
@@ -1,320 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class MSSQLWinConnection extends Connection
|
| 3 |
-
{
|
| 4 |
-
protected $host;
|
| 5 |
-
|
| 6 |
-
protected $dbname;
|
| 7 |
-
|
| 8 |
-
protected $user = "";
|
| 9 |
-
|
| 10 |
-
protected $pwd = "";
|
| 11 |
-
|
| 12 |
-
protected $options = "";
|
| 13 |
-
|
| 14 |
-
protected $ODBCString;
|
| 15 |
-
|
| 16 |
-
/**
|
| 17 |
-
* A date format string
|
| 18 |
-
* @type String
|
| 19 |
-
*/
|
| 20 |
-
protected $mssql_dmy;
|
| 21 |
-
|
| 22 |
-
protected $errExeprionMess = "";
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
function __construct( $params )
|
| 26 |
-
{
|
| 27 |
-
parent::__construct( $params );
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
/**
|
| 31 |
-
* Set db connection's properties
|
| 32 |
-
* @param Array params
|
| 33 |
-
*/
|
| 34 |
-
protected function assignConnectionParams( $params )
|
| 35 |
-
{
|
| 36 |
-
parent::assignConnectionParams( $params );
|
| 37 |
-
|
| 38 |
-
$this->ODBCString = $params["ODBCString"];
|
| 39 |
-
$this->host = $params["connInfo"][0]; //strConnectInfo1
|
| 40 |
-
|
| 41 |
-
if( $params["connInfo"][2] == "SSPI" )
|
| 42 |
-
{
|
| 43 |
-
$this->dbname = $params["connInfo"][1]; //strConnectInfo2
|
| 44 |
-
$this->options = $params["connInfo"][2]; //strConnectInfo3
|
| 45 |
-
}
|
| 46 |
-
else
|
| 47 |
-
{
|
| 48 |
-
$this->user = $params["connInfo"][1]; //strConnectInfo2
|
| 49 |
-
$this->pwd = $params["connInfo"][2]; //strConnectInfo3
|
| 50 |
-
$this->dbname = $params["connInfo"][3]; //strConnectInfo4
|
| 51 |
-
}
|
| 52 |
-
}
|
| 53 |
-
|
| 54 |
-
/**
|
| 55 |
-
* Open a connection to db
|
| 56 |
-
*/
|
| 57 |
-
public function connect()
|
| 58 |
-
{
|
| 59 |
-
global $cCodepage;
|
| 60 |
-
|
| 61 |
-
$connStrings = array();
|
| 62 |
-
if( $_SESSION["MSSQLConnString"] )
|
| 63 |
-
$connStrings[] = $_SESSION["SQLConnString"];
|
| 64 |
-
|
| 65 |
-
$connStrings[] = $this->ODBCString;
|
| 66 |
-
$providers = array( "MSOLEDBSQL", "SQLOLEDB", "SQLNCLI" );
|
| 67 |
-
foreach( $providers as $p ) {
|
| 68 |
-
if( $options == "SSPI" )
|
| 69 |
-
$connStrings[] = "PROVIDER=".$p.";SERVER=".$this->host.";DATABASE=".$this->dbname.";Integrated Security=SSPI";
|
| 70 |
-
else
|
| 71 |
-
$connStrings[] = "PROVIDER=".$p.";SERVER=".$this->host.";UID=".$this->user.";PWD=".$this->pwd.";DATABASE=".$this->dbname;
|
| 72 |
-
}
|
| 73 |
-
// go thru connection strings one by one
|
| 74 |
-
$errorString = "";
|
| 75 |
-
foreach($connStrings as $connStr)
|
| 76 |
-
{
|
| 77 |
-
try
|
| 78 |
-
{
|
| 79 |
-
$this->conn = new COM("ADODB.Connection", NULL, $cCodepage);
|
| 80 |
-
$this->conn->Open( $connStr );
|
| 81 |
-
$rs = $this->conn->Execute("select convert(datetime,'2000-11-22',121)");
|
| 82 |
-
|
| 83 |
-
$str = $rs->Fields[0]->Value;
|
| 84 |
-
$y = strpos($str, "2000");
|
| 85 |
-
$m = strpos($str, "11");
|
| 86 |
-
$d = strpos($str, "22");
|
| 87 |
-
|
| 88 |
-
$this->mssql_dmy = "mdy";
|
| 89 |
-
if( $y < $m && $m < $d )
|
| 90 |
-
$this->mssql_dmy = "ymd";
|
| 91 |
-
if( $d < $m && $m < $y )
|
| 92 |
-
$this->mssql_dmy = "dmy";
|
| 93 |
-
|
| 94 |
-
$_SESSION["MSSQLConnString"] = $connStr;
|
| 95 |
-
$this->conn->CommandTimeout = 120;
|
| 96 |
-
return $this->conn;
|
| 97 |
-
}
|
| 98 |
-
catch(com_exception $e)
|
| 99 |
-
{
|
| 100 |
-
$errorString .= "<br>".$e->getMessage();
|
| 101 |
-
}
|
| 102 |
-
}
|
| 103 |
-
$this->triggerError($errorString);
|
| 104 |
-
}
|
| 105 |
-
|
| 106 |
-
/**
|
| 107 |
-
* Close the db connection
|
| 108 |
-
*/
|
| 109 |
-
public function close()
|
| 110 |
-
{
|
| 111 |
-
$this->conn->Close();
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
/**
|
| 115 |
-
* Send an SQL query
|
| 116 |
-
* @param String sql
|
| 117 |
-
* @return Mixed
|
| 118 |
-
*/
|
| 119 |
-
public function query( $sql )
|
| 120 |
-
{
|
| 121 |
-
$this->debugInfo($sql);
|
| 122 |
-
|
| 123 |
-
try
|
| 124 |
-
{
|
| 125 |
-
$qHandle = $this->conn->Execute( $sql );
|
| 126 |
-
return new QueryResult( $this, $qHandle );
|
| 127 |
-
}
|
| 128 |
-
catch(com_exception $e)
|
| 129 |
-
{
|
| 130 |
-
$this->triggerError($e->getMessage());
|
| 131 |
-
return FALSE;
|
| 132 |
-
}
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
/**
|
| 136 |
-
* Execute an SQL query
|
| 137 |
-
* @param String sql
|
| 138 |
-
*/
|
| 139 |
-
public function exec( $sql )
|
| 140 |
-
{
|
| 141 |
-
$qResult = $this->query( $sql );
|
| 142 |
-
if( $qResult )
|
| 143 |
-
return $qResult->getQueryHandle();
|
| 144 |
-
|
| 145 |
-
return FALSE;
|
| 146 |
-
}
|
| 147 |
-
|
| 148 |
-
/**
|
| 149 |
-
* Get a description of the last error
|
| 150 |
-
* @return String
|
| 151 |
-
*/
|
| 152 |
-
public function lastError()
|
| 153 |
-
{
|
| 154 |
-
if( $this->conn->Errors->Count )
|
| 155 |
-
{
|
| 156 |
-
$errors = array();
|
| 157 |
-
for( $i=0; $i < $this->conn->Errors->Count; ++$i ) {
|
| 158 |
-
$errors[] = $this->conn->Errors[ $i ]->Description;
|
| 159 |
-
}
|
| 160 |
-
return implode( ' ', $errors );
|
| 161 |
-
}
|
| 162 |
-
|
| 163 |
-
return '';
|
| 164 |
-
}
|
| 165 |
-
|
| 166 |
-
/**
|
| 167 |
-
* Fetch a result row as an array
|
| 168 |
-
* @param Mixed qHanle The query handle
|
| 169 |
-
* @param Number assoc (optional)
|
| 170 |
-
* @return Array
|
| 171 |
-
*/
|
| 172 |
-
protected function _fetch_array($qHandle, $assoc = 1)
|
| 173 |
-
{
|
| 174 |
-
$ret = array();
|
| 175 |
-
|
| 176 |
-
if( $qHandle->EOF() )
|
| 177 |
-
return $ret;
|
| 178 |
-
|
| 179 |
-
try {
|
| 180 |
-
for( $i = 0; $i < $this->num_fields($qHandle); $i++ )
|
| 181 |
-
{
|
| 182 |
-
if( IsBinaryType( $qHandle->Fields[$i]->Type ) && $qHandle->Fields[$i]->Type != 128 )
|
| 183 |
-
{
|
| 184 |
-
$str = "";
|
| 185 |
-
if( $qHandle->Fields[$i]->ActualSize )
|
| 186 |
-
{
|
| 187 |
-
$val = $qHandle->Fields[$i]->GetChunk( $qHandle->Fields[$i]->ActualSize );
|
| 188 |
-
$str = str_pad("", count($val));
|
| 189 |
-
$j = 0;
|
| 190 |
-
foreach($val as $byte)
|
| 191 |
-
{
|
| 192 |
-
$str[ $j++ ] = chr($byte);
|
| 193 |
-
}
|
| 194 |
-
}
|
| 195 |
-
|
| 196 |
-
if( $assoc )
|
| 197 |
-
$ret[ $qHandle->Fields[$i]->Name ] = $str;
|
| 198 |
-
else
|
| 199 |
-
$ret[ $i ] = $str;
|
| 200 |
-
}
|
| 201 |
-
else
|
| 202 |
-
{
|
| 203 |
-
$value = $qHandle->Fields[$i]->Value;
|
| 204 |
-
if( is_null($value) )
|
| 205 |
-
$val = NULL;
|
| 206 |
-
else
|
| 207 |
-
{
|
| 208 |
-
if( isdatefieldtype($qHandle->Fields[$i]->Type) )
|
| 209 |
-
$value = localdatetime2db( (string)$qHandle->Fields[$i]->Value, $this->mssql_dmy );
|
| 210 |
-
if( IsNumberType($qHandle->Fields[$i]->Type) )
|
| 211 |
-
$val = floatval($value);
|
| 212 |
-
else
|
| 213 |
-
$val = strval($value);
|
| 214 |
-
}
|
| 215 |
-
if( $assoc )
|
| 216 |
-
$ret[ $qHandle->Fields[$i]->Name ] = $val;
|
| 217 |
-
else
|
| 218 |
-
$ret[ $i ] = $val;
|
| 219 |
-
}
|
| 220 |
-
}
|
| 221 |
-
$qHandle->MoveNext();
|
| 222 |
-
}
|
| 223 |
-
catch(com_exception $e)
|
| 224 |
-
{
|
| 225 |
-
$this->triggerError( $e->getMessage() );
|
| 226 |
-
}
|
| 227 |
-
|
| 228 |
-
return $ret;
|
| 229 |
-
}
|
| 230 |
-
|
| 231 |
-
/**
|
| 232 |
-
* Fetch a result row as an associative array
|
| 233 |
-
* @param Mixed qHanle The query handle
|
| 234 |
-
* @return Array
|
| 235 |
-
*/
|
| 236 |
-
public function fetch_array( $qHandle )
|
| 237 |
-
{
|
| 238 |
-
return $this->_fetch_array( $qHandle );
|
| 239 |
-
}
|
| 240 |
-
|
| 241 |
-
/**
|
| 242 |
-
* Fetch a result row as a numeric array
|
| 243 |
-
* @param Mixed qHanle The query handle
|
| 244 |
-
* @return Array
|
| 245 |
-
*/
|
| 246 |
-
public function fetch_numarray( $qHandle )
|
| 247 |
-
{
|
| 248 |
-
return $this->_fetch_array( $qHandle, 0 );
|
| 249 |
-
}
|
| 250 |
-
|
| 251 |
-
/**
|
| 252 |
-
* Free resources associated with a query result set
|
| 253 |
-
* @param Mixed qHanle The query handle
|
| 254 |
-
*/
|
| 255 |
-
public function closeQuery( $qHandle )
|
| 256 |
-
{
|
| 257 |
-
$qHandle->Close();
|
| 258 |
-
}
|
| 259 |
-
|
| 260 |
-
/**
|
| 261 |
-
* Get number of fields in a result
|
| 262 |
-
* @param Mixed qHanle The query handle
|
| 263 |
-
* @return Number
|
| 264 |
-
*/
|
| 265 |
-
public function num_fields( $qHandle )
|
| 266 |
-
{
|
| 267 |
-
return $qHandle->Fields->Count;
|
| 268 |
-
}
|
| 269 |
-
|
| 270 |
-
/**
|
| 271 |
-
* Get the name of the specified field in a result
|
| 272 |
-
* @param Mixed qHanle The query handle
|
| 273 |
-
* @param Number offset
|
| 274 |
-
* @return String
|
| 275 |
-
*/
|
| 276 |
-
public function field_name( $qHandle, $offset )
|
| 277 |
-
{
|
| 278 |
-
return $qHandle->Fields($offset)->Name;
|
| 279 |
-
}
|
| 280 |
-
|
| 281 |
-
/**
|
| 282 |
-
* @param Mixed qHandle
|
| 283 |
-
* @param Number pageSize
|
| 284 |
-
* @param Number page
|
| 285 |
-
*/
|
| 286 |
-
public function seekRecord($qHandle, $n)
|
| 287 |
-
{
|
| 288 |
-
if( !$n )
|
| 289 |
-
return;
|
| 290 |
-
|
| 291 |
-
if( $qHandle->EOF() )
|
| 292 |
-
return;
|
| 293 |
-
|
| 294 |
-
$qHandle->Move( $n );
|
| 295 |
-
}
|
| 296 |
-
|
| 297 |
-
/**
|
| 298 |
-
* Execute an SQL query with blob fields processing
|
| 299 |
-
* @param String sql
|
| 300 |
-
* @param Array blobs
|
| 301 |
-
* @param Array blobTypes
|
| 302 |
-
* @return Boolean
|
| 303 |
-
*/
|
| 304 |
-
public function execWithBlobProcessing( $sql, $blobs, $blobTypes = array(), $autoincField = null )
|
| 305 |
-
{
|
| 306 |
-
$this->debugInfo($sql);
|
| 307 |
-
|
| 308 |
-
try
|
| 309 |
-
{
|
| 310 |
-
$this->conn->Execute( $sql );
|
| 311 |
-
return true;
|
| 312 |
-
}
|
| 313 |
-
catch(com_exception $e)
|
| 314 |
-
{
|
| 315 |
-
$this->errExeprionMess = $e->getMessage();
|
| 316 |
-
return false;
|
| 317 |
-
}
|
| 318 |
-
}
|
| 319 |
-
}
|
| 320 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/MySQLConnection.php
DELETED
|
@@ -1,277 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class MySQLConnection extends Connection
|
| 3 |
-
{
|
| 4 |
-
protected $host;
|
| 5 |
-
|
| 6 |
-
protected $user;
|
| 7 |
-
|
| 8 |
-
protected $pwd;
|
| 9 |
-
|
| 10 |
-
protected $sys_dbname;
|
| 11 |
-
|
| 12 |
-
protected $port;
|
| 13 |
-
|
| 14 |
-
protected $mysqlVersion;
|
| 15 |
-
|
| 16 |
-
protected $subqueriesSupported = true;
|
| 17 |
-
|
| 18 |
-
function __construct( $params )
|
| 19 |
-
{
|
| 20 |
-
parent::__construct( $params );
|
| 21 |
-
}
|
| 22 |
-
|
| 23 |
-
/**
|
| 24 |
-
* Set db connection's properties
|
| 25 |
-
* @param Array params
|
| 26 |
-
*/
|
| 27 |
-
protected function assignConnectionParams( $params )
|
| 28 |
-
{
|
| 29 |
-
parent::assignConnectionParams( $params );
|
| 30 |
-
|
| 31 |
-
$this->host = $params["connInfo"][0]; //strConnectInfo1
|
| 32 |
-
$this->user = $params["connInfo"][1]; //strConnectInfo2
|
| 33 |
-
$this->pwd = $params["connInfo"][2]; //strConnectInfo3
|
| 34 |
-
$this->port = $params["connInfo"][3]; //strConnectInfo4
|
| 35 |
-
$this->sys_dbname = $params["connInfo"][4]; //strConnectInfo5
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
/**
|
| 39 |
-
* @return Array
|
| 40 |
-
*/
|
| 41 |
-
protected function getDbFunctionsExtraParams()
|
| 42 |
-
{
|
| 43 |
-
$extraParams = parent::getDbFunctionsExtraParams();
|
| 44 |
-
$extraParams["conn"] = $this->conn;
|
| 45 |
-
|
| 46 |
-
return $extraParams;
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
/**
|
| 50 |
-
* Open a connection to db
|
| 51 |
-
*/
|
| 52 |
-
public function connect()
|
| 53 |
-
{
|
| 54 |
-
global $cMySQLNames;
|
| 55 |
-
|
| 56 |
-
if( !$this->port )
|
| 57 |
-
$this->port = 3306;
|
| 58 |
-
$hosts = array();
|
| 59 |
-
// fix IPv6 slow connection issue
|
| 60 |
-
if( $this->host == "localhost" )
|
| 61 |
-
{
|
| 62 |
-
if( $_SESSION["myqsladdress"] )
|
| 63 |
-
$hosts[] = $_SESSION["myqsladdress"];
|
| 64 |
-
else
|
| 65 |
-
$hosts[] = "127.0.0.1";
|
| 66 |
-
}
|
| 67 |
-
$hosts[] = $this->host;
|
| 68 |
-
|
| 69 |
-
foreach( $hosts as $h )
|
| 70 |
-
{
|
| 71 |
-
$this->conn = @mysql_connect($h.":".$this->port, $this->user, $this->pwd);
|
| 72 |
-
if( $this->conn )
|
| 73 |
-
{
|
| 74 |
-
if( $this->host == "localhost" )
|
| 75 |
-
$_SESSION["myqsladdress"] = $h;
|
| 76 |
-
break;
|
| 77 |
-
}
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
if (!$this->conn || !mysql_select_db($this->sys_dbname, $this->conn))
|
| 81 |
-
{
|
| 82 |
-
unset( $_SESSION["myqsladdress"] );
|
| 83 |
-
$this->triggerError( mysql_error() );
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
-
if( $cMySQLNames != "" )
|
| 87 |
-
@mysql_query("set names ".$cMySQLNames);
|
| 88 |
-
|
| 89 |
-
$this->mysqlVersion = "4";
|
| 90 |
-
$res = @mysql_query("SHOW VARIABLES LIKE 'version'", $this->conn);
|
| 91 |
-
if( $row = @mysql_fetch_array($res, MYSQL_ASSOC) )
|
| 92 |
-
$this->mysqlVersion = $row["Value"];
|
| 93 |
-
|
| 94 |
-
if( preg_match("/^[0-4]\./", $this->mysqlVersion, $matches) && strpos($this->mysqlVersion, "MariaDB") === FALSE ) //#10818 2
|
| 95 |
-
$this->subqueriesSupported = false;
|
| 96 |
-
|
| 97 |
-
$res = @mysql_query("SELECT @@SESSION.sql_mode as mode", $this->conn);
|
| 98 |
-
if( $row = @mysql_fetch_array($res, MYSQL_ASSOC) ){
|
| 99 |
-
$sql_mode = $row["mode"];
|
| 100 |
-
$arr = array();
|
| 101 |
-
$arr = explode(",",$sql_mode);
|
| 102 |
-
$sql_mode = "";
|
| 103 |
-
for( $i=0; $i<count($arr); $i++){
|
| 104 |
-
if($arr[$i]!="STRICT_ALL_TABLES" && $arr[$i]!="STRICT_TRANS_TABLES"){
|
| 105 |
-
if( $sql_mode )
|
| 106 |
-
$sql_mode.=",";
|
| 107 |
-
$sql_mode.=$arr[$i];
|
| 108 |
-
}
|
| 109 |
-
}
|
| 110 |
-
if($sql_mode)
|
| 111 |
-
@mysql_query("set SESSION sql_mode='".$sql_mode."'", $this->conn);
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
return $this->conn;
|
| 115 |
-
}
|
| 116 |
-
|
| 117 |
-
/**
|
| 118 |
-
* Close the db connection
|
| 119 |
-
*/
|
| 120 |
-
public function close()
|
| 121 |
-
{
|
| 122 |
-
return mysql_close($this->conn);
|
| 123 |
-
}
|
| 124 |
-
|
| 125 |
-
/**
|
| 126 |
-
* Send an SQL query
|
| 127 |
-
* @param String sql
|
| 128 |
-
* @return Mixed
|
| 129 |
-
*/
|
| 130 |
-
public function query( $sql )
|
| 131 |
-
{
|
| 132 |
-
$this->debugInfo($sql);
|
| 133 |
-
|
| 134 |
-
$ret = mysql_query($sql, $this->conn);
|
| 135 |
-
if( !$ret )
|
| 136 |
-
{
|
| 137 |
-
$this->triggerError(mysql_error());
|
| 138 |
-
return FALSE;
|
| 139 |
-
}
|
| 140 |
-
|
| 141 |
-
return new QueryResult( $this, $ret );
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
-
/**
|
| 145 |
-
* Execute an SQL query
|
| 146 |
-
* @param String sql
|
| 147 |
-
*/
|
| 148 |
-
public function exec( $sql )
|
| 149 |
-
{
|
| 150 |
-
$qResult = $this->query( $sql );
|
| 151 |
-
if( $qResult )
|
| 152 |
-
return $qResult->getQueryHandle();
|
| 153 |
-
|
| 154 |
-
return FALSE;
|
| 155 |
-
}
|
| 156 |
-
|
| 157 |
-
/**
|
| 158 |
-
* Get a description of the last error
|
| 159 |
-
* @return String
|
| 160 |
-
*/
|
| 161 |
-
public function lastError()
|
| 162 |
-
{
|
| 163 |
-
return @mysql_error();
|
| 164 |
-
}
|
| 165 |
-
|
| 166 |
-
/**
|
| 167 |
-
* Get the auto generated id used in the last query
|
| 168 |
-
* @return Number
|
| 169 |
-
*/
|
| 170 |
-
public function getInsertedId($key = null, $table = null )
|
| 171 |
-
{
|
| 172 |
-
return @mysql_insert_id( $this->conn );
|
| 173 |
-
}
|
| 174 |
-
|
| 175 |
-
/**
|
| 176 |
-
* Fetch a result row as an associative array
|
| 177 |
-
* @param Mixed qHanle The query handle
|
| 178 |
-
* @return Array
|
| 179 |
-
*/
|
| 180 |
-
public function fetch_array( $qHandle )
|
| 181 |
-
{
|
| 182 |
-
return @mysql_fetch_array($qHandle, MYSQL_ASSOC);
|
| 183 |
-
}
|
| 184 |
-
|
| 185 |
-
/**
|
| 186 |
-
* Fetch a result row as a numeric array
|
| 187 |
-
* @param Mixed qHanle The query handle
|
| 188 |
-
* @return Array
|
| 189 |
-
*/
|
| 190 |
-
public function fetch_numarray( $qHandle )
|
| 191 |
-
{
|
| 192 |
-
return @mysql_fetch_array($qHandle, MYSQL_NUM);
|
| 193 |
-
}
|
| 194 |
-
|
| 195 |
-
/**
|
| 196 |
-
* Free resources associated with a query result set
|
| 197 |
-
* @param Mixed qHanle The query handle
|
| 198 |
-
*/
|
| 199 |
-
public function closeQuery( $qHandle )
|
| 200 |
-
{
|
| 201 |
-
@mysql_free_result($qHandle);
|
| 202 |
-
}
|
| 203 |
-
|
| 204 |
-
/**
|
| 205 |
-
* Get number of fields in a result
|
| 206 |
-
* @param Mixed qHanle The query handle
|
| 207 |
-
* @return Number
|
| 208 |
-
*/
|
| 209 |
-
public function num_fields( $qHandle )
|
| 210 |
-
{
|
| 211 |
-
return @mysql_num_fields($qHandle);
|
| 212 |
-
}
|
| 213 |
-
|
| 214 |
-
/**
|
| 215 |
-
* Get the name of the specified field in a result
|
| 216 |
-
* @param Mixed qHanle The query handle
|
| 217 |
-
* @param Number offset
|
| 218 |
-
* @return String
|
| 219 |
-
*/
|
| 220 |
-
public function field_name( $qHandle, $offset )
|
| 221 |
-
{
|
| 222 |
-
return @mysql_field_name($qHandle, $offset);
|
| 223 |
-
}
|
| 224 |
-
|
| 225 |
-
/**
|
| 226 |
-
* @param Mixed qHandle
|
| 227 |
-
* @param Number pageSize
|
| 228 |
-
* @param Number page
|
| 229 |
-
*/
|
| 230 |
-
public function seekRecord($qHandle, $n)
|
| 231 |
-
{
|
| 232 |
-
mysql_data_seek($qHandle, $n );
|
| 233 |
-
}
|
| 234 |
-
|
| 235 |
-
/**
|
| 236 |
-
* Check if the MYSQL version is lower than 5.0
|
| 237 |
-
* @return Boolean
|
| 238 |
-
*/
|
| 239 |
-
public function checkDBSubqueriesSupport()
|
| 240 |
-
{
|
| 241 |
-
return $this->subqueriesSupported;
|
| 242 |
-
}
|
| 243 |
-
|
| 244 |
-
/**
|
| 245 |
-
* Check if SQL queries containing joined subquery are optimized
|
| 246 |
-
* @return Boolean
|
| 247 |
-
*/
|
| 248 |
-
public function checkIfJoinSubqueriesOptimized()
|
| 249 |
-
{
|
| 250 |
-
// if MySQL of older than 5.6 version is used
|
| 251 |
-
if( preg_match("/^(?:(?:[0-4]\.)|(?:5\.[0-5]))/", $this->mysqlVersion, $matches) )
|
| 252 |
-
return false;
|
| 253 |
-
|
| 254 |
-
return true;
|
| 255 |
-
}
|
| 256 |
-
|
| 257 |
-
/**
|
| 258 |
-
* Execute an SQL query with blob fields processing
|
| 259 |
-
* @param String sql
|
| 260 |
-
* @param Array blobs
|
| 261 |
-
* @param Array blobTypes
|
| 262 |
-
* @return Boolean
|
| 263 |
-
*/
|
| 264 |
-
public function execWithBlobProcessing( $sql, $blobs, $blobTypes = array(), $autoincField = null )
|
| 265 |
-
{
|
| 266 |
-
$this->debugInfo($sql);
|
| 267 |
-
return @mysql_query($sql, $this->conn);
|
| 268 |
-
}
|
| 269 |
-
|
| 270 |
-
/**
|
| 271 |
-
* @return String
|
| 272 |
-
*/
|
| 273 |
-
public function getVersion() {
|
| 274 |
-
return $this->mysqlVersion;
|
| 275 |
-
}
|
| 276 |
-
}
|
| 277 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/MySQLiConnection.php
DELETED
|
@@ -1,331 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class MySQLiConnection extends Connection
|
| 3 |
-
{
|
| 4 |
-
protected $host;
|
| 5 |
-
|
| 6 |
-
protected $useSSL;
|
| 7 |
-
|
| 8 |
-
protected $user;
|
| 9 |
-
|
| 10 |
-
protected $pwd;
|
| 11 |
-
|
| 12 |
-
protected $port;
|
| 13 |
-
|
| 14 |
-
protected $sys_dbname;
|
| 15 |
-
|
| 16 |
-
protected $mysqlVersion;
|
| 17 |
-
|
| 18 |
-
protected $subqueriesSupported = true;
|
| 19 |
-
|
| 20 |
-
function __construct( $params )
|
| 21 |
-
{
|
| 22 |
-
parent::__construct( $params );
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
/**
|
| 26 |
-
* Set db connection's properties
|
| 27 |
-
* @param Array params
|
| 28 |
-
*/
|
| 29 |
-
protected function assignConnectionParams( $params )
|
| 30 |
-
{
|
| 31 |
-
parent::assignConnectionParams( $params );
|
| 32 |
-
|
| 33 |
-
$this->host = $params["connInfo"][0]; //strConnectInfo1
|
| 34 |
-
if (substr($this->host, 0, 4) === "ssl/") {
|
| 35 |
-
$this->host = substr($this->host, 4);
|
| 36 |
-
$this->useSSL = true;
|
| 37 |
-
} else {
|
| 38 |
-
$this->useSSL = false;
|
| 39 |
-
}
|
| 40 |
-
$this->user = $params["connInfo"][1]; //strConnectInfo2
|
| 41 |
-
$this->pwd = $params["connInfo"][2]; //strConnectInfo3
|
| 42 |
-
$this->port = $params["connInfo"][3]; //strConnectInfo4
|
| 43 |
-
$this->sys_dbname = $params["connInfo"][4]; //strConnectInfo5
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
/**
|
| 47 |
-
* @return Array
|
| 48 |
-
*/
|
| 49 |
-
protected function getDbFunctionsExtraParams()
|
| 50 |
-
{
|
| 51 |
-
$extraParams = parent::getDbFunctionsExtraParams();
|
| 52 |
-
$extraParams["conn"] = $this->conn;
|
| 53 |
-
|
| 54 |
-
return $extraParams;
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
/**
|
| 58 |
-
* Open a connection to db
|
| 59 |
-
*/
|
| 60 |
-
public function connect()
|
| 61 |
-
{
|
| 62 |
-
global $cMySQLNames;
|
| 63 |
-
|
| 64 |
-
if( !trim( $this->port ) )
|
| 65 |
-
$this->port = 3306;
|
| 66 |
-
|
| 67 |
-
$hosts = array();
|
| 68 |
-
/*
|
| 69 |
-
// no need to do this anymore
|
| 70 |
-
// fix IPv6 slow connection issue
|
| 71 |
-
if( $this->host == "localhost" )
|
| 72 |
-
{
|
| 73 |
-
if( @$_SESSION["myqsladdress"] )
|
| 74 |
-
$hosts[] = @$_SESSION["myqsladdress"];
|
| 75 |
-
else
|
| 76 |
-
$hosts[] = "127.0.0.1";
|
| 77 |
-
}
|
| 78 |
-
*/
|
| 79 |
-
$hosts[] = $this->host;
|
| 80 |
-
|
| 81 |
-
$flags = 0;
|
| 82 |
-
if ($this->useSSL) {
|
| 83 |
-
$flags = MYSQLI_CLIENT_SSL;
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
-
foreach ($hosts as $h) {
|
| 87 |
-
$this->conn = mysqli_init();
|
| 88 |
-
if (!$this->conn)
|
| 89 |
-
break;
|
| 90 |
-
|
| 91 |
-
try {
|
| 92 |
-
if (!@mysqli_real_connect($this->conn, $h, $this->user, $this->pwd, "", $this->port, "", $flags)) {
|
| 93 |
-
$this->conn = null;
|
| 94 |
-
}
|
| 95 |
-
} catch( Exception $e ) {
|
| 96 |
-
$this->conn = null;
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
if ($this->conn) {
|
| 100 |
-
if ($this->host == "localhost")
|
| 101 |
-
$_SESSION["myqsladdress"] = $h;
|
| 102 |
-
break;
|
| 103 |
-
}
|
| 104 |
-
}
|
| 105 |
-
|
| 106 |
-
if (!$this->conn)
|
| 107 |
-
{
|
| 108 |
-
unset( $_SESSION["myqsladdress"] );
|
| 109 |
-
$this->triggerError( mysqli_connect_error() );
|
| 110 |
-
return null;
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
if( !mysqli_select_db($this->conn, $this->sys_dbname) )
|
| 114 |
-
$this->triggerError( mysqli_error($this->conn) );
|
| 115 |
-
|
| 116 |
-
if( $cMySQLNames != "" )
|
| 117 |
-
@mysqli_query($this->conn, "set names ".$cMySQLNames);
|
| 118 |
-
|
| 119 |
-
$this->mysqlVersion = "4";
|
| 120 |
-
$res = @mysqli_query($this->conn, "SHOW VARIABLES LIKE 'version'");
|
| 121 |
-
if( $row = @mysqli_fetch_array($res, MYSQLI_ASSOC) )
|
| 122 |
-
$this->mysqlVersion = $row["Value"];
|
| 123 |
-
|
| 124 |
-
if( preg_match("/^[0-4]\./", $this->mysqlVersion, $matches) && strpos($this->mysqlVersion, "MariaDB") === FALSE ) //#10818 2
|
| 125 |
-
$this->subqueriesSupported = false;
|
| 126 |
-
|
| 127 |
-
$res = @mysqli_query($this->conn, "SELECT @@SESSION.sql_mode as mode");
|
| 128 |
-
if( $row = @mysqli_fetch_array($res, MYSQLI_ASSOC) ){
|
| 129 |
-
$sql_mode = $row["mode"];
|
| 130 |
-
$arr = array();
|
| 131 |
-
$arr = explode(",",$sql_mode);
|
| 132 |
-
$sql_mode = "";
|
| 133 |
-
for( $i=0; $i<count($arr); $i++){
|
| 134 |
-
if($arr[$i]!="STRICT_ALL_TABLES" && $arr[$i]!="STRICT_TRANS_TABLES"){
|
| 135 |
-
if( $sql_mode )
|
| 136 |
-
$sql_mode.=",";
|
| 137 |
-
$sql_mode.=$arr[$i];
|
| 138 |
-
}
|
| 139 |
-
}
|
| 140 |
-
if($sql_mode)
|
| 141 |
-
@mysqli_query($this->conn, "set SESSION sql_mode='".$sql_mode."'");
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
-
return $this->conn;
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
/**
|
| 148 |
-
* Close the db connection
|
| 149 |
-
*/
|
| 150 |
-
public function close()
|
| 151 |
-
{
|
| 152 |
-
return mysqli_close( $this->conn );
|
| 153 |
-
}
|
| 154 |
-
|
| 155 |
-
/**
|
| 156 |
-
* Send an SQL query
|
| 157 |
-
* @param String sql
|
| 158 |
-
* @return Mixed
|
| 159 |
-
*/
|
| 160 |
-
public function query( $sql )
|
| 161 |
-
{
|
| 162 |
-
$this->clearResultBuffer();
|
| 163 |
-
$this->debugInfo($sql);
|
| 164 |
-
|
| 165 |
-
try {
|
| 166 |
-
$ret = @mysqli_query($this->conn, $sql);
|
| 167 |
-
} catch ( Exception $e ) {
|
| 168 |
-
$this->triggerError( mysqli_error($this->conn) );
|
| 169 |
-
return false;
|
| 170 |
-
}
|
| 171 |
-
if( !$ret )
|
| 172 |
-
{
|
| 173 |
-
$this->triggerError( mysqli_error($this->conn) );
|
| 174 |
-
return FALSE;
|
| 175 |
-
}
|
| 176 |
-
|
| 177 |
-
return new QueryResult( $this, $ret );
|
| 178 |
-
}
|
| 179 |
-
|
| 180 |
-
/**
|
| 181 |
-
* Execute an SQL query
|
| 182 |
-
* @param String sql
|
| 183 |
-
*/
|
| 184 |
-
public function exec( $sql )
|
| 185 |
-
{
|
| 186 |
-
$this->clearResultBuffer();
|
| 187 |
-
try {
|
| 188 |
-
$qResult = $this->query( $sql );
|
| 189 |
-
} catch( Exception $e ) {
|
| 190 |
-
return false;
|
| 191 |
-
}
|
| 192 |
-
if( $qResult )
|
| 193 |
-
return $qResult->getQueryHandle();
|
| 194 |
-
|
| 195 |
-
return FALSE;
|
| 196 |
-
}
|
| 197 |
-
|
| 198 |
-
/**
|
| 199 |
-
* Execute an SQL query with blob fields processing
|
| 200 |
-
* @param String sql
|
| 201 |
-
* @param Array blobs
|
| 202 |
-
* @param Array blobTypes
|
| 203 |
-
* @return Boolean
|
| 204 |
-
*/
|
| 205 |
-
public function execWithBlobProcessing( $sql, $blobs, $blobTypes = array(), $autoincField = null )
|
| 206 |
-
{
|
| 207 |
-
$this->debugInfo($sql);
|
| 208 |
-
try {
|
| 209 |
-
return mysqli_query($this->conn, $sql);
|
| 210 |
-
} catch( Exception $e ) {
|
| 211 |
-
return false;
|
| 212 |
-
}
|
| 213 |
-
}
|
| 214 |
-
|
| 215 |
-
/**
|
| 216 |
-
* Get a description of the last error
|
| 217 |
-
* @return String
|
| 218 |
-
*/
|
| 219 |
-
public function lastError()
|
| 220 |
-
{
|
| 221 |
-
return @mysqli_error( $this->conn );
|
| 222 |
-
}
|
| 223 |
-
|
| 224 |
-
/**
|
| 225 |
-
* Get the auto generated id used in the last query
|
| 226 |
-
* @return Number
|
| 227 |
-
*/
|
| 228 |
-
public function getInsertedId($key = null, $table = null )
|
| 229 |
-
{
|
| 230 |
-
return @mysqli_insert_id( $this->conn );
|
| 231 |
-
}
|
| 232 |
-
|
| 233 |
-
/**
|
| 234 |
-
* Fetch a result row as an associative array
|
| 235 |
-
* @param Mixed qHanle The query handle
|
| 236 |
-
* @return Array
|
| 237 |
-
*/
|
| 238 |
-
public function fetch_array( $qHandle )
|
| 239 |
-
{
|
| 240 |
-
return @mysqli_fetch_array($qHandle, MYSQLI_ASSOC);
|
| 241 |
-
}
|
| 242 |
-
|
| 243 |
-
/**
|
| 244 |
-
* Fetch a result row as a numeric array
|
| 245 |
-
* @param Mixed qHanle The query handle
|
| 246 |
-
* @return Array
|
| 247 |
-
*/
|
| 248 |
-
public function fetch_numarray( $qHandle )
|
| 249 |
-
{
|
| 250 |
-
return @mysqli_fetch_array($qHandle, MYSQLI_NUM);
|
| 251 |
-
}
|
| 252 |
-
|
| 253 |
-
/**
|
| 254 |
-
* Free resources associated with a query result set
|
| 255 |
-
* @param Mixed qHanle The query handle
|
| 256 |
-
*/
|
| 257 |
-
public function closeQuery( $qHandle )
|
| 258 |
-
{
|
| 259 |
-
@mysqli_free_result($qHandle);
|
| 260 |
-
}
|
| 261 |
-
|
| 262 |
-
/**
|
| 263 |
-
* Get number of fields in a result
|
| 264 |
-
* @param Mixed qHanle The query handle
|
| 265 |
-
* @return Number
|
| 266 |
-
*/
|
| 267 |
-
public function num_fields( $qHandle )
|
| 268 |
-
{
|
| 269 |
-
return @mysqli_field_count($this->conn);
|
| 270 |
-
}
|
| 271 |
-
|
| 272 |
-
/**
|
| 273 |
-
* Get the name of the specified field in a result
|
| 274 |
-
* @param Mixed qHanle The query handle
|
| 275 |
-
* @param Number offset
|
| 276 |
-
* @return String
|
| 277 |
-
*/
|
| 278 |
-
public function field_name( $qHandle, $offset )
|
| 279 |
-
{
|
| 280 |
-
@mysqli_field_seek($qHandle, $offset);
|
| 281 |
-
$field = @mysqli_fetch_field($qHandle);
|
| 282 |
-
return $field ? $field->name : "";
|
| 283 |
-
}
|
| 284 |
-
|
| 285 |
-
/**
|
| 286 |
-
* @param Mixed qHandle
|
| 287 |
-
* @param Number n
|
| 288 |
-
*/
|
| 289 |
-
public function seekRecord($qHandle, $n)
|
| 290 |
-
{
|
| 291 |
-
mysqli_data_seek($qHandle, $n );
|
| 292 |
-
}
|
| 293 |
-
|
| 294 |
-
/**
|
| 295 |
-
* Check if the MYSQL version is lower than 5.0
|
| 296 |
-
* @return Boolean
|
| 297 |
-
*/
|
| 298 |
-
public function checkDBSubqueriesSupport()
|
| 299 |
-
{
|
| 300 |
-
return $this->subqueriesSupported;
|
| 301 |
-
}
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
/**
|
| 305 |
-
* Check if SQL queries containing joined subquery are optimized
|
| 306 |
-
* @return Boolean
|
| 307 |
-
*/
|
| 308 |
-
public function checkIfJoinSubqueriesOptimized()
|
| 309 |
-
{
|
| 310 |
-
// if MySQL of older than 5.6 version is used
|
| 311 |
-
if( preg_match("/^(?:(?:[0-4]\.)|(?:5\.[0-5]))/", $this->mysqlVersion, $matches) )
|
| 312 |
-
return false;
|
| 313 |
-
|
| 314 |
-
return true;
|
| 315 |
-
}
|
| 316 |
-
|
| 317 |
-
public function clearResultBuffer() {
|
| 318 |
-
while( mysqli_more_results( $this->conn ) ) {
|
| 319 |
-
mysqli_next_result( $this->conn );
|
| 320 |
-
}
|
| 321 |
-
}
|
| 322 |
-
|
| 323 |
-
/**
|
| 324 |
-
* @return String
|
| 325 |
-
*/
|
| 326 |
-
public function getVersion() {
|
| 327 |
-
return $this->mysqlVersion;
|
| 328 |
-
}
|
| 329 |
-
|
| 330 |
-
}
|
| 331 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/ODBCConnection.php
DELETED
|
@@ -1,187 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class ODBCConnection extends Connection
|
| 3 |
-
{
|
| 4 |
-
protected $ODBCString;
|
| 5 |
-
|
| 6 |
-
/**
|
| 7 |
-
* @type String
|
| 8 |
-
*/
|
| 9 |
-
protected $ODBCUID;
|
| 10 |
-
|
| 11 |
-
/**
|
| 12 |
-
* @type String
|
| 13 |
-
*/
|
| 14 |
-
protected $ODBCPWD;
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
function __construct( $params )
|
| 18 |
-
{
|
| 19 |
-
parent::__construct( $params );
|
| 20 |
-
}
|
| 21 |
-
|
| 22 |
-
/**
|
| 23 |
-
* Set db connection's properties
|
| 24 |
-
* @param Array params
|
| 25 |
-
*/
|
| 26 |
-
protected function assignConnectionParams( $params )
|
| 27 |
-
{
|
| 28 |
-
parent::assignConnectionParams( $params );
|
| 29 |
-
|
| 30 |
-
$this->ODBCString = $params["ODBCString"];
|
| 31 |
-
$this->ODBCUID = $params["ODBCUID"];
|
| 32 |
-
$this->ODBCPWD = $params["ODBCPWD"];
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
/**
|
| 36 |
-
* Open a connection to db
|
| 37 |
-
*/
|
| 38 |
-
public function connect()
|
| 39 |
-
{
|
| 40 |
-
$uid = "";
|
| 41 |
-
$pwd = "";
|
| 42 |
-
if( $this->dbType == nDATABASE_Interbase )
|
| 43 |
-
{
|
| 44 |
-
$uid = $this->ODBCUID;
|
| 45 |
-
$pwd = $this->ODBCPWD;
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
$this->conn = odbc_connect( $this->ODBCString, $uid, $pwd );
|
| 49 |
-
if( !$this->conn )
|
| 50 |
-
$this->triggerError( $this->lastError() );
|
| 51 |
-
|
| 52 |
-
return $this->conn;
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
/**
|
| 56 |
-
* Close the db connection
|
| 57 |
-
*/
|
| 58 |
-
public function close()
|
| 59 |
-
{
|
| 60 |
-
return odbc_close( $this->conn );
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
/**
|
| 64 |
-
* Send an SQL query
|
| 65 |
-
* @param String sql
|
| 66 |
-
* @return Mixed
|
| 67 |
-
*/
|
| 68 |
-
public function query( $sql )
|
| 69 |
-
{
|
| 70 |
-
$this->debugInfo($sql);
|
| 71 |
-
|
| 72 |
-
$rs = odbc_exec( $this->conn, $sql );
|
| 73 |
-
if( !$rs )
|
| 74 |
-
{
|
| 75 |
-
$this->triggerError( $this->lastError() );
|
| 76 |
-
return FALSE;
|
| 77 |
-
}
|
| 78 |
-
|
| 79 |
-
odbc_binmode($rs, ODBC_BINMODE_RETURN);
|
| 80 |
-
odbc_longreadlen($rs, 1024*1024);
|
| 81 |
-
return new QueryResult( $this, $rs );
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
/**
|
| 85 |
-
* Execute an SQL query
|
| 86 |
-
* @param String sql
|
| 87 |
-
*/
|
| 88 |
-
public function exec( $sql )
|
| 89 |
-
{
|
| 90 |
-
$this->debugInfo($sql);
|
| 91 |
-
return odbc_exec( $this->conn, $sql );
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
/**
|
| 95 |
-
* Get a description of the last error
|
| 96 |
-
* @return String
|
| 97 |
-
*/
|
| 98 |
-
public function lastError()
|
| 99 |
-
{
|
| 100 |
-
return @odbc_errormsg();
|
| 101 |
-
}
|
| 102 |
-
|
| 103 |
-
/**
|
| 104 |
-
* Fetch a result row as an associative array
|
| 105 |
-
* @param Mixed qHanle The query handle
|
| 106 |
-
* @return Array
|
| 107 |
-
*/
|
| 108 |
-
public function fetch_array( $qHandle )
|
| 109 |
-
{
|
| 110 |
-
return odbc_fetch_array($qHandle);
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
/**
|
| 114 |
-
* Fetch a result row as a numeric array
|
| 115 |
-
* @param Mixed qHanle The query handle
|
| 116 |
-
* @return Array
|
| 117 |
-
*/
|
| 118 |
-
public function fetch_numarray( $qHandle )
|
| 119 |
-
{
|
| 120 |
-
$row = array();
|
| 121 |
-
odbc_fetch_into($qHandle, $row);
|
| 122 |
-
|
| 123 |
-
return $row;
|
| 124 |
-
}
|
| 125 |
-
|
| 126 |
-
/**
|
| 127 |
-
* Free resources associated with a query result set
|
| 128 |
-
* @param Mixed qHanle The query handle
|
| 129 |
-
*/
|
| 130 |
-
public function closeQuery( $qHandle )
|
| 131 |
-
{
|
| 132 |
-
@odbc_free_result($qHandle);
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
/**
|
| 136 |
-
* Get number of fields in a result
|
| 137 |
-
* @param Mixed qHanle The query handle
|
| 138 |
-
* @return Number
|
| 139 |
-
*/
|
| 140 |
-
public function num_fields( $qHandle )
|
| 141 |
-
{
|
| 142 |
-
return @odbc_num_fields($qHandle);
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
-
/**
|
| 146 |
-
* Get the name of the specified field in a result
|
| 147 |
-
* @param Mixed qHanle The query handle
|
| 148 |
-
* @param Number offset
|
| 149 |
-
* @return String
|
| 150 |
-
*/
|
| 151 |
-
public function field_name( $qHandle, $offset )
|
| 152 |
-
{
|
| 153 |
-
return @odbc_field_name($qHandle, $offset + 1);
|
| 154 |
-
}
|
| 155 |
-
|
| 156 |
-
/**
|
| 157 |
-
* @param Mixed qHandle
|
| 158 |
-
*/
|
| 159 |
-
public function seekRecord($qHandle, $n)
|
| 160 |
-
{
|
| 161 |
-
$i = 0;
|
| 162 |
-
|
| 163 |
-
while( $i < $n )
|
| 164 |
-
{
|
| 165 |
-
odbc_fetch_row( $qHandle );
|
| 166 |
-
$i++;
|
| 167 |
-
}
|
| 168 |
-
}
|
| 169 |
-
|
| 170 |
-
/**
|
| 171 |
-
* Execute an SQL query with blob fields processing
|
| 172 |
-
* @param String sql
|
| 173 |
-
* @param Array blobs
|
| 174 |
-
* @param Array blobTypes
|
| 175 |
-
* @return Boolean
|
| 176 |
-
*/
|
| 177 |
-
public function execWithBlobProcessing( $sql, $blobs, $blobTypes = array(), $autoincField = null )
|
| 178 |
-
{
|
| 179 |
-
$this->debugInfo($sql);
|
| 180 |
-
set_error_handler("empty_error_handler");
|
| 181 |
-
$qResult = odbc_exec( $this->conn, $sql );
|
| 182 |
-
set_error_handler("runner_error_handler");
|
| 183 |
-
|
| 184 |
-
return $qResult;
|
| 185 |
-
}
|
| 186 |
-
}
|
| 187 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/OracleConnection.php
DELETED
|
@@ -1,326 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class OracleConnection extends Connection
|
| 3 |
-
{
|
| 4 |
-
protected $user;
|
| 5 |
-
|
| 6 |
-
protected $pwd;
|
| 7 |
-
|
| 8 |
-
protected $sid;
|
| 9 |
-
|
| 10 |
-
protected $error = array();
|
| 11 |
-
|
| 12 |
-
function __construct( $params )
|
| 13 |
-
{
|
| 14 |
-
parent::__construct( $params );
|
| 15 |
-
}
|
| 16 |
-
|
| 17 |
-
/**
|
| 18 |
-
* Set db connection's properties
|
| 19 |
-
* @param Array params
|
| 20 |
-
*/
|
| 21 |
-
protected function assignConnectionParams( $params )
|
| 22 |
-
{
|
| 23 |
-
parent::assignConnectionParams( $params );
|
| 24 |
-
|
| 25 |
-
$this->user = $params["connInfo"][0]; //strConnectInfo1
|
| 26 |
-
$this->pwd = $params["connInfo"][1]; //strConnectInfo2
|
| 27 |
-
$this->sid = $params["connInfo"][2]; //strConnectInfo3
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
/**
|
| 31 |
-
* Open a connection to db
|
| 32 |
-
*/
|
| 33 |
-
public function connect()
|
| 34 |
-
{
|
| 35 |
-
##if @BUILDER.strCharset == "utf-8"##
|
| 36 |
-
if( !getenv( "NLS_LANG" ) )
|
| 37 |
-
putenv( "NLS_LANG=AMERICAN_AMERICA.UTF8");
|
| 38 |
-
##endif##
|
| 39 |
-
global $useUTF8;
|
| 40 |
-
|
| 41 |
-
$this->conn = @oci_pconnect($this->user, $this->pwd, $this->sid, $useUTF8 ? 'AL32UTF8' : '' );
|
| 42 |
-
if( !$this->conn ) {
|
| 43 |
-
$this->setError( ocierror() );
|
| 44 |
-
$this->triggerError($this->lastError());
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
$stmt = ociparse($this->conn, "alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS'");
|
| 48 |
-
ociexecute($stmt);
|
| 49 |
-
$this->closeQuery( $stmt );
|
| 50 |
-
$stmt = ociparse($this->conn, "alter session set nls_timestamp_format='YYYY-MM-DD HH24:MI:SS'");
|
| 51 |
-
ociexecute($stmt);
|
| 52 |
-
$this->closeQuery( $stmt );
|
| 53 |
-
return $this->conn;
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
/**
|
| 57 |
-
* Close the db connection
|
| 58 |
-
*/
|
| 59 |
-
public function close()
|
| 60 |
-
{
|
| 61 |
-
return @ocilogoff( $this->conn );
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
/**
|
| 65 |
-
* Send an SQL query
|
| 66 |
-
* @param String sql
|
| 67 |
-
* @return Mixed
|
| 68 |
-
*/
|
| 69 |
-
public function query( $sql )
|
| 70 |
-
{
|
| 71 |
-
$this->debugInfo($sql);
|
| 72 |
-
|
| 73 |
-
$stmt = ociparse($this->conn, $sql);
|
| 74 |
-
if( !$stmt )
|
| 75 |
-
{
|
| 76 |
-
$this->setError( oci_error( $this->conn ) );
|
| 77 |
-
$this->triggerError($this->lastError());
|
| 78 |
-
return FALSE;
|
| 79 |
-
}
|
| 80 |
-
$stmt_type = ocistatementtype($stmt);
|
| 81 |
-
if( !ociexecute($stmt) )
|
| 82 |
-
{
|
| 83 |
-
$this->setError( oci_error( $stmt ) );
|
| 84 |
-
$this->closeQuery( $stmt );
|
| 85 |
-
$this->triggerError($this->lastError());
|
| 86 |
-
return FALSE;
|
| 87 |
-
}
|
| 88 |
-
|
| 89 |
-
return new QueryResult( $this, $stmt );
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
/**
|
| 93 |
-
* Execute an SQL query
|
| 94 |
-
* @param String sql
|
| 95 |
-
* @return Mixed
|
| 96 |
-
*/
|
| 97 |
-
public function exec( $sql )
|
| 98 |
-
{
|
| 99 |
-
$this->debugInfo($sql);
|
| 100 |
-
|
| 101 |
-
$stmt = ociparse($this->conn, $sql);
|
| 102 |
-
if( !$stmt )
|
| 103 |
-
{
|
| 104 |
-
$this->setError( oci_error( $this->conn ) );
|
| 105 |
-
$this->triggerError($this->lastError());
|
| 106 |
-
return FALSE;
|
| 107 |
-
}
|
| 108 |
-
$stmt_type = ocistatementtype($stmt);
|
| 109 |
-
if( !ociexecute($stmt) )
|
| 110 |
-
{
|
| 111 |
-
$this->setError( oci_error( $stmt ) );
|
| 112 |
-
$this->closeQuery( $stmt );
|
| 113 |
-
$this->triggerError($this->lastError());
|
| 114 |
-
return FALSE;
|
| 115 |
-
}
|
| 116 |
-
|
| 117 |
-
return 1;
|
| 118 |
-
}
|
| 119 |
-
|
| 120 |
-
/**
|
| 121 |
-
* Get a description of the last error
|
| 122 |
-
* @return String
|
| 123 |
-
*/
|
| 124 |
-
public function lastError()
|
| 125 |
-
{
|
| 126 |
-
if( is_array( $this->error ) && count( $this->error) > 1 )
|
| 127 |
-
return $this->error["message"];
|
| 128 |
-
|
| 129 |
-
return "";
|
| 130 |
-
}
|
| 131 |
-
|
| 132 |
-
/**
|
| 133 |
-
* Fetch a result row as an array
|
| 134 |
-
* @param Mixed qHanle The query handle
|
| 135 |
-
* @param Number flags
|
| 136 |
-
* @return Array
|
| 137 |
-
*/
|
| 138 |
-
protected function myoci_fetch_array($qHandle, $flags)
|
| 139 |
-
{
|
| 140 |
-
if( function_exists("oci_fetch_array") )
|
| 141 |
-
return oci_fetch_array($qHandle, $flags);
|
| 142 |
-
|
| 143 |
-
$data = array();
|
| 144 |
-
if( ocifetchinto($qHandle, $data, $flags) )
|
| 145 |
-
return $data;
|
| 146 |
-
|
| 147 |
-
return array();
|
| 148 |
-
}
|
| 149 |
-
|
| 150 |
-
/**
|
| 151 |
-
* Fetch a result row as an associative array
|
| 152 |
-
* @param Mixed qHanle The query handle
|
| 153 |
-
* @return Array
|
| 154 |
-
*/
|
| 155 |
-
public function fetch_array( $qHandle )
|
| 156 |
-
{
|
| 157 |
-
return $this->myoci_fetch_array($qHandle, OCI_ASSOC + OCI_RETURN_NULLS + OCI_RETURN_LOBS);
|
| 158 |
-
}
|
| 159 |
-
|
| 160 |
-
/**
|
| 161 |
-
* Fetch a result row as a numeric array
|
| 162 |
-
* @param Mixed qHanle The query handle
|
| 163 |
-
* @return Array
|
| 164 |
-
*/
|
| 165 |
-
public function fetch_numarray( $qHandle )
|
| 166 |
-
{
|
| 167 |
-
return $this->myoci_fetch_array($qHandle, OCI_NUM + OCI_RETURN_NULLS + OCI_RETURN_LOBS);
|
| 168 |
-
}
|
| 169 |
-
|
| 170 |
-
/**
|
| 171 |
-
* Free resources associated with a query result set
|
| 172 |
-
* @param Mixed qHanle The query handle
|
| 173 |
-
*/
|
| 174 |
-
public function closeQuery( $qHandle )
|
| 175 |
-
{
|
| 176 |
-
if( function_exists("oci_free_statement") )
|
| 177 |
-
oci_free_statement($qHandle);
|
| 178 |
-
else
|
| 179 |
-
ocifreestatement($qHandle);
|
| 180 |
-
}
|
| 181 |
-
|
| 182 |
-
/**
|
| 183 |
-
* Get number of fields in a result
|
| 184 |
-
* @param Mixed qHanle The query handle
|
| 185 |
-
* @return Number
|
| 186 |
-
*/
|
| 187 |
-
public function num_fields( $qHandle )
|
| 188 |
-
{
|
| 189 |
-
return OCINumCols($qHandle);
|
| 190 |
-
}
|
| 191 |
-
|
| 192 |
-
/**
|
| 193 |
-
* Get the name of the specified field in a result
|
| 194 |
-
* @param Mixed qHanle The query handle
|
| 195 |
-
* @param Number offset
|
| 196 |
-
* @return String
|
| 197 |
-
*/
|
| 198 |
-
public function field_name( $qHandle, $offset )
|
| 199 |
-
{
|
| 200 |
-
return OCIColumnName($qHandle, $offset + 1);
|
| 201 |
-
}
|
| 202 |
-
|
| 203 |
-
/**
|
| 204 |
-
* @param Mixed qHandle
|
| 205 |
-
* @param Number pageSize
|
| 206 |
-
* @param Number page
|
| 207 |
-
*/
|
| 208 |
-
public function seekRecord($qHandle, $n)
|
| 209 |
-
{
|
| 210 |
-
for($i = 0; $i < $n; $i++)
|
| 211 |
-
{
|
| 212 |
-
$this->myoci_fetch_array($qHandle, OCI_NUM + OCI_RETURN_NULLS);
|
| 213 |
-
}
|
| 214 |
-
}
|
| 215 |
-
|
| 216 |
-
/**
|
| 217 |
-
* Execute an SQL query with blob fields processing
|
| 218 |
-
* @param String sql
|
| 219 |
-
* @param Array blobs
|
| 220 |
-
* @param Array blobTypes
|
| 221 |
-
* @return Boolean
|
| 222 |
-
*/
|
| 223 |
-
public function execWithBlobProcessing( $sql, $blobs, $blobTypes = array(), $autoincField = null )
|
| 224 |
-
{
|
| 225 |
-
|
| 226 |
-
set_error_handler("empty_error_handler");
|
| 227 |
-
|
| 228 |
-
$lastIdValue = 0;
|
| 229 |
-
$locs = array();
|
| 230 |
-
|
| 231 |
-
if( count($blobs) || $autoincField !== null)
|
| 232 |
-
{
|
| 233 |
-
$idx = 1;
|
| 234 |
-
$sql.=" returning ";
|
| 235 |
-
|
| 236 |
-
$blobfields = "";
|
| 237 |
-
$blobvars = "";
|
| 238 |
-
foreach($blobs as $ekey => $value)
|
| 239 |
-
{
|
| 240 |
-
if( count($locs) )
|
| 241 |
-
{
|
| 242 |
-
$blobfields.= ",";
|
| 243 |
-
$blobvars.= ",";
|
| 244 |
-
}
|
| 245 |
-
|
| 246 |
-
$blobfields .= $this->addFieldWrappers($ekey);
|
| 247 |
-
$blobvars.= ":bnd".$idx;
|
| 248 |
-
$locs[ $ekey ] = OCINewDescriptor($this->conn, OCI_D_LOB);
|
| 249 |
-
$idx++;
|
| 250 |
-
}
|
| 251 |
-
|
| 252 |
-
if($autoincField !== null)
|
| 253 |
-
{
|
| 254 |
-
if( count($locs) )
|
| 255 |
-
{
|
| 256 |
-
$blobfields.= ",";
|
| 257 |
-
$blobvars.= ",";
|
| 258 |
-
}
|
| 259 |
-
$blobfields .= $this->addFieldWrappers($autoincField);
|
| 260 |
-
$blobvars.= ":lastId";
|
| 261 |
-
}
|
| 262 |
-
|
| 263 |
-
$sql.= $blobfields." into ".$blobvars;
|
| 264 |
-
}
|
| 265 |
-
|
| 266 |
-
$stmt = OCIParse($this->conn, $sql);
|
| 267 |
-
if( !$stmt )
|
| 268 |
-
{
|
| 269 |
-
$this->setError( oci_error( $this->conn ) );
|
| 270 |
-
return FALSE;
|
| 271 |
-
}
|
| 272 |
-
|
| 273 |
-
$idx = 1;
|
| 274 |
-
foreach($locs as $ekey => $value)
|
| 275 |
-
{
|
| 276 |
-
OCIBindByName($stmt, ":bnd".$idx, $locs[ $ekey ], -1 , OCI_B_BLOB);
|
| 277 |
-
$idx++;
|
| 278 |
-
}
|
| 279 |
-
|
| 280 |
-
if($autoincField !== null)
|
| 281 |
-
{
|
| 282 |
-
OCIBindByName($stmt, ":lastId", $lastIdValue, -1 , OCI_B_INT);
|
| 283 |
-
}
|
| 284 |
-
|
| 285 |
-
$result = OCIExecute($stmt, OCI_DEFAULT) !== false;
|
| 286 |
-
if( !$result )
|
| 287 |
-
{
|
| 288 |
-
$this->setError( oci_error( $stmt ) );
|
| 289 |
-
$this->closeQuery( $stmt );
|
| 290 |
-
return FALSE;
|
| 291 |
-
}
|
| 292 |
-
|
| 293 |
-
foreach($locs as $ekey => $value)
|
| 294 |
-
{
|
| 295 |
-
$locs[ $ekey ]->save( $blobs[ $ekey ] );
|
| 296 |
-
$locs[ $ekey ]->free();
|
| 297 |
-
}
|
| 298 |
-
|
| 299 |
-
if($autoincField !== null)
|
| 300 |
-
{
|
| 301 |
-
Connection::$lastInsertedId = $lastIdValue;
|
| 302 |
-
}
|
| 303 |
-
|
| 304 |
-
OCICommit($this->conn);
|
| 305 |
-
|
| 306 |
-
$this->closeQuery( $stmt );
|
| 307 |
-
|
| 308 |
-
set_error_handler("runner_error_handler");
|
| 309 |
-
return $result;
|
| 310 |
-
}
|
| 311 |
-
|
| 312 |
-
protected function setError( $err )
|
| 313 |
-
{
|
| 314 |
-
$this->error = $err;
|
| 315 |
-
}
|
| 316 |
-
|
| 317 |
-
public function getInsertedId( $key = null, $table = null)
|
| 318 |
-
{
|
| 319 |
-
if ( !is_null($key) && !is_null($table) )
|
| 320 |
-
{
|
| 321 |
-
return parent::getInsertedId($key, $table);
|
| 322 |
-
}
|
| 323 |
-
return OracleConnection::$lastInsertedId;
|
| 324 |
-
}
|
| 325 |
-
}
|
| 326 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/PDOConnection.php
DELETED
|
@@ -1,206 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class PDOConnection extends Connection
|
| 3 |
-
{
|
| 4 |
-
protected $connectionString;
|
| 5 |
-
|
| 6 |
-
protected $user;
|
| 7 |
-
|
| 8 |
-
protected $pass;
|
| 9 |
-
|
| 10 |
-
protected $freetdsMode = false;
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
function __construct( $params )
|
| 14 |
-
{
|
| 15 |
-
parent::__construct( $params );
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
/**
|
| 19 |
-
* Set db connection's properties
|
| 20 |
-
* @param Array params
|
| 21 |
-
*/
|
| 22 |
-
protected function assignConnectionParams( $params )
|
| 23 |
-
{
|
| 24 |
-
parent::assignConnectionParams( $params );
|
| 25 |
-
|
| 26 |
-
$this->user = $params["PDOUser"];
|
| 27 |
-
$this->pass = $params["PDOPass"];
|
| 28 |
-
$this->connectionString = $params["PDOString"];
|
| 29 |
-
|
| 30 |
-
if( substr( $this->connectionString, 0, 6 ) == "dblib:" && strtoupper(substr(PHP_OS, 0, 3)) != 'WIN' ) {
|
| 31 |
-
$this->freetdsMode = true;
|
| 32 |
-
}
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
/**
|
| 36 |
-
* Open a connection to db
|
| 37 |
-
*/
|
| 38 |
-
public function connect()
|
| 39 |
-
{
|
| 40 |
-
try
|
| 41 |
-
{
|
| 42 |
-
$this->conn = new PDO( $this->connectionString, $this->user, $this->pass);
|
| 43 |
-
}
|
| 44 |
-
catch( PDOException $e )
|
| 45 |
-
{
|
| 46 |
-
$this->triggerError( $e->getMessage() );
|
| 47 |
-
return null;
|
| 48 |
-
}
|
| 49 |
-
return $this->conn;
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
/**
|
| 53 |
-
* Close the db connection
|
| 54 |
-
*/
|
| 55 |
-
public function close()
|
| 56 |
-
{
|
| 57 |
-
$this->conn = NULL;
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
/**
|
| 61 |
-
* Send an SQL query
|
| 62 |
-
* @param String sql
|
| 63 |
-
* @return Mixed
|
| 64 |
-
*/
|
| 65 |
-
public function query( $sql )
|
| 66 |
-
{
|
| 67 |
-
$this->debugInfo($sql);
|
| 68 |
-
|
| 69 |
-
$sth = $this->conn->prepare( $sql, array( PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL ) );
|
| 70 |
-
if( !$sth )
|
| 71 |
-
{
|
| 72 |
-
$errInfo = $this->conn->errorInfo();
|
| 73 |
-
$this->triggerError( $errInfo[2] );
|
| 74 |
-
return FALSE;
|
| 75 |
-
}
|
| 76 |
-
$sth->execute();
|
| 77 |
-
return new QueryResult( $this, $sth );
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
/**
|
| 81 |
-
* Execute an SQL query
|
| 82 |
-
* @param String sql
|
| 83 |
-
* @return Mixed
|
| 84 |
-
*/
|
| 85 |
-
public function exec( $sql )
|
| 86 |
-
{
|
| 87 |
-
$this->debugInfo($sql);
|
| 88 |
-
|
| 89 |
-
$rowsAffected = $this->conn->exec( $sql );
|
| 90 |
-
$errInfo = $this->conn->errorInfo();
|
| 91 |
-
|
| 92 |
-
$error = $this->freetdsMode
|
| 93 |
-
? ($errInfo[0] !== '00000' && $errInfo[0] !== '01000')
|
| 94 |
-
: ($rowsAffected === FALSE);
|
| 95 |
-
|
| 96 |
-
if( $error ) {
|
| 97 |
-
$this->triggerError( $errInfo[2] );
|
| 98 |
-
return FALSE;
|
| 99 |
-
}
|
| 100 |
-
|
| 101 |
-
return TRUE;
|
| 102 |
-
}
|
| 103 |
-
|
| 104 |
-
/**
|
| 105 |
-
* Get a description of the last error
|
| 106 |
-
* @return String
|
| 107 |
-
*/
|
| 108 |
-
public function lastError()
|
| 109 |
-
{
|
| 110 |
-
$errInfo = $this->conn->errorInfo();
|
| 111 |
-
return $errInfo[2];
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
/**
|
| 115 |
-
* Fetch a result row as an associative array
|
| 116 |
-
* @param PDOStatement qHandle The query handle
|
| 117 |
-
* @return Array
|
| 118 |
-
*/
|
| 119 |
-
public function fetch_array( $qHandle )
|
| 120 |
-
{
|
| 121 |
-
return $qHandle->fetch( PDO::FETCH_ASSOC );
|
| 122 |
-
}
|
| 123 |
-
|
| 124 |
-
/**
|
| 125 |
-
* Fetch a result row as a numeric array
|
| 126 |
-
* @param PDOStatement qHandle The query handle
|
| 127 |
-
* @return Array
|
| 128 |
-
*/
|
| 129 |
-
public function fetch_numarray( $qHandle )
|
| 130 |
-
{
|
| 131 |
-
return $qHandle->fetch( PDO::FETCH_NUM );
|
| 132 |
-
}
|
| 133 |
-
|
| 134 |
-
/**
|
| 135 |
-
* Free resources associated with a query result set
|
| 136 |
-
* @param PDOStatement qHandle The query handle
|
| 137 |
-
*/
|
| 138 |
-
public function closeQuery( $qHandle )
|
| 139 |
-
{
|
| 140 |
-
$qHandle = NULL;
|
| 141 |
-
}
|
| 142 |
-
|
| 143 |
-
/**
|
| 144 |
-
* Get number of fields in a result
|
| 145 |
-
* @param PDOStatement qHandle The query handle
|
| 146 |
-
* @return Number
|
| 147 |
-
*/
|
| 148 |
-
public function num_fields( $qHandle )
|
| 149 |
-
{
|
| 150 |
-
return $qHandle->columnCount();
|
| 151 |
-
}
|
| 152 |
-
|
| 153 |
-
/**
|
| 154 |
-
* Get the name of the specified field in a result
|
| 155 |
-
* @param PDOStatement qHandle The query handle
|
| 156 |
-
* @param Number offset
|
| 157 |
-
* @return String
|
| 158 |
-
*/
|
| 159 |
-
public function field_name( $qHandle, $offset )
|
| 160 |
-
{
|
| 161 |
-
$meta = $qHandle->getColumnMeta( $offset );
|
| 162 |
-
if( !$meta || !$meta["name"] ) {
|
| 163 |
-
return 'column' . $offset;
|
| 164 |
-
}
|
| 165 |
-
return $meta["name"];
|
| 166 |
-
}
|
| 167 |
-
|
| 168 |
-
/**
|
| 169 |
-
* @param Mixed qHandle
|
| 170 |
-
* @param Number n
|
| 171 |
-
*/
|
| 172 |
-
public function seekRecord($qHandle, $n)
|
| 173 |
-
{
|
| 174 |
-
if( !$n )
|
| 175 |
-
return;
|
| 176 |
-
|
| 177 |
-
try {
|
| 178 |
-
$qHandle->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_ABS, $n );
|
| 179 |
-
return;
|
| 180 |
-
} catch( Exception $e ) {
|
| 181 |
-
|
| 182 |
-
}
|
| 183 |
-
|
| 184 |
-
//scroll fwd doesn't work
|
| 185 |
-
$i = 0;
|
| 186 |
-
while( $i < $n )
|
| 187 |
-
{
|
| 188 |
-
$qHandle->fetch();
|
| 189 |
-
$i++;
|
| 190 |
-
}
|
| 191 |
-
}
|
| 192 |
-
|
| 193 |
-
/**
|
| 194 |
-
* Execute an SQL query with blob fields processing
|
| 195 |
-
* @param String sql
|
| 196 |
-
* @param Array blobs
|
| 197 |
-
* @param Array blobTypes
|
| 198 |
-
* @return Boolean
|
| 199 |
-
*/
|
| 200 |
-
public function execWithBlobProcessing( $sql, $blobs, $blobTypes = array(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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/PostgreConnection.php
DELETED
|
@@ -1,250 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class PostgreConnection extends Connection
|
| 3 |
-
{
|
| 4 |
-
/**
|
| 5 |
-
* The connection string
|
| 6 |
-
* @type String
|
| 7 |
-
*/
|
| 8 |
-
protected $connstr;
|
| 9 |
-
|
| 10 |
-
/**
|
| 11 |
-
* db version
|
| 12 |
-
* @type Number
|
| 13 |
-
*/
|
| 14 |
-
public $postgreDbVersion = 8;
|
| 15 |
-
|
| 16 |
-
function __construct( $params )
|
| 17 |
-
{
|
| 18 |
-
parent::__construct( $params );
|
| 19 |
-
}
|
| 20 |
-
|
| 21 |
-
/**
|
| 22 |
-
* Set db connection's properties
|
| 23 |
-
* @param Array params
|
| 24 |
-
*/
|
| 25 |
-
protected function assignConnectionParams( $params )
|
| 26 |
-
{
|
| 27 |
-
parent::assignConnectionParams( $params );
|
| 28 |
-
|
| 29 |
-
$host = pg_escape_string( $params["connInfo"][0] ); //strConnectInfo1
|
| 30 |
-
$user = pg_escape_string( $params["connInfo"][1] ); //strConnectInfo2
|
| 31 |
-
$password = pg_escape_string( $params["connInfo"][2] ); //strConnectInfo3
|
| 32 |
-
$dbname = pg_escape_string( $params["connInfo"][4] ); //strConnectInfo5
|
| 33 |
-
$options = $params["connInfo"][3]; //strConnectInfo4
|
| 34 |
-
|
| 35 |
-
$this->connstr = "host='". $host .
|
| 36 |
-
"' user='". $user .
|
| 37 |
-
"' password='". $password .
|
| 38 |
-
"' dbname='". $dbname .
|
| 39 |
-
"' ".$options;
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
/**
|
| 43 |
-
* @return Array
|
| 44 |
-
*/
|
| 45 |
-
protected function getDbFunctionsExtraParams()
|
| 46 |
-
{
|
| 47 |
-
$extraParams = parent::getDbFunctionsExtraParams();
|
| 48 |
-
$extraParams["postgreDbVersion"] = $this->postgreDbVersion;
|
| 49 |
-
|
| 50 |
-
return $extraParams;
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
/**
|
| 54 |
-
* Open a connection to db
|
| 55 |
-
*/
|
| 56 |
-
public function connect()
|
| 57 |
-
{
|
| 58 |
-
if( GetGlobalData("showDetailedError", true) ) {
|
| 59 |
-
// there is no other way to display Postgre connection error
|
| 60 |
-
$errorMode = error_reporting( E_ALL );
|
| 61 |
-
}
|
| 62 |
-
$this->conn = pg_connect( $this->connstr );
|
| 63 |
-
if( GetGlobalData("showDetailedError", true) ) {
|
| 64 |
-
error_reporting( $errorMode );
|
| 65 |
-
}
|
| 66 |
-
if( !$this->conn )
|
| 67 |
-
$this->triggerError("Unable to connect");
|
| 68 |
-
|
| 69 |
-
$ret = pg_query("SELECT version()");
|
| 70 |
-
$row = $this->fetch_numarray($ret);
|
| 71 |
-
if( $row )
|
| 72 |
-
{
|
| 73 |
-
if( preg_match("/^PostgreSQL\s(\d{1,2})\./", $row[0], $matches) )
|
| 74 |
-
$this->postgreDbVersion = $matches[1];
|
| 75 |
-
}
|
| 76 |
-
|
| 77 |
-
return $this->conn;
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
/**
|
| 81 |
-
* Close the db connection
|
| 82 |
-
*/
|
| 83 |
-
public function close()
|
| 84 |
-
{
|
| 85 |
-
return pg_close( $this->conn );
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
/**
|
| 89 |
-
* Send an SQL query
|
| 90 |
-
* @param String sql
|
| 91 |
-
* @return Mixed
|
| 92 |
-
*/
|
| 93 |
-
public function query( $sql )
|
| 94 |
-
{
|
| 95 |
-
$this->debugInfo($sql);
|
| 96 |
-
|
| 97 |
-
if( version_compare(phpversion(),"4.2.0") >= 0 )
|
| 98 |
-
$ret = pg_query($this->conn, $sql);
|
| 99 |
-
else
|
| 100 |
-
$ret = pg_exec($this->conn, $sql);
|
| 101 |
-
|
| 102 |
-
if( !$ret )
|
| 103 |
-
{
|
| 104 |
-
$this->triggerError($this->lastError());
|
| 105 |
-
return FALSE;
|
| 106 |
-
}
|
| 107 |
-
|
| 108 |
-
return new QueryResult( $this, $ret );
|
| 109 |
-
}
|
| 110 |
-
|
| 111 |
-
/**
|
| 112 |
-
* Execute an SQL query
|
| 113 |
-
* @param String sql
|
| 114 |
-
*/
|
| 115 |
-
public function exec( $sql )
|
| 116 |
-
{
|
| 117 |
-
$qResult = $this->query( $sql );
|
| 118 |
-
if( $qResult )
|
| 119 |
-
return $qResult->getQueryHandle();
|
| 120 |
-
|
| 121 |
-
return FALSE;
|
| 122 |
-
}
|
| 123 |
-
|
| 124 |
-
/**
|
| 125 |
-
* Get a description of the last error
|
| 126 |
-
* @return String
|
| 127 |
-
*/
|
| 128 |
-
public function lastError()
|
| 129 |
-
{
|
| 130 |
-
if( version_compare(phpversion(),"4.2.0") >= 0 )
|
| 131 |
-
return @pg_last_error( $this->conn );
|
| 132 |
-
|
| 133 |
-
return "PostgreSQL error happened";
|
| 134 |
-
}
|
| 135 |
-
|
| 136 |
-
/**
|
| 137 |
-
* Get the auto generated id used in the last query
|
| 138 |
-
* @return Number
|
| 139 |
-
*/
|
| 140 |
-
public function getInsertedId($key = null, $table = null )
|
| 141 |
-
{
|
| 142 |
-
$qResult = $this->query( "select LASTVAL() as \"lv\"" );
|
| 143 |
-
if( $qResult )
|
| 144 |
-
{
|
| 145 |
-
$row = $qResult->fetchAssoc();
|
| 146 |
-
return $row["lv"];
|
| 147 |
-
}
|
| 148 |
-
return 0;
|
| 149 |
-
}
|
| 150 |
-
|
| 151 |
-
/**
|
| 152 |
-
* Fetch a result row as an associative array
|
| 153 |
-
* @param Mixed qHanle The query handle
|
| 154 |
-
* @return Array
|
| 155 |
-
*/
|
| 156 |
-
public function fetch_array( $qHandle )
|
| 157 |
-
{
|
| 158 |
-
$ret = pg_fetch_array($qHandle);
|
| 159 |
-
// remove numeric indexes
|
| 160 |
-
if( !$ret )
|
| 161 |
-
return array();
|
| 162 |
-
|
| 163 |
-
$fieldNum = 0;
|
| 164 |
-
foreach($ret as $key => $value)
|
| 165 |
-
{
|
| 166 |
-
if( is_int($key) )
|
| 167 |
-
{
|
| 168 |
-
$fieldNum = $key;
|
| 169 |
-
unset($ret[ $key ]);
|
| 170 |
-
}
|
| 171 |
-
elseif( $this->postgreDbVersion >= 9 && pg_field_type($qHandle, $fieldNum) == "bytea" && $value == "\x" )
|
| 172 |
-
{
|
| 173 |
-
$ret[ $key ] = '';
|
| 174 |
-
}
|
| 175 |
-
}
|
| 176 |
-
return $ret;
|
| 177 |
-
}
|
| 178 |
-
|
| 179 |
-
/**
|
| 180 |
-
* Fetch a result row as a numeric array
|
| 181 |
-
* @param Mixed qHanle The query handle
|
| 182 |
-
* @return Array
|
| 183 |
-
*/
|
| 184 |
-
public function fetch_numarray( $qHandle )
|
| 185 |
-
{
|
| 186 |
-
return @pg_fetch_row($qHandle);
|
| 187 |
-
}
|
| 188 |
-
|
| 189 |
-
/**
|
| 190 |
-
* Free resources associated with a query result set
|
| 191 |
-
* @param Mixed qHanle The query handle
|
| 192 |
-
*/
|
| 193 |
-
public function closeQuery( $qHandle )
|
| 194 |
-
{
|
| 195 |
-
@pg_free_result($qHandle);
|
| 196 |
-
}
|
| 197 |
-
|
| 198 |
-
/**
|
| 199 |
-
* Get number of fields in a result
|
| 200 |
-
* @param Mixed qHanle The query handle
|
| 201 |
-
* @return Number
|
| 202 |
-
*/
|
| 203 |
-
public function num_fields( $qHandle )
|
| 204 |
-
{
|
| 205 |
-
return @pg_num_fields($qHandle);
|
| 206 |
-
}
|
| 207 |
-
|
| 208 |
-
/**
|
| 209 |
-
* Get the name of the specified field in a result
|
| 210 |
-
* @param Mixed qHanle The query handle
|
| 211 |
-
* @param Number offset
|
| 212 |
-
* @return String
|
| 213 |
-
*/
|
| 214 |
-
public function field_name( $qHandle, $offset )
|
| 215 |
-
{
|
| 216 |
-
return @pg_field_name($qHandle, $offset);
|
| 217 |
-
}
|
| 218 |
-
|
| 219 |
-
/**
|
| 220 |
-
* @param Mixed qHandle
|
| 221 |
-
* @param Number pageSize
|
| 222 |
-
* @param Number page
|
| 223 |
-
*/
|
| 224 |
-
public function seekRecord($qHandle, $n)
|
| 225 |
-
{
|
| 226 |
-
pg_result_seek($qHandle, $n );
|
| 227 |
-
}
|
| 228 |
-
|
| 229 |
-
/**
|
| 230 |
-
* Execute an SQL query with blob fields processing
|
| 231 |
-
* @param String sql
|
| 232 |
-
* @param Array blobs
|
| 233 |
-
* @param Array blobTypes
|
| 234 |
-
* @return Boolean
|
| 235 |
-
*/
|
| 236 |
-
public function execWithBlobProcessing( $sql, $blobs, $blobTypes = array(), $autoincField = null )
|
| 237 |
-
{
|
| 238 |
-
$this->debugInfo($sql);
|
| 239 |
-
|
| 240 |
-
set_error_handler("empty_error_handler");
|
| 241 |
-
if( version_compare(phpversion(),"4.2.0") >= 0 )
|
| 242 |
-
$ret = pg_query($this->conn, $sql);
|
| 243 |
-
else
|
| 244 |
-
$ret = pg_exec($this->conn, $sql);
|
| 245 |
-
set_error_handler("runner_error_handler");
|
| 246 |
-
|
| 247 |
-
return $ret;
|
| 248 |
-
}
|
| 249 |
-
}
|
| 250 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/QueryResult.php
DELETED
|
@@ -1,209 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
require_once( getabspath("classes/datasource/dataresult.php") );
|
| 4 |
-
/**
|
| 5 |
-
* A wrapper of the Connection class methods
|
| 6 |
-
* basing on an SQL querty result hanle
|
| 7 |
-
*/
|
| 8 |
-
class QueryResult extends DataResult
|
| 9 |
-
{
|
| 10 |
-
/**
|
| 11 |
-
* The basic Connection object
|
| 12 |
-
* @type Connection
|
| 13 |
-
*/
|
| 14 |
-
protected $connectionObj;
|
| 15 |
-
|
| 16 |
-
/**
|
| 17 |
-
* the query result handle
|
| 18 |
-
* @type Mixed
|
| 19 |
-
*/
|
| 20 |
-
protected $handle;
|
| 21 |
-
|
| 22 |
-
protected $data;
|
| 23 |
-
|
| 24 |
-
// list of column names in the fetched query
|
| 25 |
-
protected $fieldNames = array();
|
| 26 |
-
|
| 27 |
-
protected $upperMap = array();
|
| 28 |
-
protected $fieldMap = array();
|
| 29 |
-
|
| 30 |
-
/**
|
| 31 |
-
* -1 - no data fetched. This is initial state.
|
| 32 |
-
* 0 - some data fetched
|
| 33 |
-
* 1 - unsuccessful attempt to fetch data made. EOF
|
| 34 |
-
*/
|
| 35 |
-
protected $state = -1;
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
function __construct( $connectionObj, $qHandle )
|
| 41 |
-
{
|
| 42 |
-
parent::__construct();
|
| 43 |
-
$this->connectionObj = $connectionObj;
|
| 44 |
-
$this->handle = $qHandle;
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
/**
|
| 49 |
-
* Get the query result handle
|
| 50 |
-
* @return Mixed
|
| 51 |
-
*/
|
| 52 |
-
public function getQueryHandle()
|
| 53 |
-
{
|
| 54 |
-
return $this->handle;
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
/**
|
| 58 |
-
* A wrapper for the Connection::fetch_array method
|
| 59 |
-
* @return Mixed - associative Array with record data if data is available.
|
| 60 |
-
* Otherwise it returns FALSE or empty Array depending on data provider. Use conversion to boolean to check if data exists:
|
| 61 |
-
* $data = $q->fetchAssoc();
|
| 62 |
-
* if($data)
|
| 63 |
-
* ...
|
| 64 |
-
*/
|
| 65 |
-
public function fetchAssoc()
|
| 66 |
-
{
|
| 67 |
-
if( $this->state == 1 )
|
| 68 |
-
return null;
|
| 69 |
-
|
| 70 |
-
if( $this->state == 0 )
|
| 71 |
-
{
|
| 72 |
-
$this->state = -1;
|
| 73 |
-
return $this->numericToAssoc( $this->data );
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
$ret = $this->connectionObj->fetch_array( $this->handle );
|
| 77 |
-
if( $this->fieldSubs ) {
|
| 78 |
-
$ret = $this->substituteFields( $ret );
|
| 79 |
-
}
|
| 80 |
-
$this->state = $ret ? -1 : 1;
|
| 81 |
-
return $ret;
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
/**
|
| 85 |
-
* A wrapper for the Connection::fetch_numarray method
|
| 86 |
-
* @return Mixed - integer-indexed Array with record data or empty Array or FALSE if no data available.
|
| 87 |
-
* See fetchAssoc description.
|
| 88 |
-
*/
|
| 89 |
-
public function fetchNumeric()
|
| 90 |
-
{
|
| 91 |
-
if( $this->state == 1 )
|
| 92 |
-
return null;
|
| 93 |
-
|
| 94 |
-
if( $this->state == 0 )
|
| 95 |
-
{
|
| 96 |
-
$this->state = -1;
|
| 97 |
-
return $this->data;
|
| 98 |
-
}
|
| 99 |
-
|
| 100 |
-
$ret = $this->connectionObj->fetch_numarray( $this->handle );
|
| 101 |
-
$this->state = $ret ? -1 : 1;
|
| 102 |
-
return $ret;
|
| 103 |
-
}
|
| 104 |
-
|
| 105 |
-
/**
|
| 106 |
-
* A wrapper for the Connection::closeQuery method
|
| 107 |
-
*/
|
| 108 |
-
public function closeQuery()
|
| 109 |
-
{
|
| 110 |
-
$this->connectionObj->closeQuery( $this->handle );
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
/**
|
| 114 |
-
* A wrapper for the Connection::num_fields method
|
| 115 |
-
*/
|
| 116 |
-
public function numFields()
|
| 117 |
-
{
|
| 118 |
-
return $this->connectionObj->num_fields( $this->handle );
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
/**
|
| 122 |
-
* A wrapper for the Connection::field_name method
|
| 123 |
-
*/
|
| 124 |
-
public function fieldName( $offset )
|
| 125 |
-
{
|
| 126 |
-
return $this->connectionObj->field_name( $this->handle, $offset );
|
| 127 |
-
}
|
| 128 |
-
|
| 129 |
-
/**
|
| 130 |
-
* A wrapper for the Connection::seekPage method
|
| 131 |
-
*/
|
| 132 |
-
public function seekRecord( $n )
|
| 133 |
-
{
|
| 134 |
-
$this->connectionObj->seekRecord( $this->handle, $n );
|
| 135 |
-
}
|
| 136 |
-
|
| 137 |
-
public function eof()
|
| 138 |
-
{
|
| 139 |
-
$this->prepareRecord();
|
| 140 |
-
return $this->state == 1;
|
| 141 |
-
}
|
| 142 |
-
|
| 143 |
-
protected function internalFetch()
|
| 144 |
-
{
|
| 145 |
-
if( $this->state == 1 )
|
| 146 |
-
return;
|
| 147 |
-
$this->fillColumnNames();
|
| 148 |
-
$this->data = $this->connectionObj->fetch_numarray( $this->handle );
|
| 149 |
-
$this->state = $this->data ? 0 : 1;
|
| 150 |
-
}
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
protected function fillColumnNames()
|
| 154 |
-
{
|
| 155 |
-
if( $this->fieldNames )
|
| 156 |
-
return;
|
| 157 |
-
$nFields = $this->numFields();
|
| 158 |
-
for( $i = 0; $i < $nFields; ++$i )
|
| 159 |
-
{
|
| 160 |
-
$fname = $this->fieldName( $i );
|
| 161 |
-
$this->fieldNames[] = $fname;
|
| 162 |
-
$this->fieldMap[ $fname ] = $i;
|
| 163 |
-
$this->upperMap[ strtoupper( $fname ) ] = $i;
|
| 164 |
-
}
|
| 165 |
-
}
|
| 166 |
-
|
| 167 |
-
public function next()
|
| 168 |
-
{
|
| 169 |
-
$this->prepareRecord();
|
| 170 |
-
$this->internalFetch();
|
| 171 |
-
}
|
| 172 |
-
|
| 173 |
-
protected function prepareRecord()
|
| 174 |
-
{
|
| 175 |
-
if( $this->state == -1 )
|
| 176 |
-
$this->internalFetch();
|
| 177 |
-
return $this->state != 1;
|
| 178 |
-
}
|
| 179 |
-
|
| 180 |
-
public function getData()
|
| 181 |
-
{
|
| 182 |
-
if( !$this->prepareRecord() )
|
| 183 |
-
return null;
|
| 184 |
-
return $this->numericToAssoc( $this->data );
|
| 185 |
-
}
|
| 186 |
-
|
| 187 |
-
public function getNumData()
|
| 188 |
-
{
|
| 189 |
-
if( !$this->prepareRecord() )
|
| 190 |
-
return null;
|
| 191 |
-
return $this->data;
|
| 192 |
-
}
|
| 193 |
-
|
| 194 |
-
public function count()
|
| 195 |
-
{
|
| 196 |
-
$cnt = 0;
|
| 197 |
-
while( $data = $this->fetchAssoc() ) {
|
| 198 |
-
++$cnt;
|
| 199 |
-
}
|
| 200 |
-
return $cnt;
|
| 201 |
-
}
|
| 202 |
-
|
| 203 |
-
public function reorder( $callback ) {
|
| 204 |
-
$arrayResult = ArrayResult::createFromResult( $this );
|
| 205 |
-
return $arrayResult->reorder( $callback );
|
| 206 |
-
}
|
| 207 |
-
|
| 208 |
-
}
|
| 209 |
-
?>
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/SQLite3Connection.php
DELETED
|
@@ -1,172 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class SQLite3Connection extends Connection
|
| 3 |
-
{
|
| 4 |
-
protected $dbname;
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
function __construct( $params )
|
| 8 |
-
{
|
| 9 |
-
parent::__construct( $params );
|
| 10 |
-
}
|
| 11 |
-
|
| 12 |
-
/**
|
| 13 |
-
* Set db connection's properties
|
| 14 |
-
* @param Array params
|
| 15 |
-
*/
|
| 16 |
-
protected function assignConnectionParams( $params )
|
| 17 |
-
{
|
| 18 |
-
parent::assignConnectionParams( $params );
|
| 19 |
-
|
| 20 |
-
$this->dbname = $params["connInfo"][0]; // strConnectInfo1
|
| 21 |
-
}
|
| 22 |
-
|
| 23 |
-
/**
|
| 24 |
-
* Open a connection to db
|
| 25 |
-
*/
|
| 26 |
-
public function connect()
|
| 27 |
-
{
|
| 28 |
-
$this->conn = new SQLite3( $this->dbname );
|
| 29 |
-
|
| 30 |
-
if (!$this->conn)
|
| 31 |
-
$this->triggerError($this->conn->lastErrorMsg());
|
| 32 |
-
|
| 33 |
-
return $this->conn;
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
/**
|
| 37 |
-
* Close the db connection
|
| 38 |
-
*/
|
| 39 |
-
public function close()
|
| 40 |
-
{
|
| 41 |
-
return $this->conn->close();
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
-
/**
|
| 45 |
-
* Send an SQL query
|
| 46 |
-
* @param String sql
|
| 47 |
-
* @return Mixed
|
| 48 |
-
*/
|
| 49 |
-
public function query( $sql )
|
| 50 |
-
{
|
| 51 |
-
$this->debugInfo($sql);
|
| 52 |
-
|
| 53 |
-
$ret = $this->conn->query($sql);
|
| 54 |
-
if( !$ret )
|
| 55 |
-
{
|
| 56 |
-
$this->triggerError($this->conn->lastErrorMsg());
|
| 57 |
-
return FALSE;
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
return new QueryResult( $this, $ret );
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
/**
|
| 64 |
-
* Execute an SQL query
|
| 65 |
-
* @param String sql
|
| 66 |
-
*/
|
| 67 |
-
public function exec( $sql )
|
| 68 |
-
{
|
| 69 |
-
$this->debugInfo($sql);
|
| 70 |
-
return $this->conn->exec($sql);
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
/**
|
| 74 |
-
* Get a description of the last error
|
| 75 |
-
* @return String
|
| 76 |
-
*/
|
| 77 |
-
public function lastError()
|
| 78 |
-
{
|
| 79 |
-
return @$this->conn->lastErrorMsg();
|
| 80 |
-
}
|
| 81 |
-
|
| 82 |
-
/**
|
| 83 |
-
* Get the auto generated id used in the last query
|
| 84 |
-
* @return Number
|
| 85 |
-
*/
|
| 86 |
-
public function getInsertedId($key = null, $table = null )
|
| 87 |
-
{
|
| 88 |
-
return @$this->conn->lastInsertRowID();
|
| 89 |
-
}
|
| 90 |
-
|
| 91 |
-
/**
|
| 92 |
-
* Fetch a result row as an associative array
|
| 93 |
-
* @param Mixed qHanle The query handle
|
| 94 |
-
* @return Array
|
| 95 |
-
*/
|
| 96 |
-
public function fetch_array( $qHandle )
|
| 97 |
-
{
|
| 98 |
-
return $qHandle->fetchArray($mode = SQLITE3_ASSOC);
|
| 99 |
-
}
|
| 100 |
-
|
| 101 |
-
/**
|
| 102 |
-
* Fetch a result row as a numeric array
|
| 103 |
-
* @param Mixed qHanle The query handle
|
| 104 |
-
* @return Array
|
| 105 |
-
*/
|
| 106 |
-
public function fetch_numarray( $qHandle )
|
| 107 |
-
{
|
| 108 |
-
return $qHandle->fetchArray($mode = SQLITE3_NUM);
|
| 109 |
-
}
|
| 110 |
-
|
| 111 |
-
/**
|
| 112 |
-
* Free resources associated with a query result set
|
| 113 |
-
* @param Mixed qHanle The query handle
|
| 114 |
-
*/
|
| 115 |
-
public function closeQuery( $qHandle )
|
| 116 |
-
{
|
| 117 |
-
$qHandle->finalize();
|
| 118 |
-
}
|
| 119 |
-
|
| 120 |
-
/**
|
| 121 |
-
* Get number of fields in a result
|
| 122 |
-
* @param Mixed qHanle The query handle
|
| 123 |
-
* @return Number
|
| 124 |
-
*/
|
| 125 |
-
public function num_fields( $qHandle )
|
| 126 |
-
{
|
| 127 |
-
return $qHandle->numColumns();
|
| 128 |
-
}
|
| 129 |
-
|
| 130 |
-
/**
|
| 131 |
-
* Get the name of the specified field in a result
|
| 132 |
-
* @param Mixed qHanle The query handle
|
| 133 |
-
* @param Number offset
|
| 134 |
-
* @return String
|
| 135 |
-
*/
|
| 136 |
-
public function field_name( $qHandle, $offset )
|
| 137 |
-
{
|
| 138 |
-
return $qHandle->columnName($offset);
|
| 139 |
-
}
|
| 140 |
-
|
| 141 |
-
/**
|
| 142 |
-
* @param Mixed qHandle
|
| 143 |
-
* @param Number pageSize
|
| 144 |
-
* @param Number page
|
| 145 |
-
*/
|
| 146 |
-
public function seekRecord($qHandle, $n)
|
| 147 |
-
{
|
| 148 |
-
for($i = 0; $i < $n; $i++)
|
| 149 |
-
{
|
| 150 |
-
$qHandle->fetchArray();
|
| 151 |
-
}
|
| 152 |
-
}
|
| 153 |
-
|
| 154 |
-
/**
|
| 155 |
-
* Execute an SQL query with blob fields processing
|
| 156 |
-
* @param String sql
|
| 157 |
-
* @param Array blobs
|
| 158 |
-
* @param Array blobTypes
|
| 159 |
-
* @return Boolean
|
| 160 |
-
*/
|
| 161 |
-
public function execWithBlobProcessing( $sql, $blobs, $blobTypes = array(), $autoincField = null )
|
| 162 |
-
{
|
| 163 |
-
$this->debugIn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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/apis.php
DELETED
|
@@ -1,66 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
require_once( getabspath('connections/rest.php') );
|
| 3 |
-
|
| 4 |
-
class RestManager
|
| 5 |
-
{
|
| 6 |
-
protected $_tablesConnectionIds;
|
| 7 |
-
protected $_connectionsData;
|
| 8 |
-
protected $_connectionsIdByName = array();
|
| 9 |
-
|
| 10 |
-
function __construct()
|
| 11 |
-
{
|
| 12 |
-
$this->_setConnectionsData();
|
| 13 |
-
// $this->_setTablesConnectionIds();
|
| 14 |
-
}
|
| 15 |
-
|
| 16 |
-
protected function _setTablesConnectionIds()
|
| 17 |
-
{
|
| 18 |
-
$connectionsIds = array();
|
| 19 |
-
$this->_tablesConnectionIds = &$connectionsIds;
|
| 20 |
-
}
|
| 21 |
-
|
| 22 |
-
protected function _setConnectionsData()
|
| 23 |
-
{
|
| 24 |
-
// content of this function can be modified on demo account
|
| 25 |
-
// variable names $data and $connectionsData are important
|
| 26 |
-
|
| 27 |
-
$connectionsData = array();
|
| 28 |
-
|
| 29 |
-
$this->_connectionsData = &$connectionsData;
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
public function getConnection( $id ) {
|
| 33 |
-
if( $id == spidGOOGLEDRIVE ) {
|
| 34 |
-
return getGoogleDriveConnection();
|
| 35 |
-
}
|
| 36 |
-
if( $id == spidONEDRIVE ) {
|
| 37 |
-
return getOneDriveConnection();
|
| 38 |
-
}
|
| 39 |
-
if( $id == spidDROPBOX ) {
|
| 40 |
-
return getDropboxConnection();
|
| 41 |
-
}
|
| 42 |
-
if( !$this->_connectionsData[$id] ) {
|
| 43 |
-
return null;
|
| 44 |
-
}
|
| 45 |
-
return new RestConnection( $this->_connectionsData[ $id ] );
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
public function idByName( $name ) {
|
| 49 |
-
foreach( $this->_connectionsData as $id => $data ) {
|
| 50 |
-
if( $data["connName"] == $name ) {
|
| 51 |
-
return $id;
|
| 52 |
-
}
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
// return first available
|
| 56 |
-
foreach( $this->_connectionsData as $id => $data ) {
|
| 57 |
-
return $id;
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbfunctions/DB2Functions.php
DELETED
|
@@ -1,127 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class DB2Functions extends DBFunctions
|
| 3 |
-
{
|
| 4 |
-
/**
|
| 5 |
-
* @param String str
|
| 6 |
-
* @return String
|
| 7 |
-
*/
|
| 8 |
-
public function escapeLIKEpattern( $str )
|
| 9 |
-
{
|
| 10 |
-
return $str;
|
| 11 |
-
}
|
| 12 |
-
|
| 13 |
-
/**
|
| 14 |
-
* @param String str
|
| 15 |
-
* @return String
|
| 16 |
-
*/
|
| 17 |
-
public function addSlashes( $str )
|
| 18 |
-
{
|
| 19 |
-
return str_replace("'", "''", $str);
|
| 20 |
-
}
|
| 21 |
-
|
| 22 |
-
/**
|
| 23 |
-
* @param String str
|
| 24 |
-
* @return String
|
| 25 |
-
*/
|
| 26 |
-
public function addSlashesBinary( $str )
|
| 27 |
-
{
|
| 28 |
-
return "blob(x'" . bin2hex( $str ) . "')";
|
| 29 |
-
}
|
| 30 |
-
|
| 31 |
-
/**
|
| 32 |
-
* @param String dbval
|
| 33 |
-
* @return String
|
| 34 |
-
*/
|
| 35 |
-
public function upper( $dbval )
|
| 36 |
-
{
|
| 37 |
-
return "upper(".$dbval.")";
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
/**
|
| 41 |
-
* It's called for Contains and Starts with searches
|
| 42 |
-
* @param Mixed value
|
| 43 |
-
* @param Number type (oprional)
|
| 44 |
-
* @return String
|
| 45 |
-
*/
|
| 46 |
-
public function field2char($value, $type = 3)
|
| 47 |
-
{
|
| 48 |
-
if( IsCharType($type) )
|
| 49 |
-
return $value;
|
| 50 |
-
return "char(".$value.")";
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
/**
|
| 54 |
-
* @param Mixed value
|
| 55 |
-
* @param Number type
|
| 56 |
-
* @return String
|
| 57 |
-
*/
|
| 58 |
-
public function field2time($value, $type)
|
| 59 |
-
{
|
| 60 |
-
return $value;
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
/**
|
| 64 |
-
* Get the auto generated SQL string used in the last query
|
| 65 |
-
* @param String key
|
| 66 |
-
* @param String table
|
| 67 |
-
* @return String
|
| 68 |
-
*/
|
| 69 |
-
public function getInsertedIdSQL( $key = null, $table = null)
|
| 70 |
-
{
|
| 71 |
-
return "SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1";
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
public function limitedQuery( $connection, $strSQL, $skip, $total, $applyLimit )
|
| 75 |
-
{
|
| 76 |
-
if( $applyLimit && $total >= 0 ) {
|
| 77 |
-
$strSQL .= " FETCH FIRST " . ( $total + $skip ) . " ROWS ONLY";
|
| 78 |
-
}
|
| 79 |
-
/*
|
| 80 |
-
if( $applyLimit && $connection->dbType == nDATABASE_DB2 && ( $skip || $total >= 0 ) )
|
| 81 |
-
{
|
| 82 |
-
$limits = array();
|
| 83 |
-
if( $skip )
|
| 84 |
-
$limits []= "DB2_ROW_NUMBER > " . $skip;
|
| 85 |
-
if( $total )
|
| 86 |
-
$limits []= "DB2_ROW_NUMBER <= " . ( $skip + $total );
|
| 87 |
-
$strSQL = "with DB2_QUERY as (".$strSQL.") select * from DB2_QUERY where " . implode( " and ", $limits );
|
| 88 |
-
}
|
| 89 |
-
*/
|
| 90 |
-
$qResult = $connection->query( $strSQL );
|
| 91 |
-
if( $applyLimit ) {
|
| 92 |
-
$qResult->seekRecord( $skip );
|
| 93 |
-
}
|
| 94 |
-
|
| 95 |
-
return $qResult;
|
| 96 |
-
}
|
| 97 |
-
public function intervalExpressionString( $expr, $interval )
|
| 98 |
-
{
|
| 99 |
-
return DBFunctions::intervalExprSubstr( $expr, $interval );
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
public function intervalExpressionNumber( $expr, $interval )
|
| 103 |
-
{
|
| 104 |
-
return DBFunctions::intervalExprFloor( $expr, $interval );
|
| 105 |
-
}
|
| 106 |
-
|
| 107 |
-
public function intervalExpressionDate( $expr, $interval )
|
| 108 |
-
{
|
| 109 |
-
if($interval == 1) // DATE_INTERVAL_YEAR
|
| 110 |
-
return "year(".$expr.")*10000+0101";
|
| 111 |
-
if($interval == 2) // DATE_INTERVAL_QUARTER
|
| 112 |
-
return "year(".$expr.")*10000+QUARTER(".$expr.")*100+1";
|
| 113 |
-
if($interval == 3) // DATE_INTERVAL_MONTH
|
| 114 |
-
return "year(".$expr.")*10000+month(".$expr.")*100+1";
|
| 115 |
-
if($interval == 4) // DATE_INTERVAL_WEEK
|
| 116 |
-
return "year(".$expr.")*10000+week(".$expr.")*100+01";
|
| 117 |
-
if($interval == 5) // DATE_INTERVAL_DAY
|
| 118 |
-
return "year(".$expr.")*10000+month(".$expr.")*100+day(".$expr.")";
|
| 119 |
-
if($interval == 6) // DATE_INTERVAL_HOUR
|
| 120 |
-
return "year(".$expr.")*1000000+month(".$expr.")*10000+day(".$expr.")*100+HOUR(".$expr.")";
|
| 121 |
-
if($interval == 7) // DATE_INTERVAL_MINUTE
|
| 122 |
-
return "year(".$expr.")*100000000+month(".$expr.")*1000000+day(".$expr.")*10000+HOUR(".$expr.")*100+minute(".$expr.")";
|
| 123 |
-
return $expr;
|
| 124 |
-
}
|
| 125 |
-
|
| 126 |
-
}
|
| 127 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbfunctions/DBFunctions.php
DELETED
|
@@ -1,364 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class DBFunctions
|
| 3 |
-
{
|
| 4 |
-
/**
|
| 5 |
-
* The left db wrapper
|
| 6 |
-
* @type String
|
| 7 |
-
*/
|
| 8 |
-
protected $strLeftWrapper;
|
| 9 |
-
|
| 10 |
-
/**
|
| 11 |
-
* The right db wrapper
|
| 12 |
-
* @type String
|
| 13 |
-
*/
|
| 14 |
-
protected $strRightWrapper;
|
| 15 |
-
|
| 16 |
-
protected $escapeChars = array();
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
function __construct( $params )
|
| 20 |
-
{
|
| 21 |
-
// default identifier wrappers
|
| 22 |
-
$this->strLeftWrapper = "\"";
|
| 23 |
-
$this->strRightWrapper = "\"";
|
| 24 |
-
|
| 25 |
-
$this->escapeChars[ '\'' ] = true;
|
| 26 |
-
|
| 27 |
-
if( isset( $params["leftWrap"] ) && isset( $params["rightWrap"] ) )
|
| 28 |
-
{
|
| 29 |
-
$this->strLeftWrapper = $params["leftWrap"];
|
| 30 |
-
$this->strRightWrapper = $params["rightWrap"];
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
/**
|
| 36 |
-
* @param String strName
|
| 37 |
-
* @return String
|
| 38 |
-
*/
|
| 39 |
-
public function addTableWrappers( $strName )
|
| 40 |
-
{
|
| 41 |
-
if( substr($strName, 0, 1) == $this->strLeftWrapper )
|
| 42 |
-
return $strName;
|
| 43 |
-
|
| 44 |
-
$arr = explode(".", $strName);
|
| 45 |
-
$ret = "";
|
| 46 |
-
foreach( $arr as $e )
|
| 47 |
-
{
|
| 48 |
-
if( $ret != "" )
|
| 49 |
-
$ret .= ".";
|
| 50 |
-
$ret .= $this->strLeftWrapper . $e . $this->strRightWrapper;
|
| 51 |
-
}
|
| 52 |
-
return $ret;
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
/**
|
| 57 |
-
* Tells if the database supports schemas
|
| 58 |
-
* @return boolean
|
| 59 |
-
*/
|
| 60 |
-
public function schemaSupported()
|
| 61 |
-
{
|
| 62 |
-
return true;
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
/**
|
| 66 |
-
* Tells if the database supports cross-database references:
|
| 67 |
-
* db.tablename
|
| 68 |
-
* @return boolean
|
| 69 |
-
*/
|
| 70 |
-
public function crossDbSupported()
|
| 71 |
-
{
|
| 72 |
-
return true;
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
/**
|
| 77 |
-
* Parses the table name into database, schema and table name
|
| 78 |
-
* @param string $name the table name
|
| 79 |
-
*/
|
| 80 |
-
public function getTableNameComponents($name)
|
| 81 |
-
{
|
| 82 |
-
$strippedTableName = str_replace( array($this->strLeftWrapper,$this->strRightWrapper), '', $name ) ;
|
| 83 |
-
$parts = explode('.', $strippedTableName );
|
| 84 |
-
|
| 85 |
-
$components = array();
|
| 86 |
-
$components["fullName"] = $name;
|
| 87 |
-
|
| 88 |
-
if( count($parts) == 3 && $this->crossDbSupported() && $this->schemaSupported()) {
|
| 89 |
-
// DB name, schema name and table name passed
|
| 90 |
-
$components["db"] = $parts[0];
|
| 91 |
-
$components["schema"] = $parts[1];
|
| 92 |
-
$components["table"] = $parts[2];
|
| 93 |
-
}
|
| 94 |
-
elseif ( count($parts) == 2 && ( $this->crossDbSupported() || $this->schemaSupported() ) )
|
| 95 |
-
{
|
| 96 |
-
if( $this->schemaSupported() )
|
| 97 |
-
$components["schema"] = $parts[0];
|
| 98 |
-
else
|
| 99 |
-
$components["db"] = $parts[0];
|
| 100 |
-
$components["table"] = $parts[1];
|
| 101 |
-
}
|
| 102 |
-
else
|
| 103 |
-
{
|
| 104 |
-
$components["table"] = $name;
|
| 105 |
-
}
|
| 106 |
-
|
| 107 |
-
return $components;
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
-
/**
|
| 111 |
-
* Get the auto generated SQL string used in the last query
|
| 112 |
-
* @param String key (optional)
|
| 113 |
-
* @param String table (optional)
|
| 114 |
-
* @return String
|
| 115 |
-
*/
|
| 116 |
-
public function getInsertedIdSQL( $key = null, $table = null)
|
| 117 |
-
{
|
| 118 |
-
return "SELECT MAX(" . $this->addFieldWrappers( $key ) . ") FROM " . $this->addTableWrappers( $table );
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
/**
|
| 122 |
-
* @param String strName
|
| 123 |
-
* @return String
|
| 124 |
-
*/
|
| 125 |
-
public function timeToSecWrapper( $strName )
|
| 126 |
-
{
|
| 127 |
-
return $this->addTableWrappers($strName);
|
| 128 |
-
}
|
| 129 |
-
|
| 130 |
-
/**
|
| 131 |
-
* @param String str
|
| 132 |
-
* @return String
|
| 133 |
-
*/
|
| 134 |
-
public function prepareString( $str )
|
| 135 |
-
{
|
| 136 |
-
return "'".$this->addSlashes($str)."'";
|
| 137 |
-
}
|
| 138 |
-
|
| 139 |
-
/**
|
| 140 |
-
* @param String str
|
| 141 |
-
* @return String
|
| 142 |
-
*/
|
| 143 |
-
public function addSlashes( $str )
|
| 144 |
-
{
|
| 145 |
-
return str_replace("'", "''", $str);
|
| 146 |
-
}
|
| 147 |
-
|
| 148 |
-
/**
|
| 149 |
-
* Alias for addSlashes
|
| 150 |
-
* @param String str
|
| 151 |
-
* @return String
|
| 152 |
-
*/
|
| 153 |
-
public function escapeString( $str )
|
| 154 |
-
{
|
| 155 |
-
return $this->addSlashes( $str );
|
| 156 |
-
}
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
/**
|
| 160 |
-
* adds wrappers to field name if required
|
| 161 |
-
* @param String strName
|
| 162 |
-
* @return String
|
| 163 |
-
*/
|
| 164 |
-
public function addFieldWrappers( $strName )
|
| 165 |
-
{
|
| 166 |
-
$strName = str_replace(
|
| 167 |
-
array( $this->strLeftWrapper, $this->strRightWrapper ),
|
| 168 |
-
'',
|
| 169 |
-
$strName
|
| 170 |
-
);
|
| 171 |
-
return $this->strLeftWrapper.$strName.$this->strRightWrapper;
|
| 172 |
-
}
|
| 173 |
-
|
| 174 |
-
/**
|
| 175 |
-
* Decode binary value selected from the database
|
| 176 |
-
* @param String str
|
| 177 |
-
* @return String
|
| 178 |
-
*/
|
| 179 |
-
public function stripSlashesBinary( $str )
|
| 180 |
-
{
|
| 181 |
-
return $str;
|
| 182 |
-
}
|
| 183 |
-
|
| 184 |
-
/**
|
| 185 |
-
* Checks if character at position $pos in SQL string is inside quotes.
|
| 186 |
-
* Example:
|
| 187 |
-
* select 'aaa\' 1', ' ' 2
|
| 188 |
-
* Character 1 is on quotes, 2 - not
|
| 189 |
-
* @return Boolean
|
| 190 |
-
*/
|
| 191 |
-
public function positionQuoted( $sql, $pos )
|
| 192 |
-
{
|
| 193 |
-
$inQuote = false;
|
| 194 |
-
$afterEscape = false;
|
| 195 |
-
for ($i = 0; $i < $pos; $i++)
|
| 196 |
-
{
|
| 197 |
-
$c = substr( $sql, $i, 1);
|
| 198 |
-
if( !$afterEscape )
|
| 199 |
-
{
|
| 200 |
-
if ( $c == '\'' )
|
| 201 |
-
$inQuote = !$inQuote;
|
| 202 |
-
else
|
| 203 |
-
$afterEscape = !$inQuote && isset( $this->escapeChars[ $c ] );
|
| 204 |
-
}
|
| 205 |
-
else
|
| 206 |
-
$afterEscape = false;
|
| 207 |
-
}
|
| 208 |
-
return $inQuote;
|
| 209 |
-
}
|
| 210 |
-
|
| 211 |
-
/**
|
| 212 |
-
* @param String str
|
| 213 |
-
* @return String
|
| 214 |
-
*/
|
| 215 |
-
public function escapeLIKEpattern( $str )
|
| 216 |
-
{
|
| 217 |
-
return $str;
|
| 218 |
-
}
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
/**
|
| 222 |
-
* @param String str
|
| 223 |
-
* @return String
|
| 224 |
-
*/
|
| 225 |
-
public function addSlashesBinary( $str )
|
| 226 |
-
{
|
| 227 |
-
return $this->addSlashes($str);
|
| 228 |
-
}
|
| 229 |
-
|
| 230 |
-
/**
|
| 231 |
-
* @param String dbval
|
| 232 |
-
* @return String
|
| 233 |
-
*/
|
| 234 |
-
public function upper( $dbval )
|
| 235 |
-
{
|
| 236 |
-
return $dbval;
|
| 237 |
-
}
|
| 238 |
-
|
| 239 |
-
/**
|
| 240 |
-
* @param String dbval
|
| 241 |
-
* @return String
|
| 242 |
-
*/
|
| 243 |
-
public function caseSensitiveComparison( $val1, $val2 )
|
| 244 |
-
{
|
| 245 |
-
return $val1 . ' = ' . $val2;
|
| 246 |
-
}
|
| 247 |
-
|
| 248 |
-
public function caseInsensitiveComparison( $val1, $val2 )
|
| 249 |
-
{
|
| 250 |
-
return $this->upper( $val1 ) . ' = ' . $this->upper( $val2 );
|
| 251 |
-
}
|
| 252 |
-
|
| 253 |
-
/**
|
| 254 |
-
* @param Mixed $val
|
| 255 |
-
* @return String
|
| 256 |
-
*/
|
| 257 |
-
public function addDateQuotes( $val )
|
| 258 |
-
{
|
| 259 |
-
if( $val == "" || $val === null )
|
| 260 |
-
return 'null';
|
| 261 |
-
return "'".$this->addSlashes($val)."'";
|
| 262 |
-
}
|
| 263 |
-
|
| 264 |
-
/**
|
| 265 |
-
* It's called for Contains and Starts with searches
|
| 266 |
-
* @param Mixed value
|
| 267 |
-
* @param Number type (optional)
|
| 268 |
-
* @return String
|
| 269 |
-
*/
|
| 270 |
-
public function field2char($value, $type = 3)
|
| 271 |
-
{
|
| 272 |
-
return $value;
|
| 273 |
-
}
|
| 274 |
-
|
| 275 |
-
/**
|
| 276 |
-
* @param Mixed value
|
| 277 |
-
* @param Number type
|
| 278 |
-
* @return String
|
| 279 |
-
*/
|
| 280 |
-
public function field2time($value, $type)
|
| 281 |
-
{
|
| 282 |
-
return $value;
|
| 283 |
-
}
|
| 284 |
-
|
| 285 |
-
public function limitedQuery( $connection, $strSQL, $skip, $total, $applyLimit )
|
| 286 |
-
{
|
| 287 |
-
$qResult = $connection->query( $strSQL );
|
| 288 |
-
$qResult->seekRecord( $skip );
|
| 289 |
-
return $qResult;
|
| 290 |
-
}
|
| 291 |
-
|
| 292 |
-
/**
|
| 293 |
-
* Applies group type to a character expression.
|
| 294 |
-
* <SQL expression> => substring(<SQL expression>, 0, N )
|
| 295 |
-
* @param String expr - SQL expression
|
| 296 |
-
* @param Integer interval - type of interval.
|
| 297 |
-
* 0 - whole expression, 1 first character, 2 - first two chars etc
|
| 298 |
-
* @return String
|
| 299 |
-
*/
|
| 300 |
-
public function intervalExpressionString( $expr, $interval )
|
| 301 |
-
{
|
| 302 |
-
// default implementation
|
| 303 |
-
return $expr;
|
| 304 |
-
}
|
| 305 |
-
|
| 306 |
-
/**
|
| 307 |
-
* Applies group type to a numeric expression.
|
| 308 |
-
* @param String expr - SQL expression
|
| 309 |
-
* @param Integer interval - type of interval.
|
| 310 |
-
* @return String
|
| 311 |
-
*/
|
| 312 |
-
public function intervalExpressionNumber( $expr, $interval )
|
| 313 |
-
{
|
| 314 |
-
// default implementation
|
| 315 |
-
return $expr;
|
| 316 |
-
}
|
| 317 |
-
|
| 318 |
-
/**
|
| 319 |
-
* Applies group type to a DATE expression.
|
| 320 |
-
* @param String expr - SQL expression
|
| 321 |
-
* @param Integer interval - type of interval.
|
| 322 |
-
* @return String
|
| 323 |
-
*/
|
| 324 |
-
public function intervalExpressionDate( $expr, $interval )
|
| 325 |
-
{
|
| 326 |
-
// default implementation
|
| 327 |
-
return $expr;
|
| 328 |
-
}
|
| 329 |
-
|
| 330 |
-
public static function intervalExprLeft( $expr, $interval ) {
|
| 331 |
-
if( !$interval )
|
| 332 |
-
return $expr;
|
| 333 |
-
return "left(" . $expr . ", " . $interval . ")";
|
| 334 |
-
}
|
| 335 |
-
|
| 336 |
-
public static function intervalExprSubstr( $expr, $interval ) {
|
| 337 |
-
if( !$interval )
|
| 338 |
-
return $expr;
|
| 339 |
-
return "substr(" . $expr . ", 1, " . $interval . ")";
|
| 340 |
-
}
|
| 341 |
-
|
| 342 |
-
public static function intervalExprSubstring( $expr, $interval ) {
|
| 343 |
-
if( !$interval )
|
| 344 |
-
return $expr;
|
| 345 |
-
return "substring(" . $expr . " from 1 for " . $interval . ")";
|
| 346 |
-
}
|
| 347 |
-
|
| 348 |
-
public static function intervalExprFloor( $expr, $interval ) {
|
| 349 |
-
if( !$interval )
|
| 350 |
-
return $expr;
|
| 351 |
-
return "floor( " . $expr . " / " . $interval . " ) * ".$interval;
|
| 352 |
-
}
|
| 353 |
-
|
| 354 |
-
/**
|
| 355 |
-
* Get list of initialization sql commands
|
| 356 |
-
* @return Array
|
| 357 |
-
*/
|
| 358 |
-
public function initializationSQL() {
|
| 359 |
-
return array();
|
| 360 |
-
}
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
}
|
| 364 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbfunctions/GenericFunctions.php
DELETED
|
@@ -1,19 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class GenericFunctions extends DBFunctions
|
| 3 |
-
{
|
| 4 |
-
|
| 5 |
-
/**
|
| 6 |
-
* @param String strName
|
| 7 |
-
* @return String
|
| 8 |
-
*/
|
| 9 |
-
public function addTableWrappers($strName)
|
| 10 |
-
{
|
| 11 |
-
if( $this->strLeftWrapper != "\"")
|
| 12 |
-
return $this->addFieldWrappers($strName);
|
| 13 |
-
|
| 14 |
-
return DBFunctions::addTableWrappers( $strName );
|
| 15 |
-
}
|
| 16 |
-
|
| 17 |
-
}
|
| 18 |
-
|
| 19 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbfunctions/InformixFunctions.php
DELETED
|
@@ -1,86 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class InformixFunctions extends DBFunctions
|
| 3 |
-
{
|
| 4 |
-
/**
|
| 5 |
-
* @param String str
|
| 6 |
-
* @return String
|
| 7 |
-
*/
|
| 8 |
-
public function escapeLIKEpattern( $str )
|
| 9 |
-
{
|
| 10 |
-
return $str;
|
| 11 |
-
}
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
/**
|
| 15 |
-
* @param String str
|
| 16 |
-
* @return String
|
| 17 |
-
*/
|
| 18 |
-
public function addSlashesBinary( $str )
|
| 19 |
-
{
|
| 20 |
-
return $str;
|
| 21 |
-
}
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
/**
|
| 25 |
-
* @param String dbval
|
| 26 |
-
* @return String
|
| 27 |
-
*/
|
| 28 |
-
public function upper( $dbval )
|
| 29 |
-
{
|
| 30 |
-
return "upper(".$dbval.")";
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
/**
|
| 34 |
-
* @param Mixed $val
|
| 35 |
-
* @return String
|
| 36 |
-
*/
|
| 37 |
-
public function addDateQuotes( $val )
|
| 38 |
-
{
|
| 39 |
-
if( $val == "" || $val === null )
|
| 40 |
-
return 'null';
|
| 41 |
-
$arrDate = db2time($val);
|
| 42 |
-
return "'".$arrDate[0]."-".$arrDate[1]."-".$arrDate[2]." ".$arrDate[3].":".$arrDate[4].":".$arrDate[5]."'";
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
/**
|
| 46 |
-
* It's called for Contains and Starts with searches
|
| 47 |
-
* @param Mixed value
|
| 48 |
-
* @param Number type (optional)
|
| 49 |
-
* @return String
|
| 50 |
-
*/
|
| 51 |
-
public function field2char($value, $type = 3)
|
| 52 |
-
{
|
| 53 |
-
return 'TO_CHAR(' . $value . ')';
|
| 54 |
-
}
|
| 55 |
-
/**
|
| 56 |
-
* @param Mixed value
|
| 57 |
-
* @param Number type
|
| 58 |
-
* @return String
|
| 59 |
-
*/
|
| 60 |
-
public function field2time($value, $type)
|
| 61 |
-
{
|
| 62 |
-
return $value;
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
public function limitedQuery( $connection, $strSQL, $skip, $total, $applyLimit )
|
| 66 |
-
{
|
| 67 |
-
if( $applyLimit && $total >= 0 )
|
| 68 |
-
$strSQL = AddTopIfx($strSQL, $skip + $total);
|
| 69 |
-
|
| 70 |
-
$qResult = $connection->query( $strSQL );
|
| 71 |
-
$qResult->seekRecord( $skip );
|
| 72 |
-
|
| 73 |
-
return $qResult;
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
public function intervalExpressionString( $expr, $interval )
|
| 77 |
-
{
|
| 78 |
-
return DBFunctions::intervalExprSubstring( $expr, $interval );
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
public function intervalExpressionNumber( $expr, $interval )
|
| 82 |
-
{
|
| 83 |
-
return DBFunctions::intervalExprFloor( $expr, $interval );
|
| 84 |
-
}
|
| 85 |
-
}
|
| 86 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbfunctions/MSSQLFunctions.php
DELETED
|
@@ -1,174 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class MSSQLFunctions extends DBFunctions
|
| 3 |
-
{
|
| 4 |
-
|
| 5 |
-
function __construct( $params )
|
| 6 |
-
{
|
| 7 |
-
parent::__construct($params);
|
| 8 |
-
$this->strLeftWrapper = "[";
|
| 9 |
-
$this->strRightWrapper = "]";
|
| 10 |
-
}
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
/**
|
| 14 |
-
* @param String str
|
| 15 |
-
* @return String
|
| 16 |
-
*/
|
| 17 |
-
public function escapeLIKEpattern( $str )
|
| 18 |
-
{
|
| 19 |
-
return str_replace(array('[', '%', '_'), array('[[]', '[%]', '[_]'), $str);
|
| 20 |
-
}
|
| 21 |
-
|
| 22 |
-
/**
|
| 23 |
-
* @param String str
|
| 24 |
-
* @return String
|
| 25 |
-
*/
|
| 26 |
-
public function prepareString( $str )
|
| 27 |
-
{
|
| 28 |
-
return "N'".$this->addSlashes($str)."'";
|
| 29 |
-
}
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
/**
|
| 33 |
-
* @param String str
|
| 34 |
-
* @return String
|
| 35 |
-
*/
|
| 36 |
-
public function addSlashesBinary( $str )
|
| 37 |
-
{
|
| 38 |
-
return "0x".bin2hex($str);
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
/**
|
| 42 |
-
* @param String dbval
|
| 43 |
-
* @return String
|
| 44 |
-
*/
|
| 45 |
-
public function upper( $dbval )
|
| 46 |
-
{
|
| 47 |
-
return "upper(".$dbval.")";
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
/**
|
| 51 |
-
* @param Mixed $val
|
| 52 |
-
* @return String
|
| 53 |
-
*/
|
| 54 |
-
public function addDateQuotes( $val )
|
| 55 |
-
{
|
| 56 |
-
if( $val == "" || $val === null )
|
| 57 |
-
return 'null';
|
| 58 |
-
return "convert(datetime,'".$this->addSlashes($val)."',120)";
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
/**
|
| 62 |
-
* It's called for Contains and Starts with searches
|
| 63 |
-
* @param Mixed value
|
| 64 |
-
* @param Number type (optional)
|
| 65 |
-
* @return String
|
| 66 |
-
*/
|
| 67 |
-
public function field2char($value, $type = 3)
|
| 68 |
-
{
|
| 69 |
-
if( IsCharType($type) )
|
| 70 |
-
return $value;
|
| 71 |
-
|
| 72 |
-
if( !IsDateFieldType($type) )
|
| 73 |
-
return "convert(varchar(250),".$value.")";
|
| 74 |
-
|
| 75 |
-
return "convert(varchar(50),".$value.", 120)";
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
/**
|
| 79 |
-
* @param Mixed value
|
| 80 |
-
* @param Number type
|
| 81 |
-
* @return String
|
| 82 |
-
*/
|
| 83 |
-
public function field2time($value, $type)
|
| 84 |
-
{
|
| 85 |
-
return $value;
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
/**
|
| 89 |
-
* Get the auto generated SQL string used in the last query
|
| 90 |
-
* @param String key
|
| 91 |
-
* @param String table
|
| 92 |
-
* @return String
|
| 93 |
-
*/
|
| 94 |
-
public function getInsertedIdSQL( $key = null, $table = null)
|
| 95 |
-
{
|
| 96 |
-
return "SELECT SCOPE_IDENTITY()";
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
/**
|
| 100 |
-
* @param String strName
|
| 101 |
-
* @return String
|
| 102 |
-
*/
|
| 103 |
-
public function timeToSecWrapper( $strName )
|
| 104 |
-
{
|
| 105 |
-
$wrappedFieldName = $this->addTableWrappers($strName);
|
| 106 |
-
return "(DATEPART(HOUR, " . $wrappedFieldName . ") * 3600) + (DATEPART(MINUTE, " . $wrappedFieldName . ") * 60) + (DATEPART(SECOND, " . $wrappedFieldName . "))";
|
| 107 |
-
}
|
| 108 |
-
|
| 109 |
-
public function limitedQuery( $connection, $strSQL, $skip, $total, $applyLimit )
|
| 110 |
-
{
|
| 111 |
-
if( $applyLimit && $total >= 0 )
|
| 112 |
-
$strSQL = AddTop( $strSQL, $skip + $total );
|
| 113 |
-
|
| 114 |
-
$qResult = $connection->query( $strSQL );
|
| 115 |
-
$qResult->seekRecord( $skip );
|
| 116 |
-
|
| 117 |
-
return $qResult;
|
| 118 |
-
}
|
| 119 |
-
|
| 120 |
-
public function caseSensitiveComparison( $val1, $val2 )
|
| 121 |
-
{
|
| 122 |
-
return $val1 . ' = ' . $val2 .' COLLATE SQL_Latin1_General_CP1_CS_AS';
|
| 123 |
-
}
|
| 124 |
-
|
| 125 |
-
public function intervalExpressionString( $expr, $interval )
|
| 126 |
-
{
|
| 127 |
-
return DBFunctions::intervalExprLeft( $expr, $interval );
|
| 128 |
-
}
|
| 129 |
-
|
| 130 |
-
public function intervalExpressionNumber( $expr, $interval )
|
| 131 |
-
{
|
| 132 |
-
return DBFunctions::intervalExprFloor( $expr, $interval );
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
public function intervalExpressionDate( $expr, $interval )
|
| 136 |
-
{
|
| 137 |
-
if($interval == 1) // DATE_INTERVAL_YEAR
|
| 138 |
-
return "convert(varchar(50), datepart(yyyy,".$expr.")*10000+0101)";
|
| 139 |
-
if($interval == 2) // DATE_INTERVAL_QUARTER
|
| 140 |
-
return "convert(varchar(50), datepart(yyyy,".$expr.")*10000 + datepart(qq,".$expr.")*100+1)";
|
| 141 |
-
if($interval == 3) // DATE_INTERVAL_MONTH
|
| 142 |
-
return "convert(varchar(50), datepart(yyyy,".$expr.")*10000+datepart(mm,".$expr.")*100+1)";
|
| 143 |
-
if($interval == 4) // DATE_INTERVAL_WEEK
|
| 144 |
-
return "convert(varchar(50), datepart(yyyy,".$expr.")*10000+(datepart(ww,".$expr.")-1)*100+01)";
|
| 145 |
-
if($interval == 5) // DATE_INTERVAL_DAY
|
| 146 |
-
return "convert(varchar(50), datepart(yyyy,".$expr.")*10000+datepart(mm,".$expr.")*100+datepart(dd,".$expr."))";
|
| 147 |
-
if($interval == 6) // DATE_INTERVAL_HOUR
|
| 148 |
-
return "convert(varchar(50), convert(numeric(20,0), datepart(yyyy,".$expr."))*1000000+datepart(mm,".$expr.")*10000+datepart(dd,".$expr.")*100+datepart(hh,".$expr."))";
|
| 149 |
-
if($interval == 7) // DATE_INTERVAL_MINUTE
|
| 150 |
-
return "convert(varchar(50), convert(numeric(20,0), datepart(yyyy,".$expr."))*100000000+datepart(mm,".$expr.")*1000000+datepart(dd,".$expr.")*10000+datepart(hh,".$expr.")*100+datepart(mi,".$expr."))";
|
| 151 |
-
return $expr;
|
| 152 |
-
}
|
| 153 |
-
|
| 154 |
-
public function addSlashes( $str )
|
| 155 |
-
{
|
| 156 |
-
return str_replace( array( "'", chr(0) ), array( "''", '\\u0000' ), $str);
|
| 157 |
-
}
|
| 158 |
-
|
| 159 |
-
/**
|
| 160 |
-
* Get list of initialization sql commands
|
| 161 |
-
* @return Array
|
| 162 |
-
*/
|
| 163 |
-
public function initializationSQL() {
|
| 164 |
-
global $locale_info;
|
| 165 |
-
// MSSQL days range is 1..7
|
| 166 |
-
$firstDayOfWeek = $locale_info["LOCALE_IFIRSTDAYOFWEEK"] + 1;
|
| 167 |
-
|
| 168 |
-
return array(
|
| 169 |
-
"SET DATEFIRST ".$firstDayOfWeek
|
| 170 |
-
);
|
| 171 |
-
}
|
| 172 |
-
|
| 173 |
-
}
|
| 174 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
-
|
| 10 |
-
|
| 11 |
-
function __construct( $params )
|
| 12 |
-
{
|
| 13 |
-
parent::__construct($params);
|
| 14 |
-
$this->strLeftWrapper = "`";
|
| 15 |
-
$this->strRightWrapper = "`";
|
| 16 |
-
$this->escapeChars[ '\\' ] = true;
|
| 17 |
-
|
| 18 |
-
$this->conn = $params["conn"];
|
| 19 |
-
}
|
| 20 |
-
|
| 21 |
-
/**
|
| 22 |
-
* @param String str
|
| 23 |
-
* @return String
|
| 24 |
-
*/
|
| 25 |
-
public function escapeLIKEpattern( $str )
|
| 26 |
-
{
|
| 27 |
-
return str_replace(array('\\', '%', '_'), array('\\\\', '\\%', '\\_'), $str);
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
/**
|
| 32 |
-
* @param String str
|
| 33 |
-
* @return String
|
| 34 |
-
*/
|
| 35 |
-
public function addSlashes( $str )
|
| 36 |
-
{
|
| 37 |
-
if( useMySQLiLib() && $this->conn )
|
| 38 |
-
{
|
| 39 |
-
if( $this->conn )
|
| 40 |
-
return mysqli_real_escape_string( $this->conn, $str );
|
| 41 |
-
}
|
| 42 |
-
else
|
| 43 |
-
{
|
| 44 |
-
// ODBC connection, no MySQL library included
|
| 45 |
-
return str_replace(array('\\', '\''), array('\\\\', '\\\''), $str);
|
| 46 |
-
}
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
/**
|
| 50 |
-
* @param String str
|
| 51 |
-
* @return String
|
| 52 |
-
*/
|
| 53 |
-
public function addSlashesBinary( $str )
|
| 54 |
-
{
|
| 55 |
-
if( !strlen($str) )
|
| 56 |
-
return "''";
|
| 57 |
-
|
| 58 |
-
return "0x".bin2hex($str);
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
/**
|
| 63 |
-
* @param String dbval
|
| 64 |
-
* @return String
|
| 65 |
-
*/
|
| 66 |
-
public function upper( $dbval )
|
| 67 |
-
{
|
| 68 |
-
return "upper(".$dbval.")";
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
/**
|
| 73 |
-
* It's called for Contains and Starts with searches
|
| 74 |
-
* @param Mixed value
|
| 75 |
-
* @param Number type (optional)
|
| 76 |
-
* @return String
|
| 77 |
-
*/
|
| 78 |
-
public function field2char($value, $type = 3)
|
| 79 |
-
{
|
| 80 |
-
return "CAST( " .$value .' AS CHAR )';
|
| 81 |
-
}
|
| 82 |
-
|
| 83 |
-
/**
|
| 84 |
-
* @param Mixed value
|
| 85 |
-
* @param Number type
|
| 86 |
-
* @return String
|
| 87 |
-
*/
|
| 88 |
-
public function field2time($value, $type)
|
| 89 |
-
{
|
| 90 |
-
if( IsDateFieldType($type) )
|
| 91 |
-
return "time(".$value.")";
|
| 92 |
-
|
| 93 |
-
return $value;
|
| 94 |
-
}
|
| 95 |
-
|
| 96 |
-
/**
|
| 97 |
-
* Get the auto generated SQL string used in the last query
|
| 98 |
-
* @param String key (optional)
|
| 99 |
-
* @param String table (optional)
|
| 100 |
-
* @return String
|
| 101 |
-
*/
|
| 102 |
-
public function getInsertedIdSQL( $key = null, $table = null)
|
| 103 |
-
{
|
| 104 |
-
return "SELECT LAST_INSERT_ID()";
|
| 105 |
-
}
|
| 106 |
-
|
| 107 |
-
/**
|
| 108 |
-
* @param String strName
|
| 109 |
-
* @return String
|
| 110 |
-
*/
|
| 111 |
-
public function timeToSecWrapper( $strName )
|
| 112 |
-
{
|
| 113 |
-
return "TIME_TO_SEC(" . $this->addTableWrappers($strName) . ")";
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
public function schemaSupported()
|
| 117 |
-
{
|
| 118 |
-
return false;
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
public function caseSensitiveComparison( $val1, $val2 )
|
| 122 |
-
{
|
| 123 |
-
return 'binary ' . $val1 . ' = ' . $val2;
|
| 124 |
-
}
|
| 125 |
-
|
| 126 |
-
public function limitedQuery( $connection, $strSQL, $skip, $total, $applyLimit )
|
| 127 |
-
{
|
| 128 |
-
if( $applyLimit && ( $skip || $total > 0 ) )
|
| 129 |
-
$strSQL.= " limit ". $skip . ", " . ( $total >=0 ? $total : 2000000000 );
|
| 130 |
-
return $connection->query( $strSQL );
|
| 131 |
-
}
|
| 132 |
-
|
| 133 |
-
public function intervalExpressionString( $expr, $interval )
|
| 134 |
-
{
|
| 135 |
-
return DBFunctions::intervalExprLeft( $expr, $interval );
|
| 136 |
-
}
|
| 137 |
-
|
| 138 |
-
public function intervalExpressionNumber( $expr, $interval )
|
| 139 |
-
{
|
| 140 |
-
return DBFunctions::intervalExprFloor( $expr, $interval );
|
| 141 |
-
}
|
| 142 |
-
|
| 143 |
-
protected function weekIntervalExpressionDate( $expr ) {
|
| 144 |
-
global $locale_info;
|
| 145 |
-
$firstDayOfWeek = $locale_info["LOCALE_IFIRSTDAYOFWEEK"];
|
| 146 |
-
$mode = -1;
|
| 147 |
-
if( $firstDayOfWeek == 0 ) {
|
| 148 |
-
// Monday is first day of week, week 1 - with a Monday in this year
|
| 149 |
-
$mode = 5;
|
| 150 |
-
} else if( $firstDayOfWeek == 6 ) {
|
| 151 |
-
// Sunday is first day of week, week 1 - with a Sunday in this year
|
| 152 |
-
$mode = 0;
|
| 153 |
-
}
|
| 154 |
-
|
| 155 |
-
if( $mode != -1 ) {
|
| 156 |
-
return "year(".$expr.")*10000 + week(".$expr.",".$mode.")*100+01";
|
| 157 |
-
}
|
| 158 |
-
|
| 159 |
-
return "year(".$expr.")*10000 + week(".$expr.")*100+01";
|
| 160 |
-
}
|
| 161 |
-
|
| 162 |
-
public function intervalExpressionDate( $expr, $interval )
|
| 163 |
-
{
|
| 164 |
-
if($interval == 1) // DATE_INTERVAL_YEAR
|
| 165 |
-
return "year(".$expr.")*10000 + 101"; // ???
|
| 166 |
-
if($interval == 2) // DATE_INTERVAL_QUARTER
|
| 167 |
-
return "year(".$expr.")*10000 + QUARTER(".$expr.")*100+1";
|
| 168 |
-
if($interval == 3) // DATE_INTERVAL_MONTH
|
| 169 |
-
return "year(".$expr.")*10000 + month(".$expr.")*100+1";
|
| 170 |
-
if($interval == 4) // DATE_INTERVAL_WEEK
|
| 171 |
-
return $this->weekIntervalExpressionDate( $expr );
|
| 172 |
-
if($interval == 5) // DATE_INTERVAL_DAY
|
| 173 |
-
return "year(".$expr.")*10000 + month(".$expr.")*100 + day(".$expr.")";
|
| 174 |
-
if($interval == 6) // DATE_INTERVAL_HOUR
|
| 175 |
-
return "year(".$expr.")*1000000 + month(".$expr.")*10000 + day(".$expr.")*100 + HOUR(".$expr.")";
|
| 176 |
-
if($interval == 7) // DATE_INTERVAL_MINUTE
|
| 177 |
-
return "year(".$expr.")*100000000 + month(".$expr.")*1000000 + day(".$expr.")*10000 + HOUR(".$expr.")*100 + minute(".$expr.")";
|
| 178 |
-
return $expr;
|
| 179 |
-
}
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
}
|
| 183 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbfunctions/ODBCFunctions.php
DELETED
|
@@ -1,155 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
/**
|
| 4 |
-
* Ignore the ODBC name
|
| 5 |
-
* This is MS Access functions class
|
| 6 |
-
*/
|
| 7 |
-
class ODBCFunctions extends DBFunctions
|
| 8 |
-
{
|
| 9 |
-
/**
|
| 10 |
-
* @param String str
|
| 11 |
-
* @return String
|
| 12 |
-
*/
|
| 13 |
-
public function escapeLIKEpattern( $str )
|
| 14 |
-
{
|
| 15 |
-
return $str;
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
/**
|
| 19 |
-
* @param String str
|
| 20 |
-
* @return String
|
| 21 |
-
*/
|
| 22 |
-
public function addSlashesBinary( $str )
|
| 23 |
-
{
|
| 24 |
-
if( !strlen($str) )
|
| 25 |
-
return "''";
|
| 26 |
-
return "0x".bin2hex($str);
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
-
/**
|
| 30 |
-
* @param String str
|
| 31 |
-
* @return String
|
| 32 |
-
*/
|
| 33 |
-
public function stripSlashesBinary( $str )
|
| 34 |
-
{
|
| 35 |
-
return db_stripslashesbinaryAccess($str);
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
/**
|
| 39 |
-
* @param String strName
|
| 40 |
-
* @return String
|
| 41 |
-
*/
|
| 42 |
-
public function addTableWrappers($strName)
|
| 43 |
-
{
|
| 44 |
-
if( $this->strLeftWrapper != "\"")
|
| 45 |
-
return $this->addFieldWrappers($strName);
|
| 46 |
-
|
| 47 |
-
return DBFunctions::addTableWrappers( $strName );
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
/**
|
| 51 |
-
* @param String dbval
|
| 52 |
-
* @return String
|
| 53 |
-
*/
|
| 54 |
-
public function upper( $dbval )
|
| 55 |
-
{
|
| 56 |
-
return "ucase(".$dbval.")";
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
/**
|
| 60 |
-
* @param Mixed $val
|
| 61 |
-
* @return String
|
| 62 |
-
*/
|
| 63 |
-
public function addDateQuotes( $val )
|
| 64 |
-
{
|
| 65 |
-
if( $val == "" || $val === null )
|
| 66 |
-
return 'null';
|
| 67 |
-
return "#".$this->addSlashes($val)."#";
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
/**
|
| 71 |
-
* It's called for Contains and Starts with searches
|
| 72 |
-
* @param Mixed value
|
| 73 |
-
* @param Number type (optional)
|
| 74 |
-
* @return String
|
| 75 |
-
*/
|
| 76 |
-
public function field2char($value, $type = 3)
|
| 77 |
-
{
|
| 78 |
-
return $value;
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
/**
|
| 82 |
-
* @param Mixed value
|
| 83 |
-
* @param Number type
|
| 84 |
-
* @return String
|
| 85 |
-
*/
|
| 86 |
-
public function field2time($value, $type)
|
| 87 |
-
{
|
| 88 |
-
return $value;
|
| 89 |
-
}
|
| 90 |
-
|
| 91 |
-
/**
|
| 92 |
-
* Get the auto generated SQL string used in the last query
|
| 93 |
-
* @param String key
|
| 94 |
-
* @param String table
|
| 95 |
-
* @return String
|
| 96 |
-
*/
|
| 97 |
-
public function getInsertedIdSQL( $key = null, $table = null)
|
| 98 |
-
{
|
| 99 |
-
return "SELECT @@IDENTITY";
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
/**
|
| 103 |
-
* @param String strName
|
| 104 |
-
* @return String
|
| 105 |
-
*/
|
| 106 |
-
public function timeToSecWrapper( $strName )
|
| 107 |
-
{
|
| 108 |
-
$wrappedFieldName = $this->addTableWrappers($strName);
|
| 109 |
-
return "(DATEPART(HOUR, " . $wrappedFieldName . ") * 3600) + (DATEPART(MINUTE, " . $wrappedFieldName . ") * 60) + (DATEPART(SECOND, " . $wrappedFieldName . "))";
|
| 110 |
-
}
|
| 111 |
-
|
| 112 |
-
public function limitedQuery( $connection, $strSQL, $skip, $total, $applyLimit )
|
| 113 |
-
{
|
| 114 |
-
if( $applyLimit && $total >= 0 )
|
| 115 |
-
$strSQL = AddTop($strSQL, $skip + $total );
|
| 116 |
-
|
| 117 |
-
$qResult = $connection->query( $strSQL );
|
| 118 |
-
$qResult->seekRecord( $skip );
|
| 119 |
-
|
| 120 |
-
return $qResult;
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
public function intervalExpressionString( $expr, $interval )
|
| 124 |
-
{
|
| 125 |
-
return DBFunctions::intervalExprLeft( $expr, $interval );
|
| 126 |
-
}
|
| 127 |
-
|
| 128 |
-
public function intervalExpressionNumber( $expr, $interval )
|
| 129 |
-
{
|
| 130 |
-
if( !$interval )
|
| 131 |
-
return $expr;
|
| 132 |
-
return "int( " . $expr . " / " . $interval . " ) * ".$interval;
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
public function intervalExpressionDate( $expr, $interval )
|
| 136 |
-
{
|
| 137 |
-
if($interval == 1) // DATE_INTERVAL_YEAR
|
| 138 |
-
return "Trim(datepart('yyyy',".$expr.")*10000+0101)";
|
| 139 |
-
if($interval == 2) // DATE_INTERVAL_QUARTER
|
| 140 |
-
return "Trim(datepart('yyyy',".$expr.")*10000+datepart('q',".$expr.")*100+1)";
|
| 141 |
-
if($interval == 3) // DATE_INTERVAL_MONTH
|
| 142 |
-
return "Trim(datepart('yyyy',".$expr.")*10000+datepart('m',".$expr.")*100+1)";
|
| 143 |
-
if($interval == 4) // DATE_INTERVAL_WEEK
|
| 144 |
-
return "Trim(datepart('yyyy',".$expr.")*10000+(datepart('ww',".$expr.")-1)*100+01)";
|
| 145 |
-
if($interval == 5) // DATE_INTERVAL_DAY
|
| 146 |
-
return "Trim(datepart('yyyy',".$expr.")*10000+datepart('m',".$expr.")*100+datepart('d',".$expr."))";
|
| 147 |
-
if($interval == 6) // DATE_INTERVAL_HOUR
|
| 148 |
-
return "Trim(CVar(datepart('yyyy',".$expr."))*1000000+datepart('m',".$expr.")*10000+datepart('d',".$expr.")*100+datepart('h',".$expr."))";
|
| 149 |
-
if($interval == 7) // DATE_INTERVAL_MINUTE
|
| 150 |
-
return "Trim(CVar(datepart('yyyy',".$expr."))*100000000+CVar(datepart('m',".$expr."))*1000000+datepart('d',".$expr.")*10000+datepart('h',".$expr.")*100+datepart('n',".$expr."))";
|
| 151 |
-
return $expr;
|
| 152 |
-
}
|
| 153 |
-
}
|
| 154 |
-
|
| 155 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbfunctions/OracleFunctions.php
DELETED
|
@@ -1,147 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class OracleFunctions extends DBFunctions
|
| 3 |
-
{
|
| 4 |
-
/**
|
| 5 |
-
* @param String str
|
| 6 |
-
* @return String
|
| 7 |
-
*/
|
| 8 |
-
public function escapeLIKEpattern( $str )
|
| 9 |
-
{
|
| 10 |
-
return $str;
|
| 11 |
-
}
|
| 12 |
-
|
| 13 |
-
/**
|
| 14 |
-
* @param String str
|
| 15 |
-
* @return String
|
| 16 |
-
*/
|
| 17 |
-
public function prepareString($str)
|
| 18 |
-
{
|
| 19 |
-
$ora_maxstring = 4000;
|
| 20 |
-
|
| 21 |
-
if( strlen($str) < $ora_maxstring )
|
| 22 |
-
return "'".$this->addSlashes( $str )."'";
|
| 23 |
-
|
| 24 |
-
// split ret to 4000-len substrings
|
| 25 |
-
$i = 0;
|
| 26 |
-
$out = "";
|
| 27 |
-
while( $i < strlen($str) )
|
| 28 |
-
{
|
| 29 |
-
if( strlen($out) )
|
| 30 |
-
$out.="||";
|
| 31 |
-
$out.= "to_clob('".$this->addSlashes( substr($str, $i, $ora_maxstring) )."')";
|
| 32 |
-
$i += $ora_maxstring;
|
| 33 |
-
}
|
| 34 |
-
return $out;
|
| 35 |
-
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
/**
|
| 39 |
-
* @param String str
|
| 40 |
-
* @return String
|
| 41 |
-
*/
|
| 42 |
-
function addSlashes( $str )
|
| 43 |
-
{
|
| 44 |
-
return str_replace("'", "''", $str);
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
/**
|
| 48 |
-
* @param String str
|
| 49 |
-
* @return String
|
| 50 |
-
*/
|
| 51 |
-
function addSlashesBinary( $str )
|
| 52 |
-
{
|
| 53 |
-
return $str;
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
/**
|
| 58 |
-
* @param String dbval
|
| 59 |
-
* @param String
|
| 60 |
-
*/
|
| 61 |
-
public function upper( $dbval )
|
| 62 |
-
{
|
| 63 |
-
return "upper(".$dbval.")";
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
/**
|
| 68 |
-
* @param Mixed value
|
| 69 |
-
* @param Number type (optional)
|
| 70 |
-
* @return String
|
| 71 |
-
*/
|
| 72 |
-
public function field2char($value, $type = 3)
|
| 73 |
-
{
|
| 74 |
-
return "TO_CHAR(" . $value . ")";
|
| 75 |
-
}
|
| 76 |
-
|
| 77 |
-
/**
|
| 78 |
-
* @param Mixed value
|
| 79 |
-
* @param Number type
|
| 80 |
-
* @return String
|
| 81 |
-
*/
|
| 82 |
-
public function field2time($value, $type)
|
| 83 |
-
{
|
| 84 |
-
return $value;
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
/**
|
| 88 |
-
* Get the auto generated SQL string used in the last query
|
| 89 |
-
* @param String key (optional)
|
| 90 |
-
* @param String table (optional)
|
| 91 |
-
* @return String
|
| 92 |
-
*/
|
| 93 |
-
public function getInsertedIdSQL($key = null, $table = null)
|
| 94 |
-
{
|
| 95 |
-
if (!is_null($key) && !is_null($table)) {
|
| 96 |
-
return "SELECT MAX(" . $this->addFieldWrappers($key) . ") FROM " . $this->addTableWrappers($table);
|
| 97 |
-
}
|
| 98 |
-
return false;
|
| 99 |
-
}
|
| 100 |
-
|
| 101 |
-
public function crossDbSupported()
|
| 102 |
-
{
|
| 103 |
-
return false;
|
| 104 |
-
}
|
| 105 |
-
|
| 106 |
-
public function limitedQuery( $connection, $strSQL, $skip, $total, $applyLimit )
|
| 107 |
-
{
|
| 108 |
-
if( $applyLimit && $total >= 0 )
|
| 109 |
-
$strSQL = AddRowNumber($strSQL, $skip + $total );
|
| 110 |
-
$qResult = $connection->query( $strSQL );
|
| 111 |
-
$qResult->seekRecord( $skip );
|
| 112 |
-
|
| 113 |
-
return $qResult;
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
public function intervalExpressionString( $expr, $interval )
|
| 117 |
-
{
|
| 118 |
-
return DBFunctions::intervalExprSubstr( $expr, $interval );
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
public function intervalExpressionNumber( $expr, $interval )
|
| 122 |
-
{
|
| 123 |
-
return DBFunctions::intervalExprFloor( $expr, $interval );
|
| 124 |
-
}
|
| 125 |
-
|
| 126 |
-
public function intervalExpressionDate( $expr, $interval )
|
| 127 |
-
{
|
| 128 |
-
if($interval == 1) // DATE_INTERVAL_YEAR
|
| 129 |
-
return "TO_CHAR(".$expr.", 'YYYY')*10000+0101";
|
| 130 |
-
if($interval == 2) // DATE_INTERVAL_QUARTER
|
| 131 |
-
return "TO_CHAR(".$expr.", 'YYYY')*10000+TO_CHAR(".$expr.",'Q')*100+1";
|
| 132 |
-
if($interval == 3) // DATE_INTERVAL_MONTH
|
| 133 |
-
return "TO_CHAR(".$expr.", 'YYYY')*10000+TO_CHAR(".$expr.",'MM')*100+1";
|
| 134 |
-
if($interval == 4) // DATE_INTERVAL_WEEK
|
| 135 |
-
return "TO_CHAR(".$expr.", 'YYYY')*10000+TO_CHAR(".$expr.",'W')*100+01";
|
| 136 |
-
if($interval == 5) // DATE_INTERVAL_DAY
|
| 137 |
-
return "TO_CHAR(".$expr.", 'YYYY')*10000+TO_CHAR(".$expr.",'MM')*100+TO_CHAR(".$expr.",'DD')";
|
| 138 |
-
if($interval == 6) // DATE_INTERVAL_HOUR
|
| 139 |
-
return "TO_CHAR(".$expr.", 'YYYY')*1000000+TO_CHAR(".$expr.",'MM')*10000+TO_CHAR(".$expr.",'DD')*100+TO_CHAR(".$expr.",'HH')";
|
| 140 |
-
if($interval == 7) // DATE_INTERVAL_MINUTE
|
| 141 |
-
return "TO_CHAR(".$expr.", 'YYYY')*100000000+TO_CHAR(".$expr.",'MM')*1000000+TO_CHAR(".$expr.",'DD')*10000+TO_CHAR(".$expr.",'HH')*100+TO_CHAR(".$expr.",'MI')";
|
| 142 |
-
return $expr;
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbfunctions/PostgreFunctions.php
DELETED
|
@@ -1,155 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class PostgreFunctions extends DBFunctions
|
| 3 |
-
{
|
| 4 |
-
/**
|
| 5 |
-
* db version
|
| 6 |
-
* @type Number
|
| 7 |
-
*/
|
| 8 |
-
protected $postgreDbVersion;
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
function __construct( $params )
|
| 12 |
-
{
|
| 13 |
-
parent::__construct( $params );
|
| 14 |
-
|
| 15 |
-
$this->escapeChars[ '\\' ] = true;
|
| 16 |
-
$this->postgreDbVersion = $extraParams["postgreDbVersion"];
|
| 17 |
-
}
|
| 18 |
-
|
| 19 |
-
/**
|
| 20 |
-
* @param String str
|
| 21 |
-
* @return String
|
| 22 |
-
*/
|
| 23 |
-
public function escapeLIKEpattern( $str )
|
| 24 |
-
{
|
| 25 |
-
return $str;
|
| 26 |
-
}
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
/**
|
| 30 |
-
* @param String str
|
| 31 |
-
* @return String
|
| 32 |
-
*/
|
| 33 |
-
public function addSlashes( $str )
|
| 34 |
-
{
|
| 35 |
-
return pg_escape_string( $str );
|
| 36 |
-
return parent::addSlashes( $str );
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
/**
|
| 40 |
-
* @param String str
|
| 41 |
-
* @return String
|
| 42 |
-
*/
|
| 43 |
-
public function addSlashesBinary( $str )
|
| 44 |
-
{
|
| 45 |
-
if( $this->postgreDbVersion < 9 )
|
| 46 |
-
return "'".pg_escape_bytea($str)."'";
|
| 47 |
-
|
| 48 |
-
if( !strlen($str) )
|
| 49 |
-
return "''";
|
| 50 |
-
|
| 51 |
-
return "E'\\\\x".bin2hex($str)."'";
|
| 52 |
-
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
/**
|
| 56 |
-
* @param String str
|
| 57 |
-
* @return String
|
| 58 |
-
*/
|
| 59 |
-
public function stripSlashesBinary( $str )
|
| 60 |
-
{
|
| 61 |
-
if( $this->postgreDbVersion < 9 )
|
| 62 |
-
return pg_unescape_bytea($str);
|
| 63 |
-
|
| 64 |
-
return hex2bin( substr($str, 2) );
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
/**
|
| 69 |
-
* @param String dbval
|
| 70 |
-
* @return String
|
| 71 |
-
*/
|
| 72 |
-
public function upper( $dbval )
|
| 73 |
-
{
|
| 74 |
-
return "upper(".$dbval.")";
|
| 75 |
-
}
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
/**
|
| 79 |
-
* It's called for Contains and Starts with searches
|
| 80 |
-
* @param Mixed value
|
| 81 |
-
* @param Number type (optional)
|
| 82 |
-
* @return String
|
| 83 |
-
*/
|
| 84 |
-
public function field2char( $value, $type = 3 )
|
| 85 |
-
{
|
| 86 |
-
if( IsCharType($type) )
|
| 87 |
-
return $value;
|
| 88 |
-
|
| 89 |
-
return "''||(".$value.")";
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
/**
|
| 93 |
-
* @param Mixed value
|
| 94 |
-
* @param Number type
|
| 95 |
-
* @return String
|
| 96 |
-
*/
|
| 97 |
-
public function field2time($value, $type)
|
| 98 |
-
{
|
| 99 |
-
return $value;
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
/**
|
| 103 |
-
* Get the auto generated SQL string used in the last query
|
| 104 |
-
* @param String key (optional)
|
| 105 |
-
* @param String table (optional)
|
| 106 |
-
* @return String
|
| 107 |
-
*/
|
| 108 |
-
public function getInsertedIdSQL( $key = null, $table = null)
|
| 109 |
-
{
|
| 110 |
-
return "SELECT LASTVAL()";
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
public function crossDbSupported()
|
| 114 |
-
{
|
| 115 |
-
return false;
|
| 116 |
-
}
|
| 117 |
-
public function limitedQuery( $connection, $strSQL, $skip, $total, $applyLimit )
|
| 118 |
-
{
|
| 119 |
-
if( $applyLimit && ( $skip || $total >= 0 ) ) {
|
| 120 |
-
$strSQL.= " limit ". ($total >= 0 ? $total : "ALL" )." offset ". $skip;
|
| 121 |
-
}
|
| 122 |
-
return $connection->query( $strSQL );
|
| 123 |
-
}
|
| 124 |
-
|
| 125 |
-
public function intervalExpressionString( $expr, $interval )
|
| 126 |
-
{
|
| 127 |
-
return DBFunctions::intervalExprSubstring( $expr, $interval );
|
| 128 |
-
}
|
| 129 |
-
|
| 130 |
-
public function intervalExpressionNumber( $expr, $interval )
|
| 131 |
-
{
|
| 132 |
-
return DBFunctions::intervalExprFloor( $expr, $interval );
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
public function intervalExpressionDate( $expr, $interval )
|
| 136 |
-
{
|
| 137 |
-
if($interval == 1) // DATE_INTERVAL_YEAR
|
| 138 |
-
return "date_part('year',".$expr.")*10000+0101";
|
| 139 |
-
if($interval == 2) // DATE_INTERVAL_QUARTER
|
| 140 |
-
return "date_part('year',".$expr.")*10000+date_part('quarter',".$expr.")*100+1";
|
| 141 |
-
if($interval == 3) // DATE_INTERVAL_MONTH
|
| 142 |
-
return "date_part('year',".$expr.")*10000+date_part('month',".$expr.")*100+1";
|
| 143 |
-
if($interval == 4) // DATE_INTERVAL_WEEK
|
| 144 |
-
return "date_part('year',".$expr.")*10000+(date_part('week',".$expr.")-1)*100+01";
|
| 145 |
-
if($interval == 5) // DATE_INTERVAL_DAY
|
| 146 |
-
return "date_part('year',".$expr.")*10000+date_part('month',".$expr.")*100+date_part('days',".$expr.")";
|
| 147 |
-
if($interval == 6) // DATE_INTERVAL_HOUR
|
| 148 |
-
return "date_part('year',".$expr.")*1000000+date_part('month',".$expr.")*10000+date_part('days',".$expr.")*100+date_part('hour',".$expr.")";
|
| 149 |
-
if($interval == 7) // DATE_INTERVAL_MINUTE
|
| 150 |
-
return "date_part('year',".$expr.")*100000000+date_part('month',".$expr.")*1000000+date_part('days',".$expr.")*10000+date_part('hour',".$expr.")*100+date_part('minute',".$expr.")";
|
| 151 |
-
return $expr;
|
| 152 |
-
}
|
| 153 |
-
|
| 154 |
-
}
|
| 155 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbfunctions/SQLite3Functions.php
DELETED
|
@@ -1,95 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class SQLite3Functions extends DBFunctions
|
| 3 |
-
{
|
| 4 |
-
/**
|
| 5 |
-
* @param String str
|
| 6 |
-
* @return String
|
| 7 |
-
*/
|
| 8 |
-
public function escapeLIKEpattern( $str )
|
| 9 |
-
{
|
| 10 |
-
return $str;
|
| 11 |
-
}
|
| 12 |
-
|
| 13 |
-
/**
|
| 14 |
-
* @param String str
|
| 15 |
-
* @return String
|
| 16 |
-
*/
|
| 17 |
-
public function addSlashesBinary( $str )
|
| 18 |
-
{
|
| 19 |
-
if( !strlen($str) )
|
| 20 |
-
return "x''";
|
| 21 |
-
return "x'".bin2hex($str)."'";
|
| 22 |
-
}
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
/**
|
| 26 |
-
* @param String strName
|
| 27 |
-
* @return String
|
| 28 |
-
*/
|
| 29 |
-
public function addTableWrappers($strName)
|
| 30 |
-
{
|
| 31 |
-
return $this->addFieldWrappers($strName);
|
| 32 |
-
}
|
| 33 |
-
|
| 34 |
-
/**
|
| 35 |
-
* @param String dbval
|
| 36 |
-
* @return String
|
| 37 |
-
*/
|
| 38 |
-
public function upper( $dbval )
|
| 39 |
-
{
|
| 40 |
-
return "upper(".$dbval.")";
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
/**
|
| 45 |
-
* It's called for Contains and Starts with searches
|
| 46 |
-
* @param Mixed value
|
| 47 |
-
* @param Number type (optional)
|
| 48 |
-
* @return String
|
| 49 |
-
*/
|
| 50 |
-
public function field2char($value, $type = 3)
|
| 51 |
-
{
|
| 52 |
-
return $value;
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
/**
|
| 56 |
-
* @param Mixed value
|
| 57 |
-
* @param Number type
|
| 58 |
-
* @return String
|
| 59 |
-
*/
|
| 60 |
-
public function field2time($value, $type)
|
| 61 |
-
{
|
| 62 |
-
return $value;
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
/**
|
| 66 |
-
* Get the auto generated SQL string used in the last query
|
| 67 |
-
* @param String key (optional)
|
| 68 |
-
* @param String table (optional)
|
| 69 |
-
* @return String
|
| 70 |
-
*/
|
| 71 |
-
public function getInsertedIdSQL( $key = null, $table = null)
|
| 72 |
-
{
|
| 73 |
-
return "SELECT last_insert_rowid()";
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
public function limitedQuery( $connection, $strSQL, $skip, $total, $applyLimit )
|
| 77 |
-
{
|
| 78 |
-
if( $applyLimit && ( $skip || $total > 0 ) )
|
| 79 |
-
$strSQL.= " limit ". $skip . ", " . ( $total >=0 ? $total : 2000000000 );
|
| 80 |
-
|
| 81 |
-
return $connection->query( $strSQL );
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
public function intervalExpressionString( $expr, $interval )
|
| 85 |
-
{
|
| 86 |
-
return DBFunctions::intervalExprSubstr( $expr, $interval );
|
| 87 |
-
}
|
| 88 |
-
|
| 89 |
-
public function intervalExpressionNumber( $expr, $interval )
|
| 90 |
-
{
|
| 91 |
-
return DBFunctions::intervalExprFloor( $expr, $interval );
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
}
|
| 95 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbfunctions_legacy.php
DELETED
|
@@ -1,156 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/**
|
| 3 |
-
* The set of User API functions preserving the old dbfunctions-dbconnection functions' signatures
|
| 4 |
-
* that wrap the new ConnectionManager, Connection classes' functionality.
|
| 5 |
-
* All the functions below use the default db connection only.
|
| 6 |
-
* Don't use them in PHPRunner code they are designed to maintain compatibility with old user events' code only.
|
| 7 |
-
*/
|
| 8 |
-
|
| 9 |
-
/**
|
| 10 |
-
* @param String sql
|
| 11 |
-
* @param Mixed conn (unused)
|
| 12 |
-
* @return Mixed
|
| 13 |
-
*/
|
| 14 |
-
|
| 15 |
-
function db_connect()
|
| 16 |
-
{
|
| 17 |
-
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
function db_close($conn = null )
|
| 21 |
-
{
|
| 22 |
-
}
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
/**
|
| 26 |
-
* @param String sql
|
| 27 |
-
* @param Mixed conn (unused)
|
| 28 |
-
* @return Mixed
|
| 29 |
-
*/
|
| 30 |
-
function db_query($sql, $conn = null )
|
| 31 |
-
{
|
| 32 |
-
$connection = getDefaultConnection();
|
| 33 |
-
return $connection->query( $sql )->getQueryHandle();
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
/**
|
| 37 |
-
* @param String sql
|
| 38 |
-
* @param Mixed conn (unused)
|
| 39 |
-
*/
|
| 40 |
-
function db_exec($sql, $conn = null )
|
| 41 |
-
{
|
| 42 |
-
$connection = getDefaultConnection();
|
| 43 |
-
$connection->exec( $sql );
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
/**
|
| 47 |
-
* @param Mixed qHandle
|
| 48 |
-
* @return Number
|
| 49 |
-
*/
|
| 50 |
-
function db_insertid( $qHandle )
|
| 51 |
-
{
|
| 52 |
-
$connection = getDefaultConnection();
|
| 53 |
-
return $connection->getInsertedId();
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
/**
|
| 57 |
-
* @param Mixed qHandle
|
| 58 |
-
* @return Array | Boolean
|
| 59 |
-
*/
|
| 60 |
-
function db_fetch_array( $qHandle )
|
| 61 |
-
{
|
| 62 |
-
if( is_object( $qHandle ) && get_class( $qHandle ) == "QueryResult" )
|
| 63 |
-
{
|
| 64 |
-
return $qHandle->fetchAssoc();
|
| 65 |
-
}
|
| 66 |
-
$connection = getDefaultConnection();
|
| 67 |
-
return $connection->fetch_array( $qHandle );
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
/**
|
| 71 |
-
* @param Mixed qHandle
|
| 72 |
-
* @return Array | Boolean
|
| 73 |
-
*/
|
| 74 |
-
function db_fetch_numarray( $qHandle )
|
| 75 |
-
{
|
| 76 |
-
if( is_object( $qHandle ) && get_class( $qHandle ) == "QueryResult" )
|
| 77 |
-
{
|
| 78 |
-
return $qHandle->fetchNumeric();
|
| 79 |
-
}
|
| 80 |
-
$connection = getDefaultConnection();
|
| 81 |
-
return $connection->fetch_numarray( $qHandle );
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
/**
|
| 86 |
-
* @param String str
|
| 87 |
-
* @return String
|
| 88 |
-
*/
|
| 89 |
-
function db_prepare_string( $str )
|
| 90 |
-
{
|
| 91 |
-
$connection = getDefaultConnection();
|
| 92 |
-
return $connection->prepareString( $str );
|
| 93 |
-
}
|
| 94 |
-
|
| 95 |
-
/**
|
| 96 |
-
* @param String str
|
| 97 |
-
* @return String
|
| 98 |
-
*/
|
| 99 |
-
function db_addslashes( $str )
|
| 100 |
-
{
|
| 101 |
-
$connection = getDefaultConnection();
|
| 102 |
-
return $connection->addSlashes( $str );
|
| 103 |
-
}
|
| 104 |
-
|
| 105 |
-
/**
|
| 106 |
-
* @param String str
|
| 107 |
-
* @return String
|
| 108 |
-
*/
|
| 109 |
-
function AddFieldWrappers( $str )
|
| 110 |
-
{
|
| 111 |
-
$connection = getDefaultConnection();
|
| 112 |
-
return $connection->addFieldWrappers( $str );
|
| 113 |
-
}
|
| 114 |
-
|
| 115 |
-
/**
|
| 116 |
-
* @param String str
|
| 117 |
-
* @return String
|
| 118 |
-
*/
|
| 119 |
-
function AddTableWrappers( $str )
|
| 120 |
-
{
|
| 121 |
-
$connection = getDefaultConnection();
|
| 122 |
-
return $connection->addTableWrappers( $str );
|
| 123 |
-
}
|
| 124 |
-
|
| 125 |
-
/**
|
| 126 |
-
* @param Mixed value
|
| 127 |
-
* @return String
|
| 128 |
-
*/
|
| 129 |
-
function db_upper( $value )
|
| 130 |
-
{
|
| 131 |
-
$connection = getDefaultConnection();
|
| 132 |
-
return $connection->upper( $value );
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
/**
|
| 136 |
-
* @param Mixed value
|
| 137 |
-
* @return String
|
| 138 |
-
*/
|
| 139 |
-
function db_datequotes( $value )
|
| 140 |
-
{
|
| 141 |
-
$connection = getDefaultConnection();
|
| 142 |
-
return $connection->addDateQuotes( $value );
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
-
/**
|
| 146 |
-
* @param Connection connection (optional)
|
| 147 |
-
* @return Number
|
| 148 |
-
*/
|
| 149 |
-
function GetDatabaseType( $connection = null )
|
| 150 |
-
{
|
| 151 |
-
if( is_null($connection) )
|
| 152 |
-
$connection = getDefaultConnection();
|
| 153 |
-
|
| 154 |
-
return $connection->dbType;
|
| 155 |
-
}
|
| 156 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbinfo/ADOInfo.php
DELETED
|
@@ -1,40 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class ADOInfo extends DBInfo
|
| 3 |
-
{
|
| 4 |
-
/**
|
| 5 |
-
* @return Array
|
| 6 |
-
*/
|
| 7 |
-
public function db_gettablelist()
|
| 8 |
-
{
|
| 9 |
-
$ret = array();
|
| 10 |
-
|
| 11 |
-
$qResult = $this->connectionObj->openSchema( 20 );
|
| 12 |
-
while( $data = $qResult->fetchAssoc() )
|
| 13 |
-
{
|
| 14 |
-
if( $data["TABLE_TYPE"] == "TABLE" || $data["TABLE_TYPE"] == "VIEW" )
|
| 15 |
-
$ret[] = $data["TABLE_NAME"];
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
return $ret;
|
| 19 |
-
}
|
| 20 |
-
|
| 21 |
-
/**
|
| 22 |
-
* @param String strSQL
|
| 23 |
-
* @return Array
|
| 24 |
-
*/
|
| 25 |
-
public function db_getfieldslist($strSQL)
|
| 26 |
-
{
|
| 27 |
-
$res = array();
|
| 28 |
-
|
| 29 |
-
$qResult = $this->connectionObj->query( $strSQL );
|
| 30 |
-
$rs = $qResult->getQueryHandle();
|
| 31 |
-
|
| 32 |
-
$fieldsNumber = $qResult->numFields();
|
| 33 |
-
for($i = 0; $i < $fieldsNumber; $i++)
|
| 34 |
-
{
|
| 35 |
-
$res[$i] = array("fieldname" => $rs->Fields[$i]->Name, "type" => $rs->Fields[$i]->Type, "is_nullable" => 0);
|
| 36 |
-
}
|
| 37 |
-
return $res;
|
| 38 |
-
}
|
| 39 |
-
}
|
| 40 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbinfo/DB2Info.php
DELETED
|
@@ -1,83 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class DB2Info extends DBInfo
|
| 3 |
-
{
|
| 4 |
-
/**
|
| 5 |
-
* @return Array
|
| 6 |
-
*/
|
| 7 |
-
public function db_gettablelist()
|
| 8 |
-
{
|
| 9 |
-
$ret = array();
|
| 10 |
-
|
| 11 |
-
$qResult = $this->connectionObj->query( "select TABNAME from syscat.tables order by 1,2" );
|
| 12 |
-
while( $data = $qResult->fetchAssoc() )
|
| 13 |
-
{
|
| 14 |
-
$ret[] = $data["TABNAME"];
|
| 15 |
-
}
|
| 16 |
-
|
| 17 |
-
return $ret;
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
/**
|
| 21 |
-
* @param String strSQL
|
| 22 |
-
* @return Array
|
| 23 |
-
*/
|
| 24 |
-
public function db_getfieldslist($table)
|
| 25 |
-
{
|
| 26 |
-
$res = array();
|
| 27 |
-
|
| 28 |
-
$arr = implode(".", $table);
|
| 29 |
-
$stmt = db2_columns( $this->connectionObj->conn, null , $arr[0] , $arr[1] , '%' );
|
| 30 |
-
if ( $stmt )
|
| 31 |
-
{
|
| 32 |
-
while( $rowC = db2_fetch_assoc($stmt) )
|
| 33 |
-
{
|
| 34 |
-
$ntype = $this->getFieldTypeNumber( $rowC["TYPE_NAME"] );
|
| 35 |
-
$res[ $i ] = array("fieldname" => $rowC["COLUMN_NAME"], "type" => $ntype, "is_nullable" => 0);
|
| 36 |
-
}
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
return $res;
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
/**
|
| 43 |
-
* @param String stype
|
| 44 |
-
* @return Number
|
| 45 |
-
*/
|
| 46 |
-
protected function getFieldTypeNumber( $stype )
|
| 47 |
-
{
|
| 48 |
-
switch( strtoupper($stype) )
|
| 49 |
-
{
|
| 50 |
-
case "BIGINT":
|
| 51 |
-
return 20;
|
| 52 |
-
case "BLOB":
|
| 53 |
-
return 205;
|
| 54 |
-
case "CHAR":
|
| 55 |
-
return 13;
|
| 56 |
-
case "CLOB":
|
| 57 |
-
return 201;
|
| 58 |
-
case "DATE":
|
| 59 |
-
return 7;
|
| 60 |
-
case "DECIMAL":
|
| 61 |
-
return 131;
|
| 62 |
-
case "DOUBLE":
|
| 63 |
-
return 5;
|
| 64 |
-
case "INTEGER":
|
| 65 |
-
return 3;
|
| 66 |
-
case "LONG VARCHAR":
|
| 67 |
-
return 200;
|
| 68 |
-
case "REAL":
|
| 69 |
-
return 5;
|
| 70 |
-
case "SMALLINT":
|
| 71 |
-
return 2;
|
| 72 |
-
case "TIME":
|
| 73 |
-
return 134;
|
| 74 |
-
case "TIMESTAMP":
|
| 75 |
-
return 135;
|
| 76 |
-
case "VARCHAR":
|
| 77 |
-
return 200;
|
| 78 |
-
default:
|
| 79 |
-
return "";
|
| 80 |
-
}
|
| 81 |
-
}
|
| 82 |
-
}
|
| 83 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbinfo/DBInfo.php
DELETED
|
@@ -1,19 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/**
|
| 3 |
-
* The base class containing methods
|
| 4 |
-
* extracting the database info
|
| 5 |
-
*/
|
| 6 |
-
class DBInfo
|
| 7 |
-
{
|
| 8 |
-
/**
|
| 9 |
-
* @type Connection
|
| 10 |
-
*/
|
| 11 |
-
protected $connectionObj;
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
function __construct( $connObj )
|
| 15 |
-
{
|
| 16 |
-
$this->connectionObj = $connObj;
|
| 17 |
-
}
|
| 18 |
-
}
|
| 19 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbinfo/InformixInfo.php
DELETED
|
@@ -1,94 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class InformixInfo extends DBInfo
|
| 3 |
-
{
|
| 4 |
-
/**
|
| 5 |
-
* @return Array
|
| 6 |
-
*/
|
| 7 |
-
public function db_gettablelist()
|
| 8 |
-
{
|
| 9 |
-
$ret = array();
|
| 10 |
-
|
| 11 |
-
$qResult = $this->connectionObj->query( "SELECT tabname FROM systables WHERE tabtype='T' OR tabtype='V'" );
|
| 12 |
-
while( $data = $qResult->fetchAssoc() )
|
| 13 |
-
{
|
| 14 |
-
$ret[] = $data["tabname"];
|
| 15 |
-
}
|
| 16 |
-
|
| 17 |
-
return $ret;
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
/**
|
| 21 |
-
* @param String strSQL
|
| 22 |
-
* @return Array
|
| 23 |
-
*/
|
| 24 |
-
public function db_getfieldslist($strSQL)
|
| 25 |
-
{
|
| 26 |
-
$res = array();
|
| 27 |
-
|
| 28 |
-
$qResult = $this->connectionObj->query( $strSQL );
|
| 29 |
-
$qHandle = $qResult->getQueryHandle();
|
| 30 |
-
|
| 31 |
-
$properties = ifx_fieldproperties( $qHandle );
|
| 32 |
-
foreach( $properties as $fname => $val )
|
| 33 |
-
{
|
| 34 |
-
$stype = implode(";", $val);
|
| 35 |
-
$ntype = $this->getFieldTypeNumber( $stype[0] );
|
| 36 |
-
|
| 37 |
-
$res[ $i ] = array("fieldname" => $fname, "type" => $ntype, "is_nullable" => 0);
|
| 38 |
-
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
return $res;
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
-
/**
|
| 45 |
-
* @param String stype
|
| 46 |
-
* @return Number
|
| 47 |
-
*/
|
| 48 |
-
protected function getFieldTypeNumber($stype)
|
| 49 |
-
{
|
| 50 |
-
switch( strtoupper($stype) )
|
| 51 |
-
{
|
| 52 |
-
case "SQLVCHAR":
|
| 53 |
-
return 200;
|
| 54 |
-
case "SQLTEXT":
|
| 55 |
-
return 201;
|
| 56 |
-
case "SQLINT":
|
| 57 |
-
return 3;
|
| 58 |
-
case "SQLFLOAT":
|
| 59 |
-
return 5;
|
| 60 |
-
case "SQLDATE":
|
| 61 |
-
return 7;
|
| 62 |
-
case "SQLBYTES":
|
| 63 |
-
return 205;
|
| 64 |
-
case "SQLCHAR":
|
| 65 |
-
return 129;
|
| 66 |
-
case "SQLDTIME":
|
| 67 |
-
return 135;
|
| 68 |
-
case "SQLBOOL":
|
| 69 |
-
return 13;
|
| 70 |
-
case "SQLDECIMAL":
|
| 71 |
-
return 14;
|
| 72 |
-
case "SQLINT8":
|
| 73 |
-
return 13;
|
| 74 |
-
case "SQLINTERVAL":
|
| 75 |
-
return 135;
|
| 76 |
-
case "SQLLVARCHAR":
|
| 77 |
-
return 201;
|
| 78 |
-
case "SQLMONEY":
|
| 79 |
-
return 6;
|
| 80 |
-
case "SQLNCHAR":
|
| 81 |
-
$ntype=129;
|
| 82 |
-
break;
|
| 83 |
-
case "SQLNVCHAR":
|
| 84 |
-
return 200;
|
| 85 |
-
case "SQLSMFLOAT":
|
| 86 |
-
return 4;
|
| 87 |
-
case "SQLSMINT":
|
| 88 |
-
return 2;
|
| 89 |
-
default:
|
| 90 |
-
return "";
|
| 91 |
-
}
|
| 92 |
-
}
|
| 93 |
-
}
|
| 94 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbinfo/MSSQLInfo.php
DELETED
|
@@ -1,43 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class MSSQLInfo extends DBInfo
|
| 3 |
-
{
|
| 4 |
-
/**
|
| 5 |
-
* @return Array
|
| 6 |
-
*/
|
| 7 |
-
function db_gettablelist()
|
| 8 |
-
{
|
| 9 |
-
$ret = array();
|
| 10 |
-
|
| 11 |
-
$qResult = $this->connectionObj->query( "sp_tables" );
|
| 12 |
-
while( $data = $qResult->fetchAssoc() )
|
| 13 |
-
{
|
| 14 |
-
if( strtoupper($data["TABLE_OWNER"]) != "SYS" && strtoupper($data["TABLE_OWNER"]) != "INFORMATION_SCHEMA")
|
| 15 |
-
$ret[] = $data["TABLE_OWNER"].".".$data["TABLE_NAME"];
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
return $ret;
|
| 19 |
-
}
|
| 20 |
-
|
| 21 |
-
/**
|
| 22 |
-
* @param String strSQL
|
| 23 |
-
* @return Array
|
| 24 |
-
*/
|
| 25 |
-
function db_getfieldslist($strSQL)
|
| 26 |
-
{
|
| 27 |
-
$res = array();
|
| 28 |
-
|
| 29 |
-
$qResult = $this->connectionObj->query( $strSQL );
|
| 30 |
-
$qHandle = $qResult->getQueryHandle();
|
| 31 |
-
|
| 32 |
-
$fieldsNumber = $qResult->numFields();
|
| 33 |
-
for($i = 0; $i < $fieldsNumber; $i++)
|
| 34 |
-
{
|
| 35 |
-
$ntype = $qHandle->Fields[ $i ]->Type;
|
| 36 |
-
|
| 37 |
-
$res[ $i ] = array("fieldname" => $qResult->fieldName( $i ), "type" => $ntype, "not_null" => 0);
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
return $res;
|
| 41 |
-
}
|
| 42 |
-
}
|
| 43 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbinfo/MySQLInfo.php
DELETED
|
@@ -1,114 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class MySQLInfo extends DBInfo
|
| 3 |
-
{
|
| 4 |
-
/**
|
| 5 |
-
* @return Array
|
| 6 |
-
*/
|
| 7 |
-
public function db_gettablelist()
|
| 8 |
-
{
|
| 9 |
-
$ret = array();
|
| 10 |
-
|
| 11 |
-
$qResult = $this->connectionObj->query( "select DATABASE() as dbname" );
|
| 12 |
-
$data = $qResult->fetchAssoc();
|
| 13 |
-
if( !$data )
|
| 14 |
-
return $ret;
|
| 15 |
-
|
| 16 |
-
$dbname = $data["dbname"];
|
| 17 |
-
|
| 18 |
-
$qResult = $this->connectionObj->query( "SELECT VERSION() as mysql_version" );
|
| 19 |
-
$data = $qResult->fetchAssoc();
|
| 20 |
-
$server_info = $data ? $data["mysql_version"] : 0;
|
| 21 |
-
|
| 22 |
-
if( $server_info >= 5 )
|
| 23 |
-
{
|
| 24 |
-
|
| 25 |
-
$qResult = $this->connectionObj->query( "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '".$dbname."'" );
|
| 26 |
-
while( $data = $qResult->fetchAssoc() )
|
| 27 |
-
{
|
| 28 |
-
$ret[] = $data["TABLE_NAME"];
|
| 29 |
-
}
|
| 30 |
-
|
| 31 |
-
$qResult = $this->connectionObj->query( "SELECT TABLE_NAME FROM information_schema.VIEWS WHERE TABLE_SCHEMA = '".$dbname."'" );
|
| 32 |
-
while( $data = $qResult->fetchAssoc() )
|
| 33 |
-
{
|
| 34 |
-
if( !in_array($data["TABLE_NAME"], $ret) )
|
| 35 |
-
$ret[] = $data["TABLE_NAME"];
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
sort( $ret );
|
| 39 |
-
}
|
| 40 |
-
else
|
| 41 |
-
{
|
| 42 |
-
$qResult = $this->connectionObj->query( "SHOW tables" );
|
| 43 |
-
while( $data = $qResult->fetchNumeric() )
|
| 44 |
-
{
|
| 45 |
-
$ret[] = $data[0];
|
| 46 |
-
}
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
return $ret;
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
/**
|
| 53 |
-
* @param String strSQL
|
| 54 |
-
* @return Array
|
| 55 |
-
*/
|
| 56 |
-
public function db_getfieldslist($strSQL)
|
| 57 |
-
{
|
| 58 |
-
$res = array();
|
| 59 |
-
|
| 60 |
-
$qResult = $this->connectionObj->query( $strSQL );
|
| 61 |
-
$qHandle = $qResult->getQueryHandle();
|
| 62 |
-
|
| 63 |
-
$fieldsNumber = $qResult->numFields();
|
| 64 |
-
for($i = 0; $i < $fieldsNumber; $i++)
|
| 65 |
-
{
|
| 66 |
-
$stype = mysql_field_type($qHandle, $i);
|
| 67 |
-
if( $stype == "blob" )
|
| 68 |
-
{
|
| 69 |
-
$flags = mysql_field_flags($qHandle, $i);
|
| 70 |
-
if( strpos($flags, "binary") === false )
|
| 71 |
-
$stype = "text";
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
$ntype = $this->getFieldTypeNumber( $stype );
|
| 75 |
-
|
| 76 |
-
$res[$i] = array("fieldname" => $qResult->fieldName( $i ), "type" => $ntype, "not_null" => 0);
|
| 77 |
-
}
|
| 78 |
-
return $res;
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
/**
|
| 82 |
-
* @param String stype
|
| 83 |
-
* @return Number
|
| 84 |
-
*/
|
| 85 |
-
protected function getFieldTypeNumber( $stype )
|
| 86 |
-
{
|
| 87 |
-
switch( strtoupper($stype) )
|
| 88 |
-
{
|
| 89 |
-
case "STRING":
|
| 90 |
-
return 200;
|
| 91 |
-
case "INT":
|
| 92 |
-
return 3;
|
| 93 |
-
case "REAL":
|
| 94 |
-
return 5;
|
| 95 |
-
case "TIMESTAMP":
|
| 96 |
-
return 135;;
|
| 97 |
-
case "YEAR":
|
| 98 |
-
return 3;
|
| 99 |
-
case "DATE":
|
| 100 |
-
return 7;
|
| 101 |
-
case "TIME":
|
| 102 |
-
return 134;
|
| 103 |
-
case "DATETIME":
|
| 104 |
-
return 135;
|
| 105 |
-
case "BLOB":
|
| 106 |
-
return 128;
|
| 107 |
-
case "TEXT":
|
| 108 |
-
return 201;
|
| 109 |
-
default:
|
| 110 |
-
return "";
|
| 111 |
-
}
|
| 112 |
-
}
|
| 113 |
-
}
|
| 114 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbinfo/MySQLiInfo.php
DELETED
|
@@ -1,120 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class MySQLiInfo extends DBInfo
|
| 3 |
-
{
|
| 4 |
-
/**
|
| 5 |
-
* @return Array
|
| 6 |
-
*/
|
| 7 |
-
public function db_gettablelist()
|
| 8 |
-
{
|
| 9 |
-
$ret = array();
|
| 10 |
-
|
| 11 |
-
$qResult = $this->connectionObj->query( "select DATABASE() as dbname" );
|
| 12 |
-
$data = $qResult->fetchAssoc();
|
| 13 |
-
if( !$data )
|
| 14 |
-
return $ret;
|
| 15 |
-
|
| 16 |
-
$dbname = $data["dbname"];
|
| 17 |
-
|
| 18 |
-
$qResult = $this->connectionObj->query( "SELECT VERSION() as mysqli_version" );
|
| 19 |
-
$data = $qResult->fetchAssoc();
|
| 20 |
-
$server_info = $data ? $data["mysqli_version"] : 0;
|
| 21 |
-
|
| 22 |
-
if( $server_info >= 5 )
|
| 23 |
-
{
|
| 24 |
-
$qResult = $this->connectionObj->query( "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '".$dbname."'" );
|
| 25 |
-
while( $data = $qResult->fetchAssoc() )
|
| 26 |
-
{
|
| 27 |
-
$ret[] = $data["TABLE_NAME"];
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
$qResult = $this->connectionObj->query( "SELECT TABLE_NAME FROM information_schema.VIEWS WHERE TABLE_SCHEMA = '".$dbname."'" );
|
| 31 |
-
while( $data = $qResult->fetchAssoc() )
|
| 32 |
-
{
|
| 33 |
-
if( !in_array($data["TABLE_NAME"], $ret) )
|
| 34 |
-
$ret[] = $data["TABLE_NAME"];
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
sort($ret);
|
| 38 |
-
}
|
| 39 |
-
else
|
| 40 |
-
{
|
| 41 |
-
$qResult = $this->connectionObj->query( "SHOW tables" );
|
| 42 |
-
while( $data = $qResult->fetchNumeric() )
|
| 43 |
-
{
|
| 44 |
-
$ret[] = $data[0];
|
| 45 |
-
}
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
return $ret;
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
/**
|
| 52 |
-
* @param String stype
|
| 53 |
-
* @return Number
|
| 54 |
-
*/
|
| 55 |
-
public function db_getfieldslist( $strSQL )
|
| 56 |
-
{
|
| 57 |
-
$res = array();
|
| 58 |
-
|
| 59 |
-
$rs = mysqli_query( $this->connectionObj->conn, $strSQL );
|
| 60 |
-
while( $finfo = mysqli_fetch_field($rs) )
|
| 61 |
-
{
|
| 62 |
-
$stype = $this->getFieldTypeNumber( $finfo->type, $finfo->flags );
|
| 63 |
-
|
| 64 |
-
$res[] = array("fieldname" => $finfo->name, "type" => $stype, "not_null" => 0);
|
| 65 |
-
}
|
| 66 |
-
return $res;
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
/**
|
| 70 |
-
* @param String stype
|
| 71 |
-
* @param String flags
|
| 72 |
-
* @return Number
|
| 73 |
-
*/
|
| 74 |
-
protected function getFieldTypeNumber( $stype, $flags )
|
| 75 |
-
{
|
| 76 |
-
switch($stype)
|
| 77 |
-
{
|
| 78 |
-
case 0:
|
| 79 |
-
case 246:
|
| 80 |
-
return 14;
|
| 81 |
-
case 1:
|
| 82 |
-
case 2:
|
| 83 |
-
return 2;
|
| 84 |
-
case 3:
|
| 85 |
-
case 8:
|
| 86 |
-
case 9:
|
| 87 |
-
case 13:
|
| 88 |
-
return 3;
|
| 89 |
-
case 4:
|
| 90 |
-
case 5:
|
| 91 |
-
return 5;
|
| 92 |
-
case 7:
|
| 93 |
-
case 12:
|
| 94 |
-
case 14:
|
| 95 |
-
return 135;
|
| 96 |
-
case 10:
|
| 97 |
-
return 7;
|
| 98 |
-
case 11:
|
| 99 |
-
return 134;
|
| 100 |
-
case 253:
|
| 101 |
-
return 200;
|
| 102 |
-
case 247:
|
| 103 |
-
case 248:
|
| 104 |
-
return 129;
|
| 105 |
-
case 249:
|
| 106 |
-
case 250:
|
| 107 |
-
case 251:
|
| 108 |
-
case 252:
|
| 109 |
-
if( is_numeric($flags) && $flags & 16 && $flags & 128 || strpos($flags, "binary") !== false)
|
| 110 |
-
return 128;
|
| 111 |
-
|
| 112 |
-
return 201;
|
| 113 |
-
case 254:
|
| 114 |
-
return 129;
|
| 115 |
-
default:
|
| 116 |
-
return 13;
|
| 117 |
-
}
|
| 118 |
-
}
|
| 119 |
-
}
|
| 120 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbinfo/ODBCInfo.php
DELETED
|
@@ -1,86 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class ODBCInfo extends DBInfo
|
| 3 |
-
{
|
| 4 |
-
/**
|
| 5 |
-
* @return Array
|
| 6 |
-
*/
|
| 7 |
-
public function db_gettablelist()
|
| 8 |
-
{
|
| 9 |
-
$ret = array();
|
| 10 |
-
$rs = odbc_tables( $this->connectionObj->conn );
|
| 11 |
-
while( odbc_fetch_row($rs) )
|
| 12 |
-
{
|
| 13 |
-
if( odbc_result($rs, "TABLE_TYPE") == "TABLE" || odbc_result($rs, "TABLE_TYPE") == "VIEW" )
|
| 14 |
-
$ret[] = odbc_result($rs, "TABLE_NAME");
|
| 15 |
-
}
|
| 16 |
-
|
| 17 |
-
return $ret;
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
/**
|
| 21 |
-
* @param String strSQL
|
| 22 |
-
* @return Array
|
| 23 |
-
*/
|
| 24 |
-
public function db_getfieldslist($strSQL)
|
| 25 |
-
{
|
| 26 |
-
$res = array();
|
| 27 |
-
|
| 28 |
-
$qResult = $this->connectionObj->query( $strSQL );
|
| 29 |
-
|
| 30 |
-
$fieldsNumber = $qResult->numFields();
|
| 31 |
-
for($i = 0; $i < $fieldsNumber; $i++)
|
| 32 |
-
{
|
| 33 |
-
$stype = odbc_field_type( $qResult->getQueryHandle(), $i + 1 );
|
| 34 |
-
$ntype = $this->getFieldTypeNumber( $stype );
|
| 35 |
-
|
| 36 |
-
$res[ $i ] = array("fieldname" => $qResult->fieldName( $i ), "type" => $ntype, "is_nullable" => 0);
|
| 37 |
-
}
|
| 38 |
-
return $res;
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
/**
|
| 42 |
-
* @param String stype
|
| 43 |
-
* @return Number
|
| 44 |
-
*/
|
| 45 |
-
protected function getFieldTypeNumber( $stype )
|
| 46 |
-
{
|
| 47 |
-
switch( strtoupper($stype) )
|
| 48 |
-
{
|
| 49 |
-
case "COUNTER":
|
| 50 |
-
return 3;
|
| 51 |
-
case "VARCHAR":
|
| 52 |
-
return 202;
|
| 53 |
-
case "LONGCHAR":
|
| 54 |
-
return 203;
|
| 55 |
-
case "INTEGER":
|
| 56 |
-
return 3;
|
| 57 |
-
case "BYTE":
|
| 58 |
-
return 17;
|
| 59 |
-
case "SMALLINT":
|
| 60 |
-
return 2;
|
| 61 |
-
case "REAL":
|
| 62 |
-
return 4;
|
| 63 |
-
case "DOUNLE":
|
| 64 |
-
return 5;
|
| 65 |
-
case "GUID":
|
| 66 |
-
return 72;
|
| 67 |
-
case "DECIMAL":
|
| 68 |
-
return 131;
|
| 69 |
-
case "DATETIME":
|
| 70 |
-
return 7;
|
| 71 |
-
case "CURRENCY":
|
| 72 |
-
return 6;
|
| 73 |
-
case "BIT":
|
| 74 |
-
return 11;
|
| 75 |
-
case "LONGBINARY":
|
| 76 |
-
return 205;
|
| 77 |
-
case "DOUBLE":
|
| 78 |
-
return 5;
|
| 79 |
-
case "BYTE":
|
| 80 |
-
return 11;
|
| 81 |
-
default:
|
| 82 |
-
return "";
|
| 83 |
-
}
|
| 84 |
-
}
|
| 85 |
-
}
|
| 86 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbinfo/OracleInfo.php
DELETED
|
@@ -1,80 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class OracleInfo extends DBInfo
|
| 3 |
-
{
|
| 4 |
-
/**
|
| 5 |
-
* @return Array
|
| 6 |
-
*/
|
| 7 |
-
public function db_gettablelist()
|
| 8 |
-
{
|
| 9 |
-
$ret = array();
|
| 10 |
-
$strSQL = "select owner||'.'||table_name as name,'TABLE' as type from all_tables where owner not like '%SYS%'
|
| 11 |
-
union all
|
| 12 |
-
select owner||'.'||view_name as name,'VIEW' from all_views where owner not like '%SYS%'";
|
| 13 |
-
|
| 14 |
-
$qResult = $this->connectionObj->query( $strSQL );
|
| 15 |
-
while( $data = $qResult->fetchNumeric() )
|
| 16 |
-
{
|
| 17 |
-
$ret[] = $data[0];
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
return $ret;
|
| 21 |
-
}
|
| 22 |
-
|
| 23 |
-
/**
|
| 24 |
-
* @param String strSQL
|
| 25 |
-
* @return Array
|
| 26 |
-
*/
|
| 27 |
-
public function db_getfieldslist( $strSQL )
|
| 28 |
-
{
|
| 29 |
-
$res = array();
|
| 30 |
-
$qResult = $this->connectionObj->query( $strSQL );
|
| 31 |
-
|
| 32 |
-
$fieldsNumber = $qResult->numFields();
|
| 33 |
-
for($i = 0; $i < $fieldsNumber; $i++)
|
| 34 |
-
{
|
| 35 |
-
$stype = oci_field_type( $qResult->getQueryHandle(), $i + 1 );
|
| 36 |
-
$ntype = $this->getFieldTypeNumber( $stype );
|
| 37 |
-
|
| 38 |
-
$res[$i] = array("fieldname" => $qResult->fieldName( $i ), "type"=> $ntype, "is_nullable" => 0);
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
return $res;
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
-
/**
|
| 45 |
-
* @param String stype
|
| 46 |
-
* @return Number
|
| 47 |
-
*/
|
| 48 |
-
protected function getFieldTypeNumber( $stype )
|
| 49 |
-
{
|
| 50 |
-
switch( strtoupper($stype) )
|
| 51 |
-
{
|
| 52 |
-
case "INTEGER":
|
| 53 |
-
return 3;
|
| 54 |
-
case "SMALLINT":
|
| 55 |
-
case "OCTET":
|
| 56 |
-
return 2;
|
| 57 |
-
case "NUMBER":
|
| 58 |
-
return 14;
|
| 59 |
-
case "REAL":
|
| 60 |
-
case "DOUBLE":
|
| 61 |
-
case "FLOAT":
|
| 62 |
-
return 5;
|
| 63 |
-
case "BLOB":
|
| 64 |
-
case "BFILE":
|
| 65 |
-
return 128;
|
| 66 |
-
case "CHAR":
|
| 67 |
-
return 129;
|
| 68 |
-
case "VARCHAR":
|
| 69 |
-
case "VARCHAR2":
|
| 70 |
-
return 200;
|
| 71 |
-
case "DATE":
|
| 72 |
-
return 135;
|
| 73 |
-
case "CLOB":
|
| 74 |
-
return 201;
|
| 75 |
-
default:
|
| 76 |
-
return "";
|
| 77 |
-
}
|
| 78 |
-
}
|
| 79 |
-
}
|
| 80 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbinfo/PostgreInfo.php
DELETED
|
@@ -1,84 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class PostgreInfo extends DBInfo
|
| 3 |
-
{
|
| 4 |
-
/**
|
| 5 |
-
* @return Array
|
| 6 |
-
*/
|
| 7 |
-
public function db_gettablelist()
|
| 8 |
-
{
|
| 9 |
-
$ret = array();
|
| 10 |
-
$strSQL = "select schemaname||'.'||tablename as name from pg_tables where schemaname not in ('pg_catalog','information_schema')
|
| 11 |
-
union all
|
| 12 |
-
select schemaname||'.'||viewname as name from pg_views where schemaname not in ('pg_catalog','information_schema')";
|
| 13 |
-
|
| 14 |
-
$qResult = $this->connectionObj->query( $strSQL );
|
| 15 |
-
while( $data = $qResult->fetchAssoc() )
|
| 16 |
-
{
|
| 17 |
-
$ret[] = $data["name"];
|
| 18 |
-
}
|
| 19 |
-
return $ret;
|
| 20 |
-
}
|
| 21 |
-
|
| 22 |
-
/**
|
| 23 |
-
* @param String strSQL
|
| 24 |
-
* @return Array
|
| 25 |
-
*/
|
| 26 |
-
public function db_getfieldslist( $strSQL )
|
| 27 |
-
{
|
| 28 |
-
$res = array();
|
| 29 |
-
|
| 30 |
-
$qResult = $this->connectionObj->query( $strSQL );
|
| 31 |
-
|
| 32 |
-
$fieldsNumber = $qResult->numFields();
|
| 33 |
-
for($i = 0;$i < $fieldsNumber; $i++)
|
| 34 |
-
{
|
| 35 |
-
$stype = pg_field_type( $qResult->getQueryHandle(), $i );
|
| 36 |
-
$ntype = $this->getFeldTypeNumber($stype);
|
| 37 |
-
|
| 38 |
-
$res[$i] = array("fieldname" => $qResult->fieldName( $i ), "type" => $ntype, "is_nullable" => 0);
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
return $res;
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
-
/**
|
| 45 |
-
* @param String stype
|
| 46 |
-
* @return Number
|
| 47 |
-
*/
|
| 48 |
-
protected function getFeldTypeNumber( $stype )
|
| 49 |
-
{
|
| 50 |
-
switch( strtoupper($stype) )
|
| 51 |
-
{
|
| 52 |
-
case "INT4":
|
| 53 |
-
case "INT2":
|
| 54 |
-
case "INT8":
|
| 55 |
-
return 3;
|
| 56 |
-
case "FLOAT4":
|
| 57 |
-
case "FLOAT8":
|
| 58 |
-
return 5;
|
| 59 |
-
case "NUMERIC":
|
| 60 |
-
case "MONEY":
|
| 61 |
-
return 14;
|
| 62 |
-
case "ABSTIME":
|
| 63 |
-
case "TIMESTAMP":
|
| 64 |
-
case "TIMESTAMPTZ":
|
| 65 |
-
return 135;
|
| 66 |
-
case "TIME":
|
| 67 |
-
case "TIMETZ":
|
| 68 |
-
return 134;
|
| 69 |
-
case "BYTEA":
|
| 70 |
-
return 13;
|
| 71 |
-
case "CHAR":
|
| 72 |
-
return 129;
|
| 73 |
-
case "VARCHAR":
|
| 74 |
-
return 200;
|
| 75 |
-
case "DATE":
|
| 76 |
-
return 7;
|
| 77 |
-
case "TEXT":
|
| 78 |
-
return 201;
|
| 79 |
-
default:
|
| 80 |
-
return "";
|
| 81 |
-
}
|
| 82 |
-
}
|
| 83 |
-
}
|
| 84 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/dbinfo/SQLLite3Info.php
DELETED
|
@@ -1,37 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
class SQLLite3Info extends DBInfo
|
| 3 |
-
{
|
| 4 |
-
/**
|
| 5 |
-
* @return Array
|
| 6 |
-
*/
|
| 7 |
-
public function db_gettablelist()
|
| 8 |
-
{
|
| 9 |
-
$ret = array();
|
| 10 |
-
|
| 11 |
-
$qResult = $this->connectionObj->query( "SELECT tbl_name FROM sqlite_master WHERE type='table' ORDER BY name" );
|
| 12 |
-
while( $data = $qResult->fetchAssoc() )
|
| 13 |
-
{
|
| 14 |
-
$ret[] = $data["tbl_name"];
|
| 15 |
-
}
|
| 16 |
-
|
| 17 |
-
return $ret;
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
/**
|
| 21 |
-
* @param String strSQL
|
| 22 |
-
* @return Array
|
| 23 |
-
*/
|
| 24 |
-
public function db_getfieldslist( $strSQL )
|
| 25 |
-
{
|
| 26 |
-
$res = array();
|
| 27 |
-
|
| 28 |
-
$qResult = $this->connectionObj->query( $strSQL );
|
| 29 |
-
$fieldsNumber = $qResult->numFields();
|
| 30 |
-
for($i = 0; $i < $fieldsNumber; $i++)
|
| 31 |
-
{
|
| 32 |
-
$res[ $i ] = array("fieldname" => $qResult->fieldName( $i ), "type"=> 202, "is_nullable" => 0);
|
| 33 |
-
}
|
| 34 |
-
return $res;
|
| 35 |
-
}
|
| 36 |
-
}
|
| 37 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connections/rest.php
DELETED
|
@@ -1,444 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
class RestConnection {
|
| 4 |
-
var $connId;
|
| 5 |
-
var $url;
|
| 6 |
-
var $authType;
|
| 7 |
-
var $dbType;
|
| 8 |
-
|
| 9 |
-
var $clientCredentials;
|
| 10 |
-
var $username;
|
| 11 |
-
var $password;
|
| 12 |
-
|
| 13 |
-
var $apiKey;
|
| 14 |
-
var $keyLocation;
|
| 15 |
-
var $keyParameter;
|
| 16 |
-
|
| 17 |
-
var $authUrl;
|
| 18 |
-
var $tokenUrl;
|
| 19 |
-
var $clientId;
|
| 20 |
-
var $clientSecret;
|
| 21 |
-
var $scope;
|
| 22 |
-
|
| 23 |
-
/**
|
| 24 |
-
* @var Boolean - send OAuth client_id and client_secret as Authentication URL parameters or not
|
| 25 |
-
*/
|
| 26 |
-
var $sendOauthClientId;
|
| 27 |
-
|
| 28 |
-
var $_encryptInfo;
|
| 29 |
-
|
| 30 |
-
protected $error = "";
|
| 31 |
-
protected $responseCode = "";
|
| 32 |
-
protected $response;
|
| 33 |
-
|
| 34 |
-
protected $authorizationRequest = null;
|
| 35 |
-
|
| 36 |
-
function __construct( $params ) {
|
| 37 |
-
$this->dbType = nDATABASE_REST;
|
| 38 |
-
$this->connId = $params["connId"];
|
| 39 |
-
$this->url = $params["url"];
|
| 40 |
-
$this->authType = $params["authType"];
|
| 41 |
-
|
| 42 |
-
$this->clientCredentials = $params["clientCredentials"];
|
| 43 |
-
$this->username = $params["username"];
|
| 44 |
-
$this->password = $params["password"];
|
| 45 |
-
|
| 46 |
-
$this->apiKey = $params["apiKey"];
|
| 47 |
-
$this->keyLocation = $params["keyLocation"];
|
| 48 |
-
$this->keyParameter = $params["keyParameter"];
|
| 49 |
-
|
| 50 |
-
$this->authUrl = $params["authUrl"];
|
| 51 |
-
$this->tokenUrl = $params["tokenUrl"];
|
| 52 |
-
$this->clientId = $params["clientId"];
|
| 53 |
-
$this->clientSecret = $params["clientSecret"];
|
| 54 |
-
$this->scope = $params["scope"];
|
| 55 |
-
$this->sendOauthClientId = array_key_exists( "sendOauthClientId", $params )
|
| 56 |
-
? $params[ "sendOauthClientId" ]
|
| 57 |
-
: true;
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
/**
|
| 61 |
-
* Returns JSON oject or false in case of error
|
| 62 |
-
* "content" => response body
|
| 63 |
-
* "error" => error message if any
|
| 64 |
-
*/
|
| 65 |
-
function requestJson( $urlRequest, $method, $payload = array(), $headers = null, $urlParams = null ) {
|
| 66 |
-
$request = new HttpRequest(
|
| 67 |
-
$this->url . $urlRequest,
|
| 68 |
-
$method,
|
| 69 |
-
$urlParams,
|
| 70 |
-
$payload,
|
| 71 |
-
$headers
|
| 72 |
-
);
|
| 73 |
-
return $this->sendJsonRequest( $request );
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
function createRequest( $urlRequest, $method = "GET" ) {
|
| 77 |
-
return new HttpRequest( $this->url . $urlRequest, $method );
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
/**
|
| 81 |
-
* Sends requests, parses result as JSON
|
| 82 |
-
*/
|
| 83 |
-
function sendJsonRequest( $request ) {
|
| 84 |
-
$res = &$this->requestWithAuth( $request );
|
| 85 |
-
if( $res["error"] ) {
|
| 86 |
-
return false;
|
| 87 |
-
}
|
| 88 |
-
$content = $res["content"];
|
| 89 |
-
if( $content == "" ) {
|
| 90 |
-
return "";
|
| 91 |
-
}
|
| 92 |
-
$obj = runner_json_decode( $content );
|
| 93 |
-
if( is_array($obj) && count( $obj ) == 0 && trim( $content ) != "[]" ) {
|
| 94 |
-
// unable to parse?
|
| 95 |
-
$this->error = "Unable to parse JSON result\n\n" . $content;
|
| 96 |
-
return false;
|
| 97 |
-
}
|
| 98 |
-
return $obj;
|
| 99 |
-
}
|
| 100 |
-
|
| 101 |
-
/**
|
| 102 |
-
* Returns auth data depending on clientCredentials state
|
| 103 |
-
*
|
| 104 |
-
*/
|
| 105 |
-
function oauthTokenRequestParams() {
|
| 106 |
-
|
| 107 |
-
if ( $this->clientCredentials ) {
|
| 108 |
-
return array(
|
| 109 |
-
"grant_type" => "client_credentials",
|
| 110 |
-
"scope" => $this->scope,
|
| 111 |
-
'client_secret' => $this->clientSecret,
|
| 112 |
-
'client_id' => $this->clientId
|
| 113 |
-
);
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
return array(
|
| 117 |
-
"grant_type" => "password",
|
| 118 |
-
"username" => $this->username,
|
| 119 |
-
"password" => $this->password,
|
| 120 |
-
"scope" => $this->scope
|
| 121 |
-
);
|
| 122 |
-
}
|
| 123 |
-
|
| 124 |
-
/**
|
| 125 |
-
* Obtain access token from storage of any.
|
| 126 |
-
* Refresh if needed
|
| 127 |
-
* If none, signal to the application that authorization is needed
|
| 128 |
-
*/
|
| 129 |
-
function getOauthAccessToken() {
|
| 130 |
-
$oauthToken = $this->getOauthToken();
|
| 131 |
-
// token may have expired, refresh it
|
| 132 |
-
if( $oauthToken ) {
|
| 133 |
-
$oauthToken = $this->checkRefreshOauthToken( $oauthToken );
|
| 134 |
-
}
|
| 135 |
-
if( !$oauthToken ) {
|
| 136 |
-
if( $this->authType === "oauth" ) {
|
| 137 |
-
// signal external authorization needed
|
| 138 |
-
$this->setAuthorizationRequest( $this->createUserAuthRequest() );
|
| 139 |
-
return false;
|
| 140 |
-
} else if( $this->authType === "oauthserver" ) {
|
| 141 |
-
// send auth request
|
| 142 |
-
$oauthToken = $this->requestOauthToken( $this->createOauthTokenRequest( $this->oauthTokenRequestParams() ) );
|
| 143 |
-
$this->setOauthToken( $oauthToken );
|
| 144 |
-
}
|
| 145 |
-
}
|
| 146 |
-
return $oauthToken[ "access_token" ];
|
| 147 |
-
}
|
| 148 |
-
|
| 149 |
-
function setOauthToken( $token ) {
|
| 150 |
-
$sessionKey = "oauthToken_" . $this->connId;
|
| 151 |
-
if( !$token ) {
|
| 152 |
-
unset( $_SESSION[ $sessionKey ] );
|
| 153 |
-
} else {
|
| 154 |
-
$_SESSION[ $sessionKey ] = my_json_encode( $token );
|
| 155 |
-
}
|
| 156 |
-
}
|
| 157 |
-
|
| 158 |
-
function getOauthToken() {
|
| 159 |
-
$sessionKey = "oauthToken_" . $this->connId;
|
| 160 |
-
if( !$_SESSION[ $sessionKey ] ) {
|
| 161 |
-
return false;
|
| 162 |
-
}
|
| 163 |
-
return my_json_decode( $_SESSION[ $sessionKey ] );
|
| 164 |
-
}
|
| 165 |
-
|
| 166 |
-
/**
|
| 167 |
-
* add authentication data to request
|
| 168 |
-
* @return Boolean - false if unsuccessful.
|
| 169 |
-
*/
|
| 170 |
-
function requestAddAuth( $request ) {
|
| 171 |
-
if( $this->authType === "oauth" || $this->authType === "oauthserver" ) {
|
| 172 |
-
|
| 173 |
-
$accessToken = $this->getOauthAccessToken();
|
| 174 |
-
if( !$accessToken ) {
|
| 175 |
-
$this->error = $this->error
|
| 176 |
-
? $this->error
|
| 177 |
-
: "Not autorized yet";
|
| 178 |
-
return false;
|
| 179 |
-
}
|
| 180 |
-
$request->headers["Authorization"] = "Bearer ". $accessToken;
|
| 181 |
-
}
|
| 182 |
-
else if( $this->authType === "basic" ) { // Basic HTTP
|
| 183 |
-
$request->addBasicAuthorization( $this->username, $this->password );
|
| 184 |
-
}
|
| 185 |
-
else if( $this->authType === "api" ) { // API key
|
| 186 |
-
if( $this->keyLocation == 1 ) {
|
| 187 |
-
$request->headers[ $this->keyParameter ] = $this->apiKey;
|
| 188 |
-
}
|
| 189 |
-
else if( $this->keyLocation == 0 ){
|
| 190 |
-
$request->urlParams[ $this->keyParameter ] = $this->apiKey;
|
| 191 |
-
}
|
| 192 |
-
else {
|
| 193 |
-
$request->postPayload[ $this->keyParameter ] = $this->apiKey;
|
| 194 |
-
}
|
| 195 |
-
} else if( $this->authType === "custom" ) {
|
| 196 |
-
global $globalEvents;
|
| 197 |
-
$handler = "rest_authenticate" . $this->connId;
|
| 198 |
-
$globalEvents->$handler( $this, "data", $request, null );
|
| 199 |
-
}
|
| 200 |
-
|
| 201 |
-
// in the process of authorizing
|
| 202 |
-
if( $this->getAuthorizationRequest() != null ) {
|
| 203 |
-
$this->error = "Authorization required";
|
| 204 |
-
return false;
|
| 205 |
-
}
|
| 206 |
-
return true;
|
| 207 |
-
|
| 208 |
-
}
|
| 209 |
-
|
| 210 |
-
/**
|
| 211 |
-
* @return String or false
|
| 212 |
-
*/
|
| 213 |
-
function & requestWithAuth( $request, $authenticateOnly = false ) {
|
| 214 |
-
|
| 215 |
-
$authResult = $this->requestAddAuth( $request );
|
| 216 |
-
if( !$authResult ) {
|
| 217 |
-
return false;
|
| 218 |
-
}
|
| 219 |
-
|
| 220 |
-
if( $authenticateOnly ) {
|
| 221 |
-
return "ok";
|
| 222 |
-
}
|
| 223 |
-
|
| 224 |
-
global $restResultCache;
|
| 225 |
-
$requestKey = $request->getRequestKey();
|
| 226 |
-
if( $requestKey !== null && isset( $restResultCache[ $requestKey ] ) ) {
|
| 227 |
-
return $restResultCache[ $requestKey ];
|
| 228 |
-
}
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
$ret = $this->doRequest( $request );
|
| 232 |
-
if( $ret["error"] ) {
|
| 233 |
-
return $ret;
|
| 234 |
-
}
|
| 235 |
-
|
| 236 |
-
if( $requestKey !== null )
|
| 237 |
-
$restResultCache[ $requestKey ] = &$ret;
|
| 238 |
-
return $ret;
|
| 239 |
-
}
|
| 240 |
-
|
| 241 |
-
/**
|
| 242 |
-
* @param HttpRequest request
|
| 243 |
-
* @return Array(
|
| 244 |
-
* header => string
|
| 245 |
-
* error? => string
|
| 246 |
-
* content? => string
|
| 247 |
-
* )
|
| 248 |
-
*/
|
| 249 |
-
public function doRequest( $request ) {
|
| 250 |
-
$ret = $request->run();
|
| 251 |
-
if( $ret["error"] ) {
|
| 252 |
-
$this->error = $ret["errorMessage"];
|
| 253 |
-
}
|
| 254 |
-
return $ret;
|
| 255 |
-
}
|
| 256 |
-
|
| 257 |
-
/**
|
| 258 |
-
* @return String
|
| 259 |
-
*/
|
| 260 |
-
public function lastError()
|
| 261 |
-
{
|
| 262 |
-
return $this->error;
|
| 263 |
-
}
|
| 264 |
-
|
| 265 |
-
/**
|
| 266 |
-
* @param Array params - optional array of parameters to supplement or override url parameters
|
| 267 |
-
* @return HttpRequest
|
| 268 |
-
* Array( "url" => redirect url, "state" => state to save )
|
| 269 |
-
*/
|
| 270 |
-
public function createUserAuthRequest( $params = array() ) {
|
| 271 |
-
$request = new HttpRequest( $this->authUrl, "GET" );
|
| 272 |
-
$state = generatePassword(30);
|
| 273 |
-
$request->urlParams = array(
|
| 274 |
-
'response_type' => 'code',
|
| 275 |
-
'approval_prompt' => 'auto',
|
| 276 |
-
'redirect_uri' => projectURL() . GetTableLink("oauthcallback"),
|
| 277 |
-
'client_id' => $this->clientId,
|
| 278 |
-
'state' => $state
|
| 279 |
-
);
|
| 280 |
-
if( $params ) {
|
| 281 |
-
foreach( $params as $n => $p ) {
|
| 282 |
-
$request->urlParams[ $n ] = $p;
|
| 283 |
-
}
|
| 284 |
-
}
|
| 285 |
-
if( $this->scope ) {
|
| 286 |
-
$request->urlParams["scope"] = $this->scope;
|
| 287 |
-
}
|
| 288 |
-
return $request;
|
| 289 |
-
|
| 290 |
-
}
|
| 291 |
-
|
| 292 |
-
/**
|
| 293 |
-
* Part of publis API
|
| 294 |
-
*/
|
| 295 |
-
public function requestOauthToken( $request ) {
|
| 296 |
-
$response = $this->doRequest( $request );
|
| 297 |
-
if( $response["error"] ) {
|
| 298 |
-
return false;
|
| 299 |
-
}
|
| 300 |
-
|
| 301 |
-
$result = HttpRequest::parseResponseArray( $response );
|
| 302 |
-
if( !$result["access_token"] ) {
|
| 303 |
-
$this->error = $response["header"] . $response["content"];
|
| 304 |
-
return false;
|
| 305 |
-
}
|
| 306 |
-
$accessToken = array(
|
| 307 |
-
"access_token" => $result["access_token"],
|
| 308 |
-
"refresh_token" => $result["refresh_token"]
|
| 309 |
-
);
|
| 310 |
-
if( !$result[ "refresh_token" ] && $request->postPayload[ "refresh_token" ] ) {
|
| 311 |
-
// use old refresh token
|
| 312 |
-
$accessToken[ "refresh_token" ] = $request->postPayload[ "refresh_token" ];
|
| 313 |
-
}
|
| 314 |
-
if( $result["expires_in"]) {
|
| 315 |
-
$accessToken["expires"] = time() + $result["expires_in"];
|
| 316 |
-
} else if( $result["expires"] ) {
|
| 317 |
-
$accessToken["expires"] = (int)$result["expires"];
|
| 318 |
-
|
| 319 |
-
$oauth2InceptionDate = 1349067600; // 2012-10-01
|
| 320 |
-
if ( $accessToken["expires"] <= $oauth2InceptionDate ) {
|
| 321 |
-
$accessToken["expires"] += time();
|
| 322 |
-
}
|
| 323 |
-
}
|
| 324 |
-
return $accessToken;
|
| 325 |
-
}
|
| 326 |
-
|
| 327 |
-
protected function createOauthTokenRequest( $params ) {
|
| 328 |
-
$request = new HttpRequest( $this->tokenUrl, "POST" );
|
| 329 |
-
$request->postPayload = $params;
|
| 330 |
-
$request->addBasicAuthorization( $this->clientId, $this->clientSecret );
|
| 331 |
-
$request->headers["Content-Type"] = 'application/x-www-form-urlencoded';
|
| 332 |
-
return $request;
|
| 333 |
-
|
| 334 |
-
}
|
| 335 |
-
|
| 336 |
-
public function validateCode( $code ) {
|
| 337 |
-
if( !$code ) {
|
| 338 |
-
$this->error = "Provider returned no authorization code";
|
| 339 |
-
return false;
|
| 340 |
-
}
|
| 341 |
-
if( $this->authType === "oauth" ) {
|
| 342 |
-
return $this->validateOauthCode( $code );
|
| 343 |
-
|
| 344 |
-
} else if( $this->authType === "custom" ) {
|
| 345 |
-
global $globalEvents;
|
| 346 |
-
$handler = "rest_authenticate" . $this->connId;
|
| 347 |
-
return $globalEvents->$handler( $this, "validate", null, $code );
|
| 348 |
-
}
|
| 349 |
-
}
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
public function validateOauthCode( $code ) {
|
| 353 |
-
|
| 354 |
-
$params = array(
|
| 355 |
-
'grant_type' => 'authorization_code',
|
| 356 |
-
'code' => $code,
|
| 357 |
-
'redirect_uri' => projectURL() . GetTableLink("oauthcallback")
|
| 358 |
-
);
|
| 359 |
-
if( $this->sendOauthClientId ) {
|
| 360 |
-
// Dropbox.com returns error if this parameter IS specified
|
| 361 |
-
// Other APIs either require or don't mind it.
|
| 362 |
-
$params[ 'client_id' ] = $this->clientId;
|
| 363 |
-
}
|
| 364 |
-
$accessToken = $this->requestOauthToken( $this->createOauthTokenRequest( $params ) );
|
| 365 |
-
if( !$accessToken ) {
|
| 366 |
-
return false;
|
| 367 |
-
}
|
| 368 |
-
$this->setOauthToken( $accessToken );
|
| 369 |
-
return true;
|
| 370 |
-
}
|
| 371 |
-
|
| 372 |
-
protected function checkRefreshOauthToken( $accessToken )
|
| 373 |
-
{
|
| 374 |
-
if( $this->accessTokenExpired( $accessToken ) ) {
|
| 375 |
-
if( !$accessToken['refresh_token'] ) {
|
| 376 |
-
return null;
|
| 377 |
-
}
|
| 378 |
-
$params = array(
|
| 379 |
-
'grant_type' => 'refresh_token',
|
| 380 |
-
'refresh_token' => $accessToken['refresh_token']
|
| 381 |
-
);
|
| 382 |
-
$accessToken = $this->requestOauthToken( $this->createOauthTokenRequest( $params ) );
|
| 383 |
-
$this->setOauthToken( $accessToken );
|
| 384 |
-
}
|
| 385 |
-
return $accessToken;
|
| 386 |
-
}
|
| 387 |
-
|
| 388 |
-
public function accessTokenExpired( $accessToken ) {
|
| 389 |
-
$timeAllowance = 2;
|
| 390 |
-
return $accessToken["expires"] && $accessToken["expires"] < time() - $timeAllowance;
|
| 391 |
-
}
|
| 392 |
-
|
| 393 |
-
public function isEncryptionByPHPEnabled() {
|
| 394 |
-
return false;
|
| 395 |
-
}
|
| 396 |
-
|
| 397 |
-
public function dbBased() {
|
| 398 |
-
return false;
|
| 399 |
-
}
|
| 400 |
-
|
| 401 |
-
public function close() {
|
| 402 |
-
|
| 403 |
-
}
|
| 404 |
-
|
| 405 |
-
public function checkIfJoinSubqueriesOptimized() {
|
| 406 |
-
return false;
|
| 407 |
-
}
|
| 408 |
-
|
| 409 |
-
public function checkDBSubqueriesSupport() {
|
| 410 |
-
return false;
|
| 411 |
-
}
|
| 412 |
-
|
| 413 |
-
/**
|
| 414 |
-
* Tell the application that additional authorization is required
|
| 415 |
-
*/
|
| 416 |
-
public function setAuthorizationRequest( $request ) {
|
| 417 |
-
$this->authorizationRequest = $request;
|
| 418 |
-
if( $request->urlParams["state"] )
|
| 419 |
-
|
| 420 |
-
if( !$_SESSION[ 'oauth2statemap' ] ) {
|
| 421 |
-
$_SESSION[ 'oauth2statemap' ] = array();
|
| 422 |
-
}
|
| 423 |
-
$_SESSION[ 'oauth2statemap' ][ $request->urlParams["state"] ] = $this->connId;
|
| 424 |
-
}
|
| 425 |
-
|
| 426 |
-
public function getAuthorizationRequest() {
|
| 427 |
-
return $this->authorizationRequest;
|
| 428 |
-
}
|
| 429 |
-
|
| 430 |
-
/**
|
| 431 |
-
* Check if authorization has been obtained
|
| 432 |
-
*
|
| 433 |
-
*/
|
| 434 |
-
public function checkAuthorization() {
|
| 435 |
-
if( $this->authorizationRequest )
|
| 436 |
-
return false;
|
| 437 |
-
|
| 438 |
-
$result = $this->requestWithAuth( new HttpRequest(""), true );
|
| 439 |
-
return !!$result;
|
| 440 |
-
}
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
}
|
| 444 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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