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(-) 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(-) 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 ba42cba4416a7154854417c90bc43e0c973d7895 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Thu, 11 Mar 2021 19:17:46 +0100 Subject: mssql: use getOne to get default constraint Simplifies the code, and gets rid of PHP Warnings, both on line 164 in datadict-mssqlnative.inc.php: - Trying to access array offset on value of type bool - Undefined array key "name" Fixes #696 --- datadict/datadict-mssqlnative.inc.php | 15 ++++----------- docs/changelog.md | 2 ++ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/datadict/datadict-mssqlnative.inc.php b/datadict/datadict-mssqlnative.inc.php index 09137e6a..9de75e49 100644 --- a/datadict/datadict-mssqlnative.inc.php +++ b/datadict/datadict-mssqlnative.inc.php @@ -153,17 +153,10 @@ class ADODB2_mssqlnative extends ADODB_DataDict { function DefaultConstraintname($tabname, $colname) { - $constraintname = false; - $rs = $this->connection->Execute( - "SELECT name FROM sys.default_constraints - WHERE object_name(parent_object_id) = '$tabname' - AND col_name(parent_object_id, parent_column_id) = '$colname'" - ); - if ( is_object($rs) ) { - $row = $rs->FetchRow(); - $constraintname = $row['name']; - } - return $constraintname; + $sql = "SELECT name FROM sys.default_constraints + WHERE object_name(parent_object_id) = ? + AND col_name(parent_object_id, parent_column_id) = ?"; + return $this->connection->getOne($sql, [$tabname, $colname]); } function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') diff --git a/docs/changelog.md b/docs/changelog.md index 8d99949b..bc9b5e8f 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -18,6 +18,8 @@ Older changelogs: ### Fixed +- mssql: PHP warnings in dropColumnSQL() + [#696](https://github.com/ADOdb/ADOdb/issues/696) - mysql: TypeError when calling get/setChangeSet on unset connection (PHP 8) [#686](https://github.com/ADOdb/ADOdb/issues/686) -- cgit v1.3 From 91dbbef4f56543d52f9cc97c7239b02119ab0253 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Thu, 11 Mar 2021 19:21:52 +0100 Subject: PHPDoc, camelCase for defaultConstraintName() --- datadict/datadict-mssqlnative.inc.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/datadict/datadict-mssqlnative.inc.php b/datadict/datadict-mssqlnative.inc.php index 9de75e49..b4a5eb9b 100644 --- a/datadict/datadict-mssqlnative.inc.php +++ b/datadict/datadict-mssqlnative.inc.php @@ -151,14 +151,21 @@ class ADODB2_mssqlnative extends ADODB_DataDict { return $sql; } - function DefaultConstraintname($tabname, $colname) + /** + * Get a column's default constraint. + * + * @param string $tabname + * @param string $colname + * @return string|null The Constraint's name, or null if there is none. + */ + function defaultConstraintName($tabname, $colname) { $sql = "SELECT name FROM sys.default_constraints WHERE object_name(parent_object_id) = ? AND col_name(parent_object_id, parent_column_id) = ?"; return $this->connection->getOne($sql, [$tabname, $colname]); } - + function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') { $tabname = $this->TableName ($tabname); @@ -175,7 +182,7 @@ class ADODB2_mssqlnative extends ADODB_DataDict { list(,$colname,$default) = $matches; $v = preg_replace('/^' . preg_quote($colname) . '\s/', '', $v); $t = trim(str_replace('DEFAULT '.$default,'',$v)); - if ( $constraintname = $this->DefaultConstraintname($tabname,$colname) ) { + if ( $constraintname = $this->defaultConstraintName($tabname,$colname) ) { $sql[] = 'ALTER TABLE '.$tabname.' DROP CONSTRAINT '. $constraintname; } if ($not_null) { @@ -188,7 +195,7 @@ class ADODB2_mssqlnative extends ADODB_DataDict { . ' DEFAULT ' . $default . ' FOR ' . $colname; } else { $colname = strtok($v," "); - if ( $constraintname = $this->DefaultConstraintname($tabname,$colname) ) { + if ( $constraintname = $this->defaultConstraintName($tabname,$colname) ) { $sql[] = 'ALTER TABLE '.$tabname.' DROP CONSTRAINT '. $constraintname; } if ($not_null) { @@ -226,7 +233,7 @@ class ADODB2_mssqlnative extends ADODB_DataDict { $f = array(); $s = 'ALTER TABLE ' . $tabname; foreach($flds as $v) { - if ( $constraintname = $this->DefaultConstraintname($tabname,$v) ) { + if ( $constraintname = $this->defaultConstraintName($tabname,$v) ) { $sql[] = 'ALTER TABLE ' . $tabname . ' DROP CONSTRAINT ' . $constraintname; } $f[] = ' DROP COLUMN ' . $this->NameQuote($v); -- cgit v1.3 From ac284ab4e47ca01f22096cde32b5833c60ae69ee Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Thu, 11 Mar 2021 19:27:26 +0100 Subject: Fix PHPStorm static analysis warnings - SQL syntax - unused variables - duplicated code - Whitespace - Variables and return types in PHPDoc --- adodb-datadict.inc.php | 3 +++ datadict/datadict-mssqlnative.inc.php | 44 +++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/adodb-datadict.inc.php b/adodb-datadict.inc.php index f458e1b3..30ede0e0 100644 --- a/adodb-datadict.inc.php +++ b/adodb-datadict.inc.php @@ -164,6 +164,7 @@ function lens_ParseArgs($args,$endstmtchar=',',$tokenchars='_.-') class ADODB_DataDict { + /** @var ADOConnection */ var $connection; var $debug = false; var $dropTable = 'DROP TABLE %s'; @@ -182,6 +183,8 @@ class ADODB_DataDict { var $invalidResizeTypes4 = array('CLOB','BLOB','TEXT','DATE','TIME'); // for changeTableSQL var $blobSize = 100; /// any varchar/char field this size or greater is treated as a blob /// in other words, we use a text area for editing. + /** @var string Uppercase driver name */ + var $upperName; /* * Indicates whether a BLOB/CLOB field will allow a NOT NULL setting diff --git a/datadict/datadict-mssqlnative.inc.php b/datadict/datadict-mssqlnative.inc.php index b4a5eb9b..8eee8390 100644 --- a/datadict/datadict-mssqlnative.inc.php +++ b/datadict/datadict-mssqlnative.inc.php @@ -45,7 +45,7 @@ if (!defined('ADODB_DIR')) die(); class ADODB2_mssqlnative extends ADODB_DataDict { var $databaseType = 'mssqlnative'; - var $dropIndex = 'DROP INDEX %1$s ON %2$s'; + var $dropIndex = /** @lang text */ 'DROP INDEX %1$s ON %2$s'; var $renameTable = "EXEC sp_rename '%s','%s'"; var $renameColumn = "EXEC sp_rename '%s.%s','%s'"; var $typeX = 'TEXT'; ## Alternatively, set it to VARCHAR(4000) @@ -61,7 +61,6 @@ class ADODB2_mssqlnative extends ADODB_DataDict { if (is_object($t)) { $fieldobj = $t; $t = $fieldobj->type; - $len = $fieldobj->max_length; } $_typeConversion = array( @@ -97,11 +96,11 @@ class ADODB2_mssqlnative extends ADODB_DataDict { -3 => 'X' ); - if (isset($_typeConversion[$t])) - return $_typeConversion[$t]; - - return ADODB_DEFAULT_METATYPE; + if (isset($_typeConversion[$t])) { + return $_typeConversion[$t]; + } + return ADODB_DEFAULT_METATYPE; } function ActualType($meta) @@ -141,7 +140,7 @@ class ADODB2_mssqlnative extends ADODB_DataDict { { $tabname = $this->TableName ($tabname); $f = array(); - list($lines,$pkey) = $this->_GenFields($flds); + list($lines,) = $this->_GenFields($flds); $s = "ALTER TABLE $tabname $this->addCol"; foreach($lines as $v) { $f[] = "\n $v"; @@ -171,10 +170,9 @@ class ADODB2_mssqlnative extends ADODB_DataDict { $tabname = $this->TableName ($tabname); $sql = array(); - list($lines,$pkey,$idxs) = $this->_GenFields($flds); + list($lines,,$idxs) = $this->_GenFields($flds); $alter = 'ALTER TABLE ' . $tabname . $this->alterCol . ' '; foreach($lines as $v) { - $not_null = false; if ($not_null = preg_match('/NOT NULL/i',$v)) { $v = preg_replace('/NOT NULL/i','',$v); } @@ -223,13 +221,15 @@ class ADODB2_mssqlnative extends ADODB_DataDict { * @param string $tableflds Throwaway value to make the function match the parent * @param string $tableoptions Throway value to make the function match the parent * - * @return string The SQL necessary to drop the column + * @return string[] The SQL necessary to drop the column */ function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') { $tabname = $this->TableName ($tabname); - if (!is_array($flds)) - $flds = explode(',',$flds); + if (!is_array($flds)) { + /** @noinspection PhpParamsInspection */ + $flds = explode(',', $flds); + } $f = array(); $s = 'ALTER TABLE ' . $tabname; foreach($flds as $v) { @@ -244,6 +244,8 @@ class ADODB2_mssqlnative extends ADODB_DataDict { } // return string must begin with space + + /** @noinspection DuplicatedCode */ function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) { $suffix = ''; @@ -327,6 +329,7 @@ CREATE TABLE SORT_IN_TEMPDB } */ + /** @noinspection DuplicatedCode */ function _IndexSQL($idxname, $tabname, $flds, $idxoptions) { $sql = array(); @@ -358,17 +361,18 @@ CREATE TABLE } - function _GetSize($ftype, $ty, $fsize, $fprec,$options=false) + function _GetSize($ftype, $ty, $fsize, $fprec, $options=false) { switch ($ftype) { - case 'INT': - case 'SMALLINT': - case 'TINYINT': - case 'BIGINT': + case 'INT': + case 'SMALLINT': + case 'TINYINT': + case 'BIGINT': + return $ftype; + } + if ($ty == 'T') { return $ftype; } - if ($ty == 'T') return $ftype; - return parent::_GetSize($ftype, $ty, $fsize, $fprec, $options); - + return parent::_GetSize($ftype, $ty, $fsize, $fprec, $options); } } -- cgit v1.3 From fb614c19da9ff08beb97db052d2b4cd801266b08 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Thu, 11 Mar 2021 19:28:09 +0100 Subject: Remove comment block with SQL statements syntax No need to have this in the code, just lookup the documentation. --- datadict/datadict-mssqlnative.inc.php | 72 ----------------------------------- 1 file changed, 72 deletions(-) diff --git a/datadict/datadict-mssqlnative.inc.php b/datadict/datadict-mssqlnative.inc.php index 8eee8390..b5ea2041 100644 --- a/datadict/datadict-mssqlnative.inc.php +++ b/datadict/datadict-mssqlnative.inc.php @@ -257,78 +257,6 @@ class ADODB2_mssqlnative extends ADODB_DataDict { return $suffix; } - /* -CREATE TABLE - [ database_name.[ owner ] . | owner. ] table_name - ( { < column_definition > - | column_name AS computed_column_expression - | < table_constraint > ::= [ CONSTRAINT constraint_name ] } - - | [ { PRIMARY KEY | UNIQUE } [ ,...n ] - ) - -[ ON { filegroup | DEFAULT } ] -[ TEXTIMAGE_ON { filegroup | DEFAULT } ] - -< column_definition > ::= { column_name data_type } - [ COLLATE < collation_name > ] - [ [ DEFAULT constant_expression ] - | [ IDENTITY [ ( seed , increment ) [ NOT FOR REPLICATION ] ] ] - ] - [ ROWGUIDCOL] - [ < column_constraint > ] [ ...n ] - -< column_constraint > ::= [ CONSTRAINT constraint_name ] - { [ NULL | NOT NULL ] - | [ { PRIMARY KEY | UNIQUE } - [ CLUSTERED | NONCLUSTERED ] - [ WITH FILLFACTOR = fillfactor ] - [ON {filegroup | DEFAULT} ] ] - ] - | [ [ FOREIGN KEY ] - REFERENCES ref_table [ ( ref_column ) ] - [ ON DELETE { CASCADE | NO ACTION } ] - [ ON UPDATE { CASCADE | NO ACTION } ] - [ NOT FOR REPLICATION ] - ] - | CHECK [ NOT FOR REPLICATION ] - ( logical_expression ) - } - -< table_constraint > ::= [ CONSTRAINT constraint_name ] - { [ { PRIMARY KEY | UNIQUE } - [ CLUSTERED | NONCLUSTERED ] - { ( column [ ASC | DESC ] [ ,...n ] ) } - [ WITH FILLFACTOR = fillfactor ] - [ ON { filegroup | DEFAULT } ] - ] - | FOREIGN KEY - [ ( column [ ,...n ] ) ] - REFERENCES ref_table [ ( ref_column [ ,...n ] ) ] - [ ON DELETE { CASCADE | NO ACTION } ] - [ ON UPDATE { CASCADE | NO ACTION } ] - [ NOT FOR REPLICATION ] - | CHECK [ NOT FOR REPLICATION ] - ( search_conditions ) - } - - - */ - - /* - CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name - ON { table | view } ( column [ ASC | DESC ] [ ,...n ] ) - [ WITH < index_option > [ ,...n] ] - [ ON filegroup ] - < index_option > :: = - { PAD_INDEX | - FILLFACTOR = fillfactor | - IGNORE_DUP_KEY | - DROP_EXISTING | - STATISTICS_NORECOMPUTE | - SORT_IN_TEMPDB - } -*/ /** @noinspection DuplicatedCode */ function _IndexSQL($idxname, $tabname, $flds, $idxoptions) { -- 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(-) 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(-) 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 From 099d06fc8f3f5fa8e82c0064c1b9148e89729b4c Mon Sep 17 00:00:00 2001 From: Mark Newnham Date: Mon, 15 Mar 2021 01:30:53 -0600 Subject: pdo: ensure bind parameters are presented in a numeric array Fixes #705 (cherry picked from commit fd4d6b09577ba461f522ca8f41a717c5c0a1428b) --- drivers/adodb-pdo.inc.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/adodb-pdo.inc.php b/drivers/adodb-pdo.inc.php index 6c365314..ade9c0cf 100644 --- a/drivers/adodb-pdo.inc.php +++ b/drivers/adodb-pdo.inc.php @@ -565,6 +565,10 @@ class ADODB_pdo extends ADOConnection { $this->_driver->debug = $this->debug; } if ($inputarr) { + /* + * inputarr must be numeric + */ + $inputarr = array_values($inputarr); $ok = $stmt->execute($inputarr); } else { -- cgit v1.3