From 301475187cf7f99541468806e83fa74986806580 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Wed, 10 Mar 2021 17:42:28 +0100 Subject: setConnectionParameter() method should not be final This was a mistake, as discussed in [[1]]. Fixes #694 [1]: https://github.com/ADOdb/ADOdb/issues/693#issuecomment-795251586 --- adodb.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'adodb.inc.php') diff --git a/adodb.inc.php b/adodb.inc.php index 91f02242..1e25ca23 100644 --- a/adodb.inc.php +++ b/adodb.inc.php @@ -539,7 +539,7 @@ if (!defined('_ADODB_LAYER')) { * * @example, for mssqlnative driver ('CharacterSet','UTF-8') */ - final public function setConnectionParameter($parameter,$value) { + public function setConnectionParameter($parameter, $value) { $this->connectionParameters[] = array($parameter=>$value); -- cgit v1.3 From 1cf08896f504da83d390c015b01b7ff6ad8d7291 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Wed, 10 Mar 2021 17:52:22 +0100 Subject: Improve PHPdoc for setConnectionParameter() Fix whitespace --- adodb.inc.php | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'adodb.inc.php') diff --git a/adodb.inc.php b/adodb.inc.php index 1e25ca23..57c9fe48 100644 --- a/adodb.inc.php +++ b/adodb.inc.php @@ -527,22 +527,24 @@ if (!defined('_ADODB_LAYER')) { protected $connectionParameters = array(); /** - * Adds a parameter to the connection string. - * - * These parameters are added to the connection string when connecting, - * if the driver is coded to use it. - * - * @param string $parameter The name of the parameter to set - * @param string $value The value of the parameter - * - * @return null - * - * @example, for mssqlnative driver ('CharacterSet','UTF-8') - */ + * Adds a parameter to the connection string. + * + * Parameters must be added before the connection is established; + * they are then passed on to the connect statement. + * + * If used in a portable environment, parameters set in this manner should + * be predicated on the database provider, as unexpected results may occur + * if applied to the wrong database. + * + * @param string $parameter The name of the parameter to set + * @param string $value The value of the parameter + * + * @return null + * + * @example, for mssqlnative driver ('CharacterSet','UTF-8') + */ public function setConnectionParameter($parameter, $value) { - - $this->connectionParameters[] = array($parameter=>$value); - + $this->connectionParameters[] = array($parameter => $value); } /** -- cgit v1.3 From 92346252254a4d3fb97ec0034a0832c271b68989 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Thu, 11 Mar 2021 19:32:27 +0100 Subject: PHPDoc and camelCase for newDataDictionary --- adodb-xmlschema.inc.php | 2 +- adodb-xmlschema03.inc.php | 2 +- adodb.inc.php | 10 +++++++++- replicate/adodb-replicate.inc.php | 4 ++-- tests/test-datadict.php | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) (limited to 'adodb.inc.php') diff --git a/adodb-xmlschema.inc.php b/adodb-xmlschema.inc.php index 0961b4db..0216684b 100644 --- a/adodb-xmlschema.inc.php +++ b/adodb-xmlschema.inc.php @@ -1299,7 +1299,7 @@ class adoSchema { function __construct( $db ) { $this->db = $db; $this->debug = $this->db->debug; - $this->dict = NewDataDictionary( $this->db ); + $this->dict = newDataDictionary( $this->db ); $this->sqlArray = array(); $this->schemaVersion = XMLS_SCHEMA_VERSION; $this->executeInline( XMLS_EXECUTE_INLINE ); diff --git a/adodb-xmlschema03.inc.php b/adodb-xmlschema03.inc.php index 9fb8272c..8d503d3b 100644 --- a/adodb-xmlschema03.inc.php +++ b/adodb-xmlschema03.inc.php @@ -1415,7 +1415,7 @@ class adoSchema { function __construct( $db ) { $this->db = $db; $this->debug = $this->db->debug; - $this->dict = NewDataDictionary( $this->db ); + $this->dict = newDataDictionary( $this->db ); $this->sqlArray = array(); $this->schemaVersion = XMLS_SCHEMA_VERSION; $this->executeInline( XMLS_EXECUTE_INLINE ); diff --git a/adodb.inc.php b/adodb.inc.php index 57c9fe48..747fecf2 100644 --- a/adodb.inc.php +++ b/adodb.inc.php @@ -5405,7 +5405,15 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 return new $class($conn); } - function NewDataDictionary(&$conn,$drivername=false) { + /** + * Get a new Data Dictionary object for the connection. + * + * @param ADOConnection $conn + * @param string $drivername + * + * @return ADODB_DataDict|false + */ + function newDataDictionary(&$conn, $drivername='') { if (!$drivername) { $drivername = _adodb_getdriver($conn->dataProvider,$conn->databaseType); } diff --git a/replicate/adodb-replicate.inc.php b/replicate/adodb-replicate.inc.php index f13e4af7..f1cdffad 100644 --- a/replicate/adodb-replicate.inc.php +++ b/replicate/adodb-replicate.inc.php @@ -114,8 +114,8 @@ class ADODB_Replicate { $this->connSrc2 = ($connSrc2) ? $connSrc2 : $connSrc; $this->connDest2 = ($connDest2) ? $connDest2 : $connDest; - $this->ddSrc = NewDataDictionary($connSrc); - $this->ddDest = NewDataDictionary($connDest); + $this->ddSrc = newDataDictionary($connSrc); + $this->ddDest = newDataDictionary($connDest); $this->htmlSpecialChars = isset($_SERVER['HTTP_HOST']); } diff --git a/tests/test-datadict.php b/tests/test-datadict.php index c35c3d8a..071ebf34 100644 --- a/tests/test-datadict.php +++ b/tests/test-datadict.php @@ -18,7 +18,7 @@ include_once('../adodb.inc.php'); foreach(array('sapdb','sybase','mysql','access','oci8po','odbc_mssql','odbc','db2','firebird','postgres','informix') as $dbType) { echo "

$dbType

"; $db = NewADOConnection($dbType); - $dict = NewDataDictionary($db); + $dict = newDataDictionary($db); if (!$dict) continue; $dict->debug = 1; -- cgit v1.3 From fa7997ce45243dccfc2794990111a69742c3d130 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Thu, 11 Mar 2021 19:34:03 +0100 Subject: Whitespace --- adodb-datadict.inc.php | 22 ++++++------ adodb.inc.php | 26 +++++++------- drivers/adodb-mssqlnative.inc.php | 74 ++++++++++++++++++--------------------- 3 files changed, 58 insertions(+), 64 deletions(-) (limited to 'adodb.inc.php') diff --git a/adodb-datadict.inc.php b/adodb-datadict.inc.php index 30ede0e0..5e26300f 100644 --- a/adodb-datadict.inc.php +++ b/adodb-datadict.inc.php @@ -188,13 +188,13 @@ class ADODB_DataDict { /* * Indicates whether a BLOB/CLOB field will allow a NOT NULL setting - * The type is whatever is matched to an X or X2 or B type. We must + * The type is whatever is matched to an X or X2 or B type. We must * explicitly set the value in the driver to switch the behaviour on */ public $blobAllowsNotNull; /* * Indicates whether a BLOB/CLOB field will allow a DEFAULT set - * The type is whatever is matched to an X or X2 or B type. We must + * The type is whatever is matched to an X or X2 or B type. We must * explicitly set the value in the driver to switch the behaviour on */ public $blobAllowsDefaultValue; @@ -681,11 +681,11 @@ class ADODB_DataDict { //----------------- // Parse attributes foreach($fld as $attr => $v) { - if ($attr == 2 && is_numeric($v)) + if ($attr == 2 && is_numeric($v)) $attr = 'SIZE'; - elseif ($attr == 2 && strtoupper($ftype) == 'ENUM') + elseif ($attr == 2 && strtoupper($ftype) == 'ENUM') $attr = 'ENUM'; - else if (is_numeric($attr) && $attr > 1 && !is_numeric($v)) + else if (is_numeric($attr) && $attr > 1 && !is_numeric($v)) $attr = strtoupper($v); switch($attr) { @@ -747,9 +747,9 @@ class ADODB_DataDict { * some blob types do not accept nulls, so we override the * previously defined value */ - $fnotnull = false; + $fnotnull = false; - if ($fprimary) + if ($fprimary) $pkey[] = $fname; if (($ty == 'X' || $ty == 'X2' || $ty == 'XL' || $ty == 'B') && !$this->blobAllowsDefaultValue) @@ -846,7 +846,7 @@ class ADODB_DataDict { if (strlen($fprec)) $ftype .= ",".$fprec; $ftype .= ')'; } - + /* * Handle additional options */ @@ -859,12 +859,12 @@ class ADODB_DataDict { case 'ENUM': $ftype .= '(' . $value . ')'; break; - + default: } } } - + return $ftype; } @@ -927,7 +927,7 @@ class ADODB_DataDict { return $sql; } } - + $s = "CREATE TABLE $tabname (\n"; $s .= implode(",\n", $lines); if (sizeof($pkey)>0) { diff --git a/adodb.inc.php b/adodb.inc.php index 747fecf2..a7ff42d5 100644 --- a/adodb.inc.php +++ b/adodb.inc.php @@ -178,7 +178,7 @@ if (!defined('_ADODB_LAYER')) { define('DB_AUTOQUERY_UPDATE', 2); - + function ADODB_Setup() { GLOBAL $ADODB_vers, // database version @@ -1460,8 +1460,8 @@ if (!defined('_ADODB_LAYER')) { * * @param string $table * @param string $id - - * @return mixed The last inserted ID. All databases support this, but be + + * @return mixed The last inserted ID. All databases support this, but be * aware of possible problems in multiuser environments. * Heavily test this before deploying. */ @@ -5118,13 +5118,13 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 if (!defined('ADODB_ASSOC_CASE')) { define('ADODB_ASSOC_CASE', ADODB_ASSOC_CASE_NATIVE); } - + /* * Are there special characters in the dsn password * that disrupt parse_url */ $needsSpecialCharacterHandling = false; - + $errorfn = (defined('ADODB_ERROR_HANDLER')) ? ADODB_ERROR_HANDLER : false; if (($at = strpos($db,'://')) !== FALSE) { $origdsn = $db; @@ -5151,23 +5151,23 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 * Stop # character breaking parse_url */ $cFakedsn = str_replace('#','\035',$fakedsn); - if (strcmp($fakedsn,$cFakedsn) != 0) + if (strcmp($fakedsn,$cFakedsn) != 0) { /* * There is a # in the string */ $needsSpecialCharacterHandling = true; - + /* * This allows us to successfully parse the url */ $fakedsn = $cFakedsn; - + } - + $dsna = parse_url($fakedsn); } - + if (!$dsna) { return false; } @@ -5193,13 +5193,13 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 if (!$db) { return false; } - + $dsna['host'] = isset($dsna['host']) ? rawurldecode($dsna['host']) : ''; $dsna['user'] = isset($dsna['user']) ? rawurldecode($dsna['user']) : ''; $dsna['pass'] = isset($dsna['pass']) ? rawurldecode($dsna['pass']) : ''; $dsna['path'] = isset($dsna['path']) ? rawurldecode(substr($dsna['path'],1)) : ''; # strip off initial / - if ($needsSpecialCharacterHandling) + if ($needsSpecialCharacterHandling) { /* * Revert back to the original string @@ -5440,8 +5440,6 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 return $dict; } - - /* Perform a print_r, with pre tags for better formatting. */ diff --git a/drivers/adodb-mssqlnative.inc.php b/drivers/adodb-mssqlnative.inc.php index 3ed66ac6..d14af247 100644 --- a/drivers/adodb-mssqlnative.inc.php +++ b/drivers/adodb-mssqlnative.inc.php @@ -439,9 +439,9 @@ class ADODB_mssqlnative extends ADOConnection { function ErrorNo() { $err = sqlsrv_errors(SQLSRV_ERR_ALL); - if ($err && $err[0]) + if ($err && $err[0]) return $err[0]['code']; - else + else return 0; } @@ -454,13 +454,13 @@ class ADODB_mssqlnative extends ADOConnection { ADOConnection::outp('Microsoft SQL Server native driver (mssqlnative) not installed'); return null; } - + if (!empty($this->port)) /* - * Port uses a comma + * Port uses a comma */ $argHostname .= ",".$this->port; - + $connectionInfo = $this->connectionInfo; $connectionInfo["Database"] = $argDatabasename; if ((string)$argUsername != '' || (string)$argPassword != '') @@ -471,12 +471,12 @@ class ADODB_mssqlnative extends ADOConnection { */ $connectionInfo["UID"] = $argUsername; $connectionInfo["PWD"] = $argPassword; - + if ($this->debug) ADOConnection::outp('userid or password supplied, attempting connection with SQL Server Authentication'); - + } - else + else { /* * If they don't pass either value, we won't add them to the @@ -484,11 +484,11 @@ class ADODB_mssqlnative extends ADOConnection { * to use windows authentication */ if ($this->debug) - + ADOConnection::outp('No userid or password supplied, attempting connection with Windows Authentication'); } - - + + /* * Now merge in the passed connection parameters setting */ @@ -501,7 +501,7 @@ class ADODB_mssqlnative extends ADOConnection { if ($this->debug) ADOConnection::outp("connecting to host: $argHostname params: ".var_export($connectionInfo,true)); if(!($this->_connectionID = @sqlsrv_connect($argHostname,$connectionInfo))) { - if ($this->debug) + if ($this->debug) ADOConnection::outp( 'Connection Failed: '.print_r( sqlsrv_errors(), true)); return false; } @@ -518,6 +518,7 @@ class ADODB_mssqlnative extends ADOConnection { return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename); } + function Prepare($sql) { return $sql; // prepare does not work properly with bind parameters as bind parameters are managed by sqlsrv_prepare! @@ -623,7 +624,7 @@ class ADODB_mssqlnative extends ADOConnection { return $rez; } - + function MetaIndexes($table,$primary=false, $owner = false) { $table = $this->qstr($table); @@ -899,51 +900,48 @@ class ADODB_mssqlnative extends ADOConnection { * @param string $procedureNamePattern (optional) * @param string $catalog (optional) * @param string $schemaPattern (optional) - + * @return array of stored objects in current database. * */ public function metaProcedures($procedureNamePattern = null, $catalog = null, $schemaPattern = null) { - $metaProcedures = array(); $procedureSQL = ''; $catalogSQL = ''; $schemaSQL = ''; - + if ($procedureNamePattern) $procedureSQL = "AND ROUTINE_NAME LIKE " . strtoupper($this->qstr($procedureNamePattern)); - + if ($catalog) $catalogSQL = "AND SPECIFIC_SCHEMA=" . strtoupper($this->qstr($catalog)); - + if ($schemaPattern) $schemaSQL = "AND ROUTINE_SCHEMA LIKE {$this->qstr($schemaPattern)}"; - - + $fields = " ROUTINE_NAME,ROUTINE_TYPE,ROUTINE_SCHEMA,ROUTINE_CATALOG"; - + $SQL = "SELECT $fields - FROM {$this->database}.information_schema.routines - WHERE 1=1 - $procedureSQL - $catalogSQL - $schemaSQL - ORDER BY ROUTINE_NAME - "; - + FROM {$this->database}.information_schema.routines + WHERE 1=1 + $procedureSQL + $catalogSQL + $schemaSQL + ORDER BY ROUTINE_NAME + "; + $result = $this->execute($SQL); - + if (!$result) return false; while ($r = $result->fetchRow()){ - if (!isset($r[0])) /* * Convert to numeric */ $r = array_values($r); - + $procedureName = $r[0]; $schemaName = $r[2]; $routineCatalog= $r[3]; @@ -952,13 +950,11 @@ class ADODB_mssqlnative extends ADOConnection { 'schema' => $schemaName, 'remarks' => '', ); - } - + return $metaProcedures; - } - + } /*-------------------------------------------------------------------------------------- @@ -1075,9 +1071,9 @@ class ADORecordset_mssqlnative extends ADORecordSet { * Too early */ return; - if ($this->fetchMode != ADODB_FETCH_NUM) + if ($this->fetchMode != ADODB_FETCH_NUM) return $this->fields[$colname]; - + if (!$this->bind) { $this->bind = array(); for ($i=0; $i < $this->_numOfFields; $i++) { @@ -1243,7 +1239,7 @@ class ADORecordset_mssqlnative extends ADORecordSet { $this->_queryID = false; return $rez; } - + return true; } -- cgit v1.3