From f18972a60623f9d615a485e1c78ba328c657afd1 Mon Sep 17 00:00:00 2001 From: vargenau Date: Fri, 31 Aug 2012 11:43:40 +0000 Subject: [PATCH] No tabs git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@8278 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/ASCIIMathPHP/ASCIIMathPHP-2.0.class.php | 2096 ++++++++-------- lib/DbSession/SQL.php | 6 +- lib/WikiDB/ADODB.php | 12 +- lib/WikiDB/SQL.php | 10 +- lib/WikiDB/adodb/adodb-csvlib.inc.php | 418 ++-- lib/WikiDB/adodb/adodb-error.inc.php | 132 +- lib/WikiDB/adodb/adodb-errorhandler.inc.php | 80 +- lib/WikiDB/adodb/adodb-errorpear.inc.php | 50 +- lib/WikiDB/adodb/adodb-exceptions.inc.php | 56 +- lib/WikiDB/adodb/adodb-iterator.inc.php | 40 +- lib/WikiDB/adodb/adodb-lib.inc.php | 1038 ++++---- lib/WikiDB/adodb/adodb-pear.inc.php | 554 ++--- lib/WikiDB/adodb/adodb-time.inc.php | 1152 ++++----- lib/WikiDB/adodb/drivers/adodb-access.inc.php | 98 +- lib/WikiDB/adodb/drivers/adodb-ado.inc.php | 1156 ++++----- .../adodb/drivers/adodb-ado_access.inc.php | 38 +- .../adodb/drivers/adodb-ado_mssql.inc.php | 66 +- .../adodb/drivers/adodb-borland_ibase.inc.php | 98 +- lib/WikiDB/adodb/drivers/adodb-csv.inc.php | 346 +-- lib/WikiDB/adodb/drivers/adodb-db2.inc.php | 426 ++-- lib/WikiDB/adodb/drivers/adodb-fbsql.inc.php | 472 ++-- .../adodb/drivers/adodb-firebird.inc.php | 78 +- lib/WikiDB/adodb/drivers/adodb-ibase.inc.php | 1486 ++++++------ .../adodb/drivers/adodb-informix.inc.php | 16 +- .../adodb/drivers/adodb-informix72.inc.php | 646 ++--- lib/WikiDB/adodb/drivers/adodb-ldap.inc.php | 184 +- lib/WikiDB/adodb/drivers/adodb-mssql.inc.php | 1670 ++++++------- .../adodb/drivers/adodb-mssqlnative.inc.php | 1282 +++++----- .../adodb/drivers/adodb-mssqlpo.inc.php | 64 +- lib/WikiDB/adodb/drivers/adodb-mysql.inc.php | 1186 ++++----- lib/WikiDB/adodb/drivers/adodb-mysqli.inc.php | 1584 ++++++------ lib/WikiDB/adodb/drivers/adodb-mysqlt.inc.php | 92 +- .../adodb/drivers/adodb-netezza.inc.php | 266 +- lib/WikiDB/adodb/drivers/adodb-oci8.inc.php | 2160 ++++++++--------- lib/WikiDB/adodb/drivers/adodb-oci805.inc.php | 60 +- lib/WikiDB/adodb/drivers/adodb-oci8po.inc.php | 316 +-- lib/WikiDB/adodb/drivers/adodb-odbc.inc.php | 1304 +++++----- .../adodb/drivers/adodb-odbc_mssql.inc.php | 414 ++-- .../adodb/drivers/adodb-odbc_oracle.inc.php | 180 +- lib/WikiDB/adodb/drivers/adodb-odbtp.inc.php | 1176 ++++----- .../adodb/drivers/adodb-odbtp_unicode.inc.php | 54 +- lib/WikiDB/adodb/drivers/adodb-oracle.inc.php | 462 ++-- .../adodb/drivers/adodb-postgres64.inc.php | 1670 ++++++------- .../adodb/drivers/adodb-postgres7.inc.php | 260 +- lib/WikiDB/adodb/drivers/adodb-proxy.inc.php | 26 +- lib/WikiDB/adodb/drivers/adodb-sapdb.inc.php | 52 +- .../adodb/drivers/adodb-sqlanywhere.inc.php | 86 +- lib/WikiDB/adodb/drivers/adodb-sqlite.inc.php | 538 ++-- lib/WikiDB/adodb/drivers/adodb-sybase.inc.php | 592 ++--- lib/WikiDB/adodb/drivers/adodb-vfp.inc.php | 134 +- lib/WikiDB/backend.php | 62 +- lib/WikiDB/backend/ADODB.php | 58 +- lib/WikiDB/backend/ADODB_mssqlnative.php | 2 +- lib/WikiDB/backend/ADODB_mysql.php | 58 +- lib/WikiDB/backend/ADODB_postgres7.php | 50 +- lib/WikiDB/backend/ADODB_sqlite.php | 4 +- lib/WikiDB/backend/PDO.php | 6 +- lib/WikiDB/backend/PDO_mysql.php | 18 +- lib/WikiDB/backend/PearDB.php | 36 +- lib/WikiDB/backend/PearDB_ffpgsql.php | 20 +- lib/WikiDB/backend/PearDB_mysql.php | 24 +- lib/WikiDB/backend/PearDB_pgsql.php | 18 +- lib/WikiDB/backend/cvs.php | 18 +- lib/WikiDB/backend/dba.php | 8 +- lib/WikiDB/backend/dbaBase.php | Bin 31221 -> 32175 bytes lib/WikiDB/backend/dumb/AllRevisionsIter.php | 18 +- lib/WikiDB/backend/dumb/LinkSearchIter.php | 188 +- lib/WikiDB/backend/dumb/MostRecentIter.php | 4 +- lib/WikiDB/backend/dumb/TextSearchIter.php | 24 +- lib/WikiDB/backend/dumb/WantedPagesIter.php | 6 +- lib/WikiDB/backend/file.php | 30 +- lib/WikiDB/backend/flatfile.php | 60 +- lib/WysiwygEdit/FCKeditor.php | 58 +- lib/WysiwygEdit/Wikiwyg.php | 146 +- lib/WysiwygEdit/htmlarea2.php | 4 +- lib/WysiwygEdit/tinymce.php | 22 +- lib/XMLRPC/utils.php | 34 +- lib/fpdf/chinese.php | 770 +++--- lib/fpdf/courier.php | 2 +- lib/fpdf/helvetica.php | 24 +- lib/fpdf/helveticab.php | 24 +- lib/fpdf/helveticabi.php | 24 +- lib/fpdf/helveticai.php | 24 +- lib/fpdf/japanese.php | 126 +- lib/fpdf/symbol.php | 24 +- lib/fpdf/times.php | 24 +- lib/fpdf/timesb.php | 24 +- lib/fpdf/timesbi.php | 24 +- lib/fpdf/timesi.php | 24 +- lib/fpdf/zapfdingbats.php | 24 +- lib/nusoap/nusoap.php | 1870 +++++++------- lib/pear/Cache/Container/file.php | 2 +- lib/pear/Cache/Container/imgfile.php | 2 +- lib/pear/File_Passwd.php | 12 +- tests/unit/lib/InlineParserTest.php | 72 +- tests/unit/lib/SetupWiki.php | 4 +- tests/unit/lib/TextSearchTest.php | 60 +- tests/unit/lib/XmlRpcTest.php | 14 +- tests/unit/lib/plugin/IncludePageTest.php | 40 +- tests/unit/pcre-crash.php | 2 +- tests/unit/test.php | 46 +- tests/xmlrpc/interop-server.php | 16 +- tests/xmlrpc/validate-form.php | 16 +- tests/xmlrpc/validate.php | 2 +- tests/xmlrpc/xmlrpc-servers.php | 8 +- wikilist.php | 4 +- 106 files changed, 15333 insertions(+), 15333 deletions(-) diff --git a/lib/ASCIIMathPHP/ASCIIMathPHP-2.0.class.php b/lib/ASCIIMathPHP/ASCIIMathPHP-2.0.class.php index b484843e6..59fcffebb 100644 --- a/lib/ASCIIMathPHP/ASCIIMathPHP-2.0.class.php +++ b/lib/ASCIIMathPHP/ASCIIMathPHP-2.0.class.php @@ -57,1063 +57,1063 @@ class XMLNode { - // Private variables - var $_id; - var $_name; - var $_content; - var $_mt_elem_flg; - var $_attr_arr; - var $_child_arr; - var $_nmspc; - var $_nmspc_alias; - var $_parent_id; - var $_parent_node; - - function XMLNode($id = NULL) - { - $this->_id = isset($id) ? $id : md5(uniqid(rand(),1)); - $this->_name = ''; - $this->_content = ''; - $this->_mt_elem_flg = FALSE; - $this->_attr_arr = array(); - $this->_child_arr = array(); - $this->_nmspc = ''; - $this->_nmspc_alias = ''; - $this->_parent_id = FALSE; - $this->_parent_node = NULL; - } - - function addChild(&$node) - { - $this->_child_arr[$node->getId()] = $node; - $node->setParentId($this->_id); - $node->setParentNode($this); - } - - function addChildArr(&$node_arr) - { - $key_arr = array_keys($node_arr); - $num_key = count($key_arr); - - for ($i = 0; $i < $num_key; $i++) { - $node = $node_arr[$key_arr[$i]]; - $this->addChild($node); - } - } - - function insertChildBefore($idx,&$node) - { - $key_arr = array_keys($this->_child_arr); - $num_key = count($key_arr); - $tmp_arr = arry(); - - for ($i = 0;$i < $num_key;$i++) { - if ($i == $idx) { - $tmp_arr[$node->getId()] = $node; - } - $tmp_arr[$key_arr[$i]] = $this->_child_arr[$key_arr[$i]]; - } - $this->_child_arr = $tmp_arr; - } - - function insertChildAfter($idx,&$node) - { - $key_arr = array_keys($this->_child_arr); - $num_key = count($key_arr); - $tmp_arr = arry(); - - for ($i = 0;$i < $num_key;$i++) { - $tmp_arr[$key_arr[$i]] = $this->_child_arr[$key_arr[$i]]; - if ($i == $idx) { - $tmp_arr[$node->getId()] = $node; - } - } - $this->_child_arr = $tmp_arr; - } - - function setId($id) - { - $this->_id = $id; - } - - function setName($name) - { - $this->_name = $name; - } - - function setNamepace($nmspc) - { - $this->_nmspc = $nmspc; - } - - function setNamespaceAlias($nmspc_alias) - { - $this->_nmspc_alias = $nmspc_alias; - } - - function setContent($content) - { - $this->_content = $content; - } - - function setEmptyElem($mt_elem_flg) - { - $this->_mt_elem_flg = $mt_elem_flg; - } - - function setAttr($attr_nm,$attr_val) - { - $this->_attr_arr[$attr_nm] = $attr_val; - } - - function setAttrArr($attr_arr) - { - $this->_attr_arr = $attr_arr; - } - - function setParentId($id) - { - $this->_parent_id = $id; - } - - function setParentNode(&$node) - { - $this->_parent_node = $node; - } - - function getId() - { - return($this->_id); - } - - function getName() - { - return($this->_name); - } - - function getNamespace() - { - return($this->_nmspc); - } - - function getNamespaceAlias() - { - return($this->_nmspc_alias); - } - - function getContent() - { - return($this->_content); - } - - function getAttr($attr_nm) - { - if (isset($this->_attr_arr[$attr_nm])) { - return($this->_attr_arr[$attr_nm]); - } else { - return(NULL); - } - } - - function getAttrArr() - { - return($this->_attr_arr); - } - - function getParentId() - { - return($this->parent_id); - } - - function getParentNode() - { - return($this->_parent_node); - } - - function getChild($id) - { - if (isset($this->_child_arr[$id])) { - return($this->_child_arr[$id]); - } else { - return(FALSE); - } - } - - function getFirstChild() - { - $id_arr = array_keys($this->_child_arr); - $num_child = count($id_arr); - - if ($num_child > 0) { - return($this->_child_arr[$id_arr[0]]); - } else { - return(FALSE); - } - } - - function getLastChild() - { - $id_arr = array_keys($this->_child_arr); - $num_child = count($id_arr); - - if ($num_child > 0) { - return($this->_child_arr[$id_arr[$num_child - 1]]); - } else { - return(FALSE); - } - } - - function getChildByIdx($idx) - { - $id_arr = array_keys($this->_child_arr); - - if (isset($this->_child_arr[$id_arr[$idx]])) { - return($this->_child_arr[$id_arr[$idx]]); - } else { - return(FALSE); - } - } - - function getNumChild() - { - return(count($this->_child_arr)); - } - - function removeChild($id) - { - unset($this->_child_arr[$id]); - } - - function removeChildByIdx($idx) - { - $key_arr = array_keys($this->_child_arr); - unset($this->_child_arr[$key_arr[$idx]]); - } - - function removeFirstChild() - { - $key_arr = array_keys($this->_child_arr); - unset($this->_child_arr[$key_arr[0]]); - } - - function removeLastChild() - { - $key_arr = array_keys($this->_child_arr); - unset($this->_child_arr[$key_arr[count($key_arr)-1]]); - } - - function dumpXML($indent_str = "\t") - { - $attr_txt = $this->_dumpAttr(); - $name = $this->_dumpName(); - $xmlns = $this->_dumpXmlns(); - $lvl = $this->_getCurrentLevel(); - $indent = str_pad('',$lvl,$indent_str); - - if ($this->_mt_elem_flg) { - $tag = "$indent<$name$xmlns$attr_txt />"; - return($tag); - } else { - $key_arr = array_keys($this->_child_arr); - $num_child = count($key_arr); - - $tag = "$indent<$name$xmlns$attr_txt>$this->_content"; - - for ($i = 0;$i < $num_child;$i++) { - $node = $this->_child_arr[$key_arr[$i]]; - - $child_txt = $node->dumpXML($indent_str); - $tag .= "\n$child_txt"; - } - - $tag .= ($num_child > 0 ? "\n$indent" : ""); - return($tag); - } - } - - function _dumpAttr() - { - $id_arr = array_keys($this->_attr_arr); - $id_arr_cnt = count($id_arr); - $attr_txt = ''; - - for($i = 0;$i < $id_arr_cnt;$i++) { - $key = $id_arr[$i]; - $attr_txt .= " $key=\"{$this->_attr_arr[$key]}\""; - } - - return($attr_txt); - } - - function _dumpName() - { - $alias = $this->getNamespaceAlias(); - if ($alias == '') { - return($this->getName()); - } else { - return("$alias:" . $this->getName()); - } - } - - function _dumpXmlns() - { - $nmspc = $this->getNamespace(); - $alias = $this->getNamespaceAlias(); - - if ($nmspc != '') { - if ($alias == '') { - return(" xmlns=\"" . $nmspc . "\""); - } else { - return(" xmlns:$alias=\"" . $nmspc . "\""); - } - } else { - return(''); - } - } - - function _getCurrentLevel() - { - if ($this->_parent_id === FALSE) { - return(0); - } else { - $node = $this->getParentNode(); - $lvl = $node->_getCurrentLevel(); - $lvl++; - return($lvl); - } - } + // Private variables + var $_id; + var $_name; + var $_content; + var $_mt_elem_flg; + var $_attr_arr; + var $_child_arr; + var $_nmspc; + var $_nmspc_alias; + var $_parent_id; + var $_parent_node; + + function XMLNode($id = NULL) + { + $this->_id = isset($id) ? $id : md5(uniqid(rand(),1)); + $this->_name = ''; + $this->_content = ''; + $this->_mt_elem_flg = FALSE; + $this->_attr_arr = array(); + $this->_child_arr = array(); + $this->_nmspc = ''; + $this->_nmspc_alias = ''; + $this->_parent_id = FALSE; + $this->_parent_node = NULL; + } + + function addChild(&$node) + { + $this->_child_arr[$node->getId()] = $node; + $node->setParentId($this->_id); + $node->setParentNode($this); + } + + function addChildArr(&$node_arr) + { + $key_arr = array_keys($node_arr); + $num_key = count($key_arr); + + for ($i = 0; $i < $num_key; $i++) { + $node = $node_arr[$key_arr[$i]]; + $this->addChild($node); + } + } + + function insertChildBefore($idx,&$node) + { + $key_arr = array_keys($this->_child_arr); + $num_key = count($key_arr); + $tmp_arr = arry(); + + for ($i = 0;$i < $num_key;$i++) { + if ($i == $idx) { + $tmp_arr[$node->getId()] = $node; + } + $tmp_arr[$key_arr[$i]] = $this->_child_arr[$key_arr[$i]]; + } + $this->_child_arr = $tmp_arr; + } + + function insertChildAfter($idx,&$node) + { + $key_arr = array_keys($this->_child_arr); + $num_key = count($key_arr); + $tmp_arr = arry(); + + for ($i = 0;$i < $num_key;$i++) { + $tmp_arr[$key_arr[$i]] = $this->_child_arr[$key_arr[$i]]; + if ($i == $idx) { + $tmp_arr[$node->getId()] = $node; + } + } + $this->_child_arr = $tmp_arr; + } + + function setId($id) + { + $this->_id = $id; + } + + function setName($name) + { + $this->_name = $name; + } + + function setNamepace($nmspc) + { + $this->_nmspc = $nmspc; + } + + function setNamespaceAlias($nmspc_alias) + { + $this->_nmspc_alias = $nmspc_alias; + } + + function setContent($content) + { + $this->_content = $content; + } + + function setEmptyElem($mt_elem_flg) + { + $this->_mt_elem_flg = $mt_elem_flg; + } + + function setAttr($attr_nm,$attr_val) + { + $this->_attr_arr[$attr_nm] = $attr_val; + } + + function setAttrArr($attr_arr) + { + $this->_attr_arr = $attr_arr; + } + + function setParentId($id) + { + $this->_parent_id = $id; + } + + function setParentNode(&$node) + { + $this->_parent_node = $node; + } + + function getId() + { + return($this->_id); + } + + function getName() + { + return($this->_name); + } + + function getNamespace() + { + return($this->_nmspc); + } + + function getNamespaceAlias() + { + return($this->_nmspc_alias); + } + + function getContent() + { + return($this->_content); + } + + function getAttr($attr_nm) + { + if (isset($this->_attr_arr[$attr_nm])) { + return($this->_attr_arr[$attr_nm]); + } else { + return(NULL); + } + } + + function getAttrArr() + { + return($this->_attr_arr); + } + + function getParentId() + { + return($this->parent_id); + } + + function getParentNode() + { + return($this->_parent_node); + } + + function getChild($id) + { + if (isset($this->_child_arr[$id])) { + return($this->_child_arr[$id]); + } else { + return(FALSE); + } + } + + function getFirstChild() + { + $id_arr = array_keys($this->_child_arr); + $num_child = count($id_arr); + + if ($num_child > 0) { + return($this->_child_arr[$id_arr[0]]); + } else { + return(FALSE); + } + } + + function getLastChild() + { + $id_arr = array_keys($this->_child_arr); + $num_child = count($id_arr); + + if ($num_child > 0) { + return($this->_child_arr[$id_arr[$num_child - 1]]); + } else { + return(FALSE); + } + } + + function getChildByIdx($idx) + { + $id_arr = array_keys($this->_child_arr); + + if (isset($this->_child_arr[$id_arr[$idx]])) { + return($this->_child_arr[$id_arr[$idx]]); + } else { + return(FALSE); + } + } + + function getNumChild() + { + return(count($this->_child_arr)); + } + + function removeChild($id) + { + unset($this->_child_arr[$id]); + } + + function removeChildByIdx($idx) + { + $key_arr = array_keys($this->_child_arr); + unset($this->_child_arr[$key_arr[$idx]]); + } + + function removeFirstChild() + { + $key_arr = array_keys($this->_child_arr); + unset($this->_child_arr[$key_arr[0]]); + } + + function removeLastChild() + { + $key_arr = array_keys($this->_child_arr); + unset($this->_child_arr[$key_arr[count($key_arr)-1]]); + } + + function dumpXML($indent_str = "\t") + { + $attr_txt = $this->_dumpAttr(); + $name = $this->_dumpName(); + $xmlns = $this->_dumpXmlns(); + $lvl = $this->_getCurrentLevel(); + $indent = str_pad('',$lvl,$indent_str); + + if ($this->_mt_elem_flg) { + $tag = "$indent<$name$xmlns$attr_txt />"; + return($tag); + } else { + $key_arr = array_keys($this->_child_arr); + $num_child = count($key_arr); + + $tag = "$indent<$name$xmlns$attr_txt>$this->_content"; + + for ($i = 0;$i < $num_child;$i++) { + $node = $this->_child_arr[$key_arr[$i]]; + + $child_txt = $node->dumpXML($indent_str); + $tag .= "\n$child_txt"; + } + + $tag .= ($num_child > 0 ? "\n$indent" : ""); + return($tag); + } + } + + function _dumpAttr() + { + $id_arr = array_keys($this->_attr_arr); + $id_arr_cnt = count($id_arr); + $attr_txt = ''; + + for($i = 0;$i < $id_arr_cnt;$i++) { + $key = $id_arr[$i]; + $attr_txt .= " $key=\"{$this->_attr_arr[$key]}\""; + } + + return($attr_txt); + } + + function _dumpName() + { + $alias = $this->getNamespaceAlias(); + if ($alias == '') { + return($this->getName()); + } else { + return("$alias:" . $this->getName()); + } + } + + function _dumpXmlns() + { + $nmspc = $this->getNamespace(); + $alias = $this->getNamespaceAlias(); + + if ($nmspc != '') { + if ($alias == '') { + return(" xmlns=\"" . $nmspc . "\""); + } else { + return(" xmlns:$alias=\"" . $nmspc . "\""); + } + } else { + return(''); + } + } + + function _getCurrentLevel() + { + if ($this->_parent_id === FALSE) { + return(0); + } else { + $node = $this->getParentNode(); + $lvl = $node->_getCurrentLevel(); + $lvl++; + return($lvl); + } + } } class MathMLNode extends XMLNode { - function MathMLNode($id = NULL) - { - parent::XMLNode($id); - } - - function removeBrackets() - { - if ($this->_name == 'mrow') { - if ($c_node_0 = $this->getFirstChild()) { - $c_node_0->isLeftBracket() ? $this->removeFirstChild() : 0; - } - - if ($c_node_0 = $this->getLastChild()) { - $c_node_0->isRightBracket() ? $this->removeLastChild() : 0; - } - } - } - - function isLeftBracket() - { - switch ($this->_content) { - case '{': - case '[': - case '(': - return(TRUE); - break; - } - return(FALSE); - } - - function isRightBracket() - { - switch ($this->_content) { - case '}': - case ']': - case ')': - return(TRUE); - break; - } - return(FALSE); - } + function MathMLNode($id = NULL) + { + parent::XMLNode($id); + } + + function removeBrackets() + { + if ($this->_name == 'mrow') { + if ($c_node_0 = $this->getFirstChild()) { + $c_node_0->isLeftBracket() ? $this->removeFirstChild() : 0; + } + + if ($c_node_0 = $this->getLastChild()) { + $c_node_0->isRightBracket() ? $this->removeLastChild() : 0; + } + } + } + + function isLeftBracket() + { + switch ($this->_content) { + case '{': + case '[': + case '(': + return(TRUE); + break; + } + return(FALSE); + } + + function isRightBracket() + { + switch ($this->_content) { + case '}': + case ']': + case ')': + return(TRUE); + break; + } + return(FALSE); + } } class ASCIIMathPHP { - var $_expr; - var $_curr_expr; - var $_prev_expr; - var $_symbol_arr; - var $_node_arr; - var $_node_cntr; - - function ASCIIMathPHP($symbol_arr,$expr = NULL) - { - $this->_symbol_arr = $symbol_arr; - if (isset($expr)) { - $this->setExpr($expr); - } - } - - /** - * Returns an empty node (containing a non-breaking space) 26-Apr-2006 - * - * Used when an expression is incomplete - * - * @return object - * - * @access private - */ - function emptyNode() - { - $tmp_node = $this->createNode(); - $tmp_node->setName('mn'); - $tmp_node->setContent('&#' . hexdec('200B') . ';'); - return $tmp_node; - } - - function pushExpr($prefix) // 2005-06-11 wes - { - $this->_curr_expr = $prefix . $this->_curr_expr; - } - - function setExpr($expr) - { - $this->_expr = $expr; - $this->_curr_expr = $expr; - $this->_prev_expr = $expr; - - $this->_node_arr = array(); - $this->_node_cntr = 0; - } - - function genMathML($attr_arr = NULL) - { - // node - $node_0 = $this->createNode(); - $node_0->setName('math'); - $node_0->setNamepace('http://www.w3.org/1998/Math/MathML'); - - // node - if (isset($attr_arr)) { - $node_1 = $this->createNode(); - $node_1->setName('mstyle'); - $node_1->setAttrArr($attr_arr); - - $node_arr = $this->parseExpr(); - - $node_1->addChildArr($node_arr); - $node_0->addChild($node_1); - } else { - $node_arr = $this->parseExpr(); - $node_0->addChildArr($node_arr); - } - - return TRUE; - } - - /* - function mergeNodeArr(&$node_arr_0,&$node_arr_1) - { - $key_arr_0 = array_keys($node_arr_0); - $key_arr_1 = array_keys($node_arr_1); - - $num_key_0 = count($key_arr_0); - $num_key_1 = count($key_arr_1); - - $merge_arr = array(); - - for ($i = 0;$i < $num_key_0;$i++) { - $merge_arr[$key_arr_0[$i]] = $node_arr_0[$key_arr_0[$i]]; - } - - for ($j = 0;$j < $num_key_1;$i++) { - $merge_arr[$key_arr_1[$i]] = $node_arr_1[$key_arr_1[$i]]; - } - - return($merge_arr); - } - */ - - //Broken out of parseExpr Sept 7, 2006 David Lippman for - //ASCIIMathML 1.4.7 compatibility - function parseIntExpr() - { - $sym_0 = $this->getSymbol(); - $node_0 = $this->parseSmplExpr(); - $sym = $this->getSymbol(); - - if (isset($sym['infix']) && $sym['input'] != '/') { - $this->chopExpr($sym['symlen']); - $node_1 = $this->parseSmplExpr(); - - if ($node_1 === FALSE) { //show box in place of missing argument - $node_1 = $this->emptyNode();//?? - } else { - $node_1->removeBrackets(); - } - - // If 'sub' -- subscript - if ($sym['input'] == '_') { - - $sym_1 = $this->getSymbol(); - - // If 'sup' -- superscript - if ($sym_1['input'] == '^') { - $this->chopExpr($sym_1['symlen']); - $node_2 = $this->parseSmplExpr(); - $node_2->removeBrackets(); - - $node_3 = $this->createNode(); - $node_3->setName(isset($sym_0['underover']) ? 'munderover' : 'msubsup'); - $node_3->addChild($node_0); - $node_3->addChild($node_1); - $node_3->addChild($node_2); - - $node_4 = $this->createNode(); - $node_4->setName('mrow'); - $node_4->addChild($node_3); - - return $node_4; - } else { - $node_2 = $this->createNode(); - $node_2->setName(isset($sym_0['underover']) ? 'munder' : 'msub'); - $node_2->addChild($node_0); - $node_2->addChild($node_1); - - return $node_2; - } - } else { - $node_2 = $this->createNode(); - $node_2->setName($sym['tag']); - $node_2->addChild($node_0); - $node_2->addChild($node_1); - - return($node_2); - } - } elseif ($node_0 !== FALSE) { - return($node_0); - } else { - return $this->emptyNode(); - } - - } - - function parseExpr() - { - // Child/Fragment array - $node_arr = array(); - - // Deal whole expressions like 'ax + by + c = 0' etc. - do { - $sym_0 = $this->getSymbol(); - $node_0 = $this->parseIntExpr(); - $sym = $this->getSymbol(); - // var_dump($sym); - - if (isset($sym['infix']) && $sym['input'] == '/') { - $this->chopExpr($sym['symlen']); - $node_1 = $this->parseIntExpr(); - - if ($node_1 === FALSE) { //should show box in place of missing argument - $node_1 = $this->emptyNode(); - continue; - } - - $node_1->removeBrackets(); - - // If 'div' -- divide - $node_0->removeBrackets(); - $node_2 = $this->createNode(); - $node_2->setName($sym['tag']); - $node_2->addChild($node_0); - $node_2->addChild($node_1); - $node_arr[$node_2->getId()] = $node_2; - - } elseif ($node_0 !== FALSE) { - $node_arr[$node_0->getId()] = $node_0; - } - } while (!isset($sym['right_bracket']) && $sym !== FALSE && $sym['output'] != ''); - - //var_dump($sym); - // Possibly to deal with matrices - if (isset($sym['right_bracket'])) { - $node_cnt = count($node_arr); - $key_node_arr = array_keys($node_arr); - - if ($node_cnt > 1) { - $node_5 = $node_arr[$key_node_arr[$node_cnt-1]]; - $node_6 = $node_arr[$key_node_arr[$node_cnt-2]]; - } else { - $node_5 = FALSE; - $node_6 = FALSE; - } - - // Dealing with matrices - if ($node_5 !== FALSE && $node_6 !== FALSE && - $node_cnt > 1 && - $node_5->getName() == 'mrow' && - $node_6->getName() == 'mo' && - $node_6->getContent() == ',') { - - // Checking if Node 5 has a LastChild - if ($node_7 = $node_5->getLastChild()) { - $node_7_cntnt = $node_7->getContent(); - } else { - $node_7_cntnt = FALSE; - } - - // If there is a right bracket - if ($node_7 !== FALSE && ($node_7_cntnt == ']' || $node_7_cntnt == ')')) { - - // Checking if Node 5 has a firstChild - if ($node_8 = $node_5->getFirstChild()) { - $node_8_cntnt = $node_8->getContent(); - } else { - $node_8_cntnt = FALSE; - } - - // If there is a matching left bracket - if ($node_8 !== FALSE && - (($node_8_cntnt == '(' && $node_7_cntnt == ')' && $sym['output'] != '}') || - ($node_8_cntnt == '[' && $node_7_cntnt == ']'))) { - - $is_mtrx_flg = TRUE; - $comma_pos_arr = array(); - - $i = 0; - - while ($i < $node_cnt && $is_mtrx_flg) { - $tmp_node = $node_arr[$key_node_arr[$i]]; - - if($tmp_node_first = $tmp_node->getFirstChild()) { - $tnfc = $tmp_node_first->getContent(); - } else { - $tnfc = FALSE; - } - - if($tmp_node_last = $tmp_node->getLastChild()) { - $tnlc = $tmp_node_last->getContent(); - } else { - $tnlc = FALSE; - } - - if (isset($key_node_arr[$i+1])) { - $next_tmp_node = $node_arr[$key_node_arr[$i+1]]; - $ntnn = $next_tmp_node->getName(); - $ntnc = $next_tmp_node->getContent(); - } else { - $ntnn = FALSE; - $ntnc = FALSE; - } - - // Checking each node in node array for matrix criteria - if ($is_mtrx_flg) { - $is_mtrx_flg = $tmp_node->getName() == 'mrow' && - ($i == $node_cnt-1 || $ntnn == 'mo' && $ntnc == ',') && - $tnfc == $node_8_cntnt && $tnlc == $node_7_cntnt; - } - - if ($is_mtrx_flg) { - for ($j = 0;$j < $tmp_node->getNumChild();$j++) { - $tmp_c_node = $tmp_node->getChildByIdx($j); - - if ($tmp_c_node->getContent() == ',') { - $comma_pos_arr[$i][] = $j; - } - } - } - - if ($is_mtrx_flg && $i > 1) { - - $cnt_cpan = isset($comma_pos_arr[$i]) ? count($comma_pos_arr[$i]) : NULL; - $cnt_cpap = isset($comma_pos_arr[$i-2]) ? count($comma_pos_arr[$i-2]) : NULL; - $is_mtrx_flg = $cnt_cpan == $cnt_cpap; - } - - $i += 2; - } - - // If the node passes the matrix tests - if ($is_mtrx_flg) { - $tab_node_arr = array(); - - for ($i = 0;$i < $node_cnt;$i += 2) { - $tmp_key_node_arr = array_keys($node_arr); - if (!($tmp_node = $node_arr[$tmp_key_node_arr[0]])) { - break; - } - $num_child = $tmp_node->getNumChild(); - $k = 0; - - $tmp_node->removeFirstChild(); - - $row_node_arr = array(); - $row_frag_node_arr = array(); - - for ($j = 1;$j < ($num_child-1);$j++) { - if (isset($comma_pos_arr[$i][$k]) && - $j == $comma_pos_arr[$i][$k]) { - - $tmp_node->removeFirstChild(); - - $tmp_c_node = $this->createNode(); - $tmp_c_node->setName('mtd'); - $tmp_c_node->addChildArr($row_frag_node_arr); - $row_frag_node_arr = array(); - - $row_node_arr[$tmp_c_node->getId()] = $tmp_c_node; - - $k++; - } else { - - if ($tmp_c_node = $tmp_node->getFirstChild()) { - $row_frag_node_arr[$tmp_c_node->getId()] = $tmp_c_node; - $tmp_node->removeFirstChild(); - } - } - } - - $tmp_c_node = $this->createNode(); - $tmp_c_node->setName('mtd'); - $tmp_c_node->addChildArr($row_frag_node_arr); - - $row_node_arr[$tmp_c_node->getId()] = $tmp_c_node; - - if (count($node_arr) > 2) { - $tmp_key_node_arr = array_keys($node_arr); - unset($node_arr[$tmp_key_node_arr[0]]); - unset($node_arr[$tmp_key_node_arr[1]]); - } - - $tmp_c_node = $this->createNode(); - $tmp_c_node->setName('mtr'); - $tmp_c_node->addChildArr($row_node_arr); - - $tab_node_arr[$tmp_c_node->getId()] = $tmp_c_node; - } - - $tmp_c_node = $this->createNode(); - $tmp_c_node->setName('mtable'); - $tmp_c_node->addChildArr($tab_node_arr); - - if (isset($sym['invisible'])) { - $tmp_c_node->setAttr('columnalign','left'); - } - - $key_node_arr = array_keys($node_arr); - $tmp_c_node->setId($key_node_arr[0]); - - $node_arr[$tmp_c_node->getId()] = $tmp_c_node; - } - } - } - } - - $this->chopExpr($sym['symlen']); - if (!isset($sym['invisible'])) { - $node_7 = $this->createNode(); - $node_7->setName('mo'); - $node_7->setContent($sym['output']); - $node_arr[$node_7->getId()] = $node_7; - } - } - - return($node_arr); - } - - function parseSmplExpr() - { - $sym = $this->getSymbol(); - - if (!$sym || isset($sym['right_bracket'])) //return FALSE; - return $this->emptyNode(); - - $this->chopExpr($sym['symlen']); - - // 2005-06-11 wes: add definition type support - if(isset($sym['definition'])) { - $this->pushExpr($sym['output']); - $sym = $this->getSymbol(); - $this->chopExpr($sym['symlen']); - } - - if (isset($sym['left_bracket'])) { - $node_arr = $this->parseExpr(); - - if (isset($sym['invisible'])) { - $node_0 = $this->createNode(); - $node_0->setName('mrow'); - $node_0->addChildArr($node_arr); - - return($node_0); - } else { - $node_0 = $this->createNode(); - $node_0->setName('mo'); - $node_0->setContent($sym['output']); - - $node_1 = $this->createNode(); - $node_1->setName('mrow'); - $node_1->addChild($node_0); - $node_1->addChildArr($node_arr); - - return($node_1); - } - } elseif (isset($sym['unary'])) { - - if ($sym['input'] == 'sqrt') { - $node_0 = $this->parseSmplExpr(); - $node_0->removeBrackets(); - - $node_1 = $this->createNode(); - $node_1->setName($sym['tag']); - $node_1->addChild($node_0); - - return($node_1); - } elseif (isset($sym['func'])) { //added 2006-9-7 David Lippman - $expr = ltrim($this->getCurrExpr()); - $st = $expr{0}; - $node_0 = $this->parseSmplExpr(); - //$node_0->removeBrackets(); - if ($st=='^' || $st == '_' || $st=='/' || $st=='|' || $st==',') { - $node_1 = $this->createNode(); - $node_1->setName($sym['tag']); - $node_1->setContent($sym['output']); - $this->setCurrExpr($expr); - return($node_1); - } else { - $node_1 = $this->createNode(); - $node_1->setName('mrow'); - $node_2 = $this->createNode(); - $node_2->setName($sym['tag']); - $node_2->setContent($sym['output']); - $node_1->addChild($node_2); - $node_1->addChild($node_0); - return($node_1); - } - } elseif ($sym['input'] == 'text' || $sym['input'] == 'mbox' || $sym['input'] == '"') { - $expr = ltrim($this->getCurrExpr()); - if ($sym['input']=='"') { - $end_brckt = '"'; - $txt = substr($expr,0,strpos($expr,$end_brckt)); - } else { - switch($expr{0}) { - case '(': - $end_brckt = ')'; - break; - case '[': - $end_brckt = ']'; - break; - case '{': - $end_brckt = '}'; - break; - default: - $end_brckt = chr(11); // A character that will never be matched. - break; - } - $txt = substr($expr,1,strpos($expr,$end_brckt)-1); - } - - //$txt = substr($expr,1,strpos($expr,$end_brckt)-1); - $len = strlen($txt); - - $node_0 = $this->createNode(); - $node_0->setName('mrow'); - - if ($len > 0) { - if ($txt{0} == " ") { - $node_1 = $this->createNode(); - $node_1->setName('mspace'); - $node_1->setAttr('width','1ex'); - - $node_0->addChild($node_1); - } - - $node_3 = $this->createNode(); - $node_3->setName($sym['tag']); - $node_3->setContent(trim($txt)); - - $node_0->addChild($node_3); - - if ($len > 1 && $txt{$len-1} == " ") { - $node_2 = $this->createNode(); - $node_2->setName('mspace'); - $node_2->setAttr('width','1ex'); - - $node_0->addChild($node_2); - } - - $this->chopExpr($len+2); - } - return($node_0); - - } elseif (isset($sym['acc'])) { - $node_0 = $this->parseSmplExpr(); - $node_0->removeBrackets(); - - $node_1 = $this->createNode(); - $node_1->setName($sym['tag']); - $node_1->addChild($node_0); - - $node_2 = $this->createNode(); - $node_2->setName('mo'); - $node_2->setContent($sym['output']); - - $node_1->addChild($node_2); - return($node_1); - } else { - // Font change commands -- to complete - } - } elseif (isset($sym['binary'])) { - $node_arr = array(); - - $node_0 = $this->parseSmplExpr(); - $node_0->removeBrackets(); - - $node_1 = $this->parseSmplExpr(); - $node_1->removeBrackets(); + var $_expr; + var $_curr_expr; + var $_prev_expr; + var $_symbol_arr; + var $_node_arr; + var $_node_cntr; + + function ASCIIMathPHP($symbol_arr,$expr = NULL) + { + $this->_symbol_arr = $symbol_arr; + if (isset($expr)) { + $this->setExpr($expr); + } + } + + /** + * Returns an empty node (containing a non-breaking space) 26-Apr-2006 + * + * Used when an expression is incomplete + * + * @return object + * + * @access private + */ + function emptyNode() + { + $tmp_node = $this->createNode(); + $tmp_node->setName('mn'); + $tmp_node->setContent('&#' . hexdec('200B') . ';'); + return $tmp_node; + } + + function pushExpr($prefix) // 2005-06-11 wes + { + $this->_curr_expr = $prefix . $this->_curr_expr; + } + + function setExpr($expr) + { + $this->_expr = $expr; + $this->_curr_expr = $expr; + $this->_prev_expr = $expr; + + $this->_node_arr = array(); + $this->_node_cntr = 0; + } + + function genMathML($attr_arr = NULL) + { + // node + $node_0 = $this->createNode(); + $node_0->setName('math'); + $node_0->setNamepace('http://www.w3.org/1998/Math/MathML'); + + // node + if (isset($attr_arr)) { + $node_1 = $this->createNode(); + $node_1->setName('mstyle'); + $node_1->setAttrArr($attr_arr); + + $node_arr = $this->parseExpr(); + + $node_1->addChildArr($node_arr); + $node_0->addChild($node_1); + } else { + $node_arr = $this->parseExpr(); + $node_0->addChildArr($node_arr); + } + + return TRUE; + } + + /* + function mergeNodeArr(&$node_arr_0,&$node_arr_1) + { + $key_arr_0 = array_keys($node_arr_0); + $key_arr_1 = array_keys($node_arr_1); + + $num_key_0 = count($key_arr_0); + $num_key_1 = count($key_arr_1); + + $merge_arr = array(); + + for ($i = 0;$i < $num_key_0;$i++) { + $merge_arr[$key_arr_0[$i]] = $node_arr_0[$key_arr_0[$i]]; + } + + for ($j = 0;$j < $num_key_1;$i++) { + $merge_arr[$key_arr_1[$i]] = $node_arr_1[$key_arr_1[$i]]; + } + + return($merge_arr); + } + */ + + //Broken out of parseExpr Sept 7, 2006 David Lippman for + //ASCIIMathML 1.4.7 compatibility + function parseIntExpr() + { + $sym_0 = $this->getSymbol(); + $node_0 = $this->parseSmplExpr(); + $sym = $this->getSymbol(); + + if (isset($sym['infix']) && $sym['input'] != '/') { + $this->chopExpr($sym['symlen']); + $node_1 = $this->parseSmplExpr(); + + if ($node_1 === FALSE) { //show box in place of missing argument + $node_1 = $this->emptyNode();//?? + } else { + $node_1->removeBrackets(); + } + + // If 'sub' -- subscript + if ($sym['input'] == '_') { + + $sym_1 = $this->getSymbol(); + + // If 'sup' -- superscript + if ($sym_1['input'] == '^') { + $this->chopExpr($sym_1['symlen']); + $node_2 = $this->parseSmplExpr(); + $node_2->removeBrackets(); + + $node_3 = $this->createNode(); + $node_3->setName(isset($sym_0['underover']) ? 'munderover' : 'msubsup'); + $node_3->addChild($node_0); + $node_3->addChild($node_1); + $node_3->addChild($node_2); + + $node_4 = $this->createNode(); + $node_4->setName('mrow'); + $node_4->addChild($node_3); + + return $node_4; + } else { + $node_2 = $this->createNode(); + $node_2->setName(isset($sym_0['underover']) ? 'munder' : 'msub'); + $node_2->addChild($node_0); + $node_2->addChild($node_1); + + return $node_2; + } + } else { + $node_2 = $this->createNode(); + $node_2->setName($sym['tag']); + $node_2->addChild($node_0); + $node_2->addChild($node_1); + + return($node_2); + } + } elseif ($node_0 !== FALSE) { + return($node_0); + } else { + return $this->emptyNode(); + } + + } + + function parseExpr() + { + // Child/Fragment array + $node_arr = array(); + + // Deal whole expressions like 'ax + by + c = 0' etc. + do { + $sym_0 = $this->getSymbol(); + $node_0 = $this->parseIntExpr(); + $sym = $this->getSymbol(); + // var_dump($sym); + + if (isset($sym['infix']) && $sym['input'] == '/') { + $this->chopExpr($sym['symlen']); + $node_1 = $this->parseIntExpr(); + + if ($node_1 === FALSE) { //should show box in place of missing argument + $node_1 = $this->emptyNode(); + continue; + } + + $node_1->removeBrackets(); + + // If 'div' -- divide + $node_0->removeBrackets(); + $node_2 = $this->createNode(); + $node_2->setName($sym['tag']); + $node_2->addChild($node_0); + $node_2->addChild($node_1); + $node_arr[$node_2->getId()] = $node_2; + + } elseif ($node_0 !== FALSE) { + $node_arr[$node_0->getId()] = $node_0; + } + } while (!isset($sym['right_bracket']) && $sym !== FALSE && $sym['output'] != ''); + + //var_dump($sym); + // Possibly to deal with matrices + if (isset($sym['right_bracket'])) { + $node_cnt = count($node_arr); + $key_node_arr = array_keys($node_arr); + + if ($node_cnt > 1) { + $node_5 = $node_arr[$key_node_arr[$node_cnt-1]]; + $node_6 = $node_arr[$key_node_arr[$node_cnt-2]]; + } else { + $node_5 = FALSE; + $node_6 = FALSE; + } + + // Dealing with matrices + if ($node_5 !== FALSE && $node_6 !== FALSE && + $node_cnt > 1 && + $node_5->getName() == 'mrow' && + $node_6->getName() == 'mo' && + $node_6->getContent() == ',') { + + // Checking if Node 5 has a LastChild + if ($node_7 = $node_5->getLastChild()) { + $node_7_cntnt = $node_7->getContent(); + } else { + $node_7_cntnt = FALSE; + } + + // If there is a right bracket + if ($node_7 !== FALSE && ($node_7_cntnt == ']' || $node_7_cntnt == ')')) { + + // Checking if Node 5 has a firstChild + if ($node_8 = $node_5->getFirstChild()) { + $node_8_cntnt = $node_8->getContent(); + } else { + $node_8_cntnt = FALSE; + } + + // If there is a matching left bracket + if ($node_8 !== FALSE && + (($node_8_cntnt == '(' && $node_7_cntnt == ')' && $sym['output'] != '}') || + ($node_8_cntnt == '[' && $node_7_cntnt == ']'))) { + + $is_mtrx_flg = TRUE; + $comma_pos_arr = array(); + + $i = 0; + + while ($i < $node_cnt && $is_mtrx_flg) { + $tmp_node = $node_arr[$key_node_arr[$i]]; + + if($tmp_node_first = $tmp_node->getFirstChild()) { + $tnfc = $tmp_node_first->getContent(); + } else { + $tnfc = FALSE; + } + + if($tmp_node_last = $tmp_node->getLastChild()) { + $tnlc = $tmp_node_last->getContent(); + } else { + $tnlc = FALSE; + } + + if (isset($key_node_arr[$i+1])) { + $next_tmp_node = $node_arr[$key_node_arr[$i+1]]; + $ntnn = $next_tmp_node->getName(); + $ntnc = $next_tmp_node->getContent(); + } else { + $ntnn = FALSE; + $ntnc = FALSE; + } + + // Checking each node in node array for matrix criteria + if ($is_mtrx_flg) { + $is_mtrx_flg = $tmp_node->getName() == 'mrow' && + ($i == $node_cnt-1 || $ntnn == 'mo' && $ntnc == ',') && + $tnfc == $node_8_cntnt && $tnlc == $node_7_cntnt; + } + + if ($is_mtrx_flg) { + for ($j = 0;$j < $tmp_node->getNumChild();$j++) { + $tmp_c_node = $tmp_node->getChildByIdx($j); + + if ($tmp_c_node->getContent() == ',') { + $comma_pos_arr[$i][] = $j; + } + } + } + + if ($is_mtrx_flg && $i > 1) { + + $cnt_cpan = isset($comma_pos_arr[$i]) ? count($comma_pos_arr[$i]) : NULL; + $cnt_cpap = isset($comma_pos_arr[$i-2]) ? count($comma_pos_arr[$i-2]) : NULL; + $is_mtrx_flg = $cnt_cpan == $cnt_cpap; + } + + $i += 2; + } + + // If the node passes the matrix tests + if ($is_mtrx_flg) { + $tab_node_arr = array(); + + for ($i = 0;$i < $node_cnt;$i += 2) { + $tmp_key_node_arr = array_keys($node_arr); + if (!($tmp_node = $node_arr[$tmp_key_node_arr[0]])) { + break; + } + $num_child = $tmp_node->getNumChild(); + $k = 0; + + $tmp_node->removeFirstChild(); + + $row_node_arr = array(); + $row_frag_node_arr = array(); + + for ($j = 1;$j < ($num_child-1);$j++) { + if (isset($comma_pos_arr[$i][$k]) && + $j == $comma_pos_arr[$i][$k]) { + + $tmp_node->removeFirstChild(); + + $tmp_c_node = $this->createNode(); + $tmp_c_node->setName('mtd'); + $tmp_c_node->addChildArr($row_frag_node_arr); + $row_frag_node_arr = array(); + + $row_node_arr[$tmp_c_node->getId()] = $tmp_c_node; + + $k++; + } else { + + if ($tmp_c_node = $tmp_node->getFirstChild()) { + $row_frag_node_arr[$tmp_c_node->getId()] = $tmp_c_node; + $tmp_node->removeFirstChild(); + } + } + } + + $tmp_c_node = $this->createNode(); + $tmp_c_node->setName('mtd'); + $tmp_c_node->addChildArr($row_frag_node_arr); + + $row_node_arr[$tmp_c_node->getId()] = $tmp_c_node; + + if (count($node_arr) > 2) { + $tmp_key_node_arr = array_keys($node_arr); + unset($node_arr[$tmp_key_node_arr[0]]); + unset($node_arr[$tmp_key_node_arr[1]]); + } + + $tmp_c_node = $this->createNode(); + $tmp_c_node->setName('mtr'); + $tmp_c_node->addChildArr($row_node_arr); + + $tab_node_arr[$tmp_c_node->getId()] = $tmp_c_node; + } + + $tmp_c_node = $this->createNode(); + $tmp_c_node->setName('mtable'); + $tmp_c_node->addChildArr($tab_node_arr); + + if (isset($sym['invisible'])) { + $tmp_c_node->setAttr('columnalign','left'); + } + + $key_node_arr = array_keys($node_arr); + $tmp_c_node->setId($key_node_arr[0]); + + $node_arr[$tmp_c_node->getId()] = $tmp_c_node; + } + } + } + } + + $this->chopExpr($sym['symlen']); + if (!isset($sym['invisible'])) { + $node_7 = $this->createNode(); + $node_7->setName('mo'); + $node_7->setContent($sym['output']); + $node_arr[$node_7->getId()] = $node_7; + } + } + + return($node_arr); + } + + function parseSmplExpr() + { + $sym = $this->getSymbol(); + + if (!$sym || isset($sym['right_bracket'])) //return FALSE; + return $this->emptyNode(); + + $this->chopExpr($sym['symlen']); + + // 2005-06-11 wes: add definition type support + if(isset($sym['definition'])) { + $this->pushExpr($sym['output']); + $sym = $this->getSymbol(); + $this->chopExpr($sym['symlen']); + } + + if (isset($sym['left_bracket'])) { + $node_arr = $this->parseExpr(); + + if (isset($sym['invisible'])) { + $node_0 = $this->createNode(); + $node_0->setName('mrow'); + $node_0->addChildArr($node_arr); + + return($node_0); + } else { + $node_0 = $this->createNode(); + $node_0->setName('mo'); + $node_0->setContent($sym['output']); + + $node_1 = $this->createNode(); + $node_1->setName('mrow'); + $node_1->addChild($node_0); + $node_1->addChildArr($node_arr); + + return($node_1); + } + } elseif (isset($sym['unary'])) { + + if ($sym['input'] == 'sqrt') { + $node_0 = $this->parseSmplExpr(); + $node_0->removeBrackets(); + + $node_1 = $this->createNode(); + $node_1->setName($sym['tag']); + $node_1->addChild($node_0); + + return($node_1); + } elseif (isset($sym['func'])) { //added 2006-9-7 David Lippman + $expr = ltrim($this->getCurrExpr()); + $st = $expr{0}; + $node_0 = $this->parseSmplExpr(); + //$node_0->removeBrackets(); + if ($st=='^' || $st == '_' || $st=='/' || $st=='|' || $st==',') { + $node_1 = $this->createNode(); + $node_1->setName($sym['tag']); + $node_1->setContent($sym['output']); + $this->setCurrExpr($expr); + return($node_1); + } else { + $node_1 = $this->createNode(); + $node_1->setName('mrow'); + $node_2 = $this->createNode(); + $node_2->setName($sym['tag']); + $node_2->setContent($sym['output']); + $node_1->addChild($node_2); + $node_1->addChild($node_0); + return($node_1); + } + } elseif ($sym['input'] == 'text' || $sym['input'] == 'mbox' || $sym['input'] == '"') { + $expr = ltrim($this->getCurrExpr()); + if ($sym['input']=='"') { + $end_brckt = '"'; + $txt = substr($expr,0,strpos($expr,$end_brckt)); + } else { + switch($expr{0}) { + case '(': + $end_brckt = ')'; + break; + case '[': + $end_brckt = ']'; + break; + case '{': + $end_brckt = '}'; + break; + default: + $end_brckt = chr(11); // A character that will never be matched. + break; + } + $txt = substr($expr,1,strpos($expr,$end_brckt)-1); + } + + //$txt = substr($expr,1,strpos($expr,$end_brckt)-1); + $len = strlen($txt); + + $node_0 = $this->createNode(); + $node_0->setName('mrow'); + + if ($len > 0) { + if ($txt{0} == " ") { + $node_1 = $this->createNode(); + $node_1->setName('mspace'); + $node_1->setAttr('width','1ex'); + + $node_0->addChild($node_1); + } + + $node_3 = $this->createNode(); + $node_3->setName($sym['tag']); + $node_3->setContent(trim($txt)); + + $node_0->addChild($node_3); + + if ($len > 1 && $txt{$len-1} == " ") { + $node_2 = $this->createNode(); + $node_2->setName('mspace'); + $node_2->setAttr('width','1ex'); + + $node_0->addChild($node_2); + } + + $this->chopExpr($len+2); + } + return($node_0); + + } elseif (isset($sym['acc'])) { + $node_0 = $this->parseSmplExpr(); + $node_0->removeBrackets(); + + $node_1 = $this->createNode(); + $node_1->setName($sym['tag']); + $node_1->addChild($node_0); + + $node_2 = $this->createNode(); + $node_2->setName('mo'); + $node_2->setContent($sym['output']); + + $node_1->addChild($node_2); + return($node_1); + } else { + // Font change commands -- to complete + } + } elseif (isset($sym['binary'])) { + $node_arr = array(); + + $node_0 = $this->parseSmplExpr(); + $node_0->removeBrackets(); + + $node_1 = $this->parseSmplExpr(); + $node_1->removeBrackets(); /* 2005-06-05 wes: added stackrel */ - if ($sym['input'] == 'root' || $sym['input'] == 'stackrel') { - $node_arr[$node_1->getId()] = $node_1; - $node_arr[$node_0->getId()] = $node_0; - } elseif ($sym['input'] == 'frac') { - $node_arr[$node_0->getId()] = $node_0; - $node_arr[$node_1->getId()] = $node_1; - } - - $node_2 = $this->createNode(); - $node_2->setName($sym['tag']); - $node_2->addChildArr($node_arr); - - return($node_2); - } elseif (isset($sym['infix'])) { - $node_0 = $this->createNode(); - $node_0->setName('mo'); - $node_0->setContent($sym['output']); - - return($node_0); - } elseif (isset($sym['space'])) { - $node_0 = $this->createNode(); - $node_0->setName('mrow'); - - $node_1 = $this->createNode(); - $node_1->setName('mspace'); - $node_1->setAttr('width',$sym['space']); - - $node_2 = $this->createNode(); - $node_2->setName($sym['tag']); - $node_2->setContent($sym['output']); - - $node_3 = $this->createNode(); - $node_3->setName('mspace'); - $node_3->setAttr('width',$sym['space']); - - $node_0->addChild($node_1); - $node_0->addChild($node_2); - $node_0->addChild($node_3); - - return($node_0); - } else { - - // A constant - $node_0 = $this->createNode(); - $node_0->setName($sym['tag']); - $node_0->setContent($sym['output']); - return($node_0); - } - - // Return an empty node - return $this->emptyNode(); - } - - function getMathML() - { - $root = $this->_node_arr[0]; - return($root->dumpXML()); - } - - function getCurrExpr() - { - return($this->_curr_expr); - } - - function setCurrExpr($str) - { - $this->_curr_expr = $str; - } - - function getExpr() - { - return($this->_expr); - } - - function getPrevExpr() - { - return($this->_prev_expr); - } - - function createNode() - { - $node = new MathMLNode($this->_node_cntr); - // $node->setNamespaceAlias('m'); - $this->_node_arr[$this->_node_cntr] = $node; - $this->_node_cntr++; - return($node); - } - - /** - * Gets the largest symbol in the expression (greedy). Changed from non-greedy 26-Apr-2006 - * - * @parameter boolean[optional] Chop original string? - * - * @return mixed - * - * @access private - */ - function getSymbol($chop_flg = FALSE) - { - // Implemented a reverse symbol matcher. - // Instead of going front to back, it goes back to front. Steven 26-Apr-2006 - $chr_cnt = strlen($this->_curr_expr); - - if ($chr_cnt == 0) return FALSE; - - for ($i = $chr_cnt; $i > 0; $i--) { - $sym_0 = substr($this->_curr_expr,0,$i); - - // Reading string for numeric values - if (is_numeric($sym_0)) { - - if ($chop_flg) $this->chopExpr($i); - return array('input'=>$sym_0, 'tag'=>'mn', 'output'=>$sym_0, 'symlen'=>$i); - - } elseif (isset($this->_symbol_arr[$sym_0])) { - - if ($chop_flg) $this->chopExpr($i); - $sym_arr = $this->_symbol_arr[$sym_0]; - $sym_arr['symlen'] = $i; - return $sym_arr; - } - } - - // Reading string for alphabetic constants and the minus sign - $char = $this->_curr_expr{0}; - $len_left = $chop_flg ? $this->chopExpr(1) : strlen($this->_curr_expr)-1; - - // Deals with expressions of length 1 - if ($len_left == 0 && isset($this->_symbol_arr[$char])) { - $sym_arr = $this->_symbol_arr[$char]; - $sym_arr['symlen'] = 1; - return $sym_arr; - } else { - $tag = preg_match('/[a-z]/i',$char) ? 'mi' : 'mo'; - return array('input'=>$char, 'tag'=>$tag, 'output'=>$char, 'symlen'=>1); - } - } - - function chopExpr($strlen) - { - $this->_prev_expr = $this->_curr_expr; - - if ($strlen == strlen($this->_curr_expr)) { - $this->_curr_expr = ''; - return(0); - } else { - $this->_curr_expr = ltrim(substr($this->_curr_expr,$strlen)); - return(strlen($this->_curr_expr)); - } - } + if ($sym['input'] == 'root' || $sym['input'] == 'stackrel') { + $node_arr[$node_1->getId()] = $node_1; + $node_arr[$node_0->getId()] = $node_0; + } elseif ($sym['input'] == 'frac') { + $node_arr[$node_0->getId()] = $node_0; + $node_arr[$node_1->getId()] = $node_1; + } + + $node_2 = $this->createNode(); + $node_2->setName($sym['tag']); + $node_2->addChildArr($node_arr); + + return($node_2); + } elseif (isset($sym['infix'])) { + $node_0 = $this->createNode(); + $node_0->setName('mo'); + $node_0->setContent($sym['output']); + + return($node_0); + } elseif (isset($sym['space'])) { + $node_0 = $this->createNode(); + $node_0->setName('mrow'); + + $node_1 = $this->createNode(); + $node_1->setName('mspace'); + $node_1->setAttr('width',$sym['space']); + + $node_2 = $this->createNode(); + $node_2->setName($sym['tag']); + $node_2->setContent($sym['output']); + + $node_3 = $this->createNode(); + $node_3->setName('mspace'); + $node_3->setAttr('width',$sym['space']); + + $node_0->addChild($node_1); + $node_0->addChild($node_2); + $node_0->addChild($node_3); + + return($node_0); + } else { + + // A constant + $node_0 = $this->createNode(); + $node_0->setName($sym['tag']); + $node_0->setContent($sym['output']); + return($node_0); + } + + // Return an empty node + return $this->emptyNode(); + } + + function getMathML() + { + $root = $this->_node_arr[0]; + return($root->dumpXML()); + } + + function getCurrExpr() + { + return($this->_curr_expr); + } + + function setCurrExpr($str) + { + $this->_curr_expr = $str; + } + + function getExpr() + { + return($this->_expr); + } + + function getPrevExpr() + { + return($this->_prev_expr); + } + + function createNode() + { + $node = new MathMLNode($this->_node_cntr); + // $node->setNamespaceAlias('m'); + $this->_node_arr[$this->_node_cntr] = $node; + $this->_node_cntr++; + return($node); + } + + /** + * Gets the largest symbol in the expression (greedy). Changed from non-greedy 26-Apr-2006 + * + * @parameter boolean[optional] Chop original string? + * + * @return mixed + * + * @access private + */ + function getSymbol($chop_flg = FALSE) + { + // Implemented a reverse symbol matcher. + // Instead of going front to back, it goes back to front. Steven 26-Apr-2006 + $chr_cnt = strlen($this->_curr_expr); + + if ($chr_cnt == 0) return FALSE; + + for ($i = $chr_cnt; $i > 0; $i--) { + $sym_0 = substr($this->_curr_expr,0,$i); + + // Reading string for numeric values + if (is_numeric($sym_0)) { + + if ($chop_flg) $this->chopExpr($i); + return array('input'=>$sym_0, 'tag'=>'mn', 'output'=>$sym_0, 'symlen'=>$i); + + } elseif (isset($this->_symbol_arr[$sym_0])) { + + if ($chop_flg) $this->chopExpr($i); + $sym_arr = $this->_symbol_arr[$sym_0]; + $sym_arr['symlen'] = $i; + return $sym_arr; + } + } + + // Reading string for alphabetic constants and the minus sign + $char = $this->_curr_expr{0}; + $len_left = $chop_flg ? $this->chopExpr(1) : strlen($this->_curr_expr)-1; + + // Deals with expressions of length 1 + if ($len_left == 0 && isset($this->_symbol_arr[$char])) { + $sym_arr = $this->_symbol_arr[$char]; + $sym_arr['symlen'] = 1; + return $sym_arr; + } else { + $tag = preg_match('/[a-z]/i',$char) ? 'mi' : 'mo'; + return array('input'=>$char, 'tag'=>$tag, 'output'=>$char, 'symlen'=>1); + } + } + + function chopExpr($strlen) + { + $this->_prev_expr = $this->_curr_expr; + + if ($strlen == strlen($this->_curr_expr)) { + $this->_curr_expr = ''; + return(0); + } else { + $this->_curr_expr = ltrim(substr($this->_curr_expr,$strlen)); + return(strlen($this->_curr_expr)); + } + } } ?> diff --git a/lib/DbSession/SQL.php b/lib/DbSession/SQL.php index 833052a63..4abd78a80 100644 --- a/lib/DbSession/SQL.php +++ b/lib/DbSession/SQL.php @@ -140,9 +140,9 @@ extends DbSession $qid = $dbh->quote($id); $qip = $dbh->quote($GLOBALS['request']->get('REMOTE_ADDR')); $time = $dbh->quote(time()); - if (DEBUG and $sess_data == 'wiki_user|N;') { - trigger_error("delete empty session $qid", E_USER_WARNING); - } + if (DEBUG and $sess_data == 'wiki_user|N;') { + trigger_error("delete empty session $qid", E_USER_WARNING); + } // postgres can't handle binary data in a TEXT field. if (isa($dbh, 'DB_pgsql')) $sess_data = base64_encode($sess_data); diff --git a/lib/WikiDB/ADODB.php b/lib/WikiDB/ADODB.php index c1e9ee779..0f18fac3c 100644 --- a/lib/WikiDB/ADODB.php +++ b/lib/WikiDB/ADODB.php @@ -21,11 +21,11 @@ class WikiDB_ADODB extends WikiDB $backend = $m[1]; // Do we have a override? (currently: mysql, sqlite, oracle, mssql, oci8po, postgres7) // TODO: mysqlt (innodb or bdb) - if ($backend == 'pgsql') { // PearDB DSN cross-compatiblity hack (for unit testing) - $backend = 'postgres7'; - if (is_string($dbparams['dsn'])) - $dbparams['dsn'] = $backend . ':' . substr($dbparams['dsn'], 6); - } + if ($backend == 'pgsql') { // PearDB DSN cross-compatiblity hack (for unit testing) + $backend = 'postgres7'; + if (is_string($dbparams['dsn'])) + $dbparams['dsn'] = $backend . ':' . substr($dbparams['dsn'], 6); + } if (FindFile("lib/WikiDB/backend/ADODB_".$backend.".php",true)) { $backend = 'ADODB_' . $backend; } else { @@ -34,7 +34,7 @@ class WikiDB_ADODB extends WikiDB include_once("lib/WikiDB/backend/".$backend.".php"); $backend_class = "WikiDB_backend_".$backend; $backend = new $backend_class($dbparams); - if (!$backend->_dbh->_connectionID) return false; + if (!$backend->_dbh->_connectionID) return false; $this->WikiDB($backend, $dbparams); } diff --git a/lib/WikiDB/SQL.php b/lib/WikiDB/SQL.php index de48de0f2..ca44ebd03 100644 --- a/lib/WikiDB/SQL.php +++ b/lib/WikiDB/SQL.php @@ -15,11 +15,11 @@ class WikiDB_SQL extends WikiDB $backend = $dbparams['dsn']['phptype']; elseif (preg_match('/^(\w+):/', $dbparams['dsn'], $m)) $backend = $m[1]; - if ($backend == 'postgres7') { // ADODB cross-compatiblity hack (for unit testing) - $backend = 'pgsql'; - if (is_string($dbparams['dsn'])) - $dbparams['dsn'] = $backend . ':' . substr($dbparams['dsn'], 10); - } + if ($backend == 'postgres7') { // ADODB cross-compatiblity hack (for unit testing) + $backend = 'pgsql'; + if (is_string($dbparams['dsn'])) + $dbparams['dsn'] = $backend . ':' . substr($dbparams['dsn'], 10); + } include_once ("lib/WikiDB/backend/PearDB_".$backend.".php"); $backend_class = "WikiDB_backend_PearDB_".$backend; $backend = new $backend_class($dbparams); diff --git a/lib/WikiDB/adodb/adodb-csvlib.inc.php b/lib/WikiDB/adodb/adodb-csvlib.inc.php index 01ade4d9f..a65b6585d 100644 --- a/lib/WikiDB/adodb/adodb-csvlib.inc.php +++ b/lib/WikiDB/adodb/adodb-csvlib.inc.php @@ -19,54 +19,54 @@ $ADODB_INCLUDED_CSV = 1; ============== */ - /** - * convert a recordset into special format - * - * @param rs the recordset - * - * @return the CSV formated data - */ - function _rs2serialize(&$rs,$conn=false,$sql='') - { - $max = ($rs) ? $rs->FieldCount() : 0; - - if ($sql) $sql = urlencode($sql); - // metadata setup - - if ($max <= 0 || $rs->dataProvider == 'empty') { // is insert/update/delete - if (is_object($conn)) { - $sql .= ','.$conn->Affected_Rows(); - $sql .= ','.$conn->Insert_ID(); - } else - $sql .= ',,'; - - $text = "====-1,0,$sql\n"; - return $text; - } - $tt = ($rs->timeCreated) ? $rs->timeCreated : time(); - - ## changed format from ====0 to ====1 - $line = "====1,$tt,$sql\n"; - - if ($rs->databaseType == 'array') { - $rows =& $rs->_array; - } else { - $rows = array(); - while (!$rs->EOF) { - $rows[] = $rs->fields; - $rs->MoveNext(); - } - } - - for($i=0; $i < $max; $i++) { - $o =& $rs->FetchField($i); - $flds[] = $o; - } - - $rs =& new ADORecordSet_array(); - $rs->InitArrayFields($rows,$flds); - return $line.serialize($rs); - } + /** + * convert a recordset into special format + * + * @param rs the recordset + * + * @return the CSV formated data + */ + function _rs2serialize(&$rs,$conn=false,$sql='') + { + $max = ($rs) ? $rs->FieldCount() : 0; + + if ($sql) $sql = urlencode($sql); + // metadata setup + + if ($max <= 0 || $rs->dataProvider == 'empty') { // is insert/update/delete + if (is_object($conn)) { + $sql .= ','.$conn->Affected_Rows(); + $sql .= ','.$conn->Insert_ID(); + } else + $sql .= ',,'; + + $text = "====-1,0,$sql\n"; + return $text; + } + $tt = ($rs->timeCreated) ? $rs->timeCreated : time(); + + ## changed format from ====0 to ====1 + $line = "====1,$tt,$sql\n"; + + if ($rs->databaseType == 'array') { + $rows =& $rs->_array; + } else { + $rows = array(); + while (!$rs->EOF) { + $rows[] = $rs->fields; + $rs->MoveNext(); + } + } + + for($i=0; $i < $max; $i++) { + $o =& $rs->FetchField($i); + $flds[] = $o; + } + + $rs =& new ADORecordSet_array(); + $rs->InitArrayFields($rows,$flds); + return $line.serialize($rs); + } /** @@ -80,165 +80,165 @@ $ADODB_INCLUDED_CSV = 1; * error occurred in sql INSERT/UPDATE/DELETE, * empty recordset is returned */ - function &csv2rs($url,&$err,$timeout=0) - { - $err = false; - $fp = @fopen($url,'r'); - if (!$fp) { - $err = $url.' file/URL not found'; - return false; - } - flock($fp, LOCK_SH); - $arr = array(); - $ttl = 0; - - if ($meta = fgetcsv($fp, 32000, ",")) { - // check if error message - if (strncmp($meta[0],'****',4) === 0) { - $err = trim(substr($meta[0],4,1024)); - fclose($fp); - return false; - } - // check for meta data - // $meta[0] is -1 means return an empty recordset - // $meta[1] contains a time - - if (strncmp($meta[0], '====',4) === 0) { - - if ($meta[0] == "====-1") { - if (sizeof($meta) < 5) { - $err = "Corrupt first line for format -1"; - fclose($fp); - return false; - } - fclose($fp); - - if ($timeout > 0) { - $err = " Illegal Timeout $timeout "; - return false; - } - $rs->fields = array(); - $rs->timeCreated = $meta[1]; - $rs =& new ADORecordSet($val=true); - $rs->EOF = true; - $rs->_numOfFields=0; - $rs->sql = urldecode($meta[2]); - $rs->affectedrows = (integer)$meta[3]; - $rs->insertid = $meta[4]; - return $rs; - } - # Under high volume loads, we want only 1 thread/process to _write_file - # so that we don't have 50 processes queueing to write the same data. - # We use probabilistic timeout, ahead of time. - # - # -4 sec before timeout, give processes 1/32 chance of timing out - # -2 sec before timeout, give processes 1/16 chance of timing out - # -1 sec after timeout give processes 1/4 chance of timing out - # +0 sec after timeout, give processes 100% chance of timing out - if (sizeof($meta) > 1) { - if($timeout >0){ - $tdiff = (integer)( $meta[1]+$timeout - time()); - if ($tdiff <= 2) { - switch($tdiff) { - case 4: - case 3: - if ((rand() & 31) == 0) { - fclose($fp); - $err = "Timeout 3"; - return false; - } - break; - case 2: - if ((rand() & 15) == 0) { - fclose($fp); - $err = "Timeout 2"; - return false; - } - break; - case 1: - if ((rand() & 3) == 0) { - fclose($fp); - $err = "Timeout 1"; - return false; - } - break; - default: - fclose($fp); - $err = "Timeout 0"; - return false; - } // switch - - } // if check flush cache - }// (timeout>0) - $ttl = $meta[1]; - } - //================================================ - // new cache format - use serialize extensively... - if ($meta[0] === '====1') { - // slurp in the data - $MAXSIZE = 128000; - - $text = fread($fp,$MAXSIZE); - if (strlen($text) === $MAXSIZE) { - while ($txt = fread($fp,$MAXSIZE)) { - $text .= $txt; - } - } - fclose($fp); - @$rs = unserialize($text); - if (is_object($rs)) $rs->timeCreated = $ttl; - return $rs; - } - - $meta = false; - $meta = fgetcsv($fp, 32000, ","); - if (!$meta) { - fclose($fp); - $err = "Unexpected EOF 1"; - return false; - } - } - - // Get Column definitions - $flds = array(); - foreach($meta as $o) { - $o2 = explode(':',$o); - if (sizeof($o2)!=3) { - $arr[] = $meta; - $flds = false; - break; - } - $fld =& new ADOFieldObject(); - $fld->name = urldecode($o2[0]); - $fld->type = $o2[1]; - $fld->max_length = $o2[2]; - $flds[] = $fld; - } - } else { - fclose($fp); - $err = "Recordset had unexpected EOF 2"; - return false; - } - - // slurp in the data - $MAXSIZE = 128000; - - $text = ''; - while ($txt = fread($fp,$MAXSIZE)) { - $text .= $txt; - } - - fclose($fp); - @$arr = unserialize($text); - //var_dump($arr); - if (!is_array($arr)) { - $err = "Recordset had unexpected EOF (in serialized recordset)"; - if (get_magic_quotes_runtime()) $err .= ". Magic Quotes Runtime should be disabled!"; - return false; - } - $rs =& new ADORecordSet_array(); - $rs->timeCreated = $ttl; - $rs->InitArrayFields($arr,$flds); - return $rs; - } + function &csv2rs($url,&$err,$timeout=0) + { + $err = false; + $fp = @fopen($url,'r'); + if (!$fp) { + $err = $url.' file/URL not found'; + return false; + } + flock($fp, LOCK_SH); + $arr = array(); + $ttl = 0; + + if ($meta = fgetcsv($fp, 32000, ",")) { + // check if error message + if (strncmp($meta[0],'****',4) === 0) { + $err = trim(substr($meta[0],4,1024)); + fclose($fp); + return false; + } + // check for meta data + // $meta[0] is -1 means return an empty recordset + // $meta[1] contains a time + + if (strncmp($meta[0], '====',4) === 0) { + + if ($meta[0] == "====-1") { + if (sizeof($meta) < 5) { + $err = "Corrupt first line for format -1"; + fclose($fp); + return false; + } + fclose($fp); + + if ($timeout > 0) { + $err = " Illegal Timeout $timeout "; + return false; + } + $rs->fields = array(); + $rs->timeCreated = $meta[1]; + $rs =& new ADORecordSet($val=true); + $rs->EOF = true; + $rs->_numOfFields=0; + $rs->sql = urldecode($meta[2]); + $rs->affectedrows = (integer)$meta[3]; + $rs->insertid = $meta[4]; + return $rs; + } + # Under high volume loads, we want only 1 thread/process to _write_file + # so that we don't have 50 processes queueing to write the same data. + # We use probabilistic timeout, ahead of time. + # + # -4 sec before timeout, give processes 1/32 chance of timing out + # -2 sec before timeout, give processes 1/16 chance of timing out + # -1 sec after timeout give processes 1/4 chance of timing out + # +0 sec after timeout, give processes 100% chance of timing out + if (sizeof($meta) > 1) { + if($timeout >0){ + $tdiff = (integer)( $meta[1]+$timeout - time()); + if ($tdiff <= 2) { + switch($tdiff) { + case 4: + case 3: + if ((rand() & 31) == 0) { + fclose($fp); + $err = "Timeout 3"; + return false; + } + break; + case 2: + if ((rand() & 15) == 0) { + fclose($fp); + $err = "Timeout 2"; + return false; + } + break; + case 1: + if ((rand() & 3) == 0) { + fclose($fp); + $err = "Timeout 1"; + return false; + } + break; + default: + fclose($fp); + $err = "Timeout 0"; + return false; + } // switch + + } // if check flush cache + }// (timeout>0) + $ttl = $meta[1]; + } + //================================================ + // new cache format - use serialize extensively... + if ($meta[0] === '====1') { + // slurp in the data + $MAXSIZE = 128000; + + $text = fread($fp,$MAXSIZE); + if (strlen($text) === $MAXSIZE) { + while ($txt = fread($fp,$MAXSIZE)) { + $text .= $txt; + } + } + fclose($fp); + @$rs = unserialize($text); + if (is_object($rs)) $rs->timeCreated = $ttl; + return $rs; + } + + $meta = false; + $meta = fgetcsv($fp, 32000, ","); + if (!$meta) { + fclose($fp); + $err = "Unexpected EOF 1"; + return false; + } + } + + // Get Column definitions + $flds = array(); + foreach($meta as $o) { + $o2 = explode(':',$o); + if (sizeof($o2)!=3) { + $arr[] = $meta; + $flds = false; + break; + } + $fld =& new ADOFieldObject(); + $fld->name = urldecode($o2[0]); + $fld->type = $o2[1]; + $fld->max_length = $o2[2]; + $flds[] = $fld; + } + } else { + fclose($fp); + $err = "Recordset had unexpected EOF 2"; + return false; + } + + // slurp in the data + $MAXSIZE = 128000; + + $text = ''; + while ($txt = fread($fp,$MAXSIZE)) { + $text .= $txt; + } + + fclose($fp); + @$arr = unserialize($text); + //var_dump($arr); + if (!is_array($arr)) { + $err = "Recordset had unexpected EOF (in serialized recordset)"; + if (get_magic_quotes_runtime()) $err .= ". Magic Quotes Runtime should be disabled!"; + return false; + } + $rs =& new ADORecordSet_array(); + $rs->timeCreated = $ttl; + $rs->InitArrayFields($arr,$flds); + return $rs; + } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/adodb-error.inc.php b/lib/WikiDB/adodb/adodb-error.inc.php index f9e90e9fe..126f76ba7 100644 --- a/lib/WikiDB/adodb/adodb-error.inc.php +++ b/lib/WikiDB/adodb/adodb-error.inc.php @@ -14,75 +14,75 @@ if (!defined("DB_ERROR")) define("DB_ERROR",-1); if (!defined("DB_ERROR_SYNTAX")) { - define("DB_ERROR_SYNTAX", -2); - define("DB_ERROR_CONSTRAINT", -3); - define("DB_ERROR_NOT_FOUND", -4); - define("DB_ERROR_ALREADY_EXISTS", -5); - define("DB_ERROR_UNSUPPORTED", -6); - define("DB_ERROR_MISMATCH", -7); - define("DB_ERROR_INVALID", -8); - define("DB_ERROR_NOT_CAPABLE", -9); - define("DB_ERROR_TRUNCATED", -10); - define("DB_ERROR_INVALID_NUMBER", -11); - define("DB_ERROR_INVALID_DATE", -12); - define("DB_ERROR_DIVZERO", -13); - define("DB_ERROR_NODBSELECTED", -14); - define("DB_ERROR_CANNOT_CREATE", -15); - define("DB_ERROR_CANNOT_DELETE", -16); - define("DB_ERROR_CANNOT_DROP", -17); - define("DB_ERROR_NOSUCHTABLE", -18); - define("DB_ERROR_NOSUCHFIELD", -19); - define("DB_ERROR_NEED_MORE_DATA", -20); - define("DB_ERROR_NOT_LOCKED", -21); - define("DB_ERROR_VALUE_COUNT_ON_ROW", -22); - define("DB_ERROR_INVALID_DSN", -23); - define("DB_ERROR_CONNECT_FAILED", -24); - define("DB_ERROR_EXTENSION_NOT_FOUND",-25); - define("DB_ERROR_NOSUCHDB", -25); - define("DB_ERROR_ACCESS_VIOLATION", -26); + define("DB_ERROR_SYNTAX", -2); + define("DB_ERROR_CONSTRAINT", -3); + define("DB_ERROR_NOT_FOUND", -4); + define("DB_ERROR_ALREADY_EXISTS", -5); + define("DB_ERROR_UNSUPPORTED", -6); + define("DB_ERROR_MISMATCH", -7); + define("DB_ERROR_INVALID", -8); + define("DB_ERROR_NOT_CAPABLE", -9); + define("DB_ERROR_TRUNCATED", -10); + define("DB_ERROR_INVALID_NUMBER", -11); + define("DB_ERROR_INVALID_DATE", -12); + define("DB_ERROR_DIVZERO", -13); + define("DB_ERROR_NODBSELECTED", -14); + define("DB_ERROR_CANNOT_CREATE", -15); + define("DB_ERROR_CANNOT_DELETE", -16); + define("DB_ERROR_CANNOT_DROP", -17); + define("DB_ERROR_NOSUCHTABLE", -18); + define("DB_ERROR_NOSUCHFIELD", -19); + define("DB_ERROR_NEED_MORE_DATA", -20); + define("DB_ERROR_NOT_LOCKED", -21); + define("DB_ERROR_VALUE_COUNT_ON_ROW", -22); + define("DB_ERROR_INVALID_DSN", -23); + define("DB_ERROR_CONNECT_FAILED", -24); + define("DB_ERROR_EXTENSION_NOT_FOUND",-25); + define("DB_ERROR_NOSUCHDB", -25); + define("DB_ERROR_ACCESS_VIOLATION", -26); } function adodb_errormsg($value) { global $ADODB_LANG,$ADODB_LANG_ARRAY; - if (empty($ADODB_LANG)) $ADODB_LANG = 'en'; - if (isset($ADODB_LANG_ARRAY['LANG']) && $ADODB_LANG_ARRAY['LANG'] == $ADODB_LANG) ; - else { - include_once(ADODB_DIR."/lang/adodb-$ADODB_LANG.inc.php"); + if (empty($ADODB_LANG)) $ADODB_LANG = 'en'; + if (isset($ADODB_LANG_ARRAY['LANG']) && $ADODB_LANG_ARRAY['LANG'] == $ADODB_LANG) ; + else { + include_once(ADODB_DIR."/lang/adodb-$ADODB_LANG.inc.php"); } - return isset($ADODB_LANG_ARRAY[$value]) ? $ADODB_LANG_ARRAY[$value] : $ADODB_LANG_ARRAY[DB_ERROR]; + return isset($ADODB_LANG_ARRAY[$value]) ? $ADODB_LANG_ARRAY[$value] : $ADODB_LANG_ARRAY[DB_ERROR]; } function adodb_error($provider,$dbType,$errno) { - //var_dump($errno); - if (is_numeric($errno) && $errno == 0) return 0; - switch($provider) { - case 'mysql': $map = adodb_error_mysql(); break; + //var_dump($errno); + if (is_numeric($errno) && $errno == 0) return 0; + switch($provider) { + case 'mysql': $map = adodb_error_mysql(); break; - case 'oracle': - case 'oci8': $map = adodb_error_oci8(); break; + case 'oracle': + case 'oci8': $map = adodb_error_oci8(); break; - case 'ibase': $map = adodb_error_ibase(); break; + case 'ibase': $map = adodb_error_ibase(); break; - case 'odbc': $map = adodb_error_odbc(); break; + case 'odbc': $map = adodb_error_odbc(); break; - case 'mssql': - case 'sybase': $map = adodb_error_mssql(); break; + case 'mssql': + case 'sybase': $map = adodb_error_mssql(); break; - case 'informix': $map = adodb_error_ifx(); break; + case 'informix': $map = adodb_error_ifx(); break; - case 'postgres': return adodb_error_pg($errno); break; + case 'postgres': return adodb_error_pg($errno); break; - case 'sqlite': return $map = adodb_error_sqlite(); break; - default: - return DB_ERROR; - } - //print_r($map); - //var_dump($errno); - if (isset($map[$errno])) return $map[$errno]; - return DB_ERROR; + case 'sqlite': return $map = adodb_error_sqlite(); break; + default: + return DB_ERROR; + } + //print_r($map); + //var_dump($errno); + if (isset($map[$errno])) return $map[$errno]; + return DB_ERROR; } //************************************************************************************** @@ -98,7 +98,7 @@ function adodb_error_pg($errormsg) '/parser: parse error at or near \"/' => DB_ERROR_SYNTAX, '/referential integrity violation/' => DB_ERROR_CONSTRAINT ); - reset($error_regexps); + reset($error_regexps); while (list($regexp,$code) = each($error_regexps)) { if (preg_match($regexp, $errormsg)) { return $code; @@ -131,12 +131,12 @@ static $MAP = array( 'S0012' => DB_ERROR_NOT_FOUND, 'S0021' => DB_ERROR_ALREADY_EXISTS, 'S0022' => DB_ERROR_NOT_FOUND, - 'S1000' => DB_ERROR_NOSUCHTABLE, + 'S1000' => DB_ERROR_NOSUCHTABLE, 'S1009' => DB_ERROR_INVALID, 'S1090' => DB_ERROR_INVALID, 'S1C00' => DB_ERROR_NOT_CAPABLE ); - return $MAP; + return $MAP; } function adodb_error_ibase() @@ -166,7 +166,7 @@ static $MAP = array( -924 => DB_ERROR_CONNECT_FAILED ); - return $MAP; + return $MAP; } function adodb_error_ifx() @@ -184,13 +184,13 @@ static $MAP = array( '-1212' => DB_ERROR_INVALID_DATE ); - return $MAP; + return $MAP; } function adodb_error_oci8() { static $MAP = array( - 1 => DB_ERROR_ALREADY_EXISTS, + 1 => DB_ERROR_ALREADY_EXISTS, 900 => DB_ERROR_SYNTAX, 904 => DB_ERROR_NOSUCHFIELD, 923 => DB_ERROR_SYNTAX, @@ -203,26 +203,26 @@ static $MAP = array( 2449 => DB_ERROR_CONSTRAINT ); - return $MAP; + return $MAP; } function adodb_error_mssql() { static $MAP = array( - 208 => DB_ERROR_NOSUCHTABLE, + 208 => DB_ERROR_NOSUCHTABLE, 2601 => DB_ERROR_ALREADY_EXISTS ); - return $MAP; + return $MAP; } function adodb_error_sqlite() { static $MAP = array( - 1 => DB_ERROR_SYNTAX + 1 => DB_ERROR_SYNTAX ); - return $MAP; + return $MAP; } function adodb_error_mysql() @@ -233,9 +233,9 @@ static $MAP = array( 1006 => DB_ERROR_CANNOT_CREATE, 1007 => DB_ERROR_ALREADY_EXISTS, 1008 => DB_ERROR_CANNOT_DROP, - 1045 => DB_ERROR_ACCESS_VIOLATION, + 1045 => DB_ERROR_ACCESS_VIOLATION, 1046 => DB_ERROR_NODBSELECTED, - 1049 => DB_ERROR_NOSUCHDB, + 1049 => DB_ERROR_NOSUCHDB, 1050 => DB_ERROR_ALREADY_EXISTS, 1051 => DB_ERROR_NOSUCHTABLE, 1054 => DB_ERROR_NOSUCHFIELD, @@ -245,9 +245,9 @@ static $MAP = array( 1136 => DB_ERROR_VALUE_COUNT_ON_ROW, 1146 => DB_ERROR_NOSUCHTABLE, 1048 => DB_ERROR_CONSTRAINT, - 2002 => DB_ERROR_CONNECT_FAILED + 2002 => DB_ERROR_CONNECT_FAILED ); - return $MAP; + return $MAP; } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/adodb-errorhandler.inc.php b/lib/WikiDB/adodb/adodb-errorhandler.inc.php index 1c2597ec8..f42988cdc 100644 --- a/lib/WikiDB/adodb/adodb-errorhandler.inc.php +++ b/lib/WikiDB/adodb/adodb-errorhandler.inc.php @@ -29,50 +29,50 @@ define('ADODB_ERROR_HANDLER','ADODB_Error_Handler'); */ function ADODB_Error_Handler($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection) { - if (error_reporting() == 0) return; // obey @ protocol - switch($fn) { - case 'EXECUTE': - $sql = $p1; - $inputparams = $p2; + if (error_reporting() == 0) return; // obey @ protocol + switch($fn) { + case 'EXECUTE': + $sql = $p1; + $inputparams = $p2; - $s = "$dbms error: [$errno: $errmsg] in $fn(\"$sql\")\n"; - break; + $s = "$dbms error: [$errno: $errmsg] in $fn(\"$sql\")\n"; + break; - case 'PCONNECT': - case 'CONNECT': - $host = $p1; - $database = $p2; + case 'PCONNECT': + case 'CONNECT': + $host = $p1; + $database = $p2; - $s = "$dbms error: [$errno: $errmsg] in $fn($host, '****', '****', $database)\n"; - break; - default: - $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)\n"; - break; - } - /* - * Log connection error somewhere - * 0 message is sent to PHP's system logger, using the Operating System's system - * logging mechanism or a file, depending on what the error_log configuration - * directive is set to. - * 1 message is sent by email to the address in the destination parameter. - * This is the only message type where the fourth parameter, extra_headers is used. - * This message type uses the same internal function as mail() does. - * 2 message is sent through the PHP debugging connection. - * This option is only available if remote debugging has been enabled. - * In this case, the destination parameter specifies the host name or IP address - * and optionally, port number, of the socket receiving the debug information. - * 3 message is appended to the file destination - */ - if (defined('ADODB_ERROR_LOG_TYPE')) { - $t = date('Y-m-d H:i:s'); - if (defined('ADODB_ERROR_LOG_DEST')) - error_log("($t) $s", ADODB_ERROR_LOG_TYPE, ADODB_ERROR_LOG_DEST); - else - error_log("($t) $s", ADODB_ERROR_LOG_TYPE); - } + $s = "$dbms error: [$errno: $errmsg] in $fn($host, '****', '****', $database)\n"; + break; + default: + $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)\n"; + break; + } + /* + * Log connection error somewhere + * 0 message is sent to PHP's system logger, using the Operating System's system + * logging mechanism or a file, depending on what the error_log configuration + * directive is set to. + * 1 message is sent by email to the address in the destination parameter. + * This is the only message type where the fourth parameter, extra_headers is used. + * This message type uses the same internal function as mail() does. + * 2 message is sent through the PHP debugging connection. + * This option is only available if remote debugging has been enabled. + * In this case, the destination parameter specifies the host name or IP address + * and optionally, port number, of the socket receiving the debug information. + * 3 message is appended to the file destination + */ + if (defined('ADODB_ERROR_LOG_TYPE')) { + $t = date('Y-m-d H:i:s'); + if (defined('ADODB_ERROR_LOG_DEST')) + error_log("($t) $s", ADODB_ERROR_LOG_TYPE, ADODB_ERROR_LOG_DEST); + else + error_log("($t) $s", ADODB_ERROR_LOG_TYPE); + } - //print "

$s

"; - trigger_error($s,ADODB_ERROR_HANDLER_TYPE); + //print "

$s

"; + trigger_error($s,ADODB_ERROR_HANDLER_TYPE); } ?> diff --git a/lib/WikiDB/adodb/adodb-errorpear.inc.php b/lib/WikiDB/adodb/adodb-errorpear.inc.php index f288d843d..9be103356 100644 --- a/lib/WikiDB/adodb/adodb-errorpear.inc.php +++ b/lib/WikiDB/adodb/adodb-errorpear.inc.php @@ -38,40 +38,40 @@ global $ADODB_Last_PEAR_Error; $ADODB_Last_PEAR_Error = false; * @param $errmsg the native error msg from the database * @param $p1 $fn specific parameter - see below * @param $P2 $fn specific parameter - see below - */ + */ function ADODB_Error_PEAR($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false) { global $ADODB_Last_PEAR_Error; - if (error_reporting() == 0) return; // obey @ protocol - switch($fn) { - case 'EXECUTE': - $sql = $p1; - $inputparams = $p2; + if (error_reporting() == 0) return; // obey @ protocol + switch($fn) { + case 'EXECUTE': + $sql = $p1; + $inputparams = $p2; - $s = "$dbms error: [$errno: $errmsg] in $fn(\"$sql\")"; - break; + $s = "$dbms error: [$errno: $errmsg] in $fn(\"$sql\")"; + break; - case 'PCONNECT': - case 'CONNECT': - $host = $p1; - $database = $p2; + case 'PCONNECT': + case 'CONNECT': + $host = $p1; + $database = $p2; - $s = "$dbms error: [$errno: $errmsg] in $fn('$host', ?, ?, '$database')"; - break; + $s = "$dbms error: [$errno: $errmsg] in $fn('$host', ?, ?, '$database')"; + break; - default: - $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)"; - break; - } + default: + $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)"; + break; + } - $class = ADODB_PEAR_ERROR_CLASS; - $ADODB_Last_PEAR_Error = new $class($s, $errno, - $GLOBALS['_PEAR_default_error_mode'], - $GLOBALS['_PEAR_default_error_options'], - $errmsg); + $class = ADODB_PEAR_ERROR_CLASS; + $ADODB_Last_PEAR_Error = new $class($s, $errno, + $GLOBALS['_PEAR_default_error_mode'], + $GLOBALS['_PEAR_default_error_options'], + $errmsg); - //print "

!$s

"; + //print "

!$s

"; } /** @@ -82,7 +82,7 @@ function &ADODB_PEAR_Error() { global $ADODB_Last_PEAR_Error; - return $ADODB_Last_PEAR_Error; + return $ADODB_Last_PEAR_Error; } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/adodb-exceptions.inc.php b/lib/WikiDB/adodb/adodb-exceptions.inc.php index 31db8091a..a46356e86 100644 --- a/lib/WikiDB/adodb/adodb-exceptions.inc.php +++ b/lib/WikiDB/adodb/adodb-exceptions.inc.php @@ -24,34 +24,34 @@ var $params = ''; var $host = ''; var $database = ''; - function __construct($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection) - { - switch($fn) { - case 'EXECUTE': - $this->sql = $p1; - $this->params = $p2; - $s = "$dbms error: [$errno: $errmsg] in $fn(\"$p1\")\n"; - break; + function __construct($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection) + { + switch($fn) { + case 'EXECUTE': + $this->sql = $p1; + $this->params = $p2; + $s = "$dbms error: [$errno: $errmsg] in $fn(\"$p1\")\n"; + break; - case 'PCONNECT': - case 'CONNECT': - $user = $thisConnection->user; - $s = "$dbms error: [$errno: $errmsg] in $fn($p1, '$user', '****', $p2)\n"; - break; - default: - $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)\n"; - break; - } + case 'PCONNECT': + case 'CONNECT': + $user = $thisConnection->user; + $s = "$dbms error: [$errno: $errmsg] in $fn($p1, '$user', '****', $p2)\n"; + break; + default: + $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)\n"; + break; + } - $this->dbms = $dbms; - $this->host = $thisConnection->host; - $this->database = $thisConnection->database; - $this->fn = $fn; - $this->msg = $errmsg; + $this->dbms = $dbms; + $this->host = $thisConnection->host; + $this->database = $thisConnection->database; + $this->fn = $fn; + $this->msg = $errmsg; - if (!is_numeric($errno)) $errno = -1; - parent::__construct($s,$errno); - } + if (!is_numeric($errno)) $errno = -1; + parent::__construct($s,$errno); + } } /** @@ -69,9 +69,9 @@ function adodb_throw($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection) { global $ADODB_EXCEPTION; - if (is_string($ADODB_EXCEPTION)) $errfn = $ADODB_EXCEPTION; - else $errfn = 'ADODB_EXCEPTION'; - throw new $errfn($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection); + if (is_string($ADODB_EXCEPTION)) $errfn = $ADODB_EXCEPTION; + else $errfn = 'ADODB_EXCEPTION'; + throw new $errfn($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection); } diff --git a/lib/WikiDB/adodb/adodb-iterator.inc.php b/lib/WikiDB/adodb/adodb-iterator.inc.php index e21a8a431..5b50cc26e 100644 --- a/lib/WikiDB/adodb/adodb-iterator.inc.php +++ b/lib/WikiDB/adodb/adodb-iterator.inc.php @@ -10,13 +10,13 @@ PHP5 Iterator Class: - $rs = $db->Execute("select * from adoxyz"); - foreach($rs as $k => $v) { - echo $k; print_r($v); echo "
"; - } + $rs = $db->Execute("select * from adoxyz"); + foreach($rs as $k => $v) { + echo $k; print_r($v); echo "
"; + } - Iterator code based on http://cvs.php.net/cvs.php/php-src/ext/spl/examples/cachingiterator.inc?login=2 + Iterator code based on http://cvs.php.net/cvs.php/php-src/ext/spl/examples/cachingiterator.inc?login=2 */ class ADODB_Iterator implements Iterator { @@ -24,43 +24,43 @@ private $rs; function __construct($rs) - { + { $this->rs = $rs; } function rewind() - { + { $this->rs->MoveFirst(); } - function valid() - { + function valid() + { return !$this->rs->EOF; } function key() - { + { return $this->rs->_currentRow; } function current() - { + { return $this->rs->fields; } function next() - { + { $this->rs->MoveNext(); } - function __call($func, $params) - { - return call_user_func_array(array($this->rs, $func), $params); - } + function __call($func, $params) + { + return call_user_func_array(array($this->rs, $func), $params); + } - function __toString() - { - return 'ADODB Iterator'; - } + function __toString() + { + return 'ADODB Iterator'; + } } diff --git a/lib/WikiDB/adodb/adodb-lib.inc.php b/lib/WikiDB/adodb/adodb-lib.inc.php index 51b177117..e59b97eb7 100644 --- a/lib/WikiDB/adodb/adodb-lib.inc.php +++ b/lib/WikiDB/adodb/adodb-lib.inc.php @@ -18,438 +18,438 @@ $ADODB_INCLUDED_LIB = 1; // See also http://www.php.net/manual/en/function.array-change-key-case.php function _array_change_key_case($an_array) { - if (is_array($an_array)) { - foreach($an_array as $key=>$value) - $new_array[strtoupper($key)] = $value; + if (is_array($an_array)) { + foreach($an_array as $key=>$value) + $new_array[strtoupper($key)] = $value; - return $new_array; + return $new_array; } - return $an_array; + return $an_array; } function _adodb_replace(&$zthis, $table, $fieldArray, $keyCol, $autoQuote, $has_autoinc) { - if (count($fieldArray) == 0) return 0; - $first = true; - $uSet = ''; - - if (!is_array($keyCol)) { - $keyCol = array($keyCol); - } - foreach($fieldArray as $k => $v) { - if ($autoQuote && !is_numeric($v) and strncmp($v,"'",1) !== 0 and strcasecmp($v,'null')!=0) { - $v = $zthis->qstr($v); - $fieldArray[$k] = $v; - } - if (in_array($k,$keyCol)) continue; // skip UPDATE if is key - - if ($first) { - $first = false; - $uSet = "$k=$v"; - } else - $uSet .= ",$k=$v"; - } - - $where = false; - foreach ($keyCol as $v) { - if ($where) $where .= " and $v=$fieldArray[$v]"; - else $where = "$v=$fieldArray[$v]"; - } - - if ($uSet && $where) { - $update = "UPDATE $table SET $uSet WHERE $where"; - - $rs = $zthis->Execute($update); - if ($rs) { - if ($zthis->poorAffectedRows) { - /* - The Select count(*) wipes out any errors that the update would have returned. - http://phplens.com/lens/lensforum/msgs.php?id=5696 - */ - if ($zthis->ErrorNo()<>0) return 0; - - # affected_rows == 0 if update field values identical to old values - # for mysql - which is silly. - - $cnt = $zthis->GetOne("select count(*) from $table where $where"); - if ($cnt > 0) return 1; // record already exists - } else - if (($zthis->Affected_Rows()>0)) return 1; - } - } - // print "

Error=".$this->ErrorNo().'

'; - $first = true; - foreach($fieldArray as $k => $v) { - if ($has_autoinc && in_array($k,$keyCol)) continue; // skip autoinc col - - if ($first) { - $first = false; - $iCols = "$k"; - $iVals = "$v"; - } else { - $iCols .= ",$k"; - $iVals .= ",$v"; - } - } - $insert = "INSERT INTO $table ($iCols) VALUES ($iVals)"; - $rs = $zthis->Execute($insert); - return ($rs) ? 2 : 0; + if (count($fieldArray) == 0) return 0; + $first = true; + $uSet = ''; + + if (!is_array($keyCol)) { + $keyCol = array($keyCol); + } + foreach($fieldArray as $k => $v) { + if ($autoQuote && !is_numeric($v) and strncmp($v,"'",1) !== 0 and strcasecmp($v,'null')!=0) { + $v = $zthis->qstr($v); + $fieldArray[$k] = $v; + } + if (in_array($k,$keyCol)) continue; // skip UPDATE if is key + + if ($first) { + $first = false; + $uSet = "$k=$v"; + } else + $uSet .= ",$k=$v"; + } + + $where = false; + foreach ($keyCol as $v) { + if ($where) $where .= " and $v=$fieldArray[$v]"; + else $where = "$v=$fieldArray[$v]"; + } + + if ($uSet && $where) { + $update = "UPDATE $table SET $uSet WHERE $where"; + + $rs = $zthis->Execute($update); + if ($rs) { + if ($zthis->poorAffectedRows) { + /* + The Select count(*) wipes out any errors that the update would have returned. + http://phplens.com/lens/lensforum/msgs.php?id=5696 + */ + if ($zthis->ErrorNo()<>0) return 0; + + # affected_rows == 0 if update field values identical to old values + # for mysql - which is silly. + + $cnt = $zthis->GetOne("select count(*) from $table where $where"); + if ($cnt > 0) return 1; // record already exists + } else + if (($zthis->Affected_Rows()>0)) return 1; + } + } + // print "

Error=".$this->ErrorNo().'

'; + $first = true; + foreach($fieldArray as $k => $v) { + if ($has_autoinc && in_array($k,$keyCol)) continue; // skip autoinc col + + if ($first) { + $first = false; + $iCols = "$k"; + $iVals = "$v"; + } else { + $iCols .= ",$k"; + $iVals .= ",$v"; + } + } + $insert = "INSERT INTO $table ($iCols) VALUES ($iVals)"; + $rs = $zthis->Execute($insert); + return ($rs) ? 2 : 0; } // Requires $ADODB_FETCH_MODE = ADODB_FETCH_NUM function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=false, - $size=0, $selectAttr='',$compareFields0=true) + $size=0, $selectAttr='',$compareFields0=true) { - $hasvalue = false; - - if ($multiple or is_array($defstr)) { - if ($size==0) $size=5; - $attr = " multiple size=$size"; - if (!strpos($name,'[]')) $name .= '[]'; - } else if ($size) $attr = " size=$size"; - else $attr =''; - - $s = "\n"; + $hasvalue = false; + + if ($multiple or is_array($defstr)) { + if ($size==0) $size=5; + $attr = " multiple size=$size"; + if (!strpos($name,'[]')) $name .= '[]'; + } else if ($size) $attr = " size=$size"; + else $attr =''; + + $s = "\n"; } /* - Count the number of records this sql statement will return by using - query rewriting techniques... + Count the number of records this sql statement will return by using + query rewriting techniques... - Does not work with UNIONs. + Does not work with UNIONs. */ function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0) { - $qryRecs = 0; - - if (preg_match("/^\s*SELECT\s+DISTINCT/is", $sql) || preg_match('/\s+GROUP\s+BY\s+/is',$sql)) { - // ok, has SELECT DISTINCT or GROUP BY so see if we can use a table alias - // but this is only supported by oracle and postgresql... - if ($zthis->dataProvider == 'oci8') { - - $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql); - $rewritesql = "SELECT COUNT(*) FROM ($rewritesql)"; - - } else if ( $zthis->databaseType == 'postgres' || $zthis->databaseType == 'postgres7') { - - $info = $zthis->ServerInfo(); - if (substr($info['version'],0,3) >= 7.1) { // good till version 999 - $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql); - $rewritesql = "SELECT COUNT(*) FROM ($rewritesql) _ADODB_ALIAS_"; - } - } - } else { - // now replace SELECT ... FROM with SELECT COUNT(*) FROM - - $rewritesql = preg_replace( - '/^\s*SELECT\s.*\s+FROM\s/Uis','SELECT COUNT(*) FROM ',$sql); - - // fix by alexander zhukov, alex#unipack.ru, because count(*) and 'order by' fails - // with mssql, access and postgresql. Also a good speedup optimization - skips sorting! - $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$rewritesql); - } - - if (isset($rewritesql) && $rewritesql != $sql) { - if ($secs2cache) { - // we only use half the time of secs2cache because the count can quickly - // become inaccurate if new records are added - $qryRecs = $zthis->CacheGetOne($secs2cache/2,$rewritesql,$inputarr); - - } else { - $qryRecs = $zthis->GetOne($rewritesql,$inputarr); - } - if ($qryRecs !== false) return $qryRecs; - } - - //-------------------------------------------- - // query rewrite failed - so try slower way... - - // strip off unneeded ORDER BY - $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql); - $rstest = &$zthis->Execute($rewritesql,$inputarr); - if ($rstest) { - $qryRecs = $rstest->RecordCount(); - if ($qryRecs == -1) { - global $ADODB_EXTENSION; - // some databases will return -1 on MoveLast() - change to MoveNext() - if ($ADODB_EXTENSION) { - while(!$rstest->EOF) { - adodb_movenext($rstest); - } - } else { - while(!$rstest->EOF) { - $rstest->MoveNext(); - } - } - $qryRecs = $rstest->_currentRow; - } - $rstest->Close(); - if ($qryRecs == -1) return 0; - } - - return $qryRecs; + $qryRecs = 0; + + if (preg_match("/^\s*SELECT\s+DISTINCT/is", $sql) || preg_match('/\s+GROUP\s+BY\s+/is',$sql)) { + // ok, has SELECT DISTINCT or GROUP BY so see if we can use a table alias + // but this is only supported by oracle and postgresql... + if ($zthis->dataProvider == 'oci8') { + + $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql); + $rewritesql = "SELECT COUNT(*) FROM ($rewritesql)"; + + } else if ( $zthis->databaseType == 'postgres' || $zthis->databaseType == 'postgres7') { + + $info = $zthis->ServerInfo(); + if (substr($info['version'],0,3) >= 7.1) { // good till version 999 + $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql); + $rewritesql = "SELECT COUNT(*) FROM ($rewritesql) _ADODB_ALIAS_"; + } + } + } else { + // now replace SELECT ... FROM with SELECT COUNT(*) FROM + + $rewritesql = preg_replace( + '/^\s*SELECT\s.*\s+FROM\s/Uis','SELECT COUNT(*) FROM ',$sql); + + // fix by alexander zhukov, alex#unipack.ru, because count(*) and 'order by' fails + // with mssql, access and postgresql. Also a good speedup optimization - skips sorting! + $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$rewritesql); + } + + if (isset($rewritesql) && $rewritesql != $sql) { + if ($secs2cache) { + // we only use half the time of secs2cache because the count can quickly + // become inaccurate if new records are added + $qryRecs = $zthis->CacheGetOne($secs2cache/2,$rewritesql,$inputarr); + + } else { + $qryRecs = $zthis->GetOne($rewritesql,$inputarr); + } + if ($qryRecs !== false) return $qryRecs; + } + + //-------------------------------------------- + // query rewrite failed - so try slower way... + + // strip off unneeded ORDER BY + $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql); + $rstest = &$zthis->Execute($rewritesql,$inputarr); + if ($rstest) { + $qryRecs = $rstest->RecordCount(); + if ($qryRecs == -1) { + global $ADODB_EXTENSION; + // some databases will return -1 on MoveLast() - change to MoveNext() + if ($ADODB_EXTENSION) { + while(!$rstest->EOF) { + adodb_movenext($rstest); + } + } else { + while(!$rstest->EOF) { + $rstest->MoveNext(); + } + } + $qryRecs = $rstest->_currentRow; + } + $rstest->Close(); + if ($qryRecs == -1) return 0; + } + + return $qryRecs; } /* - Code originally from "Cornel G" + Code originally from "Cornel G" - This code will not work with SQL that has UNION in it + This code will not work with SQL that has UNION in it - Also if you are using CachePageExecute(), there is a strong possibility that - data will get out of synch. use CachePageExecute() only with tables that - rarely change. + Also if you are using CachePageExecute(), there is a strong possibility that + data will get out of synch. use CachePageExecute() only with tables that + rarely change. */ function &_adodb_pageexecute_all_rows(&$zthis, $sql, $nrows, $page, - $inputarr=false, $secs2cache=0) + $inputarr=false, $secs2cache=0) { - $atfirstpage = false; - $atlastpage = false; - $lastpageno=1; - - // If an invalid nrows is supplied, - // we assume a default value of 10 rows per page - if (!isset($nrows) || $nrows <= 0) $nrows = 10; - - $qryRecs = false; //count records for no offset - - $qryRecs = _adodb_getcount($zthis,$sql,$inputarr,$secs2cache); - $lastpageno = (int) ceil($qryRecs / $nrows); - $zthis->_maxRecordCount = $qryRecs; - - // If page number <= 1, then we are at the first page - if (!isset($page) || $page <= 1) { - $page = 1; - $atfirstpage = true; - } - - // ***** Here we check whether $page is the last page or - // whether we are trying to retrieve - // a page number greater than the last page number. - if ($page >= $lastpageno) { - $page = $lastpageno; - $atlastpage = true; - } - - // We get the data we want - $offset = $nrows * ($page-1); - if ($secs2cache > 0) - $rsreturn = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr); - else - $rsreturn = &$zthis->SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache); - - - // Before returning the RecordSet, we set the pagination properties we need - if ($rsreturn) { - $rsreturn->_maxRecordCount = $qryRecs; - $rsreturn->rowsPerPage = $nrows; - $rsreturn->AbsolutePage($page); - $rsreturn->AtFirstPage($atfirstpage); - $rsreturn->AtLastPage($atlastpage); - $rsreturn->LastPageNo($lastpageno); - } - return $rsreturn; + $atfirstpage = false; + $atlastpage = false; + $lastpageno=1; + + // If an invalid nrows is supplied, + // we assume a default value of 10 rows per page + if (!isset($nrows) || $nrows <= 0) $nrows = 10; + + $qryRecs = false; //count records for no offset + + $qryRecs = _adodb_getcount($zthis,$sql,$inputarr,$secs2cache); + $lastpageno = (int) ceil($qryRecs / $nrows); + $zthis->_maxRecordCount = $qryRecs; + + // If page number <= 1, then we are at the first page + if (!isset($page) || $page <= 1) { + $page = 1; + $atfirstpage = true; + } + + // ***** Here we check whether $page is the last page or + // whether we are trying to retrieve + // a page number greater than the last page number. + if ($page >= $lastpageno) { + $page = $lastpageno; + $atlastpage = true; + } + + // We get the data we want + $offset = $nrows * ($page-1); + if ($secs2cache > 0) + $rsreturn = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr); + else + $rsreturn = &$zthis->SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache); + + + // Before returning the RecordSet, we set the pagination properties we need + if ($rsreturn) { + $rsreturn->_maxRecordCount = $qryRecs; + $rsreturn->rowsPerPage = $nrows; + $rsreturn->AbsolutePage($page); + $rsreturn->AtFirstPage($atfirstpage); + $rsreturn->AtLastPage($atlastpage); + $rsreturn->LastPageNo($lastpageno); + } + return $rsreturn; } // Iván Oliva version function &_adodb_pageexecute_no_last_page(&$zthis, $sql, $nrows, $page, $inputarr=false, $secs2cache=0) { - $atfirstpage = false; - $atlastpage = false; - - if (!isset($page) || $page <= 1) { // If page number <= 1, then we are at the first page - $page = 1; - $atfirstpage = true; - } - if ($nrows <= 0) $nrows = 10; // If an invalid nrows is supplied, we assume a default value of 10 rows per page - - // ***** Here we check whether $page is the last page or whether we are trying to retrieve a page number greater than - // the last page number. - $pagecounter = $page + 1; - $pagecounteroffset = ($pagecounter * $nrows) - $nrows; - if ($secs2cache>0) $rstest = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr); - else $rstest = &$zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $secs2cache); - if ($rstest) { - while ($rstest && $rstest->EOF && $pagecounter>0) { - $atlastpage = true; - $pagecounter--; - $pagecounteroffset = $nrows * ($pagecounter - 1); - $rstest->Close(); - if ($secs2cache>0) $rstest = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr); - else $rstest = &$zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $secs2cache); - } - if ($rstest) $rstest->Close(); - } - if ($atlastpage) { // If we are at the last page or beyond it, we are going to retrieve it - $page = $pagecounter; - if ($page == 1) $atfirstpage = true; // We have to do this again in case the last page is the same as the first - //... page, that is, the recordset has only 1 page. - } - - // We get the data we want - $offset = $nrows * ($page-1); - if ($secs2cache > 0) $rsreturn = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr); - else $rsreturn = &$zthis->SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache); - - // Before returning the RecordSet, we set the pagination properties we need - if ($rsreturn) { - $rsreturn->rowsPerPage = $nrows; - $rsreturn->AbsolutePage($page); - $rsreturn->AtFirstPage($atfirstpage); - $rsreturn->AtLastPage($atlastpage); - } - return $rsreturn; + $atfirstpage = false; + $atlastpage = false; + + if (!isset($page) || $page <= 1) { // If page number <= 1, then we are at the first page + $page = 1; + $atfirstpage = true; + } + if ($nrows <= 0) $nrows = 10; // If an invalid nrows is supplied, we assume a default value of 10 rows per page + + // ***** Here we check whether $page is the last page or whether we are trying to retrieve a page number greater than + // the last page number. + $pagecounter = $page + 1; + $pagecounteroffset = ($pagecounter * $nrows) - $nrows; + if ($secs2cache>0) $rstest = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr); + else $rstest = &$zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $secs2cache); + if ($rstest) { + while ($rstest && $rstest->EOF && $pagecounter>0) { + $atlastpage = true; + $pagecounter--; + $pagecounteroffset = $nrows * ($pagecounter - 1); + $rstest->Close(); + if ($secs2cache>0) $rstest = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr); + else $rstest = &$zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $secs2cache); + } + if ($rstest) $rstest->Close(); + } + if ($atlastpage) { // If we are at the last page or beyond it, we are going to retrieve it + $page = $pagecounter; + if ($page == 1) $atfirstpage = true; // We have to do this again in case the last page is the same as the first + //... page, that is, the recordset has only 1 page. + } + + // We get the data we want + $offset = $nrows * ($page-1); + if ($secs2cache > 0) $rsreturn = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr); + else $rsreturn = &$zthis->SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache); + + // Before returning the RecordSet, we set the pagination properties we need + if ($rsreturn) { + $rsreturn->rowsPerPage = $nrows; + $rsreturn->AbsolutePage($page); + $rsreturn->AtFirstPage($atfirstpage); + $rsreturn->AtLastPage($atlastpage); + } + return $rsreturn; } function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq=false) { - if (!$rs) { - printf(ADODB_BAD_RS,'GetUpdateSQL'); - return false; - } - - $fieldUpdatedCount = 0; - $arrFields = _array_change_key_case($arrFields); - - $hasnumeric = isset($rs->fields[0]); - $setFields = ''; - - // Loop through all of the fields in the recordset - for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++) { - // Get the field from the recordset - $field = $rs->FetchField($i); - - // If the recordset field is one - // of the fields passed in then process. - $upperfname = strtoupper($field->name); - if (adodb_key_exists($upperfname,$arrFields)) { - - // If the existing field value in the recordset - // is different from the value passed in then - // go ahead and append the field name and new value to - // the update query. - - if ($hasnumeric) $val = $rs->fields[$i]; - else if (isset($rs->fields[$upperfname])) $val = $rs->fields[$upperfname]; - else if (isset($rs->fields[$field->name])) $val = $rs->fields[$field->name]; - else if (isset($rs->fields[strtolower($upperfname)])) $val = $rs->fields[strtolower($upperfname)]; - else $val = ''; - - - if ($forceUpdate || strcmp($val, $arrFields[$upperfname])) { - // Set the counter for the number of fields that will be updated. - $fieldUpdatedCount++; - - // Based on the datatype of the field - // Format the value properly for the database - $type = $rs->MetaType($field->type); - - // is_null requires php 4.0.4 - if ((defined('ADODB_FORCE_NULLS') && is_null($arrFields[$upperfname])) || - $arrFields[$upperfname] === 'null') { - $setFields .= $field->name . " = null, "; - } else { - if ($type == 'null') { - $type = 'C'; - } - //we do this so each driver can customize the sql for - //DB specific column types. - //Oracle needs BLOB types to be handled with a returning clause - //postgres has special needs as well - $setFields .= _adodb_column_sql($zthis, 'U', $type, $upperfname, - $arrFields, $magicq); - } - } - } - } - - // If there were any modified fields then build the rest of the update query. - if ($fieldUpdatedCount > 0 || $forceUpdate) { - // Get the table name from the existing query. - preg_match("/FROM\s+".ADODB_TABLE_REGEX."/is", $rs->sql, $tableName); - - // Get the full where clause excluding the word "WHERE" from - // the existing query. - preg_match('/\sWHERE\s(.*)/is', $rs->sql, $whereClause); - - $discard = false; - // not a good hack, improvements? - if ($whereClause) - preg_match('/\s(LIMIT\s.*)/is', $whereClause[1], $discard); - else - $whereClause = array(false,false); - - if ($discard) - $whereClause[1] = substr($whereClause[1], 0, strlen($whereClause[1]) - strlen($discard[1])); - - $sql = 'UPDATE '.$tableName[1].' SET '.substr($setFields, 0, -2); - if (strlen($whereClause[1]) > 0) - $sql .= ' WHERE '.$whereClause[1]; - - return $sql; - - } else { - return false; - } + if (!$rs) { + printf(ADODB_BAD_RS,'GetUpdateSQL'); + return false; + } + + $fieldUpdatedCount = 0; + $arrFields = _array_change_key_case($arrFields); + + $hasnumeric = isset($rs->fields[0]); + $setFields = ''; + + // Loop through all of the fields in the recordset + for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++) { + // Get the field from the recordset + $field = $rs->FetchField($i); + + // If the recordset field is one + // of the fields passed in then process. + $upperfname = strtoupper($field->name); + if (adodb_key_exists($upperfname,$arrFields)) { + + // If the existing field value in the recordset + // is different from the value passed in then + // go ahead and append the field name and new value to + // the update query. + + if ($hasnumeric) $val = $rs->fields[$i]; + else if (isset($rs->fields[$upperfname])) $val = $rs->fields[$upperfname]; + else if (isset($rs->fields[$field->name])) $val = $rs->fields[$field->name]; + else if (isset($rs->fields[strtolower($upperfname)])) $val = $rs->fields[strtolower($upperfname)]; + else $val = ''; + + + if ($forceUpdate || strcmp($val, $arrFields[$upperfname])) { + // Set the counter for the number of fields that will be updated. + $fieldUpdatedCount++; + + // Based on the datatype of the field + // Format the value properly for the database + $type = $rs->MetaType($field->type); + + // is_null requires php 4.0.4 + if ((defined('ADODB_FORCE_NULLS') && is_null($arrFields[$upperfname])) || + $arrFields[$upperfname] === 'null') { + $setFields .= $field->name . " = null, "; + } else { + if ($type == 'null') { + $type = 'C'; + } + //we do this so each driver can customize the sql for + //DB specific column types. + //Oracle needs BLOB types to be handled with a returning clause + //postgres has special needs as well + $setFields .= _adodb_column_sql($zthis, 'U', $type, $upperfname, + $arrFields, $magicq); + } + } + } + } + + // If there were any modified fields then build the rest of the update query. + if ($fieldUpdatedCount > 0 || $forceUpdate) { + // Get the table name from the existing query. + preg_match("/FROM\s+".ADODB_TABLE_REGEX."/is", $rs->sql, $tableName); + + // Get the full where clause excluding the word "WHERE" from + // the existing query. + preg_match('/\sWHERE\s(.*)/is', $rs->sql, $whereClause); + + $discard = false; + // not a good hack, improvements? + if ($whereClause) + preg_match('/\s(LIMIT\s.*)/is', $whereClause[1], $discard); + else + $whereClause = array(false,false); + + if ($discard) + $whereClause[1] = substr($whereClause[1], 0, strlen($whereClause[1]) - strlen($discard[1])); + + $sql = 'UPDATE '.$tableName[1].' SET '.substr($setFields, 0, -2); + if (strlen($whereClause[1]) > 0) + $sql .= ' WHERE '.$whereClause[1]; + + return $sql; + + } else { + return false; + } } function adodb_key_exists($key, &$arr) { - if (!defined('ADODB_FORCE_NULLS')) { - // the following is the old behaviour where null or empty fields are ignored - return (!empty($arr[$key])) || (isset($arr[$key]) && strlen($arr[$key])>0); - } - - if (isset($arr[$key])) return true; - ## null check below - if (ADODB_PHPVER >= 0x4010) return array_key_exists($key,$arr); - return false; + if (!defined('ADODB_FORCE_NULLS')) { + // the following is the old behaviour where null or empty fields are ignored + return (!empty($arr[$key])) || (isset($arr[$key]) && strlen($arr[$key])>0); + } + + if (isset($arr[$key])) return true; + ## null check below + if (ADODB_PHPVER >= 0x4010) return array_key_exists($key,$arr); + return false; } /** @@ -461,80 +461,80 @@ function adodb_key_exists($key, &$arr) */ function _adodb_getinsertsql(&$zthis,&$rs,$arrFields,$magicq=false) { - $tableName = ''; - $values = ''; - $fields = ''; - $recordSet = null; - $arrFields = _array_change_key_case($arrFields); - $fieldInsertedCount = 0; - - if (is_string($rs)) { - //ok we have a table name - //try and get the column info ourself. - $tableName = $rs; - - //we need an object for the recordSet - //because we have to call MetaType. - //php can't do a $rsclass::MetaType() - $rsclass = $zthis->rsPrefix.$zthis->databaseType; - $recordSet =& new $rsclass(-1,$zthis->fetchMode); - $recordSet->connection = &$zthis; - - $columns = $zthis->MetaColumns( $tableName ); - } else if (is_subclass_of($rs, 'adorecordset')) { - for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++) - $columns[] = $rs->FetchField($i); - $recordSet =& $rs; - - } else { - printf(ADODB_BAD_RS,'GetInsertSQL'); - return false; - } - - // Loop through all of the fields in the recordset - foreach( $columns as $field ) { - $upperfname = strtoupper($field->name); - if (adodb_key_exists($upperfname,$arrFields)) { - - // Set the counter for the number of fields that will be inserted. - $fieldInsertedCount++; - - // Get the name of the fields to insert - $fields .= $field->name . ", "; - - $type = $recordSet->MetaType($field->type); - - if ((defined('ADODB_FORCE_NULLS') && is_null($arrFields[$upperfname])) || - $arrFields[$upperfname] === 'null') { - $values .= "null, "; - } else { - //we do this so each driver can customize the sql for - //DB specific column types. - //Oracle needs BLOB types to be handled with a returning clause - //postgres has special needs as well - $values .= _adodb_column_sql($zthis, 'I', $type, $upperfname, - $arrFields, $magicq); - } - } - } - - - // If there were any inserted fields then build the rest of the insert query. - if ($fieldInsertedCount <= 0) return false; - - // Get the table name from the existing query. - if (!$tableName) { - preg_match("/FROM\s+".ADODB_TABLE_REGEX."/is", $rs->sql, $tableName); - $tableName = $tableName[1]; - } - - // Strip off the comma and space on the end of both the fields - // and their values. - $fields = substr($fields, 0, -2); - $values = substr($values, 0, -2); - - // Append the fields and their values to the insert query. - return 'INSERT INTO '.$tableName.' ( '.$fields.' ) VALUES ( '.$values.' )'; + $tableName = ''; + $values = ''; + $fields = ''; + $recordSet = null; + $arrFields = _array_change_key_case($arrFields); + $fieldInsertedCount = 0; + + if (is_string($rs)) { + //ok we have a table name + //try and get the column info ourself. + $tableName = $rs; + + //we need an object for the recordSet + //because we have to call MetaType. + //php can't do a $rsclass::MetaType() + $rsclass = $zthis->rsPrefix.$zthis->databaseType; + $recordSet =& new $rsclass(-1,$zthis->fetchMode); + $recordSet->connection = &$zthis; + + $columns = $zthis->MetaColumns( $tableName ); + } else if (is_subclass_of($rs, 'adorecordset')) { + for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++) + $columns[] = $rs->FetchField($i); + $recordSet =& $rs; + + } else { + printf(ADODB_BAD_RS,'GetInsertSQL'); + return false; + } + + // Loop through all of the fields in the recordset + foreach( $columns as $field ) { + $upperfname = strtoupper($field->name); + if (adodb_key_exists($upperfname,$arrFields)) { + + // Set the counter for the number of fields that will be inserted. + $fieldInsertedCount++; + + // Get the name of the fields to insert + $fields .= $field->name . ", "; + + $type = $recordSet->MetaType($field->type); + + if ((defined('ADODB_FORCE_NULLS') && is_null($arrFields[$upperfname])) || + $arrFields[$upperfname] === 'null') { + $values .= "null, "; + } else { + //we do this so each driver can customize the sql for + //DB specific column types. + //Oracle needs BLOB types to be handled with a returning clause + //postgres has special needs as well + $values .= _adodb_column_sql($zthis, 'I', $type, $upperfname, + $arrFields, $magicq); + } + } + } + + + // If there were any inserted fields then build the rest of the insert query. + if ($fieldInsertedCount <= 0) return false; + + // Get the table name from the existing query. + if (!$tableName) { + preg_match("/FROM\s+".ADODB_TABLE_REGEX."/is", $rs->sql, $tableName); + $tableName = $tableName[1]; + } + + // Strip off the comma and space on the end of both the fields + // and their values. + $fields = substr($fields, 0, -2); + $values = substr($values, 0, -2); + + // Append the fields and their values to the insert query. + return 'INSERT INTO '.$tableName.' ( '.$fields.' ) VALUES ( '.$values.' )'; } @@ -617,59 +617,59 @@ function _adodb_column_sql_oci8(&$zthis,$action, $type, $fname, $arrFields, $mag function _adodb_column_sql(&$zthis, $action, $type, $fname, $arrFields, $magicq, $recurse=true) { - if ($recurse) { - switch($zthis->dataProvider) { - case 'postgres': - if ($type == 'L') $type = 'C'; - break; - case 'oci8': - return _adodb_column_sql_oci8($zthis, $action, $type, $fname, $arrFields, $magicq); - - } - } - - $sql = ''; - - switch($type) { - case "C": - case "X": - case 'B': - if ($action == 'I') { - $sql = $zthis->qstr($arrFields[$fname],$magicq) . ", "; - } else { - $sql .= $fname . "=" . $zthis->qstr($arrFields[$fname],$magicq) . ", "; - } - break; - - case "D": - if ($action == 'I') { - $sql = $zthis->DBDate($arrFields[$fname]) . ", "; - } else { - $sql .= $fname . "=" . $zthis->DBDate($arrFields[$fname]) . ", "; - } - break; - - case "T": - if ($action == 'I') { - $sql = $zthis->DBTimeStamp($arrFields[$fname]) . ", "; - } else { - $sql .= $fname . "=" . $zthis->DBTimeStamp($arrFields[$fname]) . ", "; - } - break; - - default: - $val = $arrFields[$fname]; - if (empty($val)) $val = '0'; - - - if ($action == 'I') { - $sql .= $val . ", "; - } else { - $sql .= $fname . "=" . $val . ", "; - } - break; - } - - return $sql; + if ($recurse) { + switch($zthis->dataProvider) { + case 'postgres': + if ($type == 'L') $type = 'C'; + break; + case 'oci8': + return _adodb_column_sql_oci8($zthis, $action, $type, $fname, $arrFields, $magicq); + + } + } + + $sql = ''; + + switch($type) { + case "C": + case "X": + case 'B': + if ($action == 'I') { + $sql = $zthis->qstr($arrFields[$fname],$magicq) . ", "; + } else { + $sql .= $fname . "=" . $zthis->qstr($arrFields[$fname],$magicq) . ", "; + } + break; + + case "D": + if ($action == 'I') { + $sql = $zthis->DBDate($arrFields[$fname]) . ", "; + } else { + $sql .= $fname . "=" . $zthis->DBDate($arrFields[$fname]) . ", "; + } + break; + + case "T": + if ($action == 'I') { + $sql = $zthis->DBTimeStamp($arrFields[$fname]) . ", "; + } else { + $sql .= $fname . "=" . $zthis->DBTimeStamp($arrFields[$fname]) . ", "; + } + break; + + default: + $val = $arrFields[$fname]; + if (empty($val)) $val = '0'; + + + if ($action == 'I') { + $sql .= $val . ", "; + } else { + $sql .= $fname . "=" . $val . ", "; + } + break; + } + + return $sql; } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/adodb-pear.inc.php b/lib/WikiDB/adodb/adodb-pear.inc.php index 45d9c2543..0cc6a816e 100644 --- a/lib/WikiDB/adodb/adodb-pear.inc.php +++ b/lib/WikiDB/adodb/adodb-pear.inc.php @@ -18,23 +18,23 @@ DB_Common --------- - query - returns PEAR_Error on error - limitQuery - return PEAR_Error on error - prepare - does not return PEAR_Error on error - execute - does not return PEAR_Error on error - setFetchMode - supports ASSOC and ORDERED - errorNative - quote - nextID - disconnect + query - returns PEAR_Error on error + limitQuery - return PEAR_Error on error + prepare - does not return PEAR_Error on error + execute - does not return PEAR_Error on error + setFetchMode - supports ASSOC and ORDERED + errorNative + quote + nextID + disconnect DB_Result --------- - numRows - returns -1 if not supported - numCols - fetchInto - does not support passing of fetchmode - fetchRows - does not support passing of fetchmode - free + numRows - returns -1 if not supported + numCols + fetchInto - does not support passing of fetchmode + fetchRows - does not support passing of fetchmode + free */ define('ADODB_PEAR',dirname(__FILE__)); @@ -89,271 +89,271 @@ define('DB_TABLEINFO_FULL', 3); class DB { - /** - * Create a new DB object for the specified database type - * - * @param $type string database type, for example "mysql" - * - * @return object a newly created DB object, or a DB error code on - * error - */ - - function &factory($type) - { - include_once(ADODB_DIR."/drivers/adodb-$type.inc.php"); - $obj = &NewADOConnection($type); - if (!is_object($obj)) $obj =& new PEAR_Error('Unknown Database Driver: '.$dsninfo['phptype'],-1); - return $obj; - } - - /** - * Create a new DB object and connect to the specified database - * - * @param $dsn mixed "data source name", see the DB::parseDSN - * method for a description of the dsn format. Can also be - * specified as an array of the format returned by DB::parseDSN. - * - * @param $options mixed if boolean (or scalar), tells whether - * this connection should be persistent (for backends that support - * this). This parameter can also be an array of options, see - * DB_common::setOption for more information on connection - * options. - * - * @return object a newly created DB connection object, or a DB - * error object on error - * - * @see DB::parseDSN - * @see DB::isError - */ - function &connect($dsn, $options = false) - { - if (is_array($dsn)) { - $dsninfo = $dsn; - } else { - $dsninfo = DB::parseDSN($dsn); - } - switch ($dsninfo["phptype"]) { - case 'pgsql': $type = 'postgres7'; break; - case 'ifx': $type = 'informix9'; break; - default: $type = $dsninfo["phptype"]; break; - } - - if (is_array($options) && isset($options["debug"]) && - $options["debug"] >= 2) { - // expose php errors with sufficient debug level - @include_once("adodb-$type.inc.php"); - } else { - @include_once("adodb-$type.inc.php"); - } - - @$obj =& NewADOConnection($type); - if (!is_object($obj)) { - $obj =& new PEAR_Error('Unknown Database Driver: '.$dsninfo['phptype'],-1); - return $obj; - } - if (is_array($options)) { - foreach($options as $k => $v) { - switch(strtolower($k)) { - case 'persistent': $persist = $v; break; - #ibase - case 'dialect': $obj->dialect = $v; break; - case 'charset': $obj->charset = $v; break; - case 'buffers': $obj->buffers = $v; break; - #ado - case 'charpage': $obj->charPage = $v; break; - #mysql - case 'clientflags': $obj->clientFlags = $v; break; - } - } - } else { - $persist = false; - } - - if (isset($dsninfo['socket'])) $dsninfo['hostspec'] .= ':'.$dsninfo['socket']; - else if (isset($dsninfo['port'])) $dsninfo['hostspec'] .= ':'.$dsninfo['port']; - - if($persist) $ok = $obj->PConnect($dsninfo['hostspec'], $dsninfo['username'],$dsninfo['password'],$dsninfo['database']); - else $ok = $obj->Connect($dsninfo['hostspec'], $dsninfo['username'],$dsninfo['password'],$dsninfo['database']); - - if (!$ok) $obj = ADODB_PEAR_Error(); - return $obj; - } - - /** - * Return the DB API version - * - * @return int the DB API version number - */ - function apiVersion() - { - return 2; - } - - /** - * Tell whether a result code from a DB method is an error - * - * @param $value int result code - * - * @return bool whether $value is an error - */ - function isError($value) - { - return (is_object($value) && + /** + * Create a new DB object for the specified database type + * + * @param $type string database type, for example "mysql" + * + * @return object a newly created DB object, or a DB error code on + * error + */ + + function &factory($type) + { + include_once(ADODB_DIR."/drivers/adodb-$type.inc.php"); + $obj = &NewADOConnection($type); + if (!is_object($obj)) $obj =& new PEAR_Error('Unknown Database Driver: '.$dsninfo['phptype'],-1); + return $obj; + } + + /** + * Create a new DB object and connect to the specified database + * + * @param $dsn mixed "data source name", see the DB::parseDSN + * method for a description of the dsn format. Can also be + * specified as an array of the format returned by DB::parseDSN. + * + * @param $options mixed if boolean (or scalar), tells whether + * this connection should be persistent (for backends that support + * this). This parameter can also be an array of options, see + * DB_common::setOption for more information on connection + * options. + * + * @return object a newly created DB connection object, or a DB + * error object on error + * + * @see DB::parseDSN + * @see DB::isError + */ + function &connect($dsn, $options = false) + { + if (is_array($dsn)) { + $dsninfo = $dsn; + } else { + $dsninfo = DB::parseDSN($dsn); + } + switch ($dsninfo["phptype"]) { + case 'pgsql': $type = 'postgres7'; break; + case 'ifx': $type = 'informix9'; break; + default: $type = $dsninfo["phptype"]; break; + } + + if (is_array($options) && isset($options["debug"]) && + $options["debug"] >= 2) { + // expose php errors with sufficient debug level + @include_once("adodb-$type.inc.php"); + } else { + @include_once("adodb-$type.inc.php"); + } + + @$obj =& NewADOConnection($type); + if (!is_object($obj)) { + $obj =& new PEAR_Error('Unknown Database Driver: '.$dsninfo['phptype'],-1); + return $obj; + } + if (is_array($options)) { + foreach($options as $k => $v) { + switch(strtolower($k)) { + case 'persistent': $persist = $v; break; + #ibase + case 'dialect': $obj->dialect = $v; break; + case 'charset': $obj->charset = $v; break; + case 'buffers': $obj->buffers = $v; break; + #ado + case 'charpage': $obj->charPage = $v; break; + #mysql + case 'clientflags': $obj->clientFlags = $v; break; + } + } + } else { + $persist = false; + } + + if (isset($dsninfo['socket'])) $dsninfo['hostspec'] .= ':'.$dsninfo['socket']; + else if (isset($dsninfo['port'])) $dsninfo['hostspec'] .= ':'.$dsninfo['port']; + + if($persist) $ok = $obj->PConnect($dsninfo['hostspec'], $dsninfo['username'],$dsninfo['password'],$dsninfo['database']); + else $ok = $obj->Connect($dsninfo['hostspec'], $dsninfo['username'],$dsninfo['password'],$dsninfo['database']); + + if (!$ok) $obj = ADODB_PEAR_Error(); + return $obj; + } + + /** + * Return the DB API version + * + * @return int the DB API version number + */ + function apiVersion() + { + return 2; + } + + /** + * Tell whether a result code from a DB method is an error + * + * @param $value int result code + * + * @return bool whether $value is an error + */ + function isError($value) + { + return (is_object($value) && (strtolower(get_class($value)) == 'db_error' || - is_subclass_of($value, 'db_error'))); - } - - - /** - * Tell whether a result code from a DB method is a warning. - * Warnings differ from errors in that they are generated by DB, - * and are not fatal. - * - * @param $value mixed result value - * - * @return bool whether $value is a warning - */ - function isWarning($value) - { - return is_object($value) && + is_subclass_of($value, 'db_error'))); + } + + + /** + * Tell whether a result code from a DB method is a warning. + * Warnings differ from errors in that they are generated by DB, + * and are not fatal. + * + * @param $value mixed result value + * + * @return bool whether $value is a warning + */ + function isWarning($value) + { + return is_object($value) && (strtolower(get_class( $value )) == "db_warning" || - is_subclass_of($value, "db_warning")); - } - - /** - * Parse a data source name - * - * @param $dsn string Data Source Name to be parsed - * - * @return array an associative array with the following keys: - * - * phptype: Database backend used in PHP (mysql, odbc etc.) - * dbsyntax: Database used with regards to SQL syntax etc. - * protocol: Communication protocol to use (tcp, unix etc.) - * hostspec: Host specification (hostname[:port]) - * database: Database to use on the DBMS server - * username: User name for login - * password: Password for login - * - * The format of the supplied DSN is in its fullest form: - * - * phptype(dbsyntax)://username:password@protocol+hostspec/database - * - * Most variations are allowed: - * - * phptype://username:password@protocol+hostspec:110//usr/db_file.db - * phptype://username:password@hostspec/database_name - * phptype://username:password@hostspec - * phptype://username@hostspec - * phptype://hostspec/database - * phptype://hostspec - * phptype(dbsyntax) - * phptype - * - * @author Tomas V.V.Cox - */ - function parseDSN($dsn) - { - if (is_array($dsn)) { - return $dsn; - } - - $parsed = array( - 'phptype' => false, - 'dbsyntax' => false, - 'protocol' => false, - 'hostspec' => false, - 'database' => false, - 'username' => false, - 'password' => false - ); - - // Find phptype and dbsyntax - if (($pos = strpos($dsn, '://')) !== false) { - $str = substr($dsn, 0, $pos); - $dsn = substr($dsn, $pos + 3); - } else { - $str = $dsn; - $dsn = NULL; - } - - // Get phptype and dbsyntax - // $str => phptype(dbsyntax) - if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) { - $parsed['phptype'] = $arr[1]; - $parsed['dbsyntax'] = (empty($arr[2])) ? $arr[1] : $arr[2]; - } else { - $parsed['phptype'] = $str; - $parsed['dbsyntax'] = $str; - } - - if (empty($dsn)) { - return $parsed; - } - - // Get (if found): username and password - // $dsn => username:password@protocol+hostspec/database - if (($at = strpos($dsn,'@')) !== false) { - $str = substr($dsn, 0, $at); - $dsn = substr($dsn, $at + 1); - if (($pos = strpos($str, ':')) !== false) { - $parsed['username'] = urldecode(substr($str, 0, $pos)); - $parsed['password'] = urldecode(substr($str, $pos + 1)); - } else { - $parsed['username'] = urldecode($str); - } - } - - // Find protocol and hostspec - // $dsn => protocol+hostspec/database - if (($pos=strpos($dsn, '/')) !== false) { - $str = substr($dsn, 0, $pos); - $dsn = substr($dsn, $pos + 1); - } else { - $str = $dsn; - $dsn = NULL; - } - - // Get protocol + hostspec - // $str => protocol+hostspec - if (($pos=strpos($str, '+')) !== false) { - $parsed['protocol'] = substr($str, 0, $pos); - $parsed['hostspec'] = urldecode(substr($str, $pos + 1)); - } else { - $parsed['hostspec'] = urldecode($str); - } - - // Get dabase if any - // $dsn => database - if (!empty($dsn)) { - $parsed['database'] = $dsn; - } - - return $parsed; - } - - /** - * Load a PHP database extension if it is not loaded already. - * - * @access public - * - * @param $name the base name of the extension (without the .so or - * .dll suffix) - * - * @return bool true if the extension was already or successfully - * loaded, false if it could not be loaded - */ - function assertExtension($name) - { - if (!extension_loaded($name)) { - $dlext = (strncmp(PHP_OS,'WIN',3) === 0) ? '.dll' : '.so'; - @dl($name . $dlext); - } - if (!extension_loaded($name)) { - return false; - } - return true; - } + is_subclass_of($value, "db_warning")); + } + + /** + * Parse a data source name + * + * @param $dsn string Data Source Name to be parsed + * + * @return array an associative array with the following keys: + * + * phptype: Database backend used in PHP (mysql, odbc etc.) + * dbsyntax: Database used with regards to SQL syntax etc. + * protocol: Communication protocol to use (tcp, unix etc.) + * hostspec: Host specification (hostname[:port]) + * database: Database to use on the DBMS server + * username: User name for login + * password: Password for login + * + * The format of the supplied DSN is in its fullest form: + * + * phptype(dbsyntax)://username:password@protocol+hostspec/database + * + * Most variations are allowed: + * + * phptype://username:password@protocol+hostspec:110//usr/db_file.db + * phptype://username:password@hostspec/database_name + * phptype://username:password@hostspec + * phptype://username@hostspec + * phptype://hostspec/database + * phptype://hostspec + * phptype(dbsyntax) + * phptype + * + * @author Tomas V.V.Cox + */ + function parseDSN($dsn) + { + if (is_array($dsn)) { + return $dsn; + } + + $parsed = array( + 'phptype' => false, + 'dbsyntax' => false, + 'protocol' => false, + 'hostspec' => false, + 'database' => false, + 'username' => false, + 'password' => false + ); + + // Find phptype and dbsyntax + if (($pos = strpos($dsn, '://')) !== false) { + $str = substr($dsn, 0, $pos); + $dsn = substr($dsn, $pos + 3); + } else { + $str = $dsn; + $dsn = NULL; + } + + // Get phptype and dbsyntax + // $str => phptype(dbsyntax) + if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) { + $parsed['phptype'] = $arr[1]; + $parsed['dbsyntax'] = (empty($arr[2])) ? $arr[1] : $arr[2]; + } else { + $parsed['phptype'] = $str; + $parsed['dbsyntax'] = $str; + } + + if (empty($dsn)) { + return $parsed; + } + + // Get (if found): username and password + // $dsn => username:password@protocol+hostspec/database + if (($at = strpos($dsn,'@')) !== false) { + $str = substr($dsn, 0, $at); + $dsn = substr($dsn, $at + 1); + if (($pos = strpos($str, ':')) !== false) { + $parsed['username'] = urldecode(substr($str, 0, $pos)); + $parsed['password'] = urldecode(substr($str, $pos + 1)); + } else { + $parsed['username'] = urldecode($str); + } + } + + // Find protocol and hostspec + // $dsn => protocol+hostspec/database + if (($pos=strpos($dsn, '/')) !== false) { + $str = substr($dsn, 0, $pos); + $dsn = substr($dsn, $pos + 1); + } else { + $str = $dsn; + $dsn = NULL; + } + + // Get protocol + hostspec + // $str => protocol+hostspec + if (($pos=strpos($str, '+')) !== false) { + $parsed['protocol'] = substr($str, 0, $pos); + $parsed['hostspec'] = urldecode(substr($str, $pos + 1)); + } else { + $parsed['hostspec'] = urldecode($str); + } + + // Get dabase if any + // $dsn => database + if (!empty($dsn)) { + $parsed['database'] = $dsn; + } + + return $parsed; + } + + /** + * Load a PHP database extension if it is not loaded already. + * + * @access public + * + * @param $name the base name of the extension (without the .so or + * .dll suffix) + * + * @return bool true if the extension was already or successfully + * loaded, false if it could not be loaded + */ + function assertExtension($name) + { + if (!extension_loaded($name)) { + $dlext = (strncmp(PHP_OS,'WIN',3) === 0) ? '.dll' : '.so'; + @dl($name . $dlext); + } + if (!extension_loaded($name)) { + return false; + } + return true; + } } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/adodb-time.inc.php b/lib/WikiDB/adodb/adodb-time.inc.php index 3454959fc..cab86758c 100644 --- a/lib/WikiDB/adodb/adodb-time.inc.php +++ b/lib/WikiDB/adodb/adodb-time.inc.php @@ -19,11 +19,11 @@ would take too long with the current implementation of adodb_mktime(). This library replaces native functions as follows:

-	getdate()  with  adodb_getdate()
-	date()     with  adodb_date()
-	gmdate()   with  adodb_gmdate()
-	mktime()   with  adodb_mktime()
-	gmmktime() with  adodb_gmmktime()
+    getdate()  with  adodb_getdate()
+    date()     with  adodb_date()
+    gmdate()   with  adodb_gmdate()
+    mktime()   with  adodb_mktime()
+    gmmktime() with  adodb_gmmktime()
 
The parameters are identical, except that adodb_date() accepts a subset @@ -49,7 +49,7 @@ October 4, 1582 (Julian) was followed immediately by Friday, October 15, Since 0.06, we handle this correctly, so: adodb_mktime(0,0,0,10,15,1582) - adodb_mktime(0,0,0,10,4,1582) - == 24 * 3600 (1 day) + == 24 * 3600 (1 day) ============================================================================= @@ -65,7 +65,7 @@ BUG REPORTS These should be posted to the ADOdb forums at - http://phplens.com/lens/lensforum/topics.php?id=4 + http://phplens.com/lens/lensforum/topics.php?id=4 ============================================================================= @@ -108,7 +108,7 @@ Q - Quarter, as in 1, 2, 3, 4 r - RFC 822 formatted date; e.g. "Thu, 21 Dec 2000 16:01:07 +0200" s - seconds; i.e. "00" to "59" S - English ordinal suffix for the day of the month, 2 characters; - i.e. "st", "nd", "rd" or "th" + i.e. "st", "nd", "rd" or "th" t - number of days in the given month; i.e. "28" to "31" T - Timezone setting of this machine; e.g. "EST" or "MDT" U - seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) @@ -117,8 +117,8 @@ Y - year, 4 digits; e.g. "1999" y - year, 2 digits; e.g. "99" z - day of the year; i.e. "0" to "365" Z - timezone offset in seconds (i.e. "-43200" to "43200"). - The offset for timezones west of UTC is always negative, - and for those east of UTC is always positive. + The offset for timezones west of UTC is always negative, + and for those east of UTC is always positive. Unsupported: @@ -158,7 +158,7 @@ are currently compulsory. NOTES Useful url for generating test timestamps: - http://www.4webhelp.net/us/timestamp.php + http://www.4webhelp.net/us/timestamp.php Possible future optimizations include @@ -170,7 +170,7 @@ b. Iterate over a block of years (say 12) when searching for the correct year. c. Implement daylight savings, which looks awfully complicated, see - http://webexhibits.org/daylightsaving/ + http://webexhibits.org/daylightsaving/ CHANGELOG @@ -235,189 +235,189 @@ First implementation. /* Initialization */ /* - Version Number + Version Number */ define('ADODB_DATE_VERSION',0.12); /* - We check for Windows as only +ve ints are accepted as dates on Windows. + We check for Windows as only +ve ints are accepted as dates on Windows. - Apparently this problem happens also with Linux, RH 7.3 and later! + Apparently this problem happens also with Linux, RH 7.3 and later! - glibc-2.2.5-34 and greater has been changed to return -1 for dates < - 1970. This used to work. The problem exists with RedHat 7.3 and 8.0 - echo (mktime(0, 0, 0, 1, 1, 1960)); // prints -1 + glibc-2.2.5-34 and greater has been changed to return -1 for dates < + 1970. This used to work. The problem exists with RedHat 7.3 and 8.0 + echo (mktime(0, 0, 0, 1, 1, 1960)); // prints -1 - References: - http://bugs.php.net/bug.php?id=20048&edit=2 - http://lists.debian.org/debian-glibc/2002/debian-glibc-200205/msg00010.html + References: + http://bugs.php.net/bug.php?id=20048&edit=2 + http://lists.debian.org/debian-glibc/2002/debian-glibc-200205/msg00010.html */ if (!defined('ADODB_ALLOW_NEGATIVE_TS')) define('ADODB_NO_NEGATIVE_TS',1); function adodb_date_test_date($y1,$m) { - //print " $y1/$m "; - $t = adodb_mktime(0,0,0,$m,13,$y1); - if ("$y1-$m-13 00:00:00" != adodb_date('Y-n-d H:i:s',$t)) { - print "$y1 error
"; - return false; - } - return true; + //print " $y1/$m "; + $t = adodb_mktime(0,0,0,$m,13,$y1); + if ("$y1-$m-13 00:00:00" != adodb_date('Y-n-d H:i:s',$t)) { + print "$y1 error
"; + return false; + } + return true; } /** - Test Suite + Test Suite */ function adodb_date_test() { - error_reporting(E_ALL); - print "

Testing adodb_date and adodb_mktime. version=".ADODB_DATE_VERSION. "

"; - set_time_limit(0); - $fail = false; - - // This flag disables calling of PHP native functions, so we can properly test the code - if (!defined('ADODB_TEST_DATES')) define('ADODB_TEST_DATES',1); - - $t = adodb_mktime(0,0,0,6,1,2102); - if (!(adodb_date('Y-m-d',$t) == '2102-06-01')) print 'Error in '.adodb_date('Y-m-d',$t).'
'; - - $t = adodb_mktime(0,0,0,2,1,2102); - if (!(adodb_date('Y-m-d',$t) == '2102-02-01')) print 'Error in '.adodb_date('Y-m-d',$t).'
'; - - - print "

Testing gregorian <=> julian conversion

"; - $t = adodb_mktime(0,0,0,10,11,1492); - //http://www.holidayorigins.com/html/columbus_day.html - Friday check - if (!(adodb_date('D Y-m-d',$t) == 'Fri 1492-10-11')) print 'Error in Columbus landing
'; - - $t = adodb_mktime(0,0,0,2,29,1500); - if (!(adodb_date('Y-m-d',$t) == '1500-02-29')) print 'Error in julian leap years
'; - - $t = adodb_mktime(0,0,0,2,29,1700); - if (!(adodb_date('Y-m-d',$t) == '1700-03-01')) print 'Error in gregorian leap years
'; - - print adodb_mktime(0,0,0,10,4,1582).' '; - print adodb_mktime(0,0,0,10,15,1582); - $diff = (adodb_mktime(0,0,0,10,15,1582) - adodb_mktime(0,0,0,10,4,1582)); - if ($diff != 3600*24) print " Error in gregorian correction = ".($diff/3600/24)." days
"; - - print " 15 Oct 1582, Fri=".(adodb_dow(1582,10,15) == 5 ? 'Fri' : 'Error')."
"; - print " 4 Oct 1582, Thu=".(adodb_dow(1582,10,4) == 4 ? 'Thu' : 'Error')."
"; - - print "

Testing overflow

"; - - $t = adodb_mktime(0,0,0,3,33,1965); - if (!(adodb_date('Y-m-d',$t) == '1965-04-02')) print 'Error in day overflow 1
'; - $t = adodb_mktime(0,0,0,4,33,1971); - if (!(adodb_date('Y-m-d',$t) == '1971-05-03')) print 'Error in day overflow 2
'; - $t = adodb_mktime(0,0,0,1,60,1965); - if (!(adodb_date('Y-m-d',$t) == '1965-03-01')) print 'Error in day overflow 3 '.adodb_date('Y-m-d',$t).'
'; - $t = adodb_mktime(0,0,0,12,32,1965); - if (!(adodb_date('Y-m-d',$t) == '1966-01-01')) print 'Error in day overflow 4 '.adodb_date('Y-m-d',$t).'
'; - $t = adodb_mktime(0,0,0,12,63,1965); - if (!(adodb_date('Y-m-d',$t) == '1966-02-01')) print 'Error in day overflow 5 '.adodb_date('Y-m-d',$t).'
'; - $t = adodb_mktime(0,0,0,13,3,1965); - if (!(adodb_date('Y-m-d',$t) == '1966-01-03')) print 'Error in mth overflow 1
'; - - print "Testing 2-digit => 4-digit year conversion

"; - if (adodb_year_digit_check(00) != 2000) print "Err 2-digit 2000
"; - if (adodb_year_digit_check(10) != 2010) print "Err 2-digit 2010
"; - if (adodb_year_digit_check(20) != 2020) print "Err 2-digit 2020
"; - if (adodb_year_digit_check(30) != 2030) print "Err 2-digit 2030
"; - if (adodb_year_digit_check(40) != 1940) print "Err 2-digit 1940
"; - if (adodb_year_digit_check(50) != 1950) print "Err 2-digit 1950
"; - if (adodb_year_digit_check(90) != 1990) print "Err 2-digit 1990
"; - - // Test string formating - print "

Testing date formating

"; - $fmt = '\d\a\t\e T Y-m-d H:i:s a A d D F g G h H i j l L m M n O \R\F\C822 r s t U w y Y z Z 2003'; - $s1 = date($fmt,0); - $s2 = adodb_date($fmt,0); - if ($s1 != $s2) { - print " date() 0 failed
$s1
$s2
"; - } - flush(); - for ($i=100; --$i > 0; ) { - - $ts = 3600.0*((rand()%60000)+(rand()%60000))+(rand()%60000); - $s1 = date($fmt,$ts); - $s2 = adodb_date($fmt,$ts); - //print "$s1
$s2

"; - $pos = strcmp($s1,$s2); - - if (($s1) != ($s2)) { - for ($j=0,$k=strlen($s1); $j < $k; $j++) { - if ($s1[$j] != $s2[$j]) { - print substr($s1,$j).' '; - break; - } - } - print "Error date(): $ts

+    error_reporting(E_ALL);
+    print "

Testing adodb_date and adodb_mktime. version=".ADODB_DATE_VERSION. "

"; + set_time_limit(0); + $fail = false; + + // This flag disables calling of PHP native functions, so we can properly test the code + if (!defined('ADODB_TEST_DATES')) define('ADODB_TEST_DATES',1); + + $t = adodb_mktime(0,0,0,6,1,2102); + if (!(adodb_date('Y-m-d',$t) == '2102-06-01')) print 'Error in '.adodb_date('Y-m-d',$t).'
'; + + $t = adodb_mktime(0,0,0,2,1,2102); + if (!(adodb_date('Y-m-d',$t) == '2102-02-01')) print 'Error in '.adodb_date('Y-m-d',$t).'
'; + + + print "

Testing gregorian <=> julian conversion

"; + $t = adodb_mktime(0,0,0,10,11,1492); + //http://www.holidayorigins.com/html/columbus_day.html - Friday check + if (!(adodb_date('D Y-m-d',$t) == 'Fri 1492-10-11')) print 'Error in Columbus landing
'; + + $t = adodb_mktime(0,0,0,2,29,1500); + if (!(adodb_date('Y-m-d',$t) == '1500-02-29')) print 'Error in julian leap years
'; + + $t = adodb_mktime(0,0,0,2,29,1700); + if (!(adodb_date('Y-m-d',$t) == '1700-03-01')) print 'Error in gregorian leap years
'; + + print adodb_mktime(0,0,0,10,4,1582).' '; + print adodb_mktime(0,0,0,10,15,1582); + $diff = (adodb_mktime(0,0,0,10,15,1582) - adodb_mktime(0,0,0,10,4,1582)); + if ($diff != 3600*24) print " Error in gregorian correction = ".($diff/3600/24)." days
"; + + print " 15 Oct 1582, Fri=".(adodb_dow(1582,10,15) == 5 ? 'Fri' : 'Error')."
"; + print " 4 Oct 1582, Thu=".(adodb_dow(1582,10,4) == 4 ? 'Thu' : 'Error')."
"; + + print "

Testing overflow

"; + + $t = adodb_mktime(0,0,0,3,33,1965); + if (!(adodb_date('Y-m-d',$t) == '1965-04-02')) print 'Error in day overflow 1
'; + $t = adodb_mktime(0,0,0,4,33,1971); + if (!(adodb_date('Y-m-d',$t) == '1971-05-03')) print 'Error in day overflow 2
'; + $t = adodb_mktime(0,0,0,1,60,1965); + if (!(adodb_date('Y-m-d',$t) == '1965-03-01')) print 'Error in day overflow 3 '.adodb_date('Y-m-d',$t).'
'; + $t = adodb_mktime(0,0,0,12,32,1965); + if (!(adodb_date('Y-m-d',$t) == '1966-01-01')) print 'Error in day overflow 4 '.adodb_date('Y-m-d',$t).'
'; + $t = adodb_mktime(0,0,0,12,63,1965); + if (!(adodb_date('Y-m-d',$t) == '1966-02-01')) print 'Error in day overflow 5 '.adodb_date('Y-m-d',$t).'
'; + $t = adodb_mktime(0,0,0,13,3,1965); + if (!(adodb_date('Y-m-d',$t) == '1966-01-03')) print 'Error in mth overflow 1
'; + + print "Testing 2-digit => 4-digit year conversion

"; + if (adodb_year_digit_check(00) != 2000) print "Err 2-digit 2000
"; + if (adodb_year_digit_check(10) != 2010) print "Err 2-digit 2010
"; + if (adodb_year_digit_check(20) != 2020) print "Err 2-digit 2020
"; + if (adodb_year_digit_check(30) != 2030) print "Err 2-digit 2030
"; + if (adodb_year_digit_check(40) != 1940) print "Err 2-digit 1940
"; + if (adodb_year_digit_check(50) != 1950) print "Err 2-digit 1950
"; + if (adodb_year_digit_check(90) != 1990) print "Err 2-digit 1990
"; + + // Test string formating + print "

Testing date formating

"; + $fmt = '\d\a\t\e T Y-m-d H:i:s a A d D F g G h H i j l L m M n O \R\F\C822 r s t U w y Y z Z 2003'; + $s1 = date($fmt,0); + $s2 = adodb_date($fmt,0); + if ($s1 != $s2) { + print " date() 0 failed
$s1
$s2
"; + } + flush(); + for ($i=100; --$i > 0; ) { + + $ts = 3600.0*((rand()%60000)+(rand()%60000))+(rand()%60000); + $s1 = date($fmt,$ts); + $s2 = adodb_date($fmt,$ts); + //print "$s1
$s2

"; + $pos = strcmp($s1,$s2); + + if (($s1) != ($s2)) { + for ($j=0,$k=strlen($s1); $j < $k; $j++) { + if ($s1[$j] != $s2[$j]) { + print substr($s1,$j).' '; + break; + } + } + print "Error date(): $ts

   \"$s1\" (date len=".strlen($s1).")
   \"$s2\" (adodb_date len=".strlen($s2).")

"; - $fail = true; - } - - $a1 = getdate($ts); - $a2 = adodb_getdate($ts); - $rez = array_diff($a1,$a2); - if (sizeof($rez)>0) { - print "Error getdate() $ts
"; - print_r($a1); - print "
"; - print_r($a2); - print "

"; - $fail = true; - } - } - - // Test generation of dates outside 1901-2038 - print "

Testing random dates between 100 and 4000

"; - adodb_date_test_date(100,1); - for ($i=100; --$i >= 0;) { - $y1 = 100+rand(0,1970-100); - $m = rand(1,12); - adodb_date_test_date($y1,$m); - - $y1 = 3000-rand(0,3000-1970); - adodb_date_test_date($y1,$m); - } - print '

'; - $start = 1960+rand(0,10); - $yrs = 12; - $i = 365.25*86400*($start-1970); - $offset = 36000+rand(10000,60000); - $max = 365*$yrs*86400; - $lastyear = 0; - - // we generate a timestamp, convert it to a date, and convert it back to a timestamp - // and check if the roundtrip broke the original timestamp value. - print "Testing $start to ".($start+$yrs).", or $max seconds, offset=$offset: "; - - for ($max += $i; $i < $max; $i += $offset) { - $ret = adodb_date('m,d,Y,H,i,s',$i); - $arr = explode(',',$ret); - if ($lastyear != $arr[2]) { - $lastyear = $arr[2]; - print " $lastyear "; - flush(); - } - $newi = adodb_mktime($arr[3],$arr[4],$arr[5],$arr[0],$arr[1],$arr[2]); - if ($i != $newi) { - print "Error at $i, adodb_mktime returned $newi ($ret)"; - $fail = true; - break; - } - } - - if (!$fail) print "

Passed !

"; - else print "

Failed :-(

"; + $fail = true; + } + + $a1 = getdate($ts); + $a2 = adodb_getdate($ts); + $rez = array_diff($a1,$a2); + if (sizeof($rez)>0) { + print "Error getdate() $ts
"; + print_r($a1); + print "
"; + print_r($a2); + print "

"; + $fail = true; + } + } + + // Test generation of dates outside 1901-2038 + print "

Testing random dates between 100 and 4000

"; + adodb_date_test_date(100,1); + for ($i=100; --$i >= 0;) { + $y1 = 100+rand(0,1970-100); + $m = rand(1,12); + adodb_date_test_date($y1,$m); + + $y1 = 3000-rand(0,3000-1970); + adodb_date_test_date($y1,$m); + } + print '

'; + $start = 1960+rand(0,10); + $yrs = 12; + $i = 365.25*86400*($start-1970); + $offset = 36000+rand(10000,60000); + $max = 365*$yrs*86400; + $lastyear = 0; + + // we generate a timestamp, convert it to a date, and convert it back to a timestamp + // and check if the roundtrip broke the original timestamp value. + print "Testing $start to ".($start+$yrs).", or $max seconds, offset=$offset: "; + + for ($max += $i; $i < $max; $i += $offset) { + $ret = adodb_date('m,d,Y,H,i,s',$i); + $arr = explode(',',$ret); + if ($lastyear != $arr[2]) { + $lastyear = $arr[2]; + print " $lastyear "; + flush(); + } + $newi = adodb_mktime($arr[3],$arr[4],$arr[5],$arr[0],$arr[1],$arr[2]); + if ($i != $newi) { + print "Error at $i, adodb_mktime returned $newi ($ret)"; + $fail = true; + break; + } + } + + if (!$fail) print "

Passed !

"; + else print "

Failed :-(

"; } /** - Returns day of week, 0 = Sunday,... 6=Saturday. - Algorithm from PEAR::Date_Calc + Returns day of week, 0 = Sunday,... 6=Saturday. + Algorithm from PEAR::Date_Calc */ function adodb_dow($year, $month, $day) { @@ -428,28 +428,28 @@ every 400 years. Thursday, October 4, 1582 (Julian) was followed immediately by Friday, October 15, 1582 (Gregorian). */ - if ($year <= 1582) { - if ($year < 1582 || - ($year == 1582 && ($month < 10 || ($month == 10 && $day < 15)))) $greg_correction = 3; - else - $greg_correction = 0; - } else - $greg_correction = 0; - - if($month > 2) - $month -= 2; - else { - $month += 10; - $year--; - } - - $day = ( floor((13 * $month - 1) / 5) + - $day + ($year % 100) + - floor(($year % 100) / 4) + - floor(($year / 100) / 4) - 2 * - floor($year / 100) + 77); - - return (($day - 7 * floor($day / 7))) + $greg_correction; + if ($year <= 1582) { + if ($year < 1582 || + ($year == 1582 && ($month < 10 || ($month == 10 && $day < 15)))) $greg_correction = 3; + else + $greg_correction = 0; + } else + $greg_correction = 0; + + if($month > 2) + $month -= 2; + else { + $month += 10; + $year--; + } + + $day = ( floor((13 * $month - 1) / 5) + + $day + ($year % 100) + + floor(($year % 100) / 4) + + floor(($year / 100) / 4) - 2 * + floor($year / 100) + 77); + + return (($day - 7 * floor($day / 7))) + $greg_correction; } @@ -459,16 +459,16 @@ Thursday, October 4, 1582 (Julian) was followed immediately by Friday, October 1 */ function _adodb_is_leap_year($year) { - if ($year % 4 != 0) return false; + if ($year % 4 != 0) return false; - if ($year % 400 == 0) { - return true; - // if gregorian calendar (>1582), century not-divisible by 400 is not leap - } else if ($year > 1582 && $year % 100 == 0 ) { - return false; - } + if ($year % 400 == 0) { + return true; + // if gregorian calendar (>1582), century not-divisible by 400 is not leap + } else if ($year > 1582 && $year % 100 == 0 ) { + return false; + } - return true; + return true; } /** @@ -476,34 +476,34 @@ function _adodb_is_leap_year($year) */ function adodb_is_leap_year($year) { - return _adodb_is_leap_year(adodb_year_digit_check($year)); + return _adodb_is_leap_year(adodb_year_digit_check($year)); } /** - Fix 2-digit years. Works for any century. - Assumes that if 2-digit is more than 30 years in future, then previous century. + Fix 2-digit years. Works for any century. + Assumes that if 2-digit is more than 30 years in future, then previous century. */ function adodb_year_digit_check($y) { - if ($y < 100) { - - $yr = (integer) date("Y"); - $century = (integer) ($yr /100); - - if ($yr%100 > 50) { - $c1 = $century + 1; - $c0 = $century; - } else { - $c1 = $century; - $c0 = $century - 1; - } - $c1 *= 100; - // if 2-digit year is less than 30 years in future, set it to this century - // otherwise if more than 30 years in future, then we set 2-digit year to the prev century. - if (($y + $c1) < $yr+30) $y = $y + $c1; - else $y = $y + $c0*100; - } - return $y; + if ($y < 100) { + + $yr = (integer) date("Y"); + $century = (integer) ($yr /100); + + if ($yr%100 > 50) { + $c1 = $century + 1; + $c0 = $century; + } else { + $c1 = $century; + $c0 = $century - 1; + } + $c1 *= 100; + // if 2-digit year is less than 30 years in future, set it to this century + // otherwise if more than 30 years in future, then we set 2-digit year to the prev century. + if (($y + $c1) < $yr+30) $y = $y + $c1; + else $y = $y + $c0*100; + } + return $y; } /** @@ -512,401 +512,401 @@ function adodb_year_digit_check($y) function adodb_get_gmt_diff() { static $TZ; - if (isset($TZ)) return $TZ; + if (isset($TZ)) return $TZ; - $TZ = mktime(0,0,0,1,2,1970,0) - gmmktime(0,0,0,1,2,1970,0); - return $TZ; + $TZ = mktime(0,0,0,1,2,1970,0) - gmmktime(0,0,0,1,2,1970,0); + return $TZ; } /** - Returns an array with date info. + Returns an array with date info. */ function adodb_getdate($d=false,$fast=false) { - if ($d === false) return getdate(); - if (!defined('ADODB_TEST_DATES')) { - if ((abs($d) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range - if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0) // if windows, must be +ve integer - return @getdate($d); - } - } - return _adodb_getdate($d); + if ($d === false) return getdate(); + if (!defined('ADODB_TEST_DATES')) { + if ((abs($d) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range + if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0) // if windows, must be +ve integer + return @getdate($d); + } + } + return _adodb_getdate($d); } /** - Low-level function that returns the getdate() array. We have a special - $fast flag, which if set to true, will return fewer array values, - and is much faster as it does not calculate dow, etc. + Low-level function that returns the getdate() array. We have a special + $fast flag, which if set to true, will return fewer array values, + and is much faster as it does not calculate dow, etc. */ function _adodb_getdate($origd=false,$fast=false,$is_gmt=false) { - $d = $origd - ($is_gmt ? 0 : adodb_get_gmt_diff()); - - $_day_power = 86400; - $_hour_power = 3600; - $_min_power = 60; - - if ($d < -12219321600) $d -= 86400*10; // if 15 Oct 1582 or earlier, gregorian correction - - $_month_table_normal = array("",31,28,31,30,31,30,31,31,30,31,30,31); - $_month_table_leaf = array("",31,29,31,30,31,30,31,31,30,31,30,31); - - if ($d < 0) { - $origd = $d; - // The valid range of a 32bit signed timestamp is typically from - // Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT - for ($a = 1970 ; --$a >= 0;) { - $lastd = $d; - - if ($leaf = _adodb_is_leap_year($a)) { - $d += $_day_power * 366; - } else - $d += $_day_power * 365; - if ($d >= 0) { - $year = $a; - break; - } - } - - $secsInYear = 86400 * ($leaf ? 366 : 365) + $lastd; - - $d = $lastd; - $mtab = ($leaf) ? $_month_table_leaf : $_month_table_normal; - for ($a = 13 ; --$a > 0;) { - $lastd = $d; - $d += $mtab[$a] * $_day_power; - if ($d >= 0) { - $month = $a; - $ndays = $mtab[$a]; - break; - } - } - - $d = $lastd; - $day = $ndays + ceil(($d+1) / ($_day_power)); - - $d += ($ndays - $day+1)* $_day_power; - $hour = floor($d/$_hour_power); - - } else { - - for ($a = 1970 ;; $a++) { - $lastd = $d; - - if ($leaf = _adodb_is_leap_year($a)) { - $d -= $_day_power * 366; - } else - $d -= $_day_power * 365; - if ($d < 0) { - $year = $a; - break; - } - } - $secsInYear = $lastd; - $d = $lastd; - $mtab = ($leaf) ? $_month_table_leaf : $_month_table_normal; - for ($a = 1 ; $a <= 12; $a++) { - $lastd = $d; - $d -= $mtab[$a] * $_day_power; - if ($d < 0) { - $month = $a; - $ndays = $mtab[$a]; - break; - } - } - $d = $lastd; - $day = ceil(($d+1) / $_day_power); - $d = $d - ($day-1) * $_day_power; - $hour = floor($d /$_hour_power); - } - - $d -= $hour * $_hour_power; - $min = floor($d/$_min_power); - $secs = $d - $min * $_min_power; - if ($fast) { - return array( - 'seconds' => $secs, - 'minutes' => $min, - 'hours' => $hour, - 'mday' => $day, - 'mon' => $month, - 'year' => $year, - 'yday' => floor($secsInYear/$_day_power), - 'leap' => $leaf, - 'ndays' => $ndays - ); - } - - - $dow = adodb_dow($year,$month,$day); - - return array( - 'seconds' => $secs, - 'minutes' => $min, - 'hours' => $hour, - 'mday' => $day, - 'wday' => $dow, - 'mon' => $month, - 'year' => $year, - 'yday' => floor($secsInYear/$_day_power), - 'weekday' => gmdate('l',$_day_power*(3+$dow)), - 'month' => gmdate('F',mktime(0,0,0,$month,2,1971)), - 0 => $origd - ); + $d = $origd - ($is_gmt ? 0 : adodb_get_gmt_diff()); + + $_day_power = 86400; + $_hour_power = 3600; + $_min_power = 60; + + if ($d < -12219321600) $d -= 86400*10; // if 15 Oct 1582 or earlier, gregorian correction + + $_month_table_normal = array("",31,28,31,30,31,30,31,31,30,31,30,31); + $_month_table_leaf = array("",31,29,31,30,31,30,31,31,30,31,30,31); + + if ($d < 0) { + $origd = $d; + // The valid range of a 32bit signed timestamp is typically from + // Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT + for ($a = 1970 ; --$a >= 0;) { + $lastd = $d; + + if ($leaf = _adodb_is_leap_year($a)) { + $d += $_day_power * 366; + } else + $d += $_day_power * 365; + if ($d >= 0) { + $year = $a; + break; + } + } + + $secsInYear = 86400 * ($leaf ? 366 : 365) + $lastd; + + $d = $lastd; + $mtab = ($leaf) ? $_month_table_leaf : $_month_table_normal; + for ($a = 13 ; --$a > 0;) { + $lastd = $d; + $d += $mtab[$a] * $_day_power; + if ($d >= 0) { + $month = $a; + $ndays = $mtab[$a]; + break; + } + } + + $d = $lastd; + $day = $ndays + ceil(($d+1) / ($_day_power)); + + $d += ($ndays - $day+1)* $_day_power; + $hour = floor($d/$_hour_power); + + } else { + + for ($a = 1970 ;; $a++) { + $lastd = $d; + + if ($leaf = _adodb_is_leap_year($a)) { + $d -= $_day_power * 366; + } else + $d -= $_day_power * 365; + if ($d < 0) { + $year = $a; + break; + } + } + $secsInYear = $lastd; + $d = $lastd; + $mtab = ($leaf) ? $_month_table_leaf : $_month_table_normal; + for ($a = 1 ; $a <= 12; $a++) { + $lastd = $d; + $d -= $mtab[$a] * $_day_power; + if ($d < 0) { + $month = $a; + $ndays = $mtab[$a]; + break; + } + } + $d = $lastd; + $day = ceil(($d+1) / $_day_power); + $d = $d - ($day-1) * $_day_power; + $hour = floor($d /$_hour_power); + } + + $d -= $hour * $_hour_power; + $min = floor($d/$_min_power); + $secs = $d - $min * $_min_power; + if ($fast) { + return array( + 'seconds' => $secs, + 'minutes' => $min, + 'hours' => $hour, + 'mday' => $day, + 'mon' => $month, + 'year' => $year, + 'yday' => floor($secsInYear/$_day_power), + 'leap' => $leaf, + 'ndays' => $ndays + ); + } + + + $dow = adodb_dow($year,$month,$day); + + return array( + 'seconds' => $secs, + 'minutes' => $min, + 'hours' => $hour, + 'mday' => $day, + 'wday' => $dow, + 'mon' => $month, + 'year' => $year, + 'yday' => floor($secsInYear/$_day_power), + 'weekday' => gmdate('l',$_day_power*(3+$dow)), + 'month' => gmdate('F',mktime(0,0,0,$month,2,1971)), + 0 => $origd + ); } function adodb_gmdate($fmt,$d=false) { - return adodb_date($fmt,$d,true); + return adodb_date($fmt,$d,true); } function adodb_date2($fmt, $d=false, $is_gmt=false) { - if ($d !== false) { - if (!preg_match( - "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})[ -]?(([0-9]{1,2}):?([0-9]{1,2}):?([0-9\.]{1,4}))?|", - ($d), $rr)) return adodb_date($fmt,false,$is_gmt); + if ($d !== false) { + if (!preg_match( + "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})[ -]?(([0-9]{1,2}):?([0-9]{1,2}):?([0-9\.]{1,4}))?|", + ($d), $rr)) return adodb_date($fmt,false,$is_gmt); - if ($rr[1] <= 100 && $rr[2]<= 1) return adodb_date($fmt,false,$is_gmt); + if ($rr[1] <= 100 && $rr[2]<= 1) return adodb_date($fmt,false,$is_gmt); - // h-m-s-MM-DD-YY - if (!isset($rr[5])) $d = adodb_mktime(0,0,0,$rr[2],$rr[3],$rr[1]); - else $d = @adodb_mktime($rr[5],$rr[6],$rr[7],$rr[2],$rr[3],$rr[1]); - } + // h-m-s-MM-DD-YY + if (!isset($rr[5])) $d = adodb_mktime(0,0,0,$rr[2],$rr[3],$rr[1]); + else $d = @adodb_mktime($rr[5],$rr[6],$rr[7],$rr[2],$rr[3],$rr[1]); + } - return adodb_date($fmt,$d,$is_gmt); + return adodb_date($fmt,$d,$is_gmt); } /** - Return formatted date based on timestamp $d + Return formatted date based on timestamp $d */ function adodb_date($fmt,$d=false,$is_gmt=false) { - if ($d === false) return date($fmt); - if (!defined('ADODB_TEST_DATES')) { - if ((abs($d) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range - if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0) // if windows, must be +ve integer - return @date($fmt,$d); - } - } - $_day_power = 86400; - - $arr = _adodb_getdate($d,true,$is_gmt); - $year = $arr['year']; - $month = $arr['mon']; - $day = $arr['mday']; - $hour = $arr['hours']; - $min = $arr['minutes']; - $secs = $arr['seconds']; - - $max = strlen($fmt); - $dates = ''; - - /* - at this point, we have the following integer vars to manipulate: - $year, $month, $day, $hour, $min, $secs - */ - for ($i=0; $i < $max; $i++) { - switch($fmt[$i]) { - case 'T': $dates .= date('T');break; - // YEAR - case 'L': $dates .= $arr['leap'] ? '1' : '0'; break; - case 'r': // Thu, 21 Dec 2000 16:01:07 +0200 - - $dates .= gmdate('D',$_day_power*(3+adodb_dow($year,$month,$day))).', ' - . ($day<10?' '.$day:$day) . ' '.date('M',mktime(0,0,0,$month,2,1971)).' '.$year.' '; - - if ($hour < 10) $dates .= '0'.$hour; else $dates .= $hour; - - if ($min < 10) $dates .= ':0'.$min; else $dates .= ':'.$min; - - if ($secs < 10) $dates .= ':0'.$secs; else $dates .= ':'.$secs; - - $gmt = adodb_get_gmt_diff(); - $dates .= sprintf(' %s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break; - - case 'Y': $dates .= $year; break; - case 'y': $dates .= substr($year,strlen($year)-2,2); break; - // MONTH - case 'm': if ($month<10) $dates .= '0'.$month; else $dates .= $month; break; - case 'Q': $dates .= ($month+3)>>2; break; - case 'n': $dates .= $month; break; - case 'M': $dates .= date('M',mktime(0,0,0,$month,2,1971)); break; - case 'F': $dates .= date('F',mktime(0,0,0,$month,2,1971)); break; - // DAY - case 't': $dates .= $arr['ndays']; break; - case 'z': $dates .= $arr['yday']; break; - case 'w': $dates .= adodb_dow($year,$month,$day); break; - case 'l': $dates .= gmdate('l',$_day_power*(3+adodb_dow($year,$month,$day))); break; - case 'D': $dates .= gmdate('D',$_day_power*(3+adodb_dow($year,$month,$day))); break; - case 'j': $dates .= $day; break; - case 'd': if ($day<10) $dates .= '0'.$day; else $dates .= $day; break; - case 'S': - $d10 = $day % 10; - if ($d10 == 1) $dates .= 'st'; - else if ($d10 == 2) $dates .= 'nd'; - else if ($d10 == 3) $dates .= 'rd'; - else $dates .= 'th'; - break; - - // HOUR - case 'Z': - $dates .= ($is_gmt) ? 0 : -adodb_get_gmt_diff(); break; - case 'O': - $gmt = ($is_gmt) ? 0 : adodb_get_gmt_diff(); - $dates .= sprintf('%s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break; - - case 'H': - if ($hour < 10) $dates .= '0'.$hour; - else $dates .= $hour; - break; - case 'h': - if ($hour > 12) $hh = $hour - 12; - else { - if ($hour == 0) $hh = '12'; - else $hh = $hour; - } - - if ($hh < 10) $dates .= '0'.$hh; - else $dates .= $hh; - break; - - case 'G': - $dates .= $hour; - break; - - case 'g': - if ($hour > 12) $hh = $hour - 12; - else { - if ($hour == 0) $hh = '12'; - else $hh = $hour; - } - $dates .= $hh; - break; - // MINUTES - case 'i': if ($min < 10) $dates .= '0'.$min; else $dates .= $min; break; - // SECONDS - case 'U': $dates .= $d; break; - case 's': if ($secs < 10) $dates .= '0'.$secs; else $dates .= $secs; break; - // AM/PM - // Note 00:00 to 11:59 is AM, while 12:00 to 23:59 is PM - case 'a': - if ($hour>=12) $dates .= 'pm'; - else $dates .= 'am'; - break; - case 'A': - if ($hour>=12) $dates .= 'PM'; - else $dates .= 'AM'; - break; - default: - $dates .= $fmt[$i]; break; - // ESCAPE - case "\\": - $i++; - if ($i < $max) $dates .= $fmt[$i]; - break; - } - } - return $dates; + if ($d === false) return date($fmt); + if (!defined('ADODB_TEST_DATES')) { + if ((abs($d) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range + if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0) // if windows, must be +ve integer + return @date($fmt,$d); + } + } + $_day_power = 86400; + + $arr = _adodb_getdate($d,true,$is_gmt); + $year = $arr['year']; + $month = $arr['mon']; + $day = $arr['mday']; + $hour = $arr['hours']; + $min = $arr['minutes']; + $secs = $arr['seconds']; + + $max = strlen($fmt); + $dates = ''; + + /* + at this point, we have the following integer vars to manipulate: + $year, $month, $day, $hour, $min, $secs + */ + for ($i=0; $i < $max; $i++) { + switch($fmt[$i]) { + case 'T': $dates .= date('T');break; + // YEAR + case 'L': $dates .= $arr['leap'] ? '1' : '0'; break; + case 'r': // Thu, 21 Dec 2000 16:01:07 +0200 + + $dates .= gmdate('D',$_day_power*(3+adodb_dow($year,$month,$day))).', ' + . ($day<10?' '.$day:$day) . ' '.date('M',mktime(0,0,0,$month,2,1971)).' '.$year.' '; + + if ($hour < 10) $dates .= '0'.$hour; else $dates .= $hour; + + if ($min < 10) $dates .= ':0'.$min; else $dates .= ':'.$min; + + if ($secs < 10) $dates .= ':0'.$secs; else $dates .= ':'.$secs; + + $gmt = adodb_get_gmt_diff(); + $dates .= sprintf(' %s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break; + + case 'Y': $dates .= $year; break; + case 'y': $dates .= substr($year,strlen($year)-2,2); break; + // MONTH + case 'm': if ($month<10) $dates .= '0'.$month; else $dates .= $month; break; + case 'Q': $dates .= ($month+3)>>2; break; + case 'n': $dates .= $month; break; + case 'M': $dates .= date('M',mktime(0,0,0,$month,2,1971)); break; + case 'F': $dates .= date('F',mktime(0,0,0,$month,2,1971)); break; + // DAY + case 't': $dates .= $arr['ndays']; break; + case 'z': $dates .= $arr['yday']; break; + case 'w': $dates .= adodb_dow($year,$month,$day); break; + case 'l': $dates .= gmdate('l',$_day_power*(3+adodb_dow($year,$month,$day))); break; + case 'D': $dates .= gmdate('D',$_day_power*(3+adodb_dow($year,$month,$day))); break; + case 'j': $dates .= $day; break; + case 'd': if ($day<10) $dates .= '0'.$day; else $dates .= $day; break; + case 'S': + $d10 = $day % 10; + if ($d10 == 1) $dates .= 'st'; + else if ($d10 == 2) $dates .= 'nd'; + else if ($d10 == 3) $dates .= 'rd'; + else $dates .= 'th'; + break; + + // HOUR + case 'Z': + $dates .= ($is_gmt) ? 0 : -adodb_get_gmt_diff(); break; + case 'O': + $gmt = ($is_gmt) ? 0 : adodb_get_gmt_diff(); + $dates .= sprintf('%s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break; + + case 'H': + if ($hour < 10) $dates .= '0'.$hour; + else $dates .= $hour; + break; + case 'h': + if ($hour > 12) $hh = $hour - 12; + else { + if ($hour == 0) $hh = '12'; + else $hh = $hour; + } + + if ($hh < 10) $dates .= '0'.$hh; + else $dates .= $hh; + break; + + case 'G': + $dates .= $hour; + break; + + case 'g': + if ($hour > 12) $hh = $hour - 12; + else { + if ($hour == 0) $hh = '12'; + else $hh = $hour; + } + $dates .= $hh; + break; + // MINUTES + case 'i': if ($min < 10) $dates .= '0'.$min; else $dates .= $min; break; + // SECONDS + case 'U': $dates .= $d; break; + case 's': if ($secs < 10) $dates .= '0'.$secs; else $dates .= $secs; break; + // AM/PM + // Note 00:00 to 11:59 is AM, while 12:00 to 23:59 is PM + case 'a': + if ($hour>=12) $dates .= 'pm'; + else $dates .= 'am'; + break; + case 'A': + if ($hour>=12) $dates .= 'PM'; + else $dates .= 'AM'; + break; + default: + $dates .= $fmt[$i]; break; + // ESCAPE + case "\\": + $i++; + if ($i < $max) $dates .= $fmt[$i]; + break; + } + } + return $dates; } /** - Returns a timestamp given a GMT/UTC time. - Note that $is_dst is not implemented and is ignored. + Returns a timestamp given a GMT/UTC time. + Note that $is_dst is not implemented and is ignored. */ function adodb_gmmktime($hr,$min,$sec,$mon,$day,$year,$is_dst=false) { - return adodb_mktime($hr,$min,$sec,$mon,$day,$year,$is_dst,true); + return adodb_mktime($hr,$min,$sec,$mon,$day,$year,$is_dst,true); } /** - Return a timestamp given a local time. Originally by jackbbs. - Note that $is_dst is not implemented and is ignored. + Return a timestamp given a local time. Originally by jackbbs. + Note that $is_dst is not implemented and is ignored. */ function adodb_mktime($hr,$min,$sec,$mon,$day,$year,$is_dst=false,$is_gmt=false) { - if (!defined('ADODB_TEST_DATES')) { - // for windows, we don't check 1970 because with timezone differences, - // 1 Jan 1970 could generate negative timestamp, which is illegal - if (!defined('ADODB_NO_NEGATIVE_TS') || ($year >= 1971)) - if (1901 < $year && $year < 2038) - return @mktime($hr,$min,$sec,$mon,$day,$year); - } - - $gmt_different = ($is_gmt) ? 0 : adodb_get_gmt_diff(); - - $hr = intval($hr); - $min = intval($min); - $sec = intval($sec); - $mon = intval($mon); - $day = intval($day); - $year = intval($year); - - - $year = adodb_year_digit_check($year); - - if ($mon > 12) { - $y = floor($mon / 12); - $year += $y; - $mon -= $y*12; - } - - $_day_power = 86400; - $_hour_power = 3600; - $_min_power = 60; - - $_month_table_normal = array("",31,28,31,30,31,30,31,31,30,31,30,31); - $_month_table_leaf = array("",31,29,31,30,31,30,31,31,30,31,30,31); - - $_total_date = 0; - if ($year >= 1970) { - for ($a = 1970 ; $a <= $year; $a++) { - $leaf = _adodb_is_leap_year($a); - if ($leaf == true) { - $loop_table = $_month_table_leaf; - $_add_date = 366; - } else { - $loop_table = $_month_table_normal; - $_add_date = 365; - } - if ($a < $year) { - $_total_date += $_add_date; - } else { - for($b=1;$b<$mon;$b++) { - $_total_date += $loop_table[$b]; - } - } - } - $_total_date +=$day-1; - $ret = $_total_date * $_day_power + $hr * $_hour_power + $min * $_min_power + $sec + $gmt_different; - - } else { - for ($a = 1969 ; $a >= $year; $a--) { - $leaf = _adodb_is_leap_year($a); - if ($leaf == true) { - $loop_table = $_month_table_leaf; - $_add_date = 366; - } else { - $loop_table = $_month_table_normal; - $_add_date = 365; - } - if ($a > $year) { $_total_date += $_add_date; - } else { - for($b=12;$b>$mon;$b--) { - $_total_date += $loop_table[$b]; - } - } - } - $_total_date += $loop_table[$mon] - $day; - - $_day_time = $hr * $_hour_power + $min * $_min_power + $sec; - $_day_time = $_day_power - $_day_time; - $ret = -( $_total_date * $_day_power + $_day_time - $gmt_different); - if ($ret < -12220185600) $ret += 10*86400; // if earlier than 5 Oct 1582 - gregorian correction - else if ($ret < -12219321600) $ret = -12219321600; // if in limbo, reset to 15 Oct 1582. - } - //print " dmy=$day/$mon/$year $hr:$min:$sec => " .$ret; - return $ret; + if (!defined('ADODB_TEST_DATES')) { + // for windows, we don't check 1970 because with timezone differences, + // 1 Jan 1970 could generate negative timestamp, which is illegal + if (!defined('ADODB_NO_NEGATIVE_TS') || ($year >= 1971)) + if (1901 < $year && $year < 2038) + return @mktime($hr,$min,$sec,$mon,$day,$year); + } + + $gmt_different = ($is_gmt) ? 0 : adodb_get_gmt_diff(); + + $hr = intval($hr); + $min = intval($min); + $sec = intval($sec); + $mon = intval($mon); + $day = intval($day); + $year = intval($year); + + + $year = adodb_year_digit_check($year); + + if ($mon > 12) { + $y = floor($mon / 12); + $year += $y; + $mon -= $y*12; + } + + $_day_power = 86400; + $_hour_power = 3600; + $_min_power = 60; + + $_month_table_normal = array("",31,28,31,30,31,30,31,31,30,31,30,31); + $_month_table_leaf = array("",31,29,31,30,31,30,31,31,30,31,30,31); + + $_total_date = 0; + if ($year >= 1970) { + for ($a = 1970 ; $a <= $year; $a++) { + $leaf = _adodb_is_leap_year($a); + if ($leaf == true) { + $loop_table = $_month_table_leaf; + $_add_date = 366; + } else { + $loop_table = $_month_table_normal; + $_add_date = 365; + } + if ($a < $year) { + $_total_date += $_add_date; + } else { + for($b=1;$b<$mon;$b++) { + $_total_date += $loop_table[$b]; + } + } + } + $_total_date +=$day-1; + $ret = $_total_date * $_day_power + $hr * $_hour_power + $min * $_min_power + $sec + $gmt_different; + + } else { + for ($a = 1969 ; $a >= $year; $a--) { + $leaf = _adodb_is_leap_year($a); + if ($leaf == true) { + $loop_table = $_month_table_leaf; + $_add_date = 366; + } else { + $loop_table = $_month_table_normal; + $_add_date = 365; + } + if ($a > $year) { $_total_date += $_add_date; + } else { + for($b=12;$b>$mon;$b--) { + $_total_date += $loop_table[$b]; + } + } + } + $_total_date += $loop_table[$mon] - $day; + + $_day_time = $hr * $_hour_power + $min * $_min_power + $sec; + $_day_time = $_day_power - $_day_time; + $ret = -( $_total_date * $_day_power + $_day_time - $gmt_different); + if ($ret < -12220185600) $ret += 10*86400; // if earlier than 5 Oct 1582 - gregorian correction + else if ($ret < -12219321600) $ret = -12219321600; // if in limbo, reset to 15 Oct 1582. + } + //print " dmy=$day/$mon/$year $hr:$min:$sec => " .$ret; + return $ret; } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/drivers/adodb-access.inc.php b/lib/WikiDB/adodb/drivers/adodb-access.inc.php index 2f77c3e99..c0d33cbe5 100644 --- a/lib/WikiDB/adodb/drivers/adodb-access.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-access.inc.php @@ -11,74 +11,74 @@ V4.22 15 Apr 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights rese Microsoft Access data driver. Requires ODBC. Works only on MS Windows. */ if (!defined('_ADODB_ODBC_LAYER')) { - include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); + include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); } if (!defined('_ADODB_ACCESS')) { - define('_ADODB_ACCESS',1); + define('_ADODB_ACCESS',1); class ADODB_access extends ADODB_odbc { - var $databaseType = 'access'; - var $hasTop = 'top'; // support mssql SELECT TOP 10 * FROM TABLE - var $fmtDate = "#Y-m-d#"; - var $fmtTimeStamp = "#Y-m-d h:i:sA#"; // note not comma - var $_bindInputArray = false; // strangely enough, setting to true does not work reliably - var $sysDate = "FORMAT(NOW,'yyyy-mm-dd')"; - var $sysTimeStamp = 'NOW'; - var $hasTransactions = false; + var $databaseType = 'access'; + var $hasTop = 'top'; // support mssql SELECT TOP 10 * FROM TABLE + var $fmtDate = "#Y-m-d#"; + var $fmtTimeStamp = "#Y-m-d h:i:sA#"; // note not comma + var $_bindInputArray = false; // strangely enough, setting to true does not work reliably + var $sysDate = "FORMAT(NOW,'yyyy-mm-dd')"; + var $sysTimeStamp = 'NOW'; + var $hasTransactions = false; - function ADODB_access() - { - global $ADODB_EXTENSION; + function ADODB_access() + { + global $ADODB_EXTENSION; - $ADODB_EXTENSION = false; - $this->ADODB_odbc(); - } + $ADODB_EXTENSION = false; + $this->ADODB_odbc(); + } - function Time() - { - return time(); - } + function Time() + { + return time(); + } - function BeginTrans() { return false;} + function BeginTrans() { return false;} - function IfNull( $field, $ifNull ) - { - return " IIF(IsNull($field), $ifNull, $field) "; // if Access - } + function IfNull( $field, $ifNull ) + { + return " IIF(IsNull($field), $ifNull, $field) "; // if Access + } /* - function &MetaTables() - { - global $ADODB_FETCH_MODE; + function &MetaTables() + { + global $ADODB_FETCH_MODE; - $savem = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - $qid = odbc_tables($this->_connectionID); - $rs = new ADORecordSet_odbc($qid); - $ADODB_FETCH_MODE = $savem; - if (!$rs) return false; + $savem = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + $qid = odbc_tables($this->_connectionID); + $rs = new ADORecordSet_odbc($qid); + $ADODB_FETCH_MODE = $savem; + if (!$rs) return false; - $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; + $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; - $arr = &$rs->GetArray(); - //print_pre($arr); - $arr2 = array(); - for ($i=0; $i < sizeof($arr); $i++) { - if ($arr[$i][2] && $arr[$i][3] != 'SYSTEM TABLE') - $arr2[] = $arr[$i][2]; - } - return $arr2; - }*/ + $arr = &$rs->GetArray(); + //print_pre($arr); + $arr2 = array(); + for ($i=0; $i < sizeof($arr); $i++) { + if ($arr[$i][2] && $arr[$i][3] != 'SYSTEM TABLE') + $arr2[] = $arr[$i][2]; + } + return $arr2; + }*/ } class ADORecordSet_access extends ADORecordSet_odbc { - var $databaseType = "access"; + var $databaseType = "access"; - function ADORecordSet_access($id,$mode=false) - { - return $this->ADORecordSet_odbc($id,$mode); - } + function ADORecordSet_access($id,$mode=false) + { + return $this->ADORecordSet_odbc($id,$mode); + } }// class } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/drivers/adodb-ado.inc.php b/lib/WikiDB/adodb/drivers/adodb-ado.inc.php index 24cf613d3..7259e6de8 100644 --- a/lib/WikiDB/adodb/drivers/adodb-ado.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-ado.inc.php @@ -8,607 +8,607 @@ Set tabs to 4 for best viewing. Latest version is available at http://php.weblogs.com/ - Microsoft ADO data driver. Requires ADO. Works only on MS Windows. + Microsoft ADO data driver. Requires ADO. Works only on MS Windows. */ define("_ADODB_ADO_LAYER", 1 ); /*-------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------*/ class ADODB_ado extends ADOConnection { - var $databaseType = "ado"; - var $_bindInputArray = false; - var $fmtDate = "'Y-m-d'"; - var $fmtTimeStamp = "'Y-m-d, h:i:sA'"; - var $replaceQuote = "''"; // string to use to replace quotes - var $dataProvider = "ado"; - var $hasAffectedRows = true; - var $adoParameterType = 201; // 201 = long varchar, 203=long wide varchar, 205 = long varbinary - var $_affectedRows = false; - var $_thisTransactions; - var $_cursor_type = 3; // 3=adOpenStatic,0=adOpenForwardOnly,1=adOpenKeyset,2=adOpenDynamic - var $_cursor_location = 3; // 2=adUseServer, 3 = adUseClient; - var $_lock_type = -1; - var $_execute_option = -1; - var $poorAffectedRows = true; - var $charPage; - - function ADODB_ado() - { - $this->_affectedRows = new VARIANT; - } - - function ServerInfo() - { - if (!empty($this->_connectionID)) $desc = $this->_connectionID->provider; - return array('description' => $desc, 'version' => ''); - } - - function _affectedrows() - { - if (PHP_VERSION >= 5) return $this->_affectedRows; - - return $this->_affectedRows->value; - } - - // you can also pass a connection string like this: - // - // $DB->Connect('USER ID=sa;PASSWORD=pwd;SERVER=mangrove;DATABASE=ai',false,false,'SQLOLEDB'); - function _connect($argHostname, $argUsername, $argPassword, $argProvider= 'MSDASQL') - { - $u = 'UID'; - $p = 'PWD'; - - if (!empty($this->charPage)) - $dbc = new COM('ADODB.Connection',null,$this->charPage); - else - $dbc = new COM('ADODB.Connection'); - - if (! $dbc) return false; - - /* special support if provider is mssql or access */ - if ($argProvider=='mssql') { - $u = 'User Id'; //User parameter name for OLEDB - $p = 'Password'; - $argProvider = "SQLOLEDB"; // SQL Server Provider - - // not yet - //if ($argDatabasename) $argHostname .= ";Initial Catalog=$argDatabasename"; - - //use trusted conection for SQL if username not specified - if (!$argUsername) $argHostname .= ";Trusted_Connection=Yes"; - } else if ($argProvider=='access') - $argProvider = "Microsoft.Jet.OLEDB.4.0"; // Microsoft Jet Provider - - if ($argProvider) $dbc->Provider = $argProvider; - - if ($argUsername) $argHostname .= ";$u=$argUsername"; - if ($argPassword)$argHostname .= ";$p=$argPassword"; - - if ($this->debug) ADOConnection::outp( "Host=".$argHostname."
\n version=$dbc->version"); - // @ added below for php 4.0.1 and earlier - @$dbc->Open((string) $argHostname); - - $this->_connectionID = $dbc; - - $dbc->CursorLocation = $this->_cursor_location; - return $dbc->State > 0; - } - - // returns true or false - function _pconnect($argHostname, $argUsername, $argPassword, $argProvider='MSDASQL') - { - return $this->_connect($argHostname,$argUsername,$argPassword,$argProvider); - } + var $databaseType = "ado"; + var $_bindInputArray = false; + var $fmtDate = "'Y-m-d'"; + var $fmtTimeStamp = "'Y-m-d, h:i:sA'"; + var $replaceQuote = "''"; // string to use to replace quotes + var $dataProvider = "ado"; + var $hasAffectedRows = true; + var $adoParameterType = 201; // 201 = long varchar, 203=long wide varchar, 205 = long varbinary + var $_affectedRows = false; + var $_thisTransactions; + var $_cursor_type = 3; // 3=adOpenStatic,0=adOpenForwardOnly,1=adOpenKeyset,2=adOpenDynamic + var $_cursor_location = 3; // 2=adUseServer, 3 = adUseClient; + var $_lock_type = -1; + var $_execute_option = -1; + var $poorAffectedRows = true; + var $charPage; + + function ADODB_ado() + { + $this->_affectedRows = new VARIANT; + } + + function ServerInfo() + { + if (!empty($this->_connectionID)) $desc = $this->_connectionID->provider; + return array('description' => $desc, 'version' => ''); + } + + function _affectedrows() + { + if (PHP_VERSION >= 5) return $this->_affectedRows; + + return $this->_affectedRows->value; + } + + // you can also pass a connection string like this: + // + // $DB->Connect('USER ID=sa;PASSWORD=pwd;SERVER=mangrove;DATABASE=ai',false,false,'SQLOLEDB'); + function _connect($argHostname, $argUsername, $argPassword, $argProvider= 'MSDASQL') + { + $u = 'UID'; + $p = 'PWD'; + + if (!empty($this->charPage)) + $dbc = new COM('ADODB.Connection',null,$this->charPage); + else + $dbc = new COM('ADODB.Connection'); + + if (! $dbc) return false; + + /* special support if provider is mssql or access */ + if ($argProvider=='mssql') { + $u = 'User Id'; //User parameter name for OLEDB + $p = 'Password'; + $argProvider = "SQLOLEDB"; // SQL Server Provider + + // not yet + //if ($argDatabasename) $argHostname .= ";Initial Catalog=$argDatabasename"; + + //use trusted conection for SQL if username not specified + if (!$argUsername) $argHostname .= ";Trusted_Connection=Yes"; + } else if ($argProvider=='access') + $argProvider = "Microsoft.Jet.OLEDB.4.0"; // Microsoft Jet Provider + + if ($argProvider) $dbc->Provider = $argProvider; + + if ($argUsername) $argHostname .= ";$u=$argUsername"; + if ($argPassword)$argHostname .= ";$p=$argPassword"; + + if ($this->debug) ADOConnection::outp( "Host=".$argHostname."
\n version=$dbc->version"); + // @ added below for php 4.0.1 and earlier + @$dbc->Open((string) $argHostname); + + $this->_connectionID = $dbc; + + $dbc->CursorLocation = $this->_cursor_location; + return $dbc->State > 0; + } + + // returns true or false + function _pconnect($argHostname, $argUsername, $argPassword, $argProvider='MSDASQL') + { + return $this->_connect($argHostname,$argUsername,$argPassword,$argProvider); + } /* - adSchemaCatalogs = 1, - adSchemaCharacterSets = 2, - adSchemaCollations = 3, - adSchemaColumns = 4, - adSchemaCheckConstraints = 5, - adSchemaConstraintColumnUsage = 6, - adSchemaConstraintTableUsage = 7, - adSchemaKeyColumnUsage = 8, - adSchemaReferentialContraints = 9, - adSchemaTableConstraints = 10, - adSchemaColumnsDomainUsage = 11, - adSchemaIndexes = 12, - adSchemaColumnPrivileges = 13, - adSchemaTablePrivileges = 14, - adSchemaUsagePrivileges = 15, - adSchemaProcedures = 16, - adSchemaSchemata = 17, - adSchemaSQLLanguages = 18, - adSchemaStatistics = 19, - adSchemaTables = 20, - adSchemaTranslations = 21, - adSchemaProviderTypes = 22, - adSchemaViews = 23, - adSchemaViewColumnUsage = 24, - adSchemaViewTableUsage = 25, - adSchemaProcedureParameters = 26, - adSchemaForeignKeys = 27, - adSchemaPrimaryKeys = 28, - adSchemaProcedureColumns = 29, - adSchemaDBInfoKeywords = 30, - adSchemaDBInfoLiterals = 31, - adSchemaCubes = 32, - adSchemaDimensions = 33, - adSchemaHierarchies = 34, - adSchemaLevels = 35, - adSchemaMeasures = 36, - adSchemaProperties = 37, - adSchemaMembers = 38 + adSchemaCatalogs = 1, + adSchemaCharacterSets = 2, + adSchemaCollations = 3, + adSchemaColumns = 4, + adSchemaCheckConstraints = 5, + adSchemaConstraintColumnUsage = 6, + adSchemaConstraintTableUsage = 7, + adSchemaKeyColumnUsage = 8, + adSchemaReferentialContraints = 9, + adSchemaTableConstraints = 10, + adSchemaColumnsDomainUsage = 11, + adSchemaIndexes = 12, + adSchemaColumnPrivileges = 13, + adSchemaTablePrivileges = 14, + adSchemaUsagePrivileges = 15, + adSchemaProcedures = 16, + adSchemaSchemata = 17, + adSchemaSQLLanguages = 18, + adSchemaStatistics = 19, + adSchemaTables = 20, + adSchemaTranslations = 21, + adSchemaProviderTypes = 22, + adSchemaViews = 23, + adSchemaViewColumnUsage = 24, + adSchemaViewTableUsage = 25, + adSchemaProcedureParameters = 26, + adSchemaForeignKeys = 27, + adSchemaPrimaryKeys = 28, + adSchemaProcedureColumns = 29, + adSchemaDBInfoKeywords = 30, + adSchemaDBInfoLiterals = 31, + adSchemaCubes = 32, + adSchemaDimensions = 33, + adSchemaHierarchies = 34, + adSchemaLevels = 35, + adSchemaMeasures = 36, + adSchemaProperties = 37, + adSchemaMembers = 38 */ - function &MetaTables() - { - $arr= array(); - $dbc = $this->_connectionID; - - $adors=@$dbc->OpenSchema(20);//tables - if ($adors){ - $f = $adors->Fields(2);//table/view name - $t = $adors->Fields(3);//table type - while (!$adors->EOF){ - $tt=substr($t->value,0,6); - if ($tt!='SYSTEM' && $tt !='ACCESS') - $arr[]=$f->value; - //print $f->value . ' ' . $t->value.'
'; - $adors->MoveNext(); - } - $adors->Close(); - } - - return $arr; - } - - function &MetaColumns($table) - { - $table = strtoupper($table); - $arr= array(); - $dbc = $this->_connectionID; - - $adors=@$dbc->OpenSchema(4);//tables - - if ($adors){ - $t = $adors->Fields(2);//table/view name - while (!$adors->EOF){ - - - if (strtoupper($t->Value) == $table) { - - $fld = new ADOFieldObject(); - $c = $adors->Fields(3); - $fld->name = $c->Value; - $fld->type = 'CHAR'; // cannot discover type in ADO! - $fld->max_length = -1; - $arr[strtoupper($fld->name)]=$fld; - } - - $adors->MoveNext(); - } - $adors->Close(); - } - - return $arr; - } - - - - - /* returns queryID or false */ - function &_query($sql,$inputarr=false) - { - - $dbc = $this->_connectionID; - - // return rs - if ($inputarr) { - - if (!empty($this->charPage)) - $oCmd = new COM('ADODB.Command',null,$this->charPage); - else - $oCmd = new COM('ADODB.Command'); - $oCmd->ActiveConnection = $dbc; - $oCmd->CommandText = $sql; - $oCmd->CommandType = 1; - - foreach($inputarr as $val) { - // name, type, direction 1 = input, len, - $this->adoParameterType = 130; - $p = $oCmd->CreateParameter('name',$this->adoParameterType,1,strlen($val),$val); - //print $p->Type.' '.$p->value; - $oCmd->Parameters->Append($p); - } - $p = false; - $rs = $oCmd->Execute(); - $e = $dbc->Errors; - if ($dbc->Errors->Count > 0) return false; - return $rs; - } - - $rs = @$dbc->Execute($sql,$this->_affectedRows, $this->_execute_option); - /* - $rs = new COM('ADODB.Recordset'); - if ($rs) { - $rs->Open ($sql, $dbc, $this->_cursor_type,$this->_lock_type, $this->_execute_option); - } - */ - if ($dbc->Errors->Count > 0) return false; - if (! $rs) return false; - - if ($rs->State == 0) return true; // 0 = adStateClosed means no records returned - return $rs; - } - - - function BeginTrans() - { - if ($this->transOff) return true; - - if (isset($this->_thisTransactions)) - if (!$this->_thisTransactions) return false; - else { - $o = $this->_connectionID->Properties("Transaction DDL"); - $this->_thisTransactions = $o ? true : false; - if (!$o) return false; - } - @$this->_connectionID->BeginTrans(); - $this->transCnt += 1; - return true; - } - function CommitTrans($ok=true) - { - if (!$ok) return $this->RollbackTrans(); - if ($this->transOff) return true; - - @$this->_connectionID->CommitTrans(); - if ($this->transCnt) @$this->transCnt -= 1; - return true; - } - function RollbackTrans() { - if ($this->transOff) return true; - @$this->_connectionID->RollbackTrans(); - if ($this->transCnt) @$this->transCnt -= 1; - return true; - } - - /* Returns: the last error message from previous database operation */ - - function ErrorMsg() - { - $errc = $this->_connectionID->Errors; - if ($errc->Count == 0) return ''; - $err = $errc->Item($errc->Count-1); - return $err->Description; - } - - function ErrorNo() - { - $errc = $this->_connectionID->Errors; - if ($errc->Count == 0) return 0; - $err = $errc->Item($errc->Count-1); - return $err->NativeError; - } - - // returns true or false - function _close() - { - if ($this->_connectionID) $this->_connectionID->Close(); - $this->_connectionID = false; - return true; - } + function &MetaTables() + { + $arr= array(); + $dbc = $this->_connectionID; + + $adors=@$dbc->OpenSchema(20);//tables + if ($adors){ + $f = $adors->Fields(2);//table/view name + $t = $adors->Fields(3);//table type + while (!$adors->EOF){ + $tt=substr($t->value,0,6); + if ($tt!='SYSTEM' && $tt !='ACCESS') + $arr[]=$f->value; + //print $f->value . ' ' . $t->value.'
'; + $adors->MoveNext(); + } + $adors->Close(); + } + + return $arr; + } + + function &MetaColumns($table) + { + $table = strtoupper($table); + $arr= array(); + $dbc = $this->_connectionID; + + $adors=@$dbc->OpenSchema(4);//tables + + if ($adors){ + $t = $adors->Fields(2);//table/view name + while (!$adors->EOF){ + + + if (strtoupper($t->Value) == $table) { + + $fld = new ADOFieldObject(); + $c = $adors->Fields(3); + $fld->name = $c->Value; + $fld->type = 'CHAR'; // cannot discover type in ADO! + $fld->max_length = -1; + $arr[strtoupper($fld->name)]=$fld; + } + + $adors->MoveNext(); + } + $adors->Close(); + } + + return $arr; + } + + + + + /* returns queryID or false */ + function &_query($sql,$inputarr=false) + { + + $dbc = $this->_connectionID; + + // return rs + if ($inputarr) { + + if (!empty($this->charPage)) + $oCmd = new COM('ADODB.Command',null,$this->charPage); + else + $oCmd = new COM('ADODB.Command'); + $oCmd->ActiveConnection = $dbc; + $oCmd->CommandText = $sql; + $oCmd->CommandType = 1; + + foreach($inputarr as $val) { + // name, type, direction 1 = input, len, + $this->adoParameterType = 130; + $p = $oCmd->CreateParameter('name',$this->adoParameterType,1,strlen($val),$val); + //print $p->Type.' '.$p->value; + $oCmd->Parameters->Append($p); + } + $p = false; + $rs = $oCmd->Execute(); + $e = $dbc->Errors; + if ($dbc->Errors->Count > 0) return false; + return $rs; + } + + $rs = @$dbc->Execute($sql,$this->_affectedRows, $this->_execute_option); + /* + $rs = new COM('ADODB.Recordset'); + if ($rs) { + $rs->Open ($sql, $dbc, $this->_cursor_type,$this->_lock_type, $this->_execute_option); + } + */ + if ($dbc->Errors->Count > 0) return false; + if (! $rs) return false; + + if ($rs->State == 0) return true; // 0 = adStateClosed means no records returned + return $rs; + } + + + function BeginTrans() + { + if ($this->transOff) return true; + + if (isset($this->_thisTransactions)) + if (!$this->_thisTransactions) return false; + else { + $o = $this->_connectionID->Properties("Transaction DDL"); + $this->_thisTransactions = $o ? true : false; + if (!$o) return false; + } + @$this->_connectionID->BeginTrans(); + $this->transCnt += 1; + return true; + } + function CommitTrans($ok=true) + { + if (!$ok) return $this->RollbackTrans(); + if ($this->transOff) return true; + + @$this->_connectionID->CommitTrans(); + if ($this->transCnt) @$this->transCnt -= 1; + return true; + } + function RollbackTrans() { + if ($this->transOff) return true; + @$this->_connectionID->RollbackTrans(); + if ($this->transCnt) @$this->transCnt -= 1; + return true; + } + + /* Returns: the last error message from previous database operation */ + + function ErrorMsg() + { + $errc = $this->_connectionID->Errors; + if ($errc->Count == 0) return ''; + $err = $errc->Item($errc->Count-1); + return $err->Description; + } + + function ErrorNo() + { + $errc = $this->_connectionID->Errors; + if ($errc->Count == 0) return 0; + $err = $errc->Item($errc->Count-1); + return $err->NativeError; + } + + // returns true or false + function _close() + { + if ($this->_connectionID) $this->_connectionID->Close(); + $this->_connectionID = false; + return true; + } } /*-------------------------------------------------------------------------------------- - Class Name: Recordset + Class Name: Recordset --------------------------------------------------------------------------------------*/ class ADORecordSet_ado extends ADORecordSet { - var $bind = false; - var $databaseType = "ado"; - var $dataProvider = "ado"; - var $_tarr = false; // caches the types - var $_flds; // and field objects - var $canSeek = true; - var $hideErrors = true; - - function ADORecordSet_ado($id,$mode=false) - { - if ($mode === false) { - global $ADODB_FETCH_MODE; - $mode = $ADODB_FETCH_MODE; - } - $this->fetchMode = $mode; - return $this->ADORecordSet($id,$mode); - } - - - // returns the field object - function FetchField($fieldOffset = -1) { - $off=$fieldOffset+1; // offsets begin at 1 - - $o= new ADOFieldObject(); - $rs = $this->_queryID; - $f = $rs->Fields($fieldOffset); - $o->name = $f->Name; - $t = $f->Type; - $o->type = $this->MetaType($t); - $o->max_length = $f->DefinedSize; - $o->ado_type = $t; - - - //print "off=$off name=$o->name type=$o->type len=$o->max_length
"; - return $o; - } - - /* Use associative array to get fields array */ - function Fields($colname) - { - if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname]; - if (!$this->bind) { - $this->bind = array(); - for ($i=0; $i < $this->_numOfFields; $i++) { - $o = $this->FetchField($i); - $this->bind[strtoupper($o->name)] = $i; - } - } - - return $this->fields[$this->bind[strtoupper($colname)]]; - } - - - function _initrs() - { - $rs = $this->_queryID; - $this->_numOfRows = $rs->RecordCount; - - $f = $rs->Fields; - $this->_numOfFields = $f->Count; - } - - - // should only be used to move forward as we normally use forward-only cursors - function _seek($row) - { - $rs = $this->_queryID; - // absoluteposition doesn't work -- my maths is wrong ? - // $rs->AbsolutePosition->$row-2; - // return true; - if ($this->_currentRow > $row) return false; - @$rs->Move((integer)$row - $this->_currentRow-1); //adBookmarkFirst - return true; - } + var $bind = false; + var $databaseType = "ado"; + var $dataProvider = "ado"; + var $_tarr = false; // caches the types + var $_flds; // and field objects + var $canSeek = true; + var $hideErrors = true; + + function ADORecordSet_ado($id,$mode=false) + { + if ($mode === false) { + global $ADODB_FETCH_MODE; + $mode = $ADODB_FETCH_MODE; + } + $this->fetchMode = $mode; + return $this->ADORecordSet($id,$mode); + } + + + // returns the field object + function FetchField($fieldOffset = -1) { + $off=$fieldOffset+1; // offsets begin at 1 + + $o= new ADOFieldObject(); + $rs = $this->_queryID; + $f = $rs->Fields($fieldOffset); + $o->name = $f->Name; + $t = $f->Type; + $o->type = $this->MetaType($t); + $o->max_length = $f->DefinedSize; + $o->ado_type = $t; + + + //print "off=$off name=$o->name type=$o->type len=$o->max_length
"; + return $o; + } + + /* Use associative array to get fields array */ + function Fields($colname) + { + if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname]; + if (!$this->bind) { + $this->bind = array(); + for ($i=0; $i < $this->_numOfFields; $i++) { + $o = $this->FetchField($i); + $this->bind[strtoupper($o->name)] = $i; + } + } + + return $this->fields[$this->bind[strtoupper($colname)]]; + } + + + function _initrs() + { + $rs = $this->_queryID; + $this->_numOfRows = $rs->RecordCount; + + $f = $rs->Fields; + $this->_numOfFields = $f->Count; + } + + + // should only be used to move forward as we normally use forward-only cursors + function _seek($row) + { + $rs = $this->_queryID; + // absoluteposition doesn't work -- my maths is wrong ? + // $rs->AbsolutePosition->$row-2; + // return true; + if ($this->_currentRow > $row) return false; + @$rs->Move((integer)$row - $this->_currentRow-1); //adBookmarkFirst + return true; + } /* - OLEDB types - - enum DBTYPEENUM - { DBTYPE_EMPTY = 0, - DBTYPE_NULL = 1, - DBTYPE_I2 = 2, - DBTYPE_I4 = 3, - DBTYPE_R4 = 4, - DBTYPE_R8 = 5, - DBTYPE_CY = 6, - DBTYPE_DATE = 7, - DBTYPE_BSTR = 8, - DBTYPE_IDISPATCH = 9, - DBTYPE_ERROR = 10, - DBTYPE_BOOL = 11, - DBTYPE_VARIANT = 12, - DBTYPE_IUNKNOWN = 13, - DBTYPE_DECIMAL = 14, - DBTYPE_UI1 = 17, - DBTYPE_ARRAY = 0x2000, - DBTYPE_BYREF = 0x4000, - DBTYPE_I1 = 16, - DBTYPE_UI2 = 18, - DBTYPE_UI4 = 19, - DBTYPE_I8 = 20, - DBTYPE_UI8 = 21, - DBTYPE_GUID = 72, - DBTYPE_VECTOR = 0x1000, - DBTYPE_RESERVED = 0x8000, - DBTYPE_BYTES = 128, - DBTYPE_STR = 129, - DBTYPE_WSTR = 130, - DBTYPE_NUMERIC = 131, - DBTYPE_UDT = 132, - DBTYPE_DBDATE = 133, - DBTYPE_DBTIME = 134, - DBTYPE_DBTIMESTAMP = 135 - - ADO Types - - adEmpty = 0, - adTinyInt = 16, - adSmallInt = 2, - adInteger = 3, - adBigInt = 20, - adUnsignedTinyInt = 17, - adUnsignedSmallInt = 18, - adUnsignedInt = 19, - adUnsignedBigInt = 21, - adSingle = 4, - adDouble = 5, - adCurrency = 6, - adDecimal = 14, - adNumeric = 131, - adBoolean = 11, - adError = 10, - adUserDefined = 132, - adVariant = 12, - adIDispatch = 9, - adIUnknown = 13, - adGUID = 72, - adDate = 7, - adDBDate = 133, - adDBTime = 134, - adDBTimeStamp = 135, - adBSTR = 8, - adChar = 129, - adVarChar = 200, - adLongVarChar = 201, - adWChar = 130, - adVarWChar = 202, - adLongVarWChar = 203, - adBinary = 128, - adVarBinary = 204, - adLongVarBinary = 205, - adChapter = 136, - adFileTime = 64, - adDBFileTime = 137, - adPropVariant = 138, - adVarNumeric = 139 + OLEDB types + + enum DBTYPEENUM + { DBTYPE_EMPTY = 0, + DBTYPE_NULL = 1, + DBTYPE_I2 = 2, + DBTYPE_I4 = 3, + DBTYPE_R4 = 4, + DBTYPE_R8 = 5, + DBTYPE_CY = 6, + DBTYPE_DATE = 7, + DBTYPE_BSTR = 8, + DBTYPE_IDISPATCH = 9, + DBTYPE_ERROR = 10, + DBTYPE_BOOL = 11, + DBTYPE_VARIANT = 12, + DBTYPE_IUNKNOWN = 13, + DBTYPE_DECIMAL = 14, + DBTYPE_UI1 = 17, + DBTYPE_ARRAY = 0x2000, + DBTYPE_BYREF = 0x4000, + DBTYPE_I1 = 16, + DBTYPE_UI2 = 18, + DBTYPE_UI4 = 19, + DBTYPE_I8 = 20, + DBTYPE_UI8 = 21, + DBTYPE_GUID = 72, + DBTYPE_VECTOR = 0x1000, + DBTYPE_RESERVED = 0x8000, + DBTYPE_BYTES = 128, + DBTYPE_STR = 129, + DBTYPE_WSTR = 130, + DBTYPE_NUMERIC = 131, + DBTYPE_UDT = 132, + DBTYPE_DBDATE = 133, + DBTYPE_DBTIME = 134, + DBTYPE_DBTIMESTAMP = 135 + + ADO Types + + adEmpty = 0, + adTinyInt = 16, + adSmallInt = 2, + adInteger = 3, + adBigInt = 20, + adUnsignedTinyInt = 17, + adUnsignedSmallInt = 18, + adUnsignedInt = 19, + adUnsignedBigInt = 21, + adSingle = 4, + adDouble = 5, + adCurrency = 6, + adDecimal = 14, + adNumeric = 131, + adBoolean = 11, + adError = 10, + adUserDefined = 132, + adVariant = 12, + adIDispatch = 9, + adIUnknown = 13, + adGUID = 72, + adDate = 7, + adDBDate = 133, + adDBTime = 134, + adDBTimeStamp = 135, + adBSTR = 8, + adChar = 129, + adVarChar = 200, + adLongVarChar = 201, + adWChar = 130, + adVarWChar = 202, + adLongVarWChar = 203, + adBinary = 128, + adVarBinary = 204, + adLongVarBinary = 205, + adChapter = 136, + adFileTime = 64, + adDBFileTime = 137, + adPropVariant = 138, + adVarNumeric = 139 */ - function MetaType($t,$len=-1,$fieldobj=false) - { - if (is_object($t)) { - $fieldobj = $t; - $t = $fieldobj->type; - $len = $fieldobj->max_length; - } - - if (!is_numeric($t)) return $t; - - switch ($t) { - case 0: - case 12: // variant - case 8: // bstr - case 129: //char - case 130: //wc - case 200: // varc - case 202:// varWC - case 128: // bin - case 204: // varBin - case 72: // guid - if ($len <= $this->blobSize) return 'C'; - - case 201: - case 203: - return 'X'; - case 128: - case 204: - case 205: - return 'B'; - case 7: - case 133: return 'D'; - - case 134: - case 135: return 'T'; - - case 11: return 'L'; - - case 16:// adTinyInt = 16, - case 2://adSmallInt = 2, - case 3://adInteger = 3, - case 4://adBigInt = 20, - case 17://adUnsignedTinyInt = 17, - case 18://adUnsignedSmallInt = 18, - case 19://adUnsignedInt = 19, - case 20://adUnsignedBigInt = 21, - return 'I'; - default: return 'N'; - } - } - - // time stamp not supported yet - function _fetch() - { - $rs = $this->_queryID; - if (!$rs or $rs->EOF) { - $this->fields = false; - return false; - } - $this->fields = array(); - - if (!$this->_tarr) { - $tarr = array(); - $flds = array(); - for ($i=0,$max = $this->_numOfFields; $i < $max; $i++) { - $f = $rs->Fields($i); - $flds[] = $f; - $tarr[] = $f->Type; - } - // bind types and flds only once - $this->_tarr = $tarr; - $this->_flds = $flds; - } - $t = reset($this->_tarr); - $f = reset($this->_flds); - - if ($this->hideErrors) $olde = error_reporting(E_ERROR|E_CORE_ERROR);// sometimes $f->value be null - for ($i=0,$max = $this->_numOfFields; $i < $max; $i++) { - - switch($t) { - case 135: // timestamp - if (!strlen((string)$f->value)) $this->fields[] = false; - else $this->fields[] = adodb_date('Y-m-d H:i:s',(float)$f->value); - break; - case 133:// A date value (yyyymmdd) - if ($val = $f->value) { - $this->fields[] = substr($val,0,4).'-'.substr($val,4,2).'-'.substr($val,6,2); - } else - $this->fields[] = false; - break; - case 7: // adDate - if (!strlen((string)$f->value)) $this->fields[] = false; - else $this->fields[] = adodb_date('Y-m-d',(float)$f->value); - break; - case 1: // null - $this->fields[] = false; - break; - case 6: // currency is not supported properly; - ADOConnection::outp( ''.$f->Name.': currency type not supported by PHP'); - $this->fields[] = (float) $f->value; - break; - default: - $this->fields[] = $f->value; - break; - } - //print " $f->value $t, "; - $f = next($this->_flds); - $t = next($this->_tarr); - } // for - if ($this->hideErrors) error_reporting($olde); - @$rs->MoveNext(); // @ needed for some versions of PHP! - - if ($this->fetchMode & ADODB_FETCH_ASSOC) { - $this->fields = &$this->GetRowAssoc(ADODB_ASSOC_CASE); - } - return true; - } - - function NextRecordSet() - { - $rs = $this->_queryID; - $this->_queryID = $rs->NextRecordSet(); - //$this->_queryID = $this->_QueryId->NextRecordSet(); - if ($this->_queryID == null) return false; - - $this->_currentRow = -1; - $this->_currentPage = -1; - $this->bind = false; - $this->fields = false; - $this->_flds = false; - $this->_tarr = false; - - $this->_inited = false; - $this->Init(); - return true; - } - - function _close() { - $this->_flds = false; - @$this->_queryID->Close();// by Pete Dishman (peterd@telephonetics.co.uk) - $this->_queryID = false; - } + function MetaType($t,$len=-1,$fieldobj=false) + { + if (is_object($t)) { + $fieldobj = $t; + $t = $fieldobj->type; + $len = $fieldobj->max_length; + } + + if (!is_numeric($t)) return $t; + + switch ($t) { + case 0: + case 12: // variant + case 8: // bstr + case 129: //char + case 130: //wc + case 200: // varc + case 202:// varWC + case 128: // bin + case 204: // varBin + case 72: // guid + if ($len <= $this->blobSize) return 'C'; + + case 201: + case 203: + return 'X'; + case 128: + case 204: + case 205: + return 'B'; + case 7: + case 133: return 'D'; + + case 134: + case 135: return 'T'; + + case 11: return 'L'; + + case 16:// adTinyInt = 16, + case 2://adSmallInt = 2, + case 3://adInteger = 3, + case 4://adBigInt = 20, + case 17://adUnsignedTinyInt = 17, + case 18://adUnsignedSmallInt = 18, + case 19://adUnsignedInt = 19, + case 20://adUnsignedBigInt = 21, + return 'I'; + default: return 'N'; + } + } + + // time stamp not supported yet + function _fetch() + { + $rs = $this->_queryID; + if (!$rs or $rs->EOF) { + $this->fields = false; + return false; + } + $this->fields = array(); + + if (!$this->_tarr) { + $tarr = array(); + $flds = array(); + for ($i=0,$max = $this->_numOfFields; $i < $max; $i++) { + $f = $rs->Fields($i); + $flds[] = $f; + $tarr[] = $f->Type; + } + // bind types and flds only once + $this->_tarr = $tarr; + $this->_flds = $flds; + } + $t = reset($this->_tarr); + $f = reset($this->_flds); + + if ($this->hideErrors) $olde = error_reporting(E_ERROR|E_CORE_ERROR);// sometimes $f->value be null + for ($i=0,$max = $this->_numOfFields; $i < $max; $i++) { + + switch($t) { + case 135: // timestamp + if (!strlen((string)$f->value)) $this->fields[] = false; + else $this->fields[] = adodb_date('Y-m-d H:i:s',(float)$f->value); + break; + case 133:// A date value (yyyymmdd) + if ($val = $f->value) { + $this->fields[] = substr($val,0,4).'-'.substr($val,4,2).'-'.substr($val,6,2); + } else + $this->fields[] = false; + break; + case 7: // adDate + if (!strlen((string)$f->value)) $this->fields[] = false; + else $this->fields[] = adodb_date('Y-m-d',(float)$f->value); + break; + case 1: // null + $this->fields[] = false; + break; + case 6: // currency is not supported properly; + ADOConnection::outp( ''.$f->Name.': currency type not supported by PHP'); + $this->fields[] = (float) $f->value; + break; + default: + $this->fields[] = $f->value; + break; + } + //print " $f->value $t, "; + $f = next($this->_flds); + $t = next($this->_tarr); + } // for + if ($this->hideErrors) error_reporting($olde); + @$rs->MoveNext(); // @ needed for some versions of PHP! + + if ($this->fetchMode & ADODB_FETCH_ASSOC) { + $this->fields = &$this->GetRowAssoc(ADODB_ASSOC_CASE); + } + return true; + } + + function NextRecordSet() + { + $rs = $this->_queryID; + $this->_queryID = $rs->NextRecordSet(); + //$this->_queryID = $this->_QueryId->NextRecordSet(); + if ($this->_queryID == null) return false; + + $this->_currentRow = -1; + $this->_currentPage = -1; + $this->bind = false; + $this->fields = false; + $this->_flds = false; + $this->_tarr = false; + + $this->_inited = false; + $this->Init(); + return true; + } + + function _close() { + $this->_flds = false; + @$this->_queryID->Close();// by Pete Dishman (peterd@telephonetics.co.uk) + $this->_queryID = false; + } } diff --git a/lib/WikiDB/adodb/drivers/adodb-ado_access.inc.php b/lib/WikiDB/adodb/drivers/adodb-ado_access.inc.php index fee7b3a21..09c22455b 100644 --- a/lib/WikiDB/adodb/drivers/adodb-ado_access.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-ado_access.inc.php @@ -8,39 +8,39 @@ Set tabs to 4 for best viewing. Latest version is available at http://php.weblogs.com/ - Microsoft Access ADO data driver. Requires ADO and ODBC. Works only on MS Windows. + Microsoft Access ADO data driver. Requires ADO and ODBC. Works only on MS Windows. */ if (!defined('_ADODB_ADO_LAYER')) { - include(ADODB_DIR."/drivers/adodb-ado.inc.php"); + include(ADODB_DIR."/drivers/adodb-ado.inc.php"); } class ADODB_ado_access extends ADODB_ado { - var $databaseType = 'ado_access'; - var $hasTop = 'top'; // support mssql SELECT TOP 10 * FROM TABLE - var $fmtDate = "#Y-m-d#"; - var $fmtTimeStamp = "#Y-m-d h:i:sA#";// note no comma - var $sysDate = "FORMAT(NOW,'yyyy-mm-dd')"; - var $sysTimeStamp = 'NOW'; - var $hasTransactions = false; + var $databaseType = 'ado_access'; + var $hasTop = 'top'; // support mssql SELECT TOP 10 * FROM TABLE + var $fmtDate = "#Y-m-d#"; + var $fmtTimeStamp = "#Y-m-d h:i:sA#";// note no comma + var $sysDate = "FORMAT(NOW,'yyyy-mm-dd')"; + var $sysTimeStamp = 'NOW'; + var $hasTransactions = false; - function ADODB_ado_access() - { - $this->ADODB_ado(); - } + function ADODB_ado_access() + { + $this->ADODB_ado(); + } - function BeginTrans() { return false;} + function BeginTrans() { return false;} } class ADORecordSet_ado_access extends ADORecordSet_ado { - var $databaseType = "ado_access"; + var $databaseType = "ado_access"; - function ADORecordSet_ado_access($id,$mode=false) - { - return $this->ADORecordSet_ado($id,$mode); - } + function ADORecordSet_ado_access($id,$mode=false) + { + return $this->ADORecordSet_ado($id,$mode); + } } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/drivers/adodb-ado_mssql.inc.php b/lib/WikiDB/adodb/drivers/adodb-ado_mssql.inc.php index 527d9f6e5..0104f13ee 100644 --- a/lib/WikiDB/adodb/drivers/adodb-ado_mssql.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-ado_mssql.inc.php @@ -16,47 +16,47 @@ Set tabs to 4 for best viewing. */ if (!defined('_ADODB_ADO_LAYER')) { - include(ADODB_DIR."/drivers/adodb-ado.inc.php"); + include(ADODB_DIR."/drivers/adodb-ado.inc.php"); } class ADODB_ado_mssql extends ADODB_ado { - var $databaseType = 'ado_mssql'; - var $hasTop = 'top'; - var $sysDate = 'GetDate()'; - var $sysTimeStamp = 'GetDate()'; - var $leftOuter = '*='; - var $rightOuter = '=*'; - var $ansiOuter = true; // for mssql7 or later - var $substr = "substring"; - var $length = 'len'; - var $upperCase = 'upper'; - - //var $_inTransaction = 1; // always open recordsets, so no transaction problems. - - function ADODB_ado_mssql() - { - $this->ADODB_ado(); - } - - function _insertid() - { - return $this->GetOne('select @@identity'); - } - - function _affectedrows() - { - return $this->GetOne('select @@rowcount'); - } + var $databaseType = 'ado_mssql'; + var $hasTop = 'top'; + var $sysDate = 'GetDate()'; + var $sysTimeStamp = 'GetDate()'; + var $leftOuter = '*='; + var $rightOuter = '=*'; + var $ansiOuter = true; // for mssql7 or later + var $substr = "substring"; + var $length = 'len'; + var $upperCase = 'upper'; + + //var $_inTransaction = 1; // always open recordsets, so no transaction problems. + + function ADODB_ado_mssql() + { + $this->ADODB_ado(); + } + + function _insertid() + { + return $this->GetOne('select @@identity'); + } + + function _affectedrows() + { + return $this->GetOne('select @@rowcount'); + } } class ADORecordSet_ado_mssql extends ADORecordSet_ado { - var $databaseType = 'ado_mssql'; + var $databaseType = 'ado_mssql'; - function ADORecordSet_ado_mssql($id,$mode=false) - { - return $this->ADORecordSet_ado($id,$mode); - } + function ADORecordSet_ado_mssql($id,$mode=false) + { + return $this->ADORecordSet_ado($id,$mode); + } } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/drivers/adodb-borland_ibase.inc.php b/lib/WikiDB/adodb/drivers/adodb-borland_ibase.inc.php index c1fc31fa9..c522ef1c0 100644 --- a/lib/WikiDB/adodb/drivers/adodb-borland_ibase.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-borland_ibase.inc.php @@ -15,65 +15,65 @@ Set tabs to 4 for best viewing. include_once(ADODB_DIR."/drivers/adodb-ibase.inc.php"); class ADODB_borland_ibase extends ADODB_ibase { - var $databaseType = "borland_ibase"; + var $databaseType = "borland_ibase"; - function ADODB_borland_ibase() - { - $this->ADODB_ibase(); - } + function ADODB_borland_ibase() + { + $this->ADODB_ibase(); + } - function ServerInfo() - { - $arr['dialect'] = $this->dialect; - switch($arr['dialect']) { - case '': - case '1': $s = 'Interbase 6.5, Dialect 1'; break; - case '2': $s = 'Interbase 6.5, Dialect 2'; break; - default: - case '3': $s = 'Interbase 6.5, Dialect 3'; break; - } - $arr['version'] = '6.5'; - $arr['description'] = $s; - return $arr; - } + function ServerInfo() + { + $arr['dialect'] = $this->dialect; + switch($arr['dialect']) { + case '': + case '1': $s = 'Interbase 6.5, Dialect 1'; break; + case '2': $s = 'Interbase 6.5, Dialect 2'; break; + default: + case '3': $s = 'Interbase 6.5, Dialect 3'; break; + } + $arr['version'] = '6.5'; + $arr['description'] = $s; + return $arr; + } - // Note that Interbase 6.5 uses ROWS instead - don't you love forking wars! - // SELECT col1, col2 FROM table ROWS 5 -- get 5 rows - // SELECT col1, col2 FROM TABLE ORDER BY col1 ROWS 3 TO 7 -- first 5 skip 2 - // Firebird uses - // SELECT FIRST 5 SKIP 2 col1, col2 FROM TABLE - function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0) - { - if ($nrows > 0) { - if ($offset <= 0) $str = " ROWS $nrows "; - else { - $a = $offset+1; - $b = $offset+$nrows; - $str = " ROWS $a TO $b"; - } - } else { - // ok, skip - $a = $offset + 1; - $str = " ROWS $a TO 999999999"; // 999 million - } - $sql .= $str; + // Note that Interbase 6.5 uses ROWS instead - don't you love forking wars! + // SELECT col1, col2 FROM table ROWS 5 -- get 5 rows + // SELECT col1, col2 FROM TABLE ORDER BY col1 ROWS 3 TO 7 -- first 5 skip 2 + // Firebird uses + // SELECT FIRST 5 SKIP 2 col1, col2 FROM TABLE + function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0) + { + if ($nrows > 0) { + if ($offset <= 0) $str = " ROWS $nrows "; + else { + $a = $offset+1; + $b = $offset+$nrows; + $str = " ROWS $a TO $b"; + } + } else { + // ok, skip + $a = $offset + 1; + $str = " ROWS $a TO 999999999"; // 999 million + } + $sql .= $str; - return ($secs2cache) ? - $this->CacheExecute($secs2cache,$sql,$inputarr) - : - $this->Execute($sql,$inputarr); - } + return ($secs2cache) ? + $this->CacheExecute($secs2cache,$sql,$inputarr) + : + $this->Execute($sql,$inputarr); + } }; class ADORecordSet_borland_ibase extends ADORecordSet_ibase { - var $databaseType = "borland_ibase"; + var $databaseType = "borland_ibase"; - function ADORecordSet_borland_ibase($id,$mode=false) - { - $this->ADORecordSet_ibase($id,$mode); - } + function ADORecordSet_borland_ibase($id,$mode=false) + { + $this->ADORecordSet_ibase($id,$mode); + } } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/drivers/adodb-csv.inc.php b/lib/WikiDB/adodb/drivers/adodb-csv.inc.php index d6bb0c92f..0576e37e3 100644 --- a/lib/WikiDB/adodb/drivers/adodb-csv.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-csv.inc.php @@ -17,182 +17,182 @@ if (! defined("_ADODB_CSV_LAYER")) { include_once(ADODB_DIR.'/adodb-csvlib.inc.php'); class ADODB_csv extends ADOConnection { - var $databaseType = 'csv'; - var $databaseProvider = 'csv'; - var $hasInsertID = true; - var $hasAffectedRows = true; - var $fmtTimeStamp = "'Y-m-d H:i:s'"; - var $_affectedrows=0; - var $_insertid=0; - var $_url; - var $replaceQuote = "''"; // string to use to replace quotes - var $hasTransactions = false; - var $_errorNo = false; - - function ADODB_csv() - { - } - - function _insertid() - { - return $this->_insertid; - } - - function _affectedrows() - { - return $this->_affectedrows; - } - - function &MetaDatabases() - { - return false; - } - - - // returns true or false - function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) - { - if (strtolower(substr($argHostname,0,7)) !== 'http://') return false; - $this->_url = $argHostname; - return true; - } - - // returns true or false - function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) - { - if (strtolower(substr($argHostname,0,7)) !== 'http://') return false; - $this->_url = $argHostname; - return true; - } - - function &MetaColumns($table) - { - return false; - } - - - // parameters use PostgreSQL convention, not MySQL - function &SelectLimit($sql,$nrows=-1,$offset=-1) - { - global $ADODB_FETCH_MODE; - - $url = $this->_url.'?sql='.urlencode($sql)."&nrows=$nrows&fetch=". - (($this->fetchMode !== false)?$this->fetchMode : $ADODB_FETCH_MODE). - "&offset=$offset"; - $err = false; - $rs = csv2rs($url,$err,false); - - if ($this->debug) print "$url
$err
"; - - $at = strpos($err,'::::'); - if ($at === false) { - $this->_errorMsg = $err; - $this->_errorNo = (integer)$err; - } else { - $this->_errorMsg = substr($err,$at+4,1024); - $this->_errorNo = -9999; - } - if ($this->_errorNo) - if ($fn = $this->raiseErrorFn) { - $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,''); - } - - if (is_object($rs)) { - - $rs->databaseType='csv'; - $rs->fetchMode = ($this->fetchMode !== false) ? $this->fetchMode : $ADODB_FETCH_MODE; - $rs->connection = &$this; - } - return $rs; - } - - // returns queryID or false - function &_Execute($sql,$inputarr=false) - { - global $ADODB_FETCH_MODE; - - if (!$this->_bindInputArray && $inputarr) { - $sqlarr = explode('?',$sql); - $sql = ''; - $i = 0; - foreach($inputarr as $v) { - - $sql .= $sqlarr[$i]; - if (gettype($v) == 'string') - $sql .= $this->qstr($v); - else if ($v === null) - $sql .= 'NULL'; - else - $sql .= $v; - $i += 1; - - } - $sql .= $sqlarr[$i]; - if ($i+1 != sizeof($sqlarr)) - print "Input Array does not match ?: ".htmlspecialchars($sql); - $inputarr = false; - } - - $url = $this->_url.'?sql='.urlencode($sql)."&fetch=". - (($this->fetchMode !== false)?$this->fetchMode : $ADODB_FETCH_MODE); - $err = false; - - - $rs = csv2rs($url,$err,false); - if ($this->debug) print urldecode($url)."
$err
"; - $at = strpos($err,'::::'); - if ($at === false) { - $this->_errorMsg = $err; - $this->_errorNo = (integer)$err; - } else { - $this->_errorMsg = substr($err,$at+4,1024); - $this->_errorNo = -9999; - } - - if ($this->_errorNo) - if ($fn = $this->raiseErrorFn) { - $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,$inputarr); - } - if (is_object($rs)) { - $rs->fetchMode = ($this->fetchMode !== false) ? $this->fetchMode : $ADODB_FETCH_MODE; - - $this->_affectedrows = $rs->affectedrows; - $this->_insertid = $rs->insertid; - $rs->databaseType='csv'; - $rs->connection = &$this; - } - return $rs; - } - - /* Returns: the last error message from previous database operation */ - function ErrorMsg() - { - return $this->_errorMsg; - } - - /* Returns: the last error number from previous database operation */ - function ErrorNo() - { - return $this->_errorNo; - } - - // returns true or false - function _close() - { - return true; - } + var $databaseType = 'csv'; + var $databaseProvider = 'csv'; + var $hasInsertID = true; + var $hasAffectedRows = true; + var $fmtTimeStamp = "'Y-m-d H:i:s'"; + var $_affectedrows=0; + var $_insertid=0; + var $_url; + var $replaceQuote = "''"; // string to use to replace quotes + var $hasTransactions = false; + var $_errorNo = false; + + function ADODB_csv() + { + } + + function _insertid() + { + return $this->_insertid; + } + + function _affectedrows() + { + return $this->_affectedrows; + } + + function &MetaDatabases() + { + return false; + } + + + // returns true or false + function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) + { + if (strtolower(substr($argHostname,0,7)) !== 'http://') return false; + $this->_url = $argHostname; + return true; + } + + // returns true or false + function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) + { + if (strtolower(substr($argHostname,0,7)) !== 'http://') return false; + $this->_url = $argHostname; + return true; + } + + function &MetaColumns($table) + { + return false; + } + + + // parameters use PostgreSQL convention, not MySQL + function &SelectLimit($sql,$nrows=-1,$offset=-1) + { + global $ADODB_FETCH_MODE; + + $url = $this->_url.'?sql='.urlencode($sql)."&nrows=$nrows&fetch=". + (($this->fetchMode !== false)?$this->fetchMode : $ADODB_FETCH_MODE). + "&offset=$offset"; + $err = false; + $rs = csv2rs($url,$err,false); + + if ($this->debug) print "$url
$err
"; + + $at = strpos($err,'::::'); + if ($at === false) { + $this->_errorMsg = $err; + $this->_errorNo = (integer)$err; + } else { + $this->_errorMsg = substr($err,$at+4,1024); + $this->_errorNo = -9999; + } + if ($this->_errorNo) + if ($fn = $this->raiseErrorFn) { + $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,''); + } + + if (is_object($rs)) { + + $rs->databaseType='csv'; + $rs->fetchMode = ($this->fetchMode !== false) ? $this->fetchMode : $ADODB_FETCH_MODE; + $rs->connection = &$this; + } + return $rs; + } + + // returns queryID or false + function &_Execute($sql,$inputarr=false) + { + global $ADODB_FETCH_MODE; + + if (!$this->_bindInputArray && $inputarr) { + $sqlarr = explode('?',$sql); + $sql = ''; + $i = 0; + foreach($inputarr as $v) { + + $sql .= $sqlarr[$i]; + if (gettype($v) == 'string') + $sql .= $this->qstr($v); + else if ($v === null) + $sql .= 'NULL'; + else + $sql .= $v; + $i += 1; + + } + $sql .= $sqlarr[$i]; + if ($i+1 != sizeof($sqlarr)) + print "Input Array does not match ?: ".htmlspecialchars($sql); + $inputarr = false; + } + + $url = $this->_url.'?sql='.urlencode($sql)."&fetch=". + (($this->fetchMode !== false)?$this->fetchMode : $ADODB_FETCH_MODE); + $err = false; + + + $rs = csv2rs($url,$err,false); + if ($this->debug) print urldecode($url)."
$err
"; + $at = strpos($err,'::::'); + if ($at === false) { + $this->_errorMsg = $err; + $this->_errorNo = (integer)$err; + } else { + $this->_errorMsg = substr($err,$at+4,1024); + $this->_errorNo = -9999; + } + + if ($this->_errorNo) + if ($fn = $this->raiseErrorFn) { + $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,$inputarr); + } + if (is_object($rs)) { + $rs->fetchMode = ($this->fetchMode !== false) ? $this->fetchMode : $ADODB_FETCH_MODE; + + $this->_affectedrows = $rs->affectedrows; + $this->_insertid = $rs->insertid; + $rs->databaseType='csv'; + $rs->connection = &$this; + } + return $rs; + } + + /* Returns: the last error message from previous database operation */ + function ErrorMsg() + { + return $this->_errorMsg; + } + + /* Returns: the last error number from previous database operation */ + function ErrorNo() + { + return $this->_errorNo; + } + + // returns true or false + function _close() + { + return true; + } } // class class ADORecordset_csv extends ADORecordset { - function ADORecordset_csv($id,$mode=false) - { - $this->ADORecordset($id,$mode); - } - - function _close() - { - return true; - } + function ADORecordset_csv($id,$mode=false) + { + $this->ADORecordset($id,$mode); + } + + function _close() + { + return true; + } } } // define diff --git a/lib/WikiDB/adodb/drivers/adodb-db2.inc.php b/lib/WikiDB/adodb/drivers/adodb-db2.inc.php index f35b5e462..27f50a2e0 100644 --- a/lib/WikiDB/adodb/drivers/adodb-db2.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-db2.inc.php @@ -83,230 +83,230 @@ Connect() when using the CLI interface. From Halmai Csongor csongor.halmai#nexum */ if (!defined('_ADODB_ODBC_LAYER')) { - include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); + include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); } if (!defined('ADODB_DB2')){ define('ADODB_DB2',1); class ADODB_DB2 extends ADODB_odbc { - var $databaseType = "db2"; - var $concat_operator = '||'; - var $sysDate = 'CURRENT_DATE'; - var $sysTimeStamp = 'CURRENT TIMESTAMP'; - // The complete string representation of a timestamp has the form - // yyyy-mm-dd-hh.mm.ss.nnnnnn. - var $fmtTimeStamp = "'Y-m-d-H.i.s'"; - var $ansiOuter = true; - var $identitySQL = 'values IDENTITY_VAL_LOCAL()'; - var $_bindInputArray = false; - var $upperCase = 'upper'; - - - function ADODB_DB2() - { - if (strncmp(PHP_OS,'WIN',3) === 0) $this->curmode = SQL_CUR_USE_ODBC; - $this->ADODB_odbc(); - } - - function IfNull( $field, $ifNull ) - { - return " COALESCE($field, $ifNull) "; // if DB2 UDB - } - - function ServerInfo() - { - //odbc_setoption($this->_connectionID,1,101 /*SQL_ATTR_ACCESS_MODE*/, 1 /*SQL_MODE_READ_ONLY*/); - $vers = $this->GetOne('select versionnumber from sysibm.sysversions'); - //odbc_setoption($this->_connectionID,1,101, 0 /*SQL_MODE_READ_WRITE*/); - return array('description'=>'DB2 ODBC driver', 'version'=>$vers); - } - - function _insertid() - { - return $this->GetOne($this->identitySQL); - } - - function RowLock($tables,$where) - { - if ($this->_autocommit) $this->BeginTrans(); - return $this->GetOne("select 1 as ignore from $tables where $where for update"); - } - - function &MetaTables($ttype=false,$showSchema=false) - { - global $ADODB_FETCH_MODE; - - $savem = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - $qid = odbc_tables($this->_connectionID); - - $rs = new ADORecordSet_odbc($qid); - - $ADODB_FETCH_MODE = $savem; - if (!$rs) return false; - - $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; - - $arr =& $rs->GetArray(); - //print_r($arr); - - $rs->Close(); - $arr2 = array(); - - if ($ttype) { - $isview = strncmp($ttype,'V',1) === 0; - } - for ($i=0; $i < sizeof($arr); $i++) { - - if (!$arr[$i][2]) continue; - if (strncmp($arr[$i][1],'SYS',3) === 0) continue; - - $type = $arr[$i][3]; - - if ($showSchema) $arr[$i][2] = $arr[$i][1].'.'.$arr[$i][2]; - - if ($ttype) { - if ($isview) { - if (strncmp($type,'V',1) === 0) $arr2[] = $arr[$i][2]; - } else if (strncmp($type,'T',1) === 0) $arr2[] = $arr[$i][2]; - } else if (strncmp($type,'S',1) !== 0) $arr2[] = $arr[$i][2]; - } - return $arr2; - } - - // Format date column in sql string given an input format that understands Y M D - function SQLDate($fmt, $col=false) - { - // use right() and replace() ? - if (!$col) $col = $this->sysDate; - $s = ''; - - $len = strlen($fmt); - for ($i=0; $i < $len; $i++) { - if ($s) $s .= '||'; - $ch = $fmt[$i]; - switch($ch) { - case 'Y': - case 'y': - $s .= "char(year($col))"; - break; - case 'M': - $s .= "substr(monthname($col),1,3)"; - break; - case 'm': - $s .= "right(digits(month($col)),2)"; - break; - case 'D': - case 'd': - $s .= "right(digits(day($col)),2)"; - break; - case 'H': - case 'h': - if ($col != $this->sysDate) $s .= "right(digits(hour($col)),2)"; - else $s .= "''"; - break; - case 'i': - case 'I': - if ($col != $this->sysDate) - $s .= "right(digits(minute($col)),2)"; - else $s .= "''"; - break; - case 'S': - case 's': - if ($col != $this->sysDate) - $s .= "right(digits(second($col)),2)"; - else $s .= "''"; - break; - default: - if ($ch == '\\') { - $i++; - $ch = substr($fmt,$i,1); - } - $s .= $this->qstr($ch); - } - } - return $s; - } - - - function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputArr=false) - { - if ($offset <= 0) { - // could also use " OPTIMIZE FOR $nrows ROWS " - if ($nrows >= 0) $sql .= " FETCH FIRST $nrows ROWS ONLY "; - $rs =& $this->Execute($sql,$inputArr); - } else { - if ($offset > 0 && $nrows < 0); - else { - $nrows += $offset; - $sql .= " FETCH FIRST $nrows ROWS ONLY "; - } - $rs =& ADOConnection::SelectLimit($sql,-1,$offset,$inputArr); - } - - return $rs; - } + var $databaseType = "db2"; + var $concat_operator = '||'; + var $sysDate = 'CURRENT_DATE'; + var $sysTimeStamp = 'CURRENT TIMESTAMP'; + // The complete string representation of a timestamp has the form + // yyyy-mm-dd-hh.mm.ss.nnnnnn. + var $fmtTimeStamp = "'Y-m-d-H.i.s'"; + var $ansiOuter = true; + var $identitySQL = 'values IDENTITY_VAL_LOCAL()'; + var $_bindInputArray = false; + var $upperCase = 'upper'; + + + function ADODB_DB2() + { + if (strncmp(PHP_OS,'WIN',3) === 0) $this->curmode = SQL_CUR_USE_ODBC; + $this->ADODB_odbc(); + } + + function IfNull( $field, $ifNull ) + { + return " COALESCE($field, $ifNull) "; // if DB2 UDB + } + + function ServerInfo() + { + //odbc_setoption($this->_connectionID,1,101 /*SQL_ATTR_ACCESS_MODE*/, 1 /*SQL_MODE_READ_ONLY*/); + $vers = $this->GetOne('select versionnumber from sysibm.sysversions'); + //odbc_setoption($this->_connectionID,1,101, 0 /*SQL_MODE_READ_WRITE*/); + return array('description'=>'DB2 ODBC driver', 'version'=>$vers); + } + + function _insertid() + { + return $this->GetOne($this->identitySQL); + } + + function RowLock($tables,$where) + { + if ($this->_autocommit) $this->BeginTrans(); + return $this->GetOne("select 1 as ignore from $tables where $where for update"); + } + + function &MetaTables($ttype=false,$showSchema=false) + { + global $ADODB_FETCH_MODE; + + $savem = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + $qid = odbc_tables($this->_connectionID); + + $rs = new ADORecordSet_odbc($qid); + + $ADODB_FETCH_MODE = $savem; + if (!$rs) return false; + + $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; + + $arr =& $rs->GetArray(); + //print_r($arr); + + $rs->Close(); + $arr2 = array(); + + if ($ttype) { + $isview = strncmp($ttype,'V',1) === 0; + } + for ($i=0; $i < sizeof($arr); $i++) { + + if (!$arr[$i][2]) continue; + if (strncmp($arr[$i][1],'SYS',3) === 0) continue; + + $type = $arr[$i][3]; + + if ($showSchema) $arr[$i][2] = $arr[$i][1].'.'.$arr[$i][2]; + + if ($ttype) { + if ($isview) { + if (strncmp($type,'V',1) === 0) $arr2[] = $arr[$i][2]; + } else if (strncmp($type,'T',1) === 0) $arr2[] = $arr[$i][2]; + } else if (strncmp($type,'S',1) !== 0) $arr2[] = $arr[$i][2]; + } + return $arr2; + } + + // Format date column in sql string given an input format that understands Y M D + function SQLDate($fmt, $col=false) + { + // use right() and replace() ? + if (!$col) $col = $this->sysDate; + $s = ''; + + $len = strlen($fmt); + for ($i=0; $i < $len; $i++) { + if ($s) $s .= '||'; + $ch = $fmt[$i]; + switch($ch) { + case 'Y': + case 'y': + $s .= "char(year($col))"; + break; + case 'M': + $s .= "substr(monthname($col),1,3)"; + break; + case 'm': + $s .= "right(digits(month($col)),2)"; + break; + case 'D': + case 'd': + $s .= "right(digits(day($col)),2)"; + break; + case 'H': + case 'h': + if ($col != $this->sysDate) $s .= "right(digits(hour($col)),2)"; + else $s .= "''"; + break; + case 'i': + case 'I': + if ($col != $this->sysDate) + $s .= "right(digits(minute($col)),2)"; + else $s .= "''"; + break; + case 'S': + case 's': + if ($col != $this->sysDate) + $s .= "right(digits(second($col)),2)"; + else $s .= "''"; + break; + default: + if ($ch == '\\') { + $i++; + $ch = substr($fmt,$i,1); + } + $s .= $this->qstr($ch); + } + } + return $s; + } + + + function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputArr=false) + { + if ($offset <= 0) { + // could also use " OPTIMIZE FOR $nrows ROWS " + if ($nrows >= 0) $sql .= " FETCH FIRST $nrows ROWS ONLY "; + $rs =& $this->Execute($sql,$inputArr); + } else { + if ($offset > 0 && $nrows < 0); + else { + $nrows += $offset; + $sql .= " FETCH FIRST $nrows ROWS ONLY "; + } + $rs =& ADOConnection::SelectLimit($sql,-1,$offset,$inputArr); + } + + return $rs; + } }; class ADORecordSet_db2 extends ADORecordSet_odbc { - var $databaseType = "db2"; - - function ADORecordSet_db2($id,$mode=false) - { - $this->ADORecordSet_odbc($id,$mode); - } - - function MetaType($t,$len=-1,$fieldobj=false) - { - if (is_object($t)) { - $fieldobj = $t; - $t = $fieldobj->type; - $len = $fieldobj->max_length; - } - - switch (strtoupper($t)) { - case 'VARCHAR': - case 'CHAR': - case 'CHARACTER': - if ($len <= $this->blobSize) return 'C'; - - case 'LONGCHAR': - case 'TEXT': - case 'CLOB': - case 'DBCLOB': // double-byte - return 'X'; - - case 'BLOB': - case 'GRAPHIC': - case 'VARGRAPHIC': - return 'B'; - - case 'DATE': - return 'D'; - - case 'TIME': - case 'TIMESTAMP': - return 'T'; - - //case 'BOOLEAN': - //case 'BIT': - // return 'L'; - - //case 'COUNTER': - // return 'R'; - - case 'INT': - case 'INTEGER': - case 'BIGINT': - case 'SMALLINT': - return 'I'; - - default: return 'N'; - } - } + var $databaseType = "db2"; + + function ADORecordSet_db2($id,$mode=false) + { + $this->ADORecordSet_odbc($id,$mode); + } + + function MetaType($t,$len=-1,$fieldobj=false) + { + if (is_object($t)) { + $fieldobj = $t; + $t = $fieldobj->type; + $len = $fieldobj->max_length; + } + + switch (strtoupper($t)) { + case 'VARCHAR': + case 'CHAR': + case 'CHARACTER': + if ($len <= $this->blobSize) return 'C'; + + case 'LONGCHAR': + case 'TEXT': + case 'CLOB': + case 'DBCLOB': // double-byte + return 'X'; + + case 'BLOB': + case 'GRAPHIC': + case 'VARGRAPHIC': + return 'B'; + + case 'DATE': + return 'D'; + + case 'TIME': + case 'TIMESTAMP': + return 'T'; + + //case 'BOOLEAN': + //case 'BIT': + // return 'L'; + + //case 'COUNTER': + // return 'R'; + + case 'INT': + case 'INTEGER': + case 'BIGINT': + case 'SMALLINT': + return 'I'; + + default: return 'N'; + } + } } } //define diff --git a/lib/WikiDB/adodb/drivers/adodb-fbsql.inc.php b/lib/WikiDB/adodb/drivers/adodb-fbsql.inc.php index 9da2f1f2f..8ce79cc15 100644 --- a/lib/WikiDB/adodb/drivers/adodb-fbsql.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-fbsql.inc.php @@ -12,250 +12,250 @@ if (! defined("_ADODB_FBSQL_LAYER")) { define("_ADODB_FBSQL_LAYER", 1 ); class ADODB_fbsql extends ADOConnection { - var $databaseType = 'fbsql'; - var $hasInsertID = true; - var $hasAffectedRows = true; - var $metaTablesSQL = "SHOW TABLES"; - var $metaColumnsSQL = "SHOW COLUMNS FROM %s"; - var $fmtTimeStamp = "'Y-m-d H:i:s'"; - var $hasLimit = false; - - function ADODB_fbsql() - { - } - - function _insertid() - { - return fbsql_insert_id($this->_connectionID); - } - - function _affectedrows() - { - return fbsql_affected_rows($this->_connectionID); - } - - function &MetaDatabases() - { - $qid = fbsql_list_dbs($this->_connectionID); - $arr = array(); - $i = 0; - $max = fbsql_num_rows($qid); - while ($i < $max) { - $arr[] = fbsql_tablename($qid,$i); - $i += 1; - } - return $arr; - } - - // returns concatenated string - function Concat() - { - $s = ""; - $arr = func_get_args(); - $first = true; - - $s = implode(',',$arr); - if (sizeof($arr) > 0) return "CONCAT($s)"; - else return ''; - } - - // returns true or false - function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) - { - $this->_connectionID = fbsql_connect($argHostname,$argUsername,$argPassword); - if ($this->_connectionID === false) return false; - if ($argDatabasename) return $this->SelectDB($argDatabasename); - return true; - } - - // returns true or false - function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) - { - $this->_connectionID = fbsql_pconnect($argHostname,$argUsername,$argPassword); - if ($this->_connectionID === false) return false; - if ($argDatabasename) return $this->SelectDB($argDatabasename); - return true; - } - - function &MetaColumns($table) - { - if ($this->metaColumnsSQL) { - - $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table)); - - if ($rs === false) return false; - - $retarr = array(); - while (!$rs->EOF){ - $fld = new ADOFieldObject(); - $fld->name = $rs->fields[0]; - $fld->type = $rs->fields[1]; - - // split type into type(length): - if (preg_match("/^(.+)\((\d+)\)$/", $fld->type, $query_array)) { - $fld->type = $query_array[1]; - $fld->max_length = $query_array[2]; - } else { - $fld->max_length = -1; - } - $fld->not_null = ($rs->fields[2] != 'YES'); - $fld->primary_key = ($rs->fields[3] == 'PRI'); - $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false); - $fld->binary = (strpos($fld->type,'blob') !== false); - - $retarr[strtoupper($fld->name)] = $fld; - $rs->MoveNext(); - } - $rs->Close(); - return $retarr; - } - return false; - } - - // returns true or false - function SelectDB($dbName) - { - $this->databaseName = $dbName; - if ($this->_connectionID) { - return @fbsql_select_db($dbName,$this->_connectionID); - } - else return false; - } - - - // returns queryID or false - function _query($sql,$inputarr) - { - return fbsql_query("$sql;",$this->_connectionID); - } - - /* Returns: the last error message from previous database operation */ - function ErrorMsg() - { - $this->_errorMsg = @fbsql_error($this->_connectionID); - return $this->_errorMsg; - } - - /* Returns: the last error number from previous database operation */ - function ErrorNo() - { - return @fbsql_errno($this->_connectionID); - } - - // returns true or false - function _close() - { - return @fbsql_close($this->_connectionID); - } + var $databaseType = 'fbsql'; + var $hasInsertID = true; + var $hasAffectedRows = true; + var $metaTablesSQL = "SHOW TABLES"; + var $metaColumnsSQL = "SHOW COLUMNS FROM %s"; + var $fmtTimeStamp = "'Y-m-d H:i:s'"; + var $hasLimit = false; + + function ADODB_fbsql() + { + } + + function _insertid() + { + return fbsql_insert_id($this->_connectionID); + } + + function _affectedrows() + { + return fbsql_affected_rows($this->_connectionID); + } + + function &MetaDatabases() + { + $qid = fbsql_list_dbs($this->_connectionID); + $arr = array(); + $i = 0; + $max = fbsql_num_rows($qid); + while ($i < $max) { + $arr[] = fbsql_tablename($qid,$i); + $i += 1; + } + return $arr; + } + + // returns concatenated string + function Concat() + { + $s = ""; + $arr = func_get_args(); + $first = true; + + $s = implode(',',$arr); + if (sizeof($arr) > 0) return "CONCAT($s)"; + else return ''; + } + + // returns true or false + function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) + { + $this->_connectionID = fbsql_connect($argHostname,$argUsername,$argPassword); + if ($this->_connectionID === false) return false; + if ($argDatabasename) return $this->SelectDB($argDatabasename); + return true; + } + + // returns true or false + function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) + { + $this->_connectionID = fbsql_pconnect($argHostname,$argUsername,$argPassword); + if ($this->_connectionID === false) return false; + if ($argDatabasename) return $this->SelectDB($argDatabasename); + return true; + } + + function &MetaColumns($table) + { + if ($this->metaColumnsSQL) { + + $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table)); + + if ($rs === false) return false; + + $retarr = array(); + while (!$rs->EOF){ + $fld = new ADOFieldObject(); + $fld->name = $rs->fields[0]; + $fld->type = $rs->fields[1]; + + // split type into type(length): + if (preg_match("/^(.+)\((\d+)\)$/", $fld->type, $query_array)) { + $fld->type = $query_array[1]; + $fld->max_length = $query_array[2]; + } else { + $fld->max_length = -1; + } + $fld->not_null = ($rs->fields[2] != 'YES'); + $fld->primary_key = ($rs->fields[3] == 'PRI'); + $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false); + $fld->binary = (strpos($fld->type,'blob') !== false); + + $retarr[strtoupper($fld->name)] = $fld; + $rs->MoveNext(); + } + $rs->Close(); + return $retarr; + } + return false; + } + + // returns true or false + function SelectDB($dbName) + { + $this->databaseName = $dbName; + if ($this->_connectionID) { + return @fbsql_select_db($dbName,$this->_connectionID); + } + else return false; + } + + + // returns queryID or false + function _query($sql,$inputarr) + { + return fbsql_query("$sql;",$this->_connectionID); + } + + /* Returns: the last error message from previous database operation */ + function ErrorMsg() + { + $this->_errorMsg = @fbsql_error($this->_connectionID); + return $this->_errorMsg; + } + + /* Returns: the last error number from previous database operation */ + function ErrorNo() + { + return @fbsql_errno($this->_connectionID); + } + + // returns true or false + function _close() + { + return @fbsql_close($this->_connectionID); + } } /*-------------------------------------------------------------------------------------- - Class Name: Recordset + Class Name: Recordset --------------------------------------------------------------------------------------*/ class ADORecordSet_fbsql extends ADORecordSet{ - var $databaseType = "fbsql"; - var $canSeek = true; - - function ADORecordSet_fbsql($queryID,$mode=false) - { - if (!$mode) { - global $ADODB_FETCH_MODE; - $mode = $ADODB_FETCH_MODE; - } - switch ($mode) { - case ADODB_FETCH_NUM: $this->fetchMode = FBSQL_NUM; break; - default: - case ADODB_FETCH_BOTH: $this->fetchMode = FBSQL_BOTH; break; - case ADODB_FETCH_ASSOC: $this->fetchMode = FBSQL_ASSOC; break; - } - return $this->ADORecordSet($queryID); - } - - function _initrs() - { - GLOBAL $ADODB_COUNTRECS; - $this->_numOfRows = ($ADODB_COUNTRECS) ? @fbsql_num_rows($this->_queryID):-1; - $this->_numOfFields = @fbsql_num_fields($this->_queryID); - } - - - - function &FetchField($fieldOffset = -1) { - if ($fieldOffset != -1) { - $o = @fbsql_fetch_field($this->_queryID, $fieldOffset); - //$o->max_length = -1; // fbsql returns the max length less spaces -- so it is unrealiable - $f = @fbsql_field_flags($this->_queryID,$fieldOffset); - $o->binary = (strpos($f,'binary')!== false); - } - else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */ - $o = @fbsql_fetch_field($this->_queryID);// fbsql returns the max length less spaces -- so it is unrealiable - //$o->max_length = -1; - } - - return $o; - } - - function _seek($row) - { - return @fbsql_data_seek($this->_queryID,$row); - } - - function _fetch($ignore_fields=false) - { - $this->fields = @fbsql_fetch_array($this->_queryID,$this->fetchMode); - return ($this->fields == true); - } - - function _close() { - return @fbsql_free_result($this->_queryID); - } - - function MetaType($t,$len=-1,$fieldobj=false) - { - if (is_object($t)) { - $fieldobj = $t; - $t = $fieldobj->type; - $len = $fieldobj->max_length; - } - $len = -1; // fbsql max_length is not accurate - switch (strtoupper($t)) { - case 'CHARACTER': - case 'CHARACTER VARYING': - case 'BLOB': - case 'CLOB': - case 'BIT': - case 'BIT VARYING': - if ($len <= $this->blobSize) return 'C'; - - // so we have to check whether binary... - case 'IMAGE': - case 'LONGBLOB': - case 'BLOB': - case 'MEDIUMBLOB': - return !empty($fieldobj->binary) ? 'B' : 'X'; - - case 'DATE': return 'D'; - - case 'TIME': - case 'TIME WITH TIME ZONE': - case 'TIMESTAMP': - case 'TIMESTAMP WITH TIME ZONE': return 'T'; - - case 'PRIMARY_KEY': - return 'R'; - case 'INTEGER': - case 'SMALLINT': - case 'BOOLEAN': - - if (!empty($fieldobj->primary_key)) return 'R'; - else return 'I'; - - default: return 'N'; - } - } + var $databaseType = "fbsql"; + var $canSeek = true; + + function ADORecordSet_fbsql($queryID,$mode=false) + { + if (!$mode) { + global $ADODB_FETCH_MODE; + $mode = $ADODB_FETCH_MODE; + } + switch ($mode) { + case ADODB_FETCH_NUM: $this->fetchMode = FBSQL_NUM; break; + default: + case ADODB_FETCH_BOTH: $this->fetchMode = FBSQL_BOTH; break; + case ADODB_FETCH_ASSOC: $this->fetchMode = FBSQL_ASSOC; break; + } + return $this->ADORecordSet($queryID); + } + + function _initrs() + { + GLOBAL $ADODB_COUNTRECS; + $this->_numOfRows = ($ADODB_COUNTRECS) ? @fbsql_num_rows($this->_queryID):-1; + $this->_numOfFields = @fbsql_num_fields($this->_queryID); + } + + + + function &FetchField($fieldOffset = -1) { + if ($fieldOffset != -1) { + $o = @fbsql_fetch_field($this->_queryID, $fieldOffset); + //$o->max_length = -1; // fbsql returns the max length less spaces -- so it is unrealiable + $f = @fbsql_field_flags($this->_queryID,$fieldOffset); + $o->binary = (strpos($f,'binary')!== false); + } + else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */ + $o = @fbsql_fetch_field($this->_queryID);// fbsql returns the max length less spaces -- so it is unrealiable + //$o->max_length = -1; + } + + return $o; + } + + function _seek($row) + { + return @fbsql_data_seek($this->_queryID,$row); + } + + function _fetch($ignore_fields=false) + { + $this->fields = @fbsql_fetch_array($this->_queryID,$this->fetchMode); + return ($this->fields == true); + } + + function _close() { + return @fbsql_free_result($this->_queryID); + } + + function MetaType($t,$len=-1,$fieldobj=false) + { + if (is_object($t)) { + $fieldobj = $t; + $t = $fieldobj->type; + $len = $fieldobj->max_length; + } + $len = -1; // fbsql max_length is not accurate + switch (strtoupper($t)) { + case 'CHARACTER': + case 'CHARACTER VARYING': + case 'BLOB': + case 'CLOB': + case 'BIT': + case 'BIT VARYING': + if ($len <= $this->blobSize) return 'C'; + + // so we have to check whether binary... + case 'IMAGE': + case 'LONGBLOB': + case 'BLOB': + case 'MEDIUMBLOB': + return !empty($fieldobj->binary) ? 'B' : 'X'; + + case 'DATE': return 'D'; + + case 'TIME': + case 'TIME WITH TIME ZONE': + case 'TIMESTAMP': + case 'TIMESTAMP WITH TIME ZONE': return 'T'; + + case 'PRIMARY_KEY': + return 'R'; + case 'INTEGER': + case 'SMALLINT': + case 'BOOLEAN': + + if (!empty($fieldobj->primary_key)) return 'R'; + else return 'I'; + + default: return 'N'; + } + } } //class } // defined diff --git a/lib/WikiDB/adodb/drivers/adodb-firebird.inc.php b/lib/WikiDB/adodb/drivers/adodb-firebird.inc.php index 1ab67c87d..762c718a9 100644 --- a/lib/WikiDB/adodb/drivers/adodb-firebird.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-firebird.inc.php @@ -14,44 +14,44 @@ Set tabs to 4 for best viewing. include_once(ADODB_DIR."/drivers/adodb-ibase.inc.php"); class ADODB_firebird extends ADODB_ibase { - var $databaseType = "firebird"; - function ADODB_firebird() - { - $this->ADODB_ibase(); - } + var $databaseType = "firebird"; + function ADODB_firebird() + { + $this->ADODB_ibase(); + } - function ServerInfo() - { - $arr['dialect'] = $this->dialect; - switch($arr['dialect']) { - case '': - case '1': $s = 'Firebird Dialect 1'; break; - case '2': $s = 'Firebird Dialect 2'; break; - default: - case '3': $s = 'Firebird Dialect 3'; break; - } - $arr['version'] = ADOConnection::_findvers($s); - $arr['description'] = $s; - return $arr; - } + function ServerInfo() + { + $arr['dialect'] = $this->dialect; + switch($arr['dialect']) { + case '': + case '1': $s = 'Firebird Dialect 1'; break; + case '2': $s = 'Firebird Dialect 2'; break; + default: + case '3': $s = 'Firebird Dialect 3'; break; + } + $arr['version'] = ADOConnection::_findvers($s); + $arr['description'] = $s; + return $arr; + } - // Note that Interbase 6.5 uses this ROWS instead - don't you love forking wars! - // SELECT col1, col2 FROM table ROWS 5 -- get 5 rows - // SELECT col1, col2 FROM TABLE ORDER BY col1 ROWS 3 TO 7 -- first 5 skip 2 - function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false, $secs=0) - { - $str = 'SELECT '; - if ($nrows >= 0) $str .= "FIRST $nrows "; - $str .=($offset>=0) ? "SKIP $offset " : ''; + // Note that Interbase 6.5 uses this ROWS instead - don't you love forking wars! + // SELECT col1, col2 FROM table ROWS 5 -- get 5 rows + // SELECT col1, col2 FROM TABLE ORDER BY col1 ROWS 3 TO 7 -- first 5 skip 2 + function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false, $secs=0) + { + $str = 'SELECT '; + if ($nrows >= 0) $str .= "FIRST $nrows "; + $str .=($offset>=0) ? "SKIP $offset " : ''; - $sql = preg_replace('/^[ \t]*select/i',$str,$sql); - if ($secs) - $rs =& $this->CacheExecute($secs,$sql,$inputarr); - else - $rs =& $this->Execute($sql,$inputarr); + $sql = preg_replace('/^[ \t]*select/i',$str,$sql); + if ($secs) + $rs =& $this->CacheExecute($secs,$sql,$inputarr); + else + $rs =& $this->Execute($sql,$inputarr); - return $rs; - } + return $rs; + } }; @@ -59,11 +59,11 @@ class ADODB_firebird extends ADODB_ibase { class ADORecordSet_firebird extends ADORecordSet_ibase { - var $databaseType = "firebird"; + var $databaseType = "firebird"; - function ADORecordSet_firebird($id,$mode=false) - { - $this->ADORecordSet_ibase($id,$mode); - } + function ADORecordSet_firebird($id,$mode=false) + { + $this->ADORecordSet_ibase($id,$mode); + } } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/drivers/adodb-ibase.inc.php b/lib/WikiDB/adodb/drivers/adodb-ibase.inc.php index 9aa293812..296b5ec01 100644 --- a/lib/WikiDB/adodb/drivers/adodb-ibase.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-ibase.inc.php @@ -10,7 +10,7 @@ V4.22 15 Apr 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights rese Interbase data driver. Requires interbase client. Works on Windows and Unix. 3 Jan 2002 -- suggestions by Hans-Peter Oeri - changed transaction handling and added experimental blob stuff + changed transaction handling and added experimental blob stuff Docs to interbase at the website http://www.synectics.co.za/php3/tutorial/IB_PHP3_API.html @@ -25,105 +25,105 @@ V4.22 15 Apr 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights rese class ADODB_ibase extends ADOConnection { - var $databaseType = "ibase"; - var $dataProvider = "ibase"; - var $replaceQuote = "''"; // string to use to replace quotes - var $ibase_timefmt = '%Y-%m-%d'; // For hours,mins,secs change to '%Y-%m-%d %H:%M:%S'; - var $fmtDate = "'Y-m-d'"; - var $fmtTimeStamp = "'Y-m-d, H:i:s'"; - var $concat_operator='||'; - var $_transactionID; - var $metaTablesSQL = "select rdb\$relation_name from rdb\$relations where rdb\$relation_name not like 'RDB\$%'"; - //OPN STUFF start - var $metaColumnsSQL = "select a.rdb\$field_name, a.rdb\$null_flag, a.rdb\$default_source, b.rdb\$field_length, b.rdb\$field_scale, b.rdb\$field_sub_type, b.rdb\$field_precision, b.rdb\$field_type from rdb\$relation_fields a, rdb\$fields b where a.rdb\$field_source = b.rdb\$field_name and a.rdb\$relation_name = '%s' order by a.rdb\$field_position asc"; - //OPN STUFF end - var $ibasetrans; - var $hasGenID = true; - var $_bindInputArray = true; - var $buffers = 0; - var $dialect = 1; - var $sysDate = "cast('TODAY' as date)"; - var $sysTimeStamp = "cast('NOW' as timestamp)"; - var $ansiOuter = true; - var $hasAffectedRows = false; - var $poorAffectedRows = true; - var $blobEncodeType = 'C'; - - function ADODB_ibase() - { - if (defined('IBASE_DEFAULT')) $this->ibasetrans = IBASE_DEFAULT; - } - - function MetaPrimaryKeys($table,$owner_notused=false,$internalKey=false) - { - if ($internalKey) return array('RDB$DB_KEY'); - - $table = strtoupper($table); - - $sql = 'SELECT S.RDB$FIELD_NAME AFIELDNAME - FROM RDB$INDICES I JOIN RDB$INDEX_SEGMENTS S ON I.RDB$INDEX_NAME=S.RDB$INDEX_NAME - WHERE I.RDB$RELATION_NAME=\''.$table.'\' and I.RDB$INDEX_NAME like \'RDB$PRIMARY%\' - ORDER BY I.RDB$INDEX_NAME,S.RDB$FIELD_POSITION'; - - $a = $this->GetCol($sql,false,true); - if ($a && sizeof($a)>0) return $a; - return false; - } - - function ServerInfo() - { - $arr['dialect'] = $this->dialect; - switch($arr['dialect']) { - case '': - case '1': $s = 'Interbase 5.5 or earlier'; break; - case '2': $s = 'Interbase 5.6'; break; - default: - case '3': $s = 'Interbase 6.0'; break; - } - $arr['version'] = ADOConnection::_findvers($s); - $arr['description'] = $s; - return $arr; - } - - function BeginTrans() - { - if ($this->transOff) return true; - $this->transCnt += 1; - $this->autoCommit = false; - $this->_transactionID = $this->_connectionID;//ibase_trans($this->ibasetrans, $this->_connectionID); - return $this->_transactionID; - } - - function CommitTrans($ok=true) - { - if (!$ok) return $this->RollbackTrans(); - if ($this->transOff) return true; - if ($this->transCnt) $this->transCnt -= 1; - $ret = false; - $this->autoCommit = true; - if ($this->_transactionID) { - //print ' commit '; - $ret = ibase_commit($this->_transactionID); - } - $this->_transactionID = false; - return $ret; - } - - function RollbackTrans() - { - if ($this->transOff) return true; - if ($this->transCnt) $this->transCnt -= 1; - $ret = false; - $this->autoCommit = true; - if ($this->_transactionID) - $ret = ibase_rollback($this->_transactionID); - $this->_transactionID = false; - - return $ret; - } - - function &MetaIndexes ($table, $primary = FALSE, $owner=false) - { + var $databaseType = "ibase"; + var $dataProvider = "ibase"; + var $replaceQuote = "''"; // string to use to replace quotes + var $ibase_timefmt = '%Y-%m-%d'; // For hours,mins,secs change to '%Y-%m-%d %H:%M:%S'; + var $fmtDate = "'Y-m-d'"; + var $fmtTimeStamp = "'Y-m-d, H:i:s'"; + var $concat_operator='||'; + var $_transactionID; + var $metaTablesSQL = "select rdb\$relation_name from rdb\$relations where rdb\$relation_name not like 'RDB\$%'"; + //OPN STUFF start + var $metaColumnsSQL = "select a.rdb\$field_name, a.rdb\$null_flag, a.rdb\$default_source, b.rdb\$field_length, b.rdb\$field_scale, b.rdb\$field_sub_type, b.rdb\$field_precision, b.rdb\$field_type from rdb\$relation_fields a, rdb\$fields b where a.rdb\$field_source = b.rdb\$field_name and a.rdb\$relation_name = '%s' order by a.rdb\$field_position asc"; + //OPN STUFF end + var $ibasetrans; + var $hasGenID = true; + var $_bindInputArray = true; + var $buffers = 0; + var $dialect = 1; + var $sysDate = "cast('TODAY' as date)"; + var $sysTimeStamp = "cast('NOW' as timestamp)"; + var $ansiOuter = true; + var $hasAffectedRows = false; + var $poorAffectedRows = true; + var $blobEncodeType = 'C'; + + function ADODB_ibase() + { + if (defined('IBASE_DEFAULT')) $this->ibasetrans = IBASE_DEFAULT; + } + + function MetaPrimaryKeys($table,$owner_notused=false,$internalKey=false) + { + if ($internalKey) return array('RDB$DB_KEY'); + + $table = strtoupper($table); + + $sql = 'SELECT S.RDB$FIELD_NAME AFIELDNAME + FROM RDB$INDICES I JOIN RDB$INDEX_SEGMENTS S ON I.RDB$INDEX_NAME=S.RDB$INDEX_NAME + WHERE I.RDB$RELATION_NAME=\''.$table.'\' and I.RDB$INDEX_NAME like \'RDB$PRIMARY%\' + ORDER BY I.RDB$INDEX_NAME,S.RDB$FIELD_POSITION'; + + $a = $this->GetCol($sql,false,true); + if ($a && sizeof($a)>0) return $a; + return false; + } + + function ServerInfo() + { + $arr['dialect'] = $this->dialect; + switch($arr['dialect']) { + case '': + case '1': $s = 'Interbase 5.5 or earlier'; break; + case '2': $s = 'Interbase 5.6'; break; + default: + case '3': $s = 'Interbase 6.0'; break; + } + $arr['version'] = ADOConnection::_findvers($s); + $arr['description'] = $s; + return $arr; + } + + function BeginTrans() + { + if ($this->transOff) return true; + $this->transCnt += 1; + $this->autoCommit = false; + $this->_transactionID = $this->_connectionID;//ibase_trans($this->ibasetrans, $this->_connectionID); + return $this->_transactionID; + } + + function CommitTrans($ok=true) + { + if (!$ok) return $this->RollbackTrans(); + if ($this->transOff) return true; + if ($this->transCnt) $this->transCnt -= 1; + $ret = false; + $this->autoCommit = true; + if ($this->_transactionID) { + //print ' commit '; + $ret = ibase_commit($this->_transactionID); + } + $this->_transactionID = false; + return $ret; + } + + function RollbackTrans() + { + if ($this->transOff) return true; + if ($this->transCnt) $this->transCnt -= 1; + $ret = false; + $this->autoCommit = true; + if ($this->_transactionID) + $ret = ibase_rollback($this->_transactionID); + $this->_transactionID = false; + + return $ret; + } + + function &MetaIndexes ($table, $primary = FALSE, $owner=false) + { // save old fetch mode global $ADODB_FETCH_MODE; @@ -135,37 +135,37 @@ class ADODB_ibase extends ADOConnection { $table = strtoupper($table); $sql = "SELECT * FROM RDB\$INDICES WHERE RDB\$RELATION_NAME = '".$table."'"; if (!$primary) { - $sql .= " AND RDB\$INDEX_NAME NOT LIKE 'RDB\$%'"; + $sql .= " AND RDB\$INDEX_NAME NOT LIKE 'RDB\$%'"; } else { - $sql .= " AND RDB\$INDEX_NAME NOT LIKE 'RDB\$FOREIGN%'"; + $sql .= " AND RDB\$INDEX_NAME NOT LIKE 'RDB\$FOREIGN%'"; } // get index details $rs = $this->Execute($sql); if (!is_object($rs)) { - // restore fetchmode - if (isset($savem)) { - $this->SetFetchMode($savem); - } - $ADODB_FETCH_MODE = $save; + // restore fetchmode + if (isset($savem)) { + $this->SetFetchMode($savem); + } + $ADODB_FETCH_MODE = $save; return FALSE; } $indexes = array (); - while ($row = $rs->FetchRow()) { - $index = $row[0]; + while ($row = $rs->FetchRow()) { + $index = $row[0]; if (!isset($indexes[$index])) { - if (is_null($row[3])) {$row[3] = 0;} + if (is_null($row[3])) {$row[3] = 0;} $indexes[$index] = array( 'unique' => ($row[3] == 1), 'columns' => array() ); } - $sql = "SELECT * FROM RDB\$INDEX_SEGMENTS WHERE RDB\$INDEX_NAME = '".$name."' ORDER BY RDB\$FIELD_POSITION ASC"; - $rs1 = $this->Execute($sql); + $sql = "SELECT * FROM RDB\$INDEX_SEGMENTS WHERE RDB\$INDEX_NAME = '".$name."' ORDER BY RDB\$FIELD_POSITION ASC"; + $rs1 = $this->Execute($sql); while ($row1 = $rs1->FetchRow()) { - $indexes[$index]['columns'][$row1[2]] = $row1[1]; - } - } + $indexes[$index]['columns'][$row1[2]] = $row1[1]; + } + } // restore fetchmode if (isset($savem)) { $this->SetFetchMode($savem); @@ -173,642 +173,642 @@ class ADODB_ibase extends ADOConnection { $ADODB_FETCH_MODE = $save; return $indexes; - } - - - // See http://community.borland.com/article/0,1410,25844,00.html - function RowLock($tables,$where,$col) - { - if ($this->autoCommit) $this->BeginTrans(); - $this->Execute("UPDATE $table SET $col=$col WHERE $where "); // is this correct - jlim? - return 1; - } - - - function CreateSequence($seqname,$startID=1) - { - $ok = $this->Execute(("INSERT INTO RDB\$GENERATORS (RDB\$GENERATOR_NAME) VALUES (UPPER('$seqname'))" )); - if (!$ok) return false; - return $this->Execute("SET GENERATOR $seqname TO ".($startID-1).';'); - } - - function DropSequence($seqname) - { - $seqname = strtoupper($seqname); - $this->Execute("delete from RDB\$GENERATORS where RDB\$GENERATOR_NAME='$seqname'"); - } - - function GenID($seqname='adodbseq',$startID=1) - { - $getnext = ("SELECT Gen_ID($seqname,1) FROM RDB\$DATABASE"); - $rs = @$this->Execute($getnext); - if (!$rs) { - $this->Execute(("INSERT INTO RDB\$GENERATORS (RDB\$GENERATOR_NAME) VALUES (UPPER('$seqname'))" )); - $this->Execute("SET GENERATOR $seqname TO ".($startID-1).';'); - $rs = $this->Execute($getnext); - } - if ($rs && !$rs->EOF) $this->genID = (integer) reset($rs->fields); - else $this->genID = 0; // false - - if ($rs) $rs->Close(); - - return $this->genID; - } - - function SelectDB($dbName) - { - return false; - } - - function _handleerror() - { - $this->_errorMsg = ibase_errmsg(); - } - - function ErrorNo() - { - if (preg_match('/error code = ([\-0-9]*)/i', $this->_errorMsg,$arr)) return (integer) $arr[1]; - else return 0; - } - - function ErrorMsg() - { - return $this->_errorMsg; - } - - // returns true or false - function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) - { - if (!function_exists('ibase_pconnect')) return false; - if ($argDatabasename) $argHostname .= ':'.$argDatabasename; - $this->_connectionID = ibase_connect($argHostname,$argUsername,$argPassword,$this->charSet,$this->buffers,$this->dialect); - if ($this->dialect != 1) { // http://www.ibphoenix.com/ibp_60_del_id_ds.html - $this->replaceQuote = "''"; - } - if ($this->_connectionID === false) { - $this->_handleerror(); - return false; - } - - ibase_timefmt($this->ibase_timefmt); - return true; - } - // returns true or false - function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) - { - if (!function_exists('ibase_pconnect')) return false; - if ($argDatabasename) $argHostname .= ':'.$argDatabasename; - $this->_connectionID = ibase_pconnect($argHostname,$argUsername,$argPassword,$this->charSet,$this->buffers,$this->dialect); - if ($this->dialect != 1) { // http://www.ibphoenix.com/ibp_60_del_id_ds.html - $this->replaceQuote = "''"; - } - if ($this->_connectionID === false) { - $this->_handleerror(); - return false; - } - - ibase_timefmt($this->ibase_timefmt); - return true; - } - - function Prepare($sql) - { - $stmt = ibase_prepare($this->_connectionID,$sql); - if (!$stmt) return false; - return array($sql,$stmt); - } - - // returns query ID if successful, otherwise false - // there have been reports of problems with nested queries - the code is probably not re-entrant? - function _query($sql,$iarr=false) - { - - if (!$this->autoCommit && $this->_transactionID) { - $conn = $this->_transactionID; - $docommit = false; - } else { - $conn = $this->_connectionID; - $docommit = true; - } - if (is_array($sql)) { - $fn = 'ibase_execute'; - $sql = $sql[1]; - - if (is_array($iarr)) { - if (ADODB_PHPVER >= 0x4050) { // actually 4.0.4 - if ( !isset($iarr[0]) ) $iarr[0] = ''; // PHP5 compat hack - $fnarr =& array_merge( array($sql) , $iarr); - $ret = call_user_func_array($fn,$fnarr); - } else { - switch(sizeof($iarr)) { - case 1: $ret = $fn($sql,$iarr[0]); break; - case 2: $ret = $fn($sql,$iarr[0],$iarr[1]); break; - case 3: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2]); break; - case 4: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3]); break; - case 5: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4]); break; - case 6: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5]); break; - case 7: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6]); break; - default: ADOConnection::outp( "Too many parameters to ibase query $sql"); - case 8: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6],$iarr[7]); break; - } - } - } else $ret = $fn($sql); - } else { - $fn = 'ibase_query'; - - if (is_array($iarr)) { - if (ADODB_PHPVER >= 0x4050) { // actually 4.0.4 - if ( !isset($iarr[0]) ) $iarr[0] = ''; // PHP5 compat hack - $fnarr =& array_merge( array($conn,$sql) , $iarr); - $ret = call_user_func_array($fn,$fnarr); - } else { - switch(sizeof($iarr)) { - case 1: $ret = $fn($conn,$sql,$iarr[0]); break; - case 2: $ret = $fn($conn,$sql,$iarr[0],$iarr[1]); break; - case 3: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2]); break; - case 4: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3]); break; - case 5: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4]); break; - case 6: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5]); break; - case 7: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6]); break; - default: ADOConnection::outp( "Too many parameters to ibase query $sql"); - case 8: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6],$iarr[7]); break; - } - } - } else $ret = $fn($conn,$sql); - } - if ($docommit && $ret === true) ibase_commit($this->_connectionID); - - $this->_handleerror(); - return $ret; - } - - // returns true or false - function _close() - { - if (!$this->autoCommit) @ibase_rollback($this->_connectionID); - return @ibase_close($this->_connectionID); - } - - //OPN STUFF start - function _ConvertFieldType(&$fld, $ftype, $flen, $fscale, $fsubtype, $fprecision, $isInterbase6) - { - $fscale = abs($fscale); - $fld->max_length = $flen; - $fld->scale = null; - switch($ftype){ - case 7: - case 8: - if ($isInterbase6) { - switch($fsubtype){ - case 0: - $fld->type = ($ftype == 7 ? 'smallint' : 'integer'); - break; - case 1: - $fld->type = 'numeric'; - $fld->max_length = $fprecision; - $fld->scale = $fscale; - break; - case 2: - $fld->type = 'decimal'; - $fld->max_length = $fprecision; - $fld->scale = $fscale; - break; - } // switch - } else { - if ($fscale !=0) { - $fld->type = 'decimal'; - $fld->scale = $fscale; - $fld->max_length = ($ftype == 7 ? 4 : 9); - } else { - $fld->type = ($ftype == 7 ? 'smallint' : 'integer'); - } - } - break; - case 16: - if ($isInterbase6) { - switch($fsubtype){ - case 0: - $fld->type = 'decimal'; - $fld->max_length = 18; - $fld->scale = 0; - break; - case 1: - $fld->type = 'numeric'; - $fld->max_length = $fprecision; - $fld->scale = $fscale; - break; - case 2: - $fld->type = 'decimal'; - $fld->max_length = $fprecision; - $fld->scale = $fscale; - break; - } // switch - } - break; - case 10: - $fld->type = 'float'; - break; - case 14: - $fld->type = 'char'; - break; - case 27: - if ($fscale !=0) { - $fld->type = 'decimal'; - $fld->max_length = 15; - $fld->scale = 5; - } else { - $fld->type = 'double'; - } - break; - case 35: - if ($isInterbase6) { - $fld->type = 'timestamp'; - } else { - $fld->type = 'date'; - } - break; - case 12: - case 13: - $fld->type = 'date'; - break; - case 37: - $fld->type = 'varchar'; - break; - case 40: - $fld->type = 'cstring'; - break; - case 261: - $fld->type = 'blob'; - $fld->max_length = -1; - break; - } // switch - } - //OPN STUFF end - // returns array of ADOFieldObjects for current table - function &MetaColumns($table) - { - global $ADODB_FETCH_MODE; - - if ($this->metaColumnsSQL) { - - $save = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - - $rs = $this->Execute(sprintf($this->metaColumnsSQL,strtoupper($table))); - - $ADODB_FETCH_MODE = $save; - if ($rs === false) return false; - - $retarr = array(); - //OPN STUFF start - $isInterbase6 = ($this->dialect==3 ? true : false); - //OPN STUFF end - while (!$rs->EOF) { //print_r($rs->fields); - $fld = new ADOFieldObject(); - $fld->name = trim($rs->fields[0]); - //OPN STUFF start - $this->_ConvertFieldType($fld, $rs->fields[7], $rs->fields[3], $rs->fields[4], $rs->fields[5], $rs->fields[6], $isInterbase6); - if (isset($rs->fields[1]) && $rs->fields[1]) { - $fld->not_null = true; - } - if (isset($rs->fields[2])) { - - $fld->has_default = true; - $d = substr($rs->fields[2],strlen('default ')); - switch ($fld->type) - { - case 'smallint': - case 'integer': $fld->default_value = (int) $d; break; - case 'char': - case 'blob': - case 'text': - case 'varchar': $fld->default_value = (string) substr($d,1,strlen($d)-2); break; - case 'double': - case 'float': $fld->default_value = (float) $d; break; - default: $fld->default_value = $d; break; - } - // case 35:$tt = 'TIMESTAMP'; break; - } - if ((isset($rs->fields[5])) && ($fld->type == 'blob')) { - $fld->sub_type = $rs->fields[5]; - } else { - $fld->sub_type = null; - } - //OPN STUFF end - if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld; - else $retarr[strtoupper($fld->name)] = $fld; - - $rs->MoveNext(); - } - $rs->Close(); - return $retarr; - } - return false; - } - - function BlobEncode( $blob ) - { - $blobid = ibase_blob_create( $this->_connectionID); - ibase_blob_add( $blobid, $blob ); - return ibase_blob_close( $blobid ); - } - - // since we auto-decode all blob's since 2.42, - // BlobDecode should not do any transforms - function BlobDecode($blob) - { - return $blob; - } - - - - - // old blobdecode function - // still used to auto-decode all blob's - function _BlobDecode( $blob ) - { - $blobid = ibase_blob_open( $blob ); - $realblob = ibase_blob_get( $blobid,$this->maxblobsize); // 2nd param is max size of blob -- Kevin Boillet - while($string = ibase_blob_get($blobid, 8192)){ - $realblob .= $string; - } - ibase_blob_close( $blobid ); - - return( $realblob ); - } - - function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB') - { - $fd = fopen($path,'rb'); - if ($fd === false) return false; - $blob_id = ibase_blob_create($this->_connectionID); - - /* fill with data */ - - while ($val = fread($fd,32768)){ - ibase_blob_add($blob_id, $val); - } - - /* close and get $blob_id_str for inserting into table */ - $blob_id_str = ibase_blob_close($blob_id); - - fclose($fd); - return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; - } - - /* - Insert a null into the blob field of the table first. - Then use UpdateBlob to store the blob. - - Usage: - - $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); - $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); - */ - function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') - { - $blob_id = ibase_blob_create($this->_connectionID); - - // ibase_blob_add($blob_id, $val); - - // replacement that solves the problem by which only the first modulus 64K / - // of $val are stored at the blob field //////////////////////////////////// - // Thx Abel Berenstein aberenstein#afip.gov.ar - $len = strlen($val); - $chunk_size = 32768; - $tail_size = $len % $chunk_size; - $n_chunks = ($len - $tail_size) / $chunk_size; - - for ($n = 0; $n < $n_chunks; $n++) { - $start = $n * $chunk_size; - $data = substr($val, $start, $chunk_size); - ibase_blob_add($blob_id, $data); - } - - if ($tail_size) { - $start = $n_chunks * $chunk_size; - $data = substr($val, $start, $tail_size); - ibase_blob_add($blob_id, $data); - } - // end replacement ///////////////////////////////////////////////////////// - - $blob_id_str = ibase_blob_close($blob_id); - - return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; - - } - - - function OldUpdateBlob($table,$column,$val,$where,$blobtype='BLOB') - { - $blob_id = ibase_blob_create($this->_connectionID); - ibase_blob_add($blob_id, $val); - $blob_id_str = ibase_blob_close($blob_id); - return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; - } - - // Format date column in sql string given an input format that understands Y M D - // Only since Interbase 6.0 - uses EXTRACT - // problem - does not zero-fill the day and month yet - function SQLDate($fmt, $col=false) - { - if (!$col) $col = $this->sysDate; - $s = ''; - - $len = strlen($fmt); - for ($i=0; $i < $len; $i++) { - if ($s) $s .= '||'; - $ch = $fmt[$i]; - switch($ch) { - case 'Y': - case 'y': - $s .= "extract(year from $col)"; - break; - case 'M': - case 'm': - $s .= "extract(month from $col)"; - break; - case 'Q': - case 'q': - $s .= "cast(((extract(month from $col)+2) / 3) as integer)"; - break; - case 'D': - case 'd': - $s .= "(extract(day from $col))"; - break; - case 'H': - case 'h': - $s .= "(extract(hour from $col))"; - break; - case 'I': - case 'i': - $s .= "(extract(minute from $col))"; - break; - case 'S': - case 's': - $s .= "CAST((extract(second from $col)) AS INTEGER)"; - break; - - default: - if ($ch == '\\') { - $i++; - $ch = substr($fmt,$i,1); - } - $s .= $this->qstr($ch); - break; - } - } - return $s; - } + } + + + // See http://community.borland.com/article/0,1410,25844,00.html + function RowLock($tables,$where,$col) + { + if ($this->autoCommit) $this->BeginTrans(); + $this->Execute("UPDATE $table SET $col=$col WHERE $where "); // is this correct - jlim? + return 1; + } + + + function CreateSequence($seqname,$startID=1) + { + $ok = $this->Execute(("INSERT INTO RDB\$GENERATORS (RDB\$GENERATOR_NAME) VALUES (UPPER('$seqname'))" )); + if (!$ok) return false; + return $this->Execute("SET GENERATOR $seqname TO ".($startID-1).';'); + } + + function DropSequence($seqname) + { + $seqname = strtoupper($seqname); + $this->Execute("delete from RDB\$GENERATORS where RDB\$GENERATOR_NAME='$seqname'"); + } + + function GenID($seqname='adodbseq',$startID=1) + { + $getnext = ("SELECT Gen_ID($seqname,1) FROM RDB\$DATABASE"); + $rs = @$this->Execute($getnext); + if (!$rs) { + $this->Execute(("INSERT INTO RDB\$GENERATORS (RDB\$GENERATOR_NAME) VALUES (UPPER('$seqname'))" )); + $this->Execute("SET GENERATOR $seqname TO ".($startID-1).';'); + $rs = $this->Execute($getnext); + } + if ($rs && !$rs->EOF) $this->genID = (integer) reset($rs->fields); + else $this->genID = 0; // false + + if ($rs) $rs->Close(); + + return $this->genID; + } + + function SelectDB($dbName) + { + return false; + } + + function _handleerror() + { + $this->_errorMsg = ibase_errmsg(); + } + + function ErrorNo() + { + if (preg_match('/error code = ([\-0-9]*)/i', $this->_errorMsg,$arr)) return (integer) $arr[1]; + else return 0; + } + + function ErrorMsg() + { + return $this->_errorMsg; + } + + // returns true or false + function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) + { + if (!function_exists('ibase_pconnect')) return false; + if ($argDatabasename) $argHostname .= ':'.$argDatabasename; + $this->_connectionID = ibase_connect($argHostname,$argUsername,$argPassword,$this->charSet,$this->buffers,$this->dialect); + if ($this->dialect != 1) { // http://www.ibphoenix.com/ibp_60_del_id_ds.html + $this->replaceQuote = "''"; + } + if ($this->_connectionID === false) { + $this->_handleerror(); + return false; + } + + ibase_timefmt($this->ibase_timefmt); + return true; + } + // returns true or false + function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) + { + if (!function_exists('ibase_pconnect')) return false; + if ($argDatabasename) $argHostname .= ':'.$argDatabasename; + $this->_connectionID = ibase_pconnect($argHostname,$argUsername,$argPassword,$this->charSet,$this->buffers,$this->dialect); + if ($this->dialect != 1) { // http://www.ibphoenix.com/ibp_60_del_id_ds.html + $this->replaceQuote = "''"; + } + if ($this->_connectionID === false) { + $this->_handleerror(); + return false; + } + + ibase_timefmt($this->ibase_timefmt); + return true; + } + + function Prepare($sql) + { + $stmt = ibase_prepare($this->_connectionID,$sql); + if (!$stmt) return false; + return array($sql,$stmt); + } + + // returns query ID if successful, otherwise false + // there have been reports of problems with nested queries - the code is probably not re-entrant? + function _query($sql,$iarr=false) + { + + if (!$this->autoCommit && $this->_transactionID) { + $conn = $this->_transactionID; + $docommit = false; + } else { + $conn = $this->_connectionID; + $docommit = true; + } + if (is_array($sql)) { + $fn = 'ibase_execute'; + $sql = $sql[1]; + + if (is_array($iarr)) { + if (ADODB_PHPVER >= 0x4050) { // actually 4.0.4 + if ( !isset($iarr[0]) ) $iarr[0] = ''; // PHP5 compat hack + $fnarr =& array_merge( array($sql) , $iarr); + $ret = call_user_func_array($fn,$fnarr); + } else { + switch(sizeof($iarr)) { + case 1: $ret = $fn($sql,$iarr[0]); break; + case 2: $ret = $fn($sql,$iarr[0],$iarr[1]); break; + case 3: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2]); break; + case 4: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3]); break; + case 5: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4]); break; + case 6: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5]); break; + case 7: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6]); break; + default: ADOConnection::outp( "Too many parameters to ibase query $sql"); + case 8: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6],$iarr[7]); break; + } + } + } else $ret = $fn($sql); + } else { + $fn = 'ibase_query'; + + if (is_array($iarr)) { + if (ADODB_PHPVER >= 0x4050) { // actually 4.0.4 + if ( !isset($iarr[0]) ) $iarr[0] = ''; // PHP5 compat hack + $fnarr =& array_merge( array($conn,$sql) , $iarr); + $ret = call_user_func_array($fn,$fnarr); + } else { + switch(sizeof($iarr)) { + case 1: $ret = $fn($conn,$sql,$iarr[0]); break; + case 2: $ret = $fn($conn,$sql,$iarr[0],$iarr[1]); break; + case 3: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2]); break; + case 4: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3]); break; + case 5: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4]); break; + case 6: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5]); break; + case 7: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6]); break; + default: ADOConnection::outp( "Too many parameters to ibase query $sql"); + case 8: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6],$iarr[7]); break; + } + } + } else $ret = $fn($conn,$sql); + } + if ($docommit && $ret === true) ibase_commit($this->_connectionID); + + $this->_handleerror(); + return $ret; + } + + // returns true or false + function _close() + { + if (!$this->autoCommit) @ibase_rollback($this->_connectionID); + return @ibase_close($this->_connectionID); + } + + //OPN STUFF start + function _ConvertFieldType(&$fld, $ftype, $flen, $fscale, $fsubtype, $fprecision, $isInterbase6) + { + $fscale = abs($fscale); + $fld->max_length = $flen; + $fld->scale = null; + switch($ftype){ + case 7: + case 8: + if ($isInterbase6) { + switch($fsubtype){ + case 0: + $fld->type = ($ftype == 7 ? 'smallint' : 'integer'); + break; + case 1: + $fld->type = 'numeric'; + $fld->max_length = $fprecision; + $fld->scale = $fscale; + break; + case 2: + $fld->type = 'decimal'; + $fld->max_length = $fprecision; + $fld->scale = $fscale; + break; + } // switch + } else { + if ($fscale !=0) { + $fld->type = 'decimal'; + $fld->scale = $fscale; + $fld->max_length = ($ftype == 7 ? 4 : 9); + } else { + $fld->type = ($ftype == 7 ? 'smallint' : 'integer'); + } + } + break; + case 16: + if ($isInterbase6) { + switch($fsubtype){ + case 0: + $fld->type = 'decimal'; + $fld->max_length = 18; + $fld->scale = 0; + break; + case 1: + $fld->type = 'numeric'; + $fld->max_length = $fprecision; + $fld->scale = $fscale; + break; + case 2: + $fld->type = 'decimal'; + $fld->max_length = $fprecision; + $fld->scale = $fscale; + break; + } // switch + } + break; + case 10: + $fld->type = 'float'; + break; + case 14: + $fld->type = 'char'; + break; + case 27: + if ($fscale !=0) { + $fld->type = 'decimal'; + $fld->max_length = 15; + $fld->scale = 5; + } else { + $fld->type = 'double'; + } + break; + case 35: + if ($isInterbase6) { + $fld->type = 'timestamp'; + } else { + $fld->type = 'date'; + } + break; + case 12: + case 13: + $fld->type = 'date'; + break; + case 37: + $fld->type = 'varchar'; + break; + case 40: + $fld->type = 'cstring'; + break; + case 261: + $fld->type = 'blob'; + $fld->max_length = -1; + break; + } // switch + } + //OPN STUFF end + // returns array of ADOFieldObjects for current table + function &MetaColumns($table) + { + global $ADODB_FETCH_MODE; + + if ($this->metaColumnsSQL) { + + $save = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + + $rs = $this->Execute(sprintf($this->metaColumnsSQL,strtoupper($table))); + + $ADODB_FETCH_MODE = $save; + if ($rs === false) return false; + + $retarr = array(); + //OPN STUFF start + $isInterbase6 = ($this->dialect==3 ? true : false); + //OPN STUFF end + while (!$rs->EOF) { //print_r($rs->fields); + $fld = new ADOFieldObject(); + $fld->name = trim($rs->fields[0]); + //OPN STUFF start + $this->_ConvertFieldType($fld, $rs->fields[7], $rs->fields[3], $rs->fields[4], $rs->fields[5], $rs->fields[6], $isInterbase6); + if (isset($rs->fields[1]) && $rs->fields[1]) { + $fld->not_null = true; + } + if (isset($rs->fields[2])) { + + $fld->has_default = true; + $d = substr($rs->fields[2],strlen('default ')); + switch ($fld->type) + { + case 'smallint': + case 'integer': $fld->default_value = (int) $d; break; + case 'char': + case 'blob': + case 'text': + case 'varchar': $fld->default_value = (string) substr($d,1,strlen($d)-2); break; + case 'double': + case 'float': $fld->default_value = (float) $d; break; + default: $fld->default_value = $d; break; + } + // case 35:$tt = 'TIMESTAMP'; break; + } + if ((isset($rs->fields[5])) && ($fld->type == 'blob')) { + $fld->sub_type = $rs->fields[5]; + } else { + $fld->sub_type = null; + } + //OPN STUFF end + if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld; + else $retarr[strtoupper($fld->name)] = $fld; + + $rs->MoveNext(); + } + $rs->Close(); + return $retarr; + } + return false; + } + + function BlobEncode( $blob ) + { + $blobid = ibase_blob_create( $this->_connectionID); + ibase_blob_add( $blobid, $blob ); + return ibase_blob_close( $blobid ); + } + + // since we auto-decode all blob's since 2.42, + // BlobDecode should not do any transforms + function BlobDecode($blob) + { + return $blob; + } + + + + + // old blobdecode function + // still used to auto-decode all blob's + function _BlobDecode( $blob ) + { + $blobid = ibase_blob_open( $blob ); + $realblob = ibase_blob_get( $blobid,$this->maxblobsize); // 2nd param is max size of blob -- Kevin Boillet + while($string = ibase_blob_get($blobid, 8192)){ + $realblob .= $string; + } + ibase_blob_close( $blobid ); + + return( $realblob ); + } + + function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB') + { + $fd = fopen($path,'rb'); + if ($fd === false) return false; + $blob_id = ibase_blob_create($this->_connectionID); + + /* fill with data */ + + while ($val = fread($fd,32768)){ + ibase_blob_add($blob_id, $val); + } + + /* close and get $blob_id_str for inserting into table */ + $blob_id_str = ibase_blob_close($blob_id); + + fclose($fd); + return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; + } + + /* + Insert a null into the blob field of the table first. + Then use UpdateBlob to store the blob. + + Usage: + + $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); + $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); + */ + function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') + { + $blob_id = ibase_blob_create($this->_connectionID); + + // ibase_blob_add($blob_id, $val); + + // replacement that solves the problem by which only the first modulus 64K / + // of $val are stored at the blob field //////////////////////////////////// + // Thx Abel Berenstein aberenstein#afip.gov.ar + $len = strlen($val); + $chunk_size = 32768; + $tail_size = $len % $chunk_size; + $n_chunks = ($len - $tail_size) / $chunk_size; + + for ($n = 0; $n < $n_chunks; $n++) { + $start = $n * $chunk_size; + $data = substr($val, $start, $chunk_size); + ibase_blob_add($blob_id, $data); + } + + if ($tail_size) { + $start = $n_chunks * $chunk_size; + $data = substr($val, $start, $tail_size); + ibase_blob_add($blob_id, $data); + } + // end replacement ///////////////////////////////////////////////////////// + + $blob_id_str = ibase_blob_close($blob_id); + + return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; + + } + + + function OldUpdateBlob($table,$column,$val,$where,$blobtype='BLOB') + { + $blob_id = ibase_blob_create($this->_connectionID); + ibase_blob_add($blob_id, $val); + $blob_id_str = ibase_blob_close($blob_id); + return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; + } + + // Format date column in sql string given an input format that understands Y M D + // Only since Interbase 6.0 - uses EXTRACT + // problem - does not zero-fill the day and month yet + function SQLDate($fmt, $col=false) + { + if (!$col) $col = $this->sysDate; + $s = ''; + + $len = strlen($fmt); + for ($i=0; $i < $len; $i++) { + if ($s) $s .= '||'; + $ch = $fmt[$i]; + switch($ch) { + case 'Y': + case 'y': + $s .= "extract(year from $col)"; + break; + case 'M': + case 'm': + $s .= "extract(month from $col)"; + break; + case 'Q': + case 'q': + $s .= "cast(((extract(month from $col)+2) / 3) as integer)"; + break; + case 'D': + case 'd': + $s .= "(extract(day from $col))"; + break; + case 'H': + case 'h': + $s .= "(extract(hour from $col))"; + break; + case 'I': + case 'i': + $s .= "(extract(minute from $col))"; + break; + case 'S': + case 's': + $s .= "CAST((extract(second from $col)) AS INTEGER)"; + break; + + default: + if ($ch == '\\') { + $i++; + $ch = substr($fmt,$i,1); + } + $s .= $this->qstr($ch); + break; + } + } + return $s; + } } /*-------------------------------------------------------------------------------------- - Class Name: Recordset + Class Name: Recordset --------------------------------------------------------------------------------------*/ class ADORecordset_ibase extends ADORecordSet { - var $databaseType = "ibase"; - var $bind=false; - var $_cacheType; - - function ADORecordset_ibase($id,$mode=false) - { - global $ADODB_FETCH_MODE; - - $this->fetchMode = ($mode === false) ? $ADODB_FETCH_MODE : $mode; - return $this->ADORecordSet($id); - } - - /* Returns: an object containing field information. - Get column information in the Recordset object. fetchField() can be used in order to obtain information about - fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by - fetchField() is retrieved. */ - - function &FetchField($fieldOffset = -1) - { - $fld = new ADOFieldObject; - $ibf = ibase_field_info($this->_queryID,$fieldOffset); - $fld->name = strtolower($ibf['alias']); - if (empty($fld->name)) $fld->name = strtolower($ibf['name']); - $fld->type = $ibf['type']; - $fld->max_length = $ibf['length']; - return $fld; - } - - function _initrs() - { - $this->_numOfRows = -1; - $this->_numOfFields = @ibase_num_fields($this->_queryID); - - // cache types for blob decode check - for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { - $f1 = $this->FetchField($i); - $this->_cacheType[] = $f1->type; - } - } - - function _seek($row) - { - return false; - } - - - - function _fetch() - { - $f = @ibase_fetch_row($this->_queryID); - if ($f === false) { - $this->fields = false; - return false; - } - // OPN stuff start - optimized - // fix missing nulls and decode blobs automatically - - global $ADODB_ANSI_PADDING_OFF; - //$ADODB_ANSI_PADDING_OFF=1; - $rtrim = !empty($ADODB_ANSI_PADDING_OFF); - - for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { - if ($this->_cacheType[$i]=="BLOB") { - if (isset($f[$i])) { - $f[$i] = $this->connection->_BlobDecode($f[$i]); - } else { - $f[$i] = null; - } - } else { - if (!isset($f[$i])) { - $f[$i] = null; - } else if ($rtrim && is_string($f[$i])) { - $f[$i] = rtrim($f[$i]); - } - } - } - // OPN stuff end - - $this->fields = $f; - if ($this->fetchMode == ADODB_FETCH_ASSOC) { - $this->fields = &$this->GetRowAssoc(ADODB_ASSOC_CASE); - } else if ($this->fetchMode == ADODB_FETCH_BOTH) { - $this->fields =& array_merge($this->fields,$this->GetRowAssoc(ADODB_ASSOC_CASE)); - } - return true; - } - - /* Use associative array to get fields array */ - function Fields($colname) - { - if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname]; - if (!$this->bind) { - $this->bind = array(); - for ($i=0; $i < $this->_numOfFields; $i++) { - $o = $this->FetchField($i); - $this->bind[strtoupper($o->name)] = $i; - } - } - - return $this->fields[$this->bind[strtoupper($colname)]]; - - } - - - function _close() - { - return @ibase_free_result($this->_queryID); - } - - function MetaType($t,$len=-1,$fieldobj=false) - { - if (is_object($t)) { - $fieldobj = $t; - $t = $fieldobj->type; - $len = $fieldobj->max_length; - } - switch (strtoupper($t)) { - case 'CHAR': - return 'C'; - - case 'TEXT': - case 'VARCHAR': - case 'VARYING': - if ($len <= $this->blobSize) return 'C'; - return 'X'; - case 'BLOB': - return 'B'; - - case 'TIMESTAMP': - case 'DATE': return 'D'; - - //case 'T': return 'T'; - - //case 'L': return 'L'; - case 'INT': - case 'SHORT': - case 'INTEGER': return 'I'; - default: return 'N'; - } - } + var $databaseType = "ibase"; + var $bind=false; + var $_cacheType; + + function ADORecordset_ibase($id,$mode=false) + { + global $ADODB_FETCH_MODE; + + $this->fetchMode = ($mode === false) ? $ADODB_FETCH_MODE : $mode; + return $this->ADORecordSet($id); + } + + /* Returns: an object containing field information. + Get column information in the Recordset object. fetchField() can be used in order to obtain information about + fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by + fetchField() is retrieved. */ + + function &FetchField($fieldOffset = -1) + { + $fld = new ADOFieldObject; + $ibf = ibase_field_info($this->_queryID,$fieldOffset); + $fld->name = strtolower($ibf['alias']); + if (empty($fld->name)) $fld->name = strtolower($ibf['name']); + $fld->type = $ibf['type']; + $fld->max_length = $ibf['length']; + return $fld; + } + + function _initrs() + { + $this->_numOfRows = -1; + $this->_numOfFields = @ibase_num_fields($this->_queryID); + + // cache types for blob decode check + for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { + $f1 = $this->FetchField($i); + $this->_cacheType[] = $f1->type; + } + } + + function _seek($row) + { + return false; + } + + + + function _fetch() + { + $f = @ibase_fetch_row($this->_queryID); + if ($f === false) { + $this->fields = false; + return false; + } + // OPN stuff start - optimized + // fix missing nulls and decode blobs automatically + + global $ADODB_ANSI_PADDING_OFF; + //$ADODB_ANSI_PADDING_OFF=1; + $rtrim = !empty($ADODB_ANSI_PADDING_OFF); + + for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { + if ($this->_cacheType[$i]=="BLOB") { + if (isset($f[$i])) { + $f[$i] = $this->connection->_BlobDecode($f[$i]); + } else { + $f[$i] = null; + } + } else { + if (!isset($f[$i])) { + $f[$i] = null; + } else if ($rtrim && is_string($f[$i])) { + $f[$i] = rtrim($f[$i]); + } + } + } + // OPN stuff end + + $this->fields = $f; + if ($this->fetchMode == ADODB_FETCH_ASSOC) { + $this->fields = &$this->GetRowAssoc(ADODB_ASSOC_CASE); + } else if ($this->fetchMode == ADODB_FETCH_BOTH) { + $this->fields =& array_merge($this->fields,$this->GetRowAssoc(ADODB_ASSOC_CASE)); + } + return true; + } + + /* Use associative array to get fields array */ + function Fields($colname) + { + if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname]; + if (!$this->bind) { + $this->bind = array(); + for ($i=0; $i < $this->_numOfFields; $i++) { + $o = $this->FetchField($i); + $this->bind[strtoupper($o->name)] = $i; + } + } + + return $this->fields[$this->bind[strtoupper($colname)]]; + + } + + + function _close() + { + return @ibase_free_result($this->_queryID); + } + + function MetaType($t,$len=-1,$fieldobj=false) + { + if (is_object($t)) { + $fieldobj = $t; + $t = $fieldobj->type; + $len = $fieldobj->max_length; + } + switch (strtoupper($t)) { + case 'CHAR': + return 'C'; + + case 'TEXT': + case 'VARCHAR': + case 'VARYING': + if ($len <= $this->blobSize) return 'C'; + return 'X'; + case 'BLOB': + return 'B'; + + case 'TIMESTAMP': + case 'DATE': return 'D'; + + //case 'T': return 'T'; + + //case 'L': return 'L'; + case 'INT': + case 'SHORT': + case 'INTEGER': return 'I'; + default: return 'N'; + } + } } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/drivers/adodb-informix.inc.php b/lib/WikiDB/adodb/drivers/adodb-informix.inc.php index 228a406c2..d4766257e 100644 --- a/lib/WikiDB/adodb/drivers/adodb-informix.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-informix.inc.php @@ -15,16 +15,16 @@ include_once(ADODB_DIR.'/drivers/adodb-informix72.inc.php'); class ADODB_informix extends ADODB_informix72 { - var $databaseType = "informix"; - var $hasTop = 'FIRST'; - var $ansiOuter = true; + var $databaseType = "informix"; + var $hasTop = 'FIRST'; + var $ansiOuter = true; } class ADORecordset_informix extends ADORecordset_informix72 { - var $databaseType = "informix"; - function ADORecordset_informix($id,$mode=false) - { - $this->ADORecordset_informix72($id,$mode); - } + var $databaseType = "informix"; + function ADORecordset_informix($id,$mode=false) + { + $this->ADORecordset_informix72($id,$mode); + } } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/drivers/adodb-informix72.inc.php b/lib/WikiDB/adodb/drivers/adodb-informix72.inc.php index 8109dfb37..3cb910845 100644 --- a/lib/WikiDB/adodb/drivers/adodb-informix72.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-informix72.inc.php @@ -17,376 +17,376 @@ V4.22 15 Apr 2004 (c) 2000-2004 John Lim. All rights reserved. if (!defined('IFX_SCROLL')) define('IFX_SCROLL',1); class ADODB_informix72 extends ADOConnection { - var $databaseType = "informix72"; - var $dataProvider = "informix"; - var $replaceQuote = "''"; // string to use to replace quotes - var $fmtDate = "'Y-m-d'"; - var $fmtTimeStamp = "'Y-m-d H:i:s'"; - var $hasInsertID = true; - var $hasAffectedRows = true; - var $upperCase = 'upper'; + var $databaseType = "informix72"; + var $dataProvider = "informix"; + var $replaceQuote = "''"; // string to use to replace quotes + var $fmtDate = "'Y-m-d'"; + var $fmtTimeStamp = "'Y-m-d H:i:s'"; + var $hasInsertID = true; + var $hasAffectedRows = true; + var $upperCase = 'upper'; var $substr = 'substr'; - var $metaTablesSQL="select tabname from systables"; - var $metaColumnsSQL = + var $metaTablesSQL="select tabname from systables"; + var $metaColumnsSQL = "select c.colname, c.coltype, c.collength, d.default - from syscolumns c, systables t,sysdefaults d - where c.tabid=t.tabid and d.tabid=t.tabid and d.colno=c.colno and tabname='%s'"; + from syscolumns c, systables t,sysdefaults d + where c.tabid=t.tabid and d.tabid=t.tabid and d.colno=c.colno and tabname='%s'"; // var $metaColumnsSQL = "select colname, coltype, collength from syscolumns c, systables t where c.tabid=t.tabid and tabname='%s'"; - var $concat_operator = '||'; - - var $lastQuery = false; - var $has_insertid = true; - - var $_autocommit = true; - var $_bindInputArray = true; // set to true if ADOConnection.Execute() permits binding of array parameters. - var $sysDate = 'TODAY'; - var $sysTimeStamp = 'CURRENT'; - var $cursorType = IFX_SCROLL; // IFX_SCROLL or IFX_HOLD or 0 - - function ADODB_informix72() - { - // alternatively, use older method: - //putenv("DBDATE=Y4MD-"); - - // force ISO date format - putenv('GL_DATE=%Y-%m-%d'); - - if (function_exists('ifx_byteasvarchar')) { - ifx_byteasvarchar(1); // Mode "0" will return a blob id, and mode "1" will return a varchar with text content. - ifx_textasvarchar(1); // Mode "0" will return a blob id, and mode "1" will return a varchar with text content. - ifx_blobinfile_mode(0); // Mode "0" means save Byte-Blobs in memory, and mode "1" means save Byte-Blobs in a file. - } - } - - function ServerInfo() - { - if (isset($this->version)) return $this->version; - - $arr['description'] = $this->GetOne("select DBINFO('version','full') from systables where tabid = 1"); - $arr['version'] = $this->GetOne("select DBINFO('version','major')||"."||DBINFO('version','minor') from systables where tabid = 1"); - $this->version = $arr; - return $arr; - } - - - - function _insertid() - { - $sqlca =ifx_getsqlca($this->lastQuery); - return @$sqlca["sqlerrd1"]; - } - - function _affectedrows() - { - if ($this->lastQuery) { - return @ifx_affected_rows ($this->lastQuery); - } - return 0; - } - - function BeginTrans() - { - if ($this->transOff) return true; - $this->transCnt += 1; - $this->Execute('BEGIN'); - $this->_autocommit = false; - return true; - } - - function CommitTrans($ok=true) - { - if (!$ok) return $this->RollbackTrans(); - if ($this->transOff) return true; - if ($this->transCnt) $this->transCnt -= 1; - $this->Execute('COMMIT'); - $this->_autocommit = true; - return true; - } - - function RollbackTrans() - { - if ($this->transOff) return true; - if ($this->transCnt) $this->transCnt -= 1; - $this->Execute('ROLLBACK'); - $this->_autocommit = true; - return true; - } - - function RowLock($tables,$where) - { - if ($this->_autocommit) $this->BeginTrans(); - return $this->GetOne("select 1 as ignore from $tables where $where for update"); - } - - /* Returns: the last error message from previous database operation - Note: This function is NOT available for Microsoft SQL Server. */ - - function ErrorMsg() - { - if (!empty($this->_logsql)) return $this->_errorMsg; - $this->_errorMsg = ifx_errormsg(); - return $this->_errorMsg; - } - - function ErrorNo() - { - preg_match("/.*SQLCODE=([^\]]*)/",ifx_error(),$parse); //!EOS - if (is_array($parse) && isset($parse[1])) return (int)$parse[1]; - return 0; - } + var $concat_operator = '||'; + + var $lastQuery = false; + var $has_insertid = true; + + var $_autocommit = true; + var $_bindInputArray = true; // set to true if ADOConnection.Execute() permits binding of array parameters. + var $sysDate = 'TODAY'; + var $sysTimeStamp = 'CURRENT'; + var $cursorType = IFX_SCROLL; // IFX_SCROLL or IFX_HOLD or 0 + + function ADODB_informix72() + { + // alternatively, use older method: + //putenv("DBDATE=Y4MD-"); + + // force ISO date format + putenv('GL_DATE=%Y-%m-%d'); + + if (function_exists('ifx_byteasvarchar')) { + ifx_byteasvarchar(1); // Mode "0" will return a blob id, and mode "1" will return a varchar with text content. + ifx_textasvarchar(1); // Mode "0" will return a blob id, and mode "1" will return a varchar with text content. + ifx_blobinfile_mode(0); // Mode "0" means save Byte-Blobs in memory, and mode "1" means save Byte-Blobs in a file. + } + } + + function ServerInfo() + { + if (isset($this->version)) return $this->version; + + $arr['description'] = $this->GetOne("select DBINFO('version','full') from systables where tabid = 1"); + $arr['version'] = $this->GetOne("select DBINFO('version','major')||"."||DBINFO('version','minor') from systables where tabid = 1"); + $this->version = $arr; + return $arr; + } + + + + function _insertid() + { + $sqlca =ifx_getsqlca($this->lastQuery); + return @$sqlca["sqlerrd1"]; + } + + function _affectedrows() + { + if ($this->lastQuery) { + return @ifx_affected_rows ($this->lastQuery); + } + return 0; + } + + function BeginTrans() + { + if ($this->transOff) return true; + $this->transCnt += 1; + $this->Execute('BEGIN'); + $this->_autocommit = false; + return true; + } + + function CommitTrans($ok=true) + { + if (!$ok) return $this->RollbackTrans(); + if ($this->transOff) return true; + if ($this->transCnt) $this->transCnt -= 1; + $this->Execute('COMMIT'); + $this->_autocommit = true; + return true; + } + + function RollbackTrans() + { + if ($this->transOff) return true; + if ($this->transCnt) $this->transCnt -= 1; + $this->Execute('ROLLBACK'); + $this->_autocommit = true; + return true; + } + + function RowLock($tables,$where) + { + if ($this->_autocommit) $this->BeginTrans(); + return $this->GetOne("select 1 as ignore from $tables where $where for update"); + } + + /* Returns: the last error message from previous database operation + Note: This function is NOT available for Microsoft SQL Server. */ + + function ErrorMsg() + { + if (!empty($this->_logsql)) return $this->_errorMsg; + $this->_errorMsg = ifx_errormsg(); + return $this->_errorMsg; + } + + function ErrorNo() + { + preg_match("/.*SQLCODE=([^\]]*)/",ifx_error(),$parse); //!EOS + if (is_array($parse) && isset($parse[1])) return (int)$parse[1]; + return 0; + } function &MetaColumns($table) - { - global $ADODB_FETCH_MODE; - - if (!empty($this->metaColumnsSQL)) { - $save = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); - $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table)); - if (isset($savem)) $this->SetFetchMode($savem); - $ADODB_FETCH_MODE = $save; - if ($rs === false) return false; - - $retarr = array(); - while (!$rs->EOF) { //print_r($rs->fields); - $fld = new ADOFieldObject(); - $fld->name = $rs->fields[0]; - $fld->type = $rs->fields[1]; - $fld->max_length = $rs->fields[2]; - if (trim($rs->fields[3]) != "AAAAAA 0") { - $fld->has_default = 1; - $fld->default_value = $rs->fields[3]; - } else { - $fld->has_default = 0; - } + { + global $ADODB_FETCH_MODE; + + if (!empty($this->metaColumnsSQL)) { + $save = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); + $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table)); + if (isset($savem)) $this->SetFetchMode($savem); + $ADODB_FETCH_MODE = $save; + if ($rs === false) return false; + + $retarr = array(); + while (!$rs->EOF) { //print_r($rs->fields); + $fld = new ADOFieldObject(); + $fld->name = $rs->fields[0]; + $fld->type = $rs->fields[1]; + $fld->max_length = $rs->fields[2]; + if (trim($rs->fields[3]) != "AAAAAA 0") { + $fld->has_default = 1; + $fld->default_value = $rs->fields[3]; + } else { + $fld->has_default = 0; + } $retarr[strtolower($fld->name)] = $fld; - $rs->MoveNext(); - } + $rs->MoveNext(); + } - $rs->Close(); - return $retarr; - } + $rs->Close(); + return $retarr; + } - return false; - } + return false; + } function &xMetaColumns($table) { - return ADOConnection::MetaColumns($table,false); + return ADOConnection::MetaColumns($table,false); } function UpdateBlob($table, $column, $val, $where, $blobtype = 'BLOB') { - $type = ($blobtype == 'TEXT') ? 1 : 0; - $blobid = ifx_create_blob($type,0,$val); - return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blobid)); + $type = ($blobtype == 'TEXT') ? 1 : 0; + $blobid = ifx_create_blob($type,0,$val); + return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blobid)); } function BlobDecode($blobid) { - return function_exists('ifx_byteasvarchar') ? $blobid : @ifx_get_blob($blobid); + return function_exists('ifx_byteasvarchar') ? $blobid : @ifx_get_blob($blobid); } - // returns true or false + // returns true or false function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) - { - if (!function_exists('ifx_connect')) return false; - - $dbs = $argDatabasename . "@" . $argHostname; - if ($argHostname) putenv("INFORMIXSERVER=$argHostname"); - putenv("INFORMIXSERVER=".trim($argHostname)); - $this->_connectionID = ifx_connect($dbs,$argUsername,$argPassword); - if ($this->_connectionID === false) return false; - #if ($argDatabasename) return $this->SelectDB($argDatabasename); - return true; - } - - // returns true or false + { + if (!function_exists('ifx_connect')) return false; + + $dbs = $argDatabasename . "@" . $argHostname; + if ($argHostname) putenv("INFORMIXSERVER=$argHostname"); + putenv("INFORMIXSERVER=".trim($argHostname)); + $this->_connectionID = ifx_connect($dbs,$argUsername,$argPassword); + if ($this->_connectionID === false) return false; + #if ($argDatabasename) return $this->SelectDB($argDatabasename); + return true; + } + + // returns true or false function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) - { - if (!function_exists('ifx_connect')) return false; - - $dbs = $argDatabasename . "@" . $argHostname; - putenv("INFORMIXSERVER=".trim($argHostname)); - $this->_connectionID = ifx_pconnect($dbs,$argUsername,$argPassword); - if ($this->_connectionID === false) return false; - #if ($argDatabasename) return $this->SelectDB($argDatabasename); - return true; - } + { + if (!function_exists('ifx_connect')) return false; + + $dbs = $argDatabasename . "@" . $argHostname; + putenv("INFORMIXSERVER=".trim($argHostname)); + $this->_connectionID = ifx_pconnect($dbs,$argUsername,$argPassword); + if ($this->_connectionID === false) return false; + #if ($argDatabasename) return $this->SelectDB($argDatabasename); + return true; + } /* - // ifx_do does not accept bind parameters - weird ??? - function Prepare($sql) - { - $stmt = ifx_prepare($sql); - if (!$stmt) return $sql; - else return array($sql,$stmt); - } + // ifx_do does not accept bind parameters - weird ??? + function Prepare($sql) + { + $stmt = ifx_prepare($sql); + if (!$stmt) return $sql; + else return array($sql,$stmt); + } */ - // returns query ID if successful, otherwise false - function _query($sql,$inputarr) - { - global $ADODB_COUNTRECS; - - // String parameters have to be converted using ifx_create_char - if ($inputarr) { - foreach($inputarr as $v) { - if (gettype($v) == 'string') { - $tab[] = ifx_create_char($v); - } - else { - $tab[] = $v; - } - } - } - - // In case of select statement, we use a scroll cursor in order - // to be able to call "move", or "movefirst" statements - if (!$ADODB_COUNTRECS && preg_match("/^\s*select/is", $sql)) { - if ($inputarr) { - $this->lastQuery = ifx_query($sql,$this->_connectionID, $this->cursorType, $tab); - } - else { - $this->lastQuery = ifx_query($sql,$this->_connectionID, $this->cursorType); - } - } - else { - if ($inputarr) { - $this->lastQuery = ifx_query($sql,$this->_connectionID, $tab); - } - else { - $this->lastQuery = ifx_query($sql,$this->_connectionID); - } - } - - // Following line have been commented because autocommit mode is - // not supported by informix SE 7.2 - - //if ($this->_autocommit) ifx_query('COMMIT',$this->_connectionID); - - return $this->lastQuery; - } - - // returns true or false - function _close() - { - $this->lastQuery = false; - return ifx_close($this->_connectionID); - } + // returns query ID if successful, otherwise false + function _query($sql,$inputarr) + { + global $ADODB_COUNTRECS; + + // String parameters have to be converted using ifx_create_char + if ($inputarr) { + foreach($inputarr as $v) { + if (gettype($v) == 'string') { + $tab[] = ifx_create_char($v); + } + else { + $tab[] = $v; + } + } + } + + // In case of select statement, we use a scroll cursor in order + // to be able to call "move", or "movefirst" statements + if (!$ADODB_COUNTRECS && preg_match("/^\s*select/is", $sql)) { + if ($inputarr) { + $this->lastQuery = ifx_query($sql,$this->_connectionID, $this->cursorType, $tab); + } + else { + $this->lastQuery = ifx_query($sql,$this->_connectionID, $this->cursorType); + } + } + else { + if ($inputarr) { + $this->lastQuery = ifx_query($sql,$this->_connectionID, $tab); + } + else { + $this->lastQuery = ifx_query($sql,$this->_connectionID); + } + } + + // Following line have been commented because autocommit mode is + // not supported by informix SE 7.2 + + //if ($this->_autocommit) ifx_query('COMMIT',$this->_connectionID); + + return $this->lastQuery; + } + + // returns true or false + function _close() + { + $this->lastQuery = false; + return ifx_close($this->_connectionID); + } } /*-------------------------------------------------------------------------------------- - Class Name: Recordset + Class Name: Recordset --------------------------------------------------------------------------------------*/ class ADORecordset_informix72 extends ADORecordSet { - var $databaseType = "informix72"; - var $canSeek = true; - var $_fieldprops = false; - - function ADORecordset_informix72($id,$mode=false) - { - if ($mode === false) { - global $ADODB_FETCH_MODE; - $mode = $ADODB_FETCH_MODE; - } - $this->fetchMode = $mode; - return $this->ADORecordSet($id); - } - - - - /* Returns: an object containing field information. - Get column information in the Recordset object. fetchField() can be used in order to obtain information about - fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by - fetchField() is retrieved. */ - function &FetchField($fieldOffset = -1) - { - if (empty($this->_fieldprops)) { - $fp = ifx_fieldproperties($this->_queryID); - foreach($fp as $k => $v) { - $o = new ADOFieldObject; - $o->name = $k; - $arr = explode(';', $v); //"SQLTYPE;length;precision;scale;ISNULLABLE" - $o->type = $arr[0]; - $o->max_length = $arr[1]; - $this->_fieldprops[] = $o; - $o->not_null = $arr[4]=="N"; - } - } - return $this->_fieldprops[$fieldOffset]; - } - - function _initrs() - { - $this->_numOfRows = -1; // ifx_affected_rows not reliable, only returns estimate -- ($ADODB_COUNTRECS)? ifx_affected_rows($this->_queryID):-1; - $this->_numOfFields = ifx_num_fields($this->_queryID); - } - - function _seek($row) - { - return @ifx_fetch_row($this->_queryID, $row); - } + var $databaseType = "informix72"; + var $canSeek = true; + var $_fieldprops = false; + + function ADORecordset_informix72($id,$mode=false) + { + if ($mode === false) { + global $ADODB_FETCH_MODE; + $mode = $ADODB_FETCH_MODE; + } + $this->fetchMode = $mode; + return $this->ADORecordSet($id); + } + + + + /* Returns: an object containing field information. + Get column information in the Recordset object. fetchField() can be used in order to obtain information about + fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by + fetchField() is retrieved. */ + function &FetchField($fieldOffset = -1) + { + if (empty($this->_fieldprops)) { + $fp = ifx_fieldproperties($this->_queryID); + foreach($fp as $k => $v) { + $o = new ADOFieldObject; + $o->name = $k; + $arr = explode(';', $v); //"SQLTYPE;length;precision;scale;ISNULLABLE" + $o->type = $arr[0]; + $o->max_length = $arr[1]; + $this->_fieldprops[] = $o; + $o->not_null = $arr[4]=="N"; + } + } + return $this->_fieldprops[$fieldOffset]; + } + + function _initrs() + { + $this->_numOfRows = -1; // ifx_affected_rows not reliable, only returns estimate -- ($ADODB_COUNTRECS)? ifx_affected_rows($this->_queryID):-1; + $this->_numOfFields = ifx_num_fields($this->_queryID); + } + + function _seek($row) + { + return @ifx_fetch_row($this->_queryID, $row); + } function MoveLast() { - $this->fields = @ifx_fetch_row($this->_queryID, "LAST"); - if ($this->fields) $this->EOF = false; - $this->_currentRow = -1; - - if ($this->fetchMode == ADODB_FETCH_NUM) { - foreach($this->fields as $v) { - $arr[] = $v; - } - $this->fields = $arr; - } - - return true; + $this->fields = @ifx_fetch_row($this->_queryID, "LAST"); + if ($this->fields) $this->EOF = false; + $this->_currentRow = -1; + + if ($this->fetchMode == ADODB_FETCH_NUM) { + foreach($this->fields as $v) { + $arr[] = $v; + } + $this->fields = $arr; + } + + return true; } function MoveFirst() - { - $this->fields = @ifx_fetch_row($this->_queryID, "FIRST"); - if ($this->fields) $this->EOF = false; - $this->_currentRow = 0; - - if ($this->fetchMode == ADODB_FETCH_NUM) { - foreach($this->fields as $v) { - $arr[] = $v; - } - $this->fields = $arr; - } - - return true; + { + $this->fields = @ifx_fetch_row($this->_queryID, "FIRST"); + if ($this->fields) $this->EOF = false; + $this->_currentRow = 0; + + if ($this->fetchMode == ADODB_FETCH_NUM) { + foreach($this->fields as $v) { + $arr[] = $v; + } + $this->fields = $arr; + } + + return true; } function _fetch($ignore_fields=false) { - $this->fields = @ifx_fetch_row($this->_queryID); - - if (!is_array($this->fields)) return false; - - if ($this->fetchMode == ADODB_FETCH_NUM) { - foreach($this->fields as $v) { - $arr[] = $v; - } - $this->fields = $arr; - } - return true; - } - - /* close() only needs to be called if you are worried about using too much memory while your script - is running. All associated result memory for the specified result identifier will automatically be freed. */ - function _close() - { - return ifx_free_result($this->_queryID); - } + $this->fields = @ifx_fetch_row($this->_queryID); + + if (!is_array($this->fields)) return false; + + if ($this->fetchMode == ADODB_FETCH_NUM) { + foreach($this->fields as $v) { + $arr[] = $v; + } + $this->fields = $arr; + } + return true; + } + + /* close() only needs to be called if you are worried about using too much memory while your script + is running. All associated result memory for the specified result identifier will automatically be freed. */ + function _close() + { + return ifx_free_result($this->_queryID); + } } ?> diff --git a/lib/WikiDB/adodb/drivers/adodb-ldap.inc.php b/lib/WikiDB/adodb/drivers/adodb-ldap.inc.php index 88414335a..802b878f8 100644 --- a/lib/WikiDB/adodb/drivers/adodb-ldap.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-ldap.inc.php @@ -13,9 +13,9 @@ class ADODB_ldap extends ADOConnection { var $databaseType = 'ldap'; - var $dataProvider = 'ldap'; + var $dataProvider = 'ldap'; - # Connection information + # Connection information var $username = false; var $password = false; @@ -24,51 +24,51 @@ class ADODB_ldap extends ADOConnection { var $dn; - function ADODB_ldap() - { + function ADODB_ldap() + { - } + } - // returns true or false + // returns true or false - function _connect( $host, $username, $password, $ldapbase ) - { + function _connect( $host, $username, $password, $ldapbase ) + { - if ( !function_exists( 'ldap_connect' ) ) return false; + if ( !function_exists( 'ldap_connect' ) ) return false; - $conn_info = array( $host ); + $conn_info = array( $host ); - if ( strstr( $host, ':' ) ) { - $conn_info = explode(':', $host); - } + if ( strstr( $host, ':' ) ) { + $conn_info = explode(':', $host); + } - $this->_connectionID = ldap_connect( $conn_info[0], $conn_info[1] ) - or die( 'Could not connect to ' . $this->_connectionID ); - if ($username && $password) { - $bind = ldap_bind( $this->_connectionID, $username, $password ) - or die( 'Could not bind to ' . $this->_connectionID . ' with $username & $password'); - } else { - $bind = ldap_bind( $this->_connectionID ) - or die( 'Could not bind anonymously to ' . $this->_connectionID ); - } - return $this->_connectionID; + $this->_connectionID = ldap_connect( $conn_info[0], $conn_info[1] ) + or die( 'Could not connect to ' . $this->_connectionID ); + if ($username && $password) { + $bind = ldap_bind( $this->_connectionID, $username, $password ) + or die( 'Could not bind to ' . $this->_connectionID . ' with $username & $password'); + } else { + $bind = ldap_bind( $this->_connectionID ) + or die( 'Could not bind anonymously to ' . $this->_connectionID ); + } + return $this->_connectionID; } - /* returns _queryID or false */ - function _query($sql,$inputarr) - { - $rs = ldap_search( $this->_connectionID, $this->database, $sql ); + /* returns _queryID or false */ + function _query($sql,$inputarr) + { + $rs = ldap_search( $this->_connectionID, $this->database, $sql ); return $rs; - } + } /* closes the LDAP connection */ - function _close() - { - @ldap_close( $this->_connectionID ); - $this->_connectionID = false; - } + function _close() + { + @ldap_close( $this->_connectionID ); + $this->_connectionID = false; + } function ServerInfo() { @@ -168,56 +168,56 @@ class ADODB_ldap extends ADOConnection { } /*-------------------------------------------------------------------------------------- - Class Name: Recordset + Class Name: Recordset --------------------------------------------------------------------------------------*/ class ADORecordSet_ldap extends ADORecordSet{ - var $databaseType = "ldap"; - var $canSeek = false; - var $_entryID; /* keeps track of the entry resource identifier */ - - function ADORecordSet_ldap($queryID,$mode=false) - { - if ($mode === false) { - global $ADODB_FETCH_MODE; - $mode = $ADODB_FETCH_MODE; - } - switch ($mode) - { - case ADODB_FETCH_NUM: - $this->fetchMode = LDAP_NUM; - break; - case ADODB_FETCH_ASSOC: - $this->fetchMode = LDAP_ASSOC; - break; - default: - case ADODB_FETCH_DEFAULT: - case ADODB_FETCH_BOTH: - $this->fetchMode = LDAP_BOTH; - break; - } - - $this->ADORecordSet($queryID); - } - - function _initrs() - { - /* - This could be teaked to respect the $COUNTRECS directive from ADODB - It's currently being used in the _fetch() function and the - GetAssoc() function + var $databaseType = "ldap"; + var $canSeek = false; + var $_entryID; /* keeps track of the entry resource identifier */ + + function ADORecordSet_ldap($queryID,$mode=false) + { + if ($mode === false) { + global $ADODB_FETCH_MODE; + $mode = $ADODB_FETCH_MODE; + } + switch ($mode) + { + case ADODB_FETCH_NUM: + $this->fetchMode = LDAP_NUM; + break; + case ADODB_FETCH_ASSOC: + $this->fetchMode = LDAP_ASSOC; + break; + default: + case ADODB_FETCH_DEFAULT: + case ADODB_FETCH_BOTH: + $this->fetchMode = LDAP_BOTH; + break; + } + + $this->ADORecordSet($queryID); + } + + function _initrs() + { + /* + This could be teaked to respect the $COUNTRECS directive from ADODB + It's currently being used in the _fetch() function and the + GetAssoc() function */ - $this->_numOfRows = ldap_count_entries( $this->connection->_connectionID, $this->_queryID ); + $this->_numOfRows = ldap_count_entries( $this->connection->_connectionID, $this->_queryID ); - } + } /* Return whole recordset as a multi-dimensional associative array - */ - function &GetAssoc($force_array = false, $first2cols = false) - { - $records = $this->_numOfRows; + */ + function &GetAssoc($force_array = false, $first2cols = false) + { + $records = $this->_numOfRows; $results = array(); for ( $i=0; $i < $records; $i++ ) { foreach ( $this->fields as $k=>$v ) { @@ -232,11 +232,11 @@ class ADORecordSet_ldap extends ADORecordSet{ } } - return $results; - } + return $results; + } function &GetRowAssoc() - { + { $results = array(); foreach ( $this->fields as $k=>$v ) { if ( is_array( $v ) ) { @@ -249,8 +249,8 @@ class ADORecordSet_ldap extends ADORecordSet{ } } - return $results; - } + return $results; + } function GetRowNums() { @@ -270,20 +270,20 @@ class ADORecordSet_ldap extends ADORecordSet{ return $results; } - function _fetch() - { - if ( $this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0 ) - return false; + function _fetch() + { + if ( $this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0 ) + return false; if ( $this->_currentRow == 0 ) { - $this->_entryID = ldap_first_entry( $this->connection->_connectionID, $this->_queryID ); + $this->_entryID = ldap_first_entry( $this->connection->_connectionID, $this->_queryID ); } else { $this->_entryID = ldap_next_entry( $this->connection->_connectionID, $this->_entryID ); } - $this->fields = ldap_get_attributes( $this->connection->_connectionID, $this->_entryID ); - $this->_numOfFields = $this->fields['count']; - switch ( $this->fetchMode ) { + $this->fields = ldap_get_attributes( $this->connection->_connectionID, $this->_entryID ); + $this->_numOfFields = $this->fields['count']; + switch ( $this->fetchMode ) { case LDAP_ASSOC: $this->fields = $this->GetRowAssoc(); @@ -298,12 +298,12 @@ class ADORecordSet_ldap extends ADORecordSet{ break; } return ( is_array( $this->fields ) ); - } + } - function _close() { - @ldap_free_result( $this->_queryID ); - $this->_queryID = false; - } + function _close() { + @ldap_free_result( $this->_queryID ); + $this->_queryID = false; + } } ?> diff --git a/lib/WikiDB/adodb/drivers/adodb-mssql.inc.php b/lib/WikiDB/adodb/drivers/adodb-mssql.inc.php index defa12e54..c242348cf 100644 --- a/lib/WikiDB/adodb/drivers/adodb-mssql.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-mssql.inc.php @@ -10,7 +10,7 @@ Set tabs to 4 for best viewing. Native mssql driver. Requires mssql client. Works on Windows. To configure for Unix, see - http://phpbuilder.com/columns/alberto20000919.php3 + http://phpbuilder.com/columns/alberto20000919.php3 */ @@ -36,15 +36,15 @@ Set tabs to 4 for best viewing. // has datetime converstion to YYYY-MM-DD format, and also mssql_fetch_assoc if (ADODB_PHPVER >= 0x4300) { // docs say 4.2.0, but testing shows only since 4.3.0 does it work! - @ini_set('mssql.datetimeconvert',0); + @ini_set('mssql.datetimeconvert',0); } else { global $ADODB_mssql_mths; // array, months must be upper-case - $ADODB_mssql_date_order = 'mdy'; - $ADODB_mssql_mths = array( - 'JAN'=>1,'FEB'=>2,'MAR'=>3,'APR'=>4,'MAY'=>5,'JUN'=>6, - 'JUL'=>7,'AUG'=>8,'SEP'=>9,'OCT'=>10,'NOV'=>11,'DEC'=>12); + $ADODB_mssql_date_order = 'mdy'; + $ADODB_mssql_mths = array( + 'JAN'=>1,'FEB'=>2,'MAR'=>3,'APR'=>4,'MAY'=>5,'JUN'=>6, + 'JUL'=>7,'AUG'=>8,'SEP'=>9,'OCT'=>10,'NOV'=>11,'DEC'=>12); } //--------------------------------------------------------------------------- @@ -54,869 +54,869 @@ global $ADODB_mssql_mths; // array, months must be upper-case function AutoDetect_MSSQL_Date_Order($conn) { global $ADODB_mssql_date_order; - $adate = $conn->GetOne('select getdate()'); - if ($adate) { - $anum = (int) $adate; - if ($anum > 0) { - if ($anum > 31) { - //ADOConnection::outp( "MSSQL: YYYY-MM-DD date format not supported currently"); - } else - $ADODB_mssql_date_order = 'dmy'; - } else - $ADODB_mssql_date_order = 'mdy'; - } + $adate = $conn->GetOne('select getdate()'); + if ($adate) { + $anum = (int) $adate; + if ($anum > 0) { + if ($anum > 31) { + //ADOConnection::outp( "MSSQL: YYYY-MM-DD date format not supported currently"); + } else + $ADODB_mssql_date_order = 'dmy'; + } else + $ADODB_mssql_date_order = 'mdy'; + } } class ADODB_mssql extends ADOConnection { - var $databaseType = "mssql"; - var $dataProvider = "mssql"; - var $replaceQuote = "''"; // string to use to replace quotes - var $fmtDate = "'Y-m-d'"; - var $fmtTimeStamp = "'Y-m-d h:i:sA'"; - var $hasInsertID = true; - var $substr = "substring"; - var $length = 'len'; - var $upperCase = 'upper'; - var $hasAffectedRows = true; - var $metaDatabasesSQL = "select name from sysdatabases where name <> 'master'"; - var $metaTablesSQL="select name,case when type='U' then 'T' else 'V' end from sysobjects where (type='U' or type='V') and (name not in ('sysallocations','syscolumns','syscomments','sysdepends','sysfilegroups','sysfiles','sysfiles1','sysforeignkeys','sysfulltextcatalogs','sysindexes','sysindexkeys','sysmembers','sysobjects','syspermissions','sysprotects','sysreferences','systypes','sysusers','sysalternates','sysconstraints','syssegments','REFERENTIAL_CONSTRAINTS','CHECK_CONSTRAINTS','CONSTRAINT_TABLE_USAGE','CONSTRAINT_COLUMN_USAGE','VIEWS','VIEW_TABLE_USAGE','VIEW_COLUMN_USAGE','SCHEMATA','TABLES','TABLE_CONSTRAINTS','TABLE_PRIVILEGES','COLUMNS','COLUMN_DOMAIN_USAGE','COLUMN_PRIVILEGES','DOMAINS','DOMAIN_CONSTRAINTS','KEY_COLUMN_USAGE','dtproperties'))"; - var $metaColumnsSQL = # xtype==61 is datetime + var $databaseType = "mssql"; + var $dataProvider = "mssql"; + var $replaceQuote = "''"; // string to use to replace quotes + var $fmtDate = "'Y-m-d'"; + var $fmtTimeStamp = "'Y-m-d h:i:sA'"; + var $hasInsertID = true; + var $substr = "substring"; + var $length = 'len'; + var $upperCase = 'upper'; + var $hasAffectedRows = true; + var $metaDatabasesSQL = "select name from sysdatabases where name <> 'master'"; + var $metaTablesSQL="select name,case when type='U' then 'T' else 'V' end from sysobjects where (type='U' or type='V') and (name not in ('sysallocations','syscolumns','syscomments','sysdepends','sysfilegroups','sysfiles','sysfiles1','sysforeignkeys','sysfulltextcatalogs','sysindexes','sysindexkeys','sysmembers','sysobjects','syspermissions','sysprotects','sysreferences','systypes','sysusers','sysalternates','sysconstraints','syssegments','REFERENTIAL_CONSTRAINTS','CHECK_CONSTRAINTS','CONSTRAINT_TABLE_USAGE','CONSTRAINT_COLUMN_USAGE','VIEWS','VIEW_TABLE_USAGE','VIEW_COLUMN_USAGE','SCHEMATA','TABLES','TABLE_CONSTRAINTS','TABLE_PRIVILEGES','COLUMNS','COLUMN_DOMAIN_USAGE','COLUMN_PRIVILEGES','DOMAINS','DOMAIN_CONSTRAINTS','KEY_COLUMN_USAGE','dtproperties'))"; + var $metaColumnsSQL = # xtype==61 is datetime "select c.name,t.name,c.length, - (case when c.xusertype=61 then 0 else c.xprec end), - (case when c.xusertype=61 then 0 else c.xscale end) - from syscolumns c join systypes t on t.xusertype=c.xusertype join sysobjects o on o.id=c.id where o.name='%s'"; - var $hasTop = 'top'; // support mssql SELECT TOP 10 * FROM TABLE - var $hasGenID = true; - var $sysDate = 'convert(datetime,convert(char,GetDate(),102),102)'; - var $sysTimeStamp = 'GetDate()'; - var $_has_mssql_init; - var $maxParameterLen = 4000; - var $arrayClass = 'ADORecordSet_array_mssql'; - var $uniqueSort = true; - var $leftOuter = '*='; - var $rightOuter = '=*'; - var $ansiOuter = true; // for mssql7 or later - var $poorAffectedRows = true; - var $identitySQL = 'select @@IDENTITY'; // 'select SCOPE_IDENTITY'; # for mssql 2000 - var $uniqueOrderBy = true; - var $_bindInputArray = true; - - - function ADODB_mssql() - { - $this->_has_mssql_init = (strnatcmp(PHP_VERSION,'4.1.0')>=0); - } - - function ServerInfo() - { - global $ADODB_FETCH_MODE; - - $stmt = $this->PrepareSP('sp_server_info'); - $val = 2; - if ($this->fetchMode === false) { - $savem = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - } else - $savem = $this->SetFetchMode(ADODB_FETCH_NUM); - - - $this->Parameter($stmt,$val,'attribute_id'); - $row = $this->GetRow($stmt); - - //$row = $this->GetRow("execute sp_server_info 2"); - - if ($this->fetchMode === false) { - $ADODB_FETCH_MODE = $savem; - } else - $this->SetFetchMode($savem); - - $arr['description'] = $row[2]; - $arr['version'] = ADOConnection::_findvers($arr['description']); - return $arr; - } - - function IfNull( $field, $ifNull ) - { - return " ISNULL($field, $ifNull) "; // if MS SQL Server - } - - function _insertid() - { - // SCOPE_IDENTITY() - // Returns the last IDENTITY value inserted into an IDENTITY column in - // the same scope. A scope is a module -- a stored procedure, trigger, - // function, or batch. Thus, two statements are in the same scope if - // they are in the same stored procedure, function, or batch. - return $this->GetOne($this->identitySQL); - } - - function _affectedrows() - { - return $this->GetOne('select @@rowcount'); - } - - var $_dropSeqSQL = "drop table %s"; - - function CreateSequence($seq='adodbseq',$start=1) - { - $start -= 1; - $this->Execute("create table $seq (id float(53))"); - $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)"); - if (!$ok) { - $this->Execute('ROLLBACK TRANSACTION adodbseq'); - return false; - } - $this->Execute('COMMIT TRANSACTION adodbseq'); - return true; - } - - function GenID($seq='adodbseq',$start=1) - { - //$this->debug=1; - $this->Execute('BEGIN TRANSACTION adodbseq'); - $ok = $this->Execute("update $seq with (tablock,holdlock) set id = id + 1"); - if (!$ok) { - $this->Execute("create table $seq (id float(53))"); - $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)"); - if (!$ok) { - $this->Execute('ROLLBACK TRANSACTION adodbseq'); - return false; - } - $this->Execute('COMMIT TRANSACTION adodbseq'); - return $start; - } - $num = $this->GetOne("select id from $seq"); - $this->Execute('COMMIT TRANSACTION adodbseq'); - return $num; - - // in old implementation, pre 1.90, we returned GUID... - //return $this->GetOne("SELECT CONVERT(varchar(255), NEWID()) AS 'Char'"); - } - - - function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) - { - if ($nrows > 0 && $offset <= 0) { - $sql = preg_replace( - '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop." $nrows ",$sql); - $rs =& $this->Execute($sql,$inputarr); - } else - $rs =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); - - return $rs; - } - - - // Format date column in sql string given an input format that understands Y M D - function SQLDate($fmt, $col=false) - { - if (!$col) $col = $this->sysTimeStamp; - $s = ''; - - $len = strlen($fmt); - for ($i=0; $i < $len; $i++) { - if ($s) $s .= '+'; - $ch = $fmt[$i]; - switch($ch) { - case 'Y': - case 'y': - $s .= "datename(yyyy,$col)"; - break; - case 'M': - $s .= "convert(char(3),$col,0)"; - break; - case 'm': - $s .= "replace(str(month($col),2),' ','0')"; - break; - case 'Q': - case 'q': - $s .= "datename(quarter,$col)"; - break; - case 'D': - case 'd': - $s .= "replace(str(day($col),2),' ','0')"; - break; - case 'h': - $s .= "substring(convert(char(14),$col,0),13,2)"; - break; - - case 'H': - $s .= "replace(str(datepart(hh,$col),2),' ','0')"; - break; - - case 'i': - $s .= "replace(str(datepart(mi,$col),2),' ','0')"; - break; - case 's': - $s .= "replace(str(datepart(ss,$col),2),' ','0')"; - break; - case 'a': - case 'A': - $s .= "substring(convert(char(19),$col,0),18,2)"; - break; - - default: - if ($ch == '\\') { - $i++; - $ch = substr($fmt,$i,1); - } - $s .= $this->qstr($ch); - break; - } - } - return $s; - } - - - function BeginTrans() - { - if ($this->transOff) return true; - $this->transCnt += 1; - $this->Execute('BEGIN TRAN'); - return true; - } - - function CommitTrans($ok=true) - { - if ($this->transOff) return true; - if (!$ok) return $this->RollbackTrans(); - if ($this->transCnt) $this->transCnt -= 1; - $this->Execute('COMMIT TRAN'); - return true; - } - function RollbackTrans() - { - if ($this->transOff) return true; - if ($this->transCnt) $this->transCnt -= 1; - $this->Execute('ROLLBACK TRAN'); - return true; - } - - /* - Usage: - - $this->BeginTrans(); - $this->RowLock('table1,table2','table1.id=33 and table2.id=table1.id'); # lock row 33 for both tables - - # some operation on both tables table1 and table2 - - $this->CommitTrans(); - - See http://www.swynk.com/friends/achigrik/SQL70Locks.asp - */ - function RowLock($tables,$where) - { - if (!$this->transCnt) $this->BeginTrans(); - return $this->GetOne("select top 1 null as ignore from $tables with (ROWLOCK,HOLDLOCK) where $where"); - } - - function MetaForeignKeys($table, $owner=false, $upper=false) - { - global $ADODB_FETCH_MODE; - - $save = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - $table = $this->qstr(strtoupper($table)); - - $sql = + (case when c.xusertype=61 then 0 else c.xprec end), + (case when c.xusertype=61 then 0 else c.xscale end) + from syscolumns c join systypes t on t.xusertype=c.xusertype join sysobjects o on o.id=c.id where o.name='%s'"; + var $hasTop = 'top'; // support mssql SELECT TOP 10 * FROM TABLE + var $hasGenID = true; + var $sysDate = 'convert(datetime,convert(char,GetDate(),102),102)'; + var $sysTimeStamp = 'GetDate()'; + var $_has_mssql_init; + var $maxParameterLen = 4000; + var $arrayClass = 'ADORecordSet_array_mssql'; + var $uniqueSort = true; + var $leftOuter = '*='; + var $rightOuter = '=*'; + var $ansiOuter = true; // for mssql7 or later + var $poorAffectedRows = true; + var $identitySQL = 'select @@IDENTITY'; // 'select SCOPE_IDENTITY'; # for mssql 2000 + var $uniqueOrderBy = true; + var $_bindInputArray = true; + + + function ADODB_mssql() + { + $this->_has_mssql_init = (strnatcmp(PHP_VERSION,'4.1.0')>=0); + } + + function ServerInfo() + { + global $ADODB_FETCH_MODE; + + $stmt = $this->PrepareSP('sp_server_info'); + $val = 2; + if ($this->fetchMode === false) { + $savem = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + } else + $savem = $this->SetFetchMode(ADODB_FETCH_NUM); + + + $this->Parameter($stmt,$val,'attribute_id'); + $row = $this->GetRow($stmt); + + //$row = $this->GetRow("execute sp_server_info 2"); + + if ($this->fetchMode === false) { + $ADODB_FETCH_MODE = $savem; + } else + $this->SetFetchMode($savem); + + $arr['description'] = $row[2]; + $arr['version'] = ADOConnection::_findvers($arr['description']); + return $arr; + } + + function IfNull( $field, $ifNull ) + { + return " ISNULL($field, $ifNull) "; // if MS SQL Server + } + + function _insertid() + { + // SCOPE_IDENTITY() + // Returns the last IDENTITY value inserted into an IDENTITY column in + // the same scope. A scope is a module -- a stored procedure, trigger, + // function, or batch. Thus, two statements are in the same scope if + // they are in the same stored procedure, function, or batch. + return $this->GetOne($this->identitySQL); + } + + function _affectedrows() + { + return $this->GetOne('select @@rowcount'); + } + + var $_dropSeqSQL = "drop table %s"; + + function CreateSequence($seq='adodbseq',$start=1) + { + $start -= 1; + $this->Execute("create table $seq (id float(53))"); + $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)"); + if (!$ok) { + $this->Execute('ROLLBACK TRANSACTION adodbseq'); + return false; + } + $this->Execute('COMMIT TRANSACTION adodbseq'); + return true; + } + + function GenID($seq='adodbseq',$start=1) + { + //$this->debug=1; + $this->Execute('BEGIN TRANSACTION adodbseq'); + $ok = $this->Execute("update $seq with (tablock,holdlock) set id = id + 1"); + if (!$ok) { + $this->Execute("create table $seq (id float(53))"); + $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)"); + if (!$ok) { + $this->Execute('ROLLBACK TRANSACTION adodbseq'); + return false; + } + $this->Execute('COMMIT TRANSACTION adodbseq'); + return $start; + } + $num = $this->GetOne("select id from $seq"); + $this->Execute('COMMIT TRANSACTION adodbseq'); + return $num; + + // in old implementation, pre 1.90, we returned GUID... + //return $this->GetOne("SELECT CONVERT(varchar(255), NEWID()) AS 'Char'"); + } + + + function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) + { + if ($nrows > 0 && $offset <= 0) { + $sql = preg_replace( + '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop." $nrows ",$sql); + $rs =& $this->Execute($sql,$inputarr); + } else + $rs =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); + + return $rs; + } + + + // Format date column in sql string given an input format that understands Y M D + function SQLDate($fmt, $col=false) + { + if (!$col) $col = $this->sysTimeStamp; + $s = ''; + + $len = strlen($fmt); + for ($i=0; $i < $len; $i++) { + if ($s) $s .= '+'; + $ch = $fmt[$i]; + switch($ch) { + case 'Y': + case 'y': + $s .= "datename(yyyy,$col)"; + break; + case 'M': + $s .= "convert(char(3),$col,0)"; + break; + case 'm': + $s .= "replace(str(month($col),2),' ','0')"; + break; + case 'Q': + case 'q': + $s .= "datename(quarter,$col)"; + break; + case 'D': + case 'd': + $s .= "replace(str(day($col),2),' ','0')"; + break; + case 'h': + $s .= "substring(convert(char(14),$col,0),13,2)"; + break; + + case 'H': + $s .= "replace(str(datepart(hh,$col),2),' ','0')"; + break; + + case 'i': + $s .= "replace(str(datepart(mi,$col),2),' ','0')"; + break; + case 's': + $s .= "replace(str(datepart(ss,$col),2),' ','0')"; + break; + case 'a': + case 'A': + $s .= "substring(convert(char(19),$col,0),18,2)"; + break; + + default: + if ($ch == '\\') { + $i++; + $ch = substr($fmt,$i,1); + } + $s .= $this->qstr($ch); + break; + } + } + return $s; + } + + + function BeginTrans() + { + if ($this->transOff) return true; + $this->transCnt += 1; + $this->Execute('BEGIN TRAN'); + return true; + } + + function CommitTrans($ok=true) + { + if ($this->transOff) return true; + if (!$ok) return $this->RollbackTrans(); + if ($this->transCnt) $this->transCnt -= 1; + $this->Execute('COMMIT TRAN'); + return true; + } + function RollbackTrans() + { + if ($this->transOff) return true; + if ($this->transCnt) $this->transCnt -= 1; + $this->Execute('ROLLBACK TRAN'); + return true; + } + + /* + Usage: + + $this->BeginTrans(); + $this->RowLock('table1,table2','table1.id=33 and table2.id=table1.id'); # lock row 33 for both tables + + # some operation on both tables table1 and table2 + + $this->CommitTrans(); + + See http://www.swynk.com/friends/achigrik/SQL70Locks.asp + */ + function RowLock($tables,$where) + { + if (!$this->transCnt) $this->BeginTrans(); + return $this->GetOne("select top 1 null as ignore from $tables with (ROWLOCK,HOLDLOCK) where $where"); + } + + function MetaForeignKeys($table, $owner=false, $upper=false) + { + global $ADODB_FETCH_MODE; + + $save = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + $table = $this->qstr(strtoupper($table)); + + $sql = "select object_name(constid) as constraint_name, - col_name(fkeyid, fkey) as column_name, - object_name(rkeyid) as referenced_table_name, - col_name(rkeyid, rkey) as referenced_column_name + col_name(fkeyid, fkey) as column_name, + object_name(rkeyid) as referenced_table_name, + col_name(rkeyid, rkey) as referenced_column_name from sysforeignkeys where upper(object_name(fkeyid)) = $table order by constraint_name, referenced_table_name, keyno"; - $constraints =& $this->GetArray($sql); - - $ADODB_FETCH_MODE = $save; - - $arr = false; - foreach($constraints as $constr) { - //print_r($constr); - $arr[$constr[0]][$constr[2]][] = $constr[1].'='.$constr[3]; - } - if (!$arr) return false; - - $arr2 = false; - - foreach($arr as $k => $v) { - foreach($v as $a => $b) { - if ($upper) $a = strtoupper($a); - $arr2[$a] = $b; - } - } - return $arr2; - } - - //From: Fernando Moreira - function MetaDatabases() - { - if(@mssql_select_db("master")) { - $qry=$this->metaDatabasesSQL; - if($rs=@mssql_query($qry)){ - $tmpAr=$ar=array(); - while($tmpAr=@mssql_fetch_row($rs)) - $ar[]=$tmpAr[0]; - @mssql_select_db($this->databaseName); - if(sizeof($ar)) - return($ar); - else - return(false); - } else { - @mssql_select_db($this->databaseName); - return(false); - } - } - return(false); - } - - // "Stein-Aksel Basma" - // tested with MSSQL 2000 - function MetaPrimaryKeys($table) - { - $sql = "select k.column_name from information_schema.key_column_usage k, - information_schema.table_constraints tc - where tc.constraint_name = k.constraint_name and tc.constraint_type = - 'PRIMARY KEY' and k.table_name = '$table'"; - - $a = $this->GetCol($sql); - if ($a && sizeof($a)>0) return $a; - return false; - } - - - function &MetaTables($ttype=false,$showSchema=false,$mask=false) - { - if ($mask) { - $save = $this->metaTablesSQL; - $mask = $this->qstr(($mask)); - $this->metaTablesSQL .= " AND name like $mask"; - } - $ret =& ADOConnection::MetaTables($ttype,$showSchema); - - if ($mask) { - $this->metaTablesSQL = $save; - } - return $ret; - } - - function SelectDB($dbName) - { - $this->databaseName = $dbName; - if ($this->_connectionID) { - return @mssql_select_db($dbName); - } - else return false; - } - - function ErrorMsg() - { - if (empty($this->_errorMsg)){ - $this->_errorMsg = mssql_get_last_message(); - } - return $this->_errorMsg; - } - - function ErrorNo() - { - if ($this->_logsql && $this->_errorCode !== false) return $this->_errorCode; - if (empty($this->_errorMsg)) { - $this->_errorMsg = mssql_get_last_message(); - } - $id = @mssql_query("select @@ERROR",$this->_connectionID); - if (!$id) return false; - $arr = mssql_fetch_array($id); - @mssql_free_result($id); - if (is_array($arr)) return $arr[0]; - else return -1; - } - - // returns true or false - function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) - { - if (!function_exists('mssql_pconnect')) return false; - $this->_connectionID = mssql_connect($argHostname,$argUsername,$argPassword); - if ($this->_connectionID === false) return false; - if ($argDatabasename) return $this->SelectDB($argDatabasename); - return true; - } - - - // returns true or false - function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) - { - if (!function_exists('mssql_pconnect')) return false; - $this->_connectionID = mssql_pconnect($argHostname,$argUsername,$argPassword); - if ($this->_connectionID === false) return false; - - // persistent connections can forget to rollback on crash, so we do it here. - if ($this->autoRollback) { - $cnt = $this->GetOne('select @@TRANCOUNT'); - while (--$cnt >= 0) $this->Execute('ROLLBACK TRAN'); - } - if ($argDatabasename) return $this->SelectDB($argDatabasename); - return true; - } - - function Prepare($sql) - { - $sqlarr = explode('?',$sql); - if (sizeof($sqlarr) <= 1) return $sql; - $sql2 = $sqlarr[0]; - for ($i = 1, $max = sizeof($sqlarr); $i < $max; $i++) { - $sql2 .= '@P'.($i-1) . $sqlarr[$i]; - } - return array($sql,$this->qstr($sql2),$max); - } - - function PrepareSP($sql) - { - if (!$this->_has_mssql_init) { - ADOConnection::outp( "PrepareSP: mssql_init only available since PHP 4.1.0"); - return $sql; - } - $stmt = mssql_init($sql,$this->_connectionID); - if (!$stmt) return $sql; - return array($sql,$stmt); - } - - /* - Usage: - $stmt = $db->PrepareSP('SP_RUNSOMETHING'); -- takes 2 params, @myid and @group - - # note that the parameter does not have @ in front! - $db->Parameter($stmt,$id,'myid'); - $db->Parameter($stmt,$group,'group',false,64); - $db->Execute($stmt); - - @param $stmt Statement returned by Prepare() or PrepareSP(). - @param $var PHP variable to bind to. Can set to null (for isNull support). - @param $name Name of stored procedure variable name to bind to. - @param [$isOutput] Indicates direction of parameter 0/false=IN 1=OUT 2= IN/OUT. This is ignored in oci8. - @param [$maxLen] Holds an maximum length of the variable. - @param [$type] The data type of $var. Legal values depend on driver. - - See mssql_bind documentation at php.net. - */ - function Parameter(&$stmt, &$var, $name, $isOutput=false, $maxLen=4000, $type=false) - { - if (!$this->_has_mssql_init) { - ADOConnection::outp( "Parameter: mssql_bind only available since PHP 4.1.0"); - return $sql; - } - - $isNull = is_null($var); // php 4.0.4 and above... - - if ($type === false) - switch(gettype($var)) { - default: - case 'string': $type = SQLCHAR; break; - case 'double': $type = SQLFLT8; break; - case 'integer': $type = SQLINT4; break; - case 'boolean': $type = SQLINT1; break; # SQLBIT not supported in 4.1.0 - } - - if ($this->debug) { - $prefix = ($isOutput) ? 'Out' : 'In'; - $ztype = (empty($type)) ? 'false' : $type; - ADOConnection::outp( "{$prefix}Parameter(\$stmt, \$php_var='$var', \$name='$name', \$maxLen=$maxLen, \$type=$ztype);"); - } - /* - See http://phplens.com/lens/lensforum/msgs.php?id=7231 - - RETVAL is HARD CODED into php_mssql extension: - The return value (a long integer value) is treated like a special OUTPUT parameter, - called "RETVAL" (without the @). See the example at mssql_execute to - see how it works. - type: one of this new supported PHP constants. - SQLTEXT, SQLVARCHAR,SQLCHAR, SQLINT1,SQLINT2, SQLINT4, SQLBIT,SQLFLT8 - */ - if ($name !== 'RETVAL') $name = '@'.$name; - return mssql_bind($stmt[1], $name, $var, $type, $isOutput, $isNull, $maxLen); - } - - /* - Unfortunately, it appears that mssql cannot handle varbinary > 255 chars - So all your blobs must be of type "image". - - Remember to set in php.ini the following... - - ; Valid range 0 - 2147483647. Default = 4096. - mssql.textlimit = 0 ; zero to pass through - - ; Valid range 0 - 2147483647. Default = 4096. - mssql.textsize = 0 ; zero to pass through - */ - function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') - { - $sql = "UPDATE $table SET $column=0x".bin2hex($val)." WHERE $where"; - return $this->Execute($sql) != false; - } - - // returns query ID if successful, otherwise false - function _query($sql,$inputarr) - { - $this->_errorMsg = false; - if (is_array($inputarr)) { - - # bind input params with sp_executesql: - # see http://www.quest-pipelines.com/newsletter-v3/0402_F.htm - # works only with sql server 7 and newer - if (!is_array($sql)) $sql = $this->Prepare($sql); - $params = ''; - $decl = ''; - $i = 0; - foreach($inputarr as $v) { - if ($decl) { - $decl .= ', '; - $params .= ', '; - } - if (is_string($v)) { - $len = strlen($v); - if ($len == 0) $len = 1; - - if ($len > 4000 ) { - // NVARCHAR is max 4000 chars. Let's use NTEXT - $decl .= "@P$i NTEXT"; - } else { - $decl .= "@P$i NVARCHAR($len)"; - } - - $params .= "@P$i=N". (strncmp($v,"'",1)==0? $v : $this->qstr($v)); - } else if (is_integer($v)) { - $decl .= "@P$i INT"; - $params .= "@P$i=".$v; - } else { - $decl .= "@P$i FLOAT"; - $params .= "@P$i=".$v; - } - $i += 1; - } - $decl = $this->qstr($decl); - if ($this->debug) ADOConnection::outp("sp_executesql N{$sql[1]},N$decl,$params"); - $rez = mssql_query("sp_executesql N{$sql[1]},N$decl,$params"); - - } else if (is_array($sql)) { - # PrepareSP() - $rez = mssql_execute($sql[1]); - - } else { - $rez = mssql_query($sql,$this->_connectionID); - } - return $rez; - } - - // returns true or false - function _close() - { - if ($this->transCnt) $this->RollbackTrans(); - $rez = @mssql_close($this->_connectionID); - $this->_connectionID = false; - return $rez; - } - - // mssql uses a default date like Dec 30 2000 12:00AM - function UnixDate($v) - { - return ADORecordSet_array_mssql::UnixDate($v); - } - - function UnixTimeStamp($v) - { - return ADORecordSet_array_mssql::UnixTimeStamp($v); - } + $constraints =& $this->GetArray($sql); + + $ADODB_FETCH_MODE = $save; + + $arr = false; + foreach($constraints as $constr) { + //print_r($constr); + $arr[$constr[0]][$constr[2]][] = $constr[1].'='.$constr[3]; + } + if (!$arr) return false; + + $arr2 = false; + + foreach($arr as $k => $v) { + foreach($v as $a => $b) { + if ($upper) $a = strtoupper($a); + $arr2[$a] = $b; + } + } + return $arr2; + } + + //From: Fernando Moreira + function MetaDatabases() + { + if(@mssql_select_db("master")) { + $qry=$this->metaDatabasesSQL; + if($rs=@mssql_query($qry)){ + $tmpAr=$ar=array(); + while($tmpAr=@mssql_fetch_row($rs)) + $ar[]=$tmpAr[0]; + @mssql_select_db($this->databaseName); + if(sizeof($ar)) + return($ar); + else + return(false); + } else { + @mssql_select_db($this->databaseName); + return(false); + } + } + return(false); + } + + // "Stein-Aksel Basma" + // tested with MSSQL 2000 + function MetaPrimaryKeys($table) + { + $sql = "select k.column_name from information_schema.key_column_usage k, + information_schema.table_constraints tc + where tc.constraint_name = k.constraint_name and tc.constraint_type = + 'PRIMARY KEY' and k.table_name = '$table'"; + + $a = $this->GetCol($sql); + if ($a && sizeof($a)>0) return $a; + return false; + } + + + function &MetaTables($ttype=false,$showSchema=false,$mask=false) + { + if ($mask) { + $save = $this->metaTablesSQL; + $mask = $this->qstr(($mask)); + $this->metaTablesSQL .= " AND name like $mask"; + } + $ret =& ADOConnection::MetaTables($ttype,$showSchema); + + if ($mask) { + $this->metaTablesSQL = $save; + } + return $ret; + } + + function SelectDB($dbName) + { + $this->databaseName = $dbName; + if ($this->_connectionID) { + return @mssql_select_db($dbName); + } + else return false; + } + + function ErrorMsg() + { + if (empty($this->_errorMsg)){ + $this->_errorMsg = mssql_get_last_message(); + } + return $this->_errorMsg; + } + + function ErrorNo() + { + if ($this->_logsql && $this->_errorCode !== false) return $this->_errorCode; + if (empty($this->_errorMsg)) { + $this->_errorMsg = mssql_get_last_message(); + } + $id = @mssql_query("select @@ERROR",$this->_connectionID); + if (!$id) return false; + $arr = mssql_fetch_array($id); + @mssql_free_result($id); + if (is_array($arr)) return $arr[0]; + else return -1; + } + + // returns true or false + function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) + { + if (!function_exists('mssql_pconnect')) return false; + $this->_connectionID = mssql_connect($argHostname,$argUsername,$argPassword); + if ($this->_connectionID === false) return false; + if ($argDatabasename) return $this->SelectDB($argDatabasename); + return true; + } + + + // returns true or false + function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) + { + if (!function_exists('mssql_pconnect')) return false; + $this->_connectionID = mssql_pconnect($argHostname,$argUsername,$argPassword); + if ($this->_connectionID === false) return false; + + // persistent connections can forget to rollback on crash, so we do it here. + if ($this->autoRollback) { + $cnt = $this->GetOne('select @@TRANCOUNT'); + while (--$cnt >= 0) $this->Execute('ROLLBACK TRAN'); + } + if ($argDatabasename) return $this->SelectDB($argDatabasename); + return true; + } + + function Prepare($sql) + { + $sqlarr = explode('?',$sql); + if (sizeof($sqlarr) <= 1) return $sql; + $sql2 = $sqlarr[0]; + for ($i = 1, $max = sizeof($sqlarr); $i < $max; $i++) { + $sql2 .= '@P'.($i-1) . $sqlarr[$i]; + } + return array($sql,$this->qstr($sql2),$max); + } + + function PrepareSP($sql) + { + if (!$this->_has_mssql_init) { + ADOConnection::outp( "PrepareSP: mssql_init only available since PHP 4.1.0"); + return $sql; + } + $stmt = mssql_init($sql,$this->_connectionID); + if (!$stmt) return $sql; + return array($sql,$stmt); + } + + /* + Usage: + $stmt = $db->PrepareSP('SP_RUNSOMETHING'); -- takes 2 params, @myid and @group + + # note that the parameter does not have @ in front! + $db->Parameter($stmt,$id,'myid'); + $db->Parameter($stmt,$group,'group',false,64); + $db->Execute($stmt); + + @param $stmt Statement returned by Prepare() or PrepareSP(). + @param $var PHP variable to bind to. Can set to null (for isNull support). + @param $name Name of stored procedure variable name to bind to. + @param [$isOutput] Indicates direction of parameter 0/false=IN 1=OUT 2= IN/OUT. This is ignored in oci8. + @param [$maxLen] Holds an maximum length of the variable. + @param [$type] The data type of $var. Legal values depend on driver. + + See mssql_bind documentation at php.net. + */ + function Parameter(&$stmt, &$var, $name, $isOutput=false, $maxLen=4000, $type=false) + { + if (!$this->_has_mssql_init) { + ADOConnection::outp( "Parameter: mssql_bind only available since PHP 4.1.0"); + return $sql; + } + + $isNull = is_null($var); // php 4.0.4 and above... + + if ($type === false) + switch(gettype($var)) { + default: + case 'string': $type = SQLCHAR; break; + case 'double': $type = SQLFLT8; break; + case 'integer': $type = SQLINT4; break; + case 'boolean': $type = SQLINT1; break; # SQLBIT not supported in 4.1.0 + } + + if ($this->debug) { + $prefix = ($isOutput) ? 'Out' : 'In'; + $ztype = (empty($type)) ? 'false' : $type; + ADOConnection::outp( "{$prefix}Parameter(\$stmt, \$php_var='$var', \$name='$name', \$maxLen=$maxLen, \$type=$ztype);"); + } + /* + See http://phplens.com/lens/lensforum/msgs.php?id=7231 + + RETVAL is HARD CODED into php_mssql extension: + The return value (a long integer value) is treated like a special OUTPUT parameter, + called "RETVAL" (without the @). See the example at mssql_execute to + see how it works. - type: one of this new supported PHP constants. + SQLTEXT, SQLVARCHAR,SQLCHAR, SQLINT1,SQLINT2, SQLINT4, SQLBIT,SQLFLT8 + */ + if ($name !== 'RETVAL') $name = '@'.$name; + return mssql_bind($stmt[1], $name, $var, $type, $isOutput, $isNull, $maxLen); + } + + /* + Unfortunately, it appears that mssql cannot handle varbinary > 255 chars + So all your blobs must be of type "image". + + Remember to set in php.ini the following... + + ; Valid range 0 - 2147483647. Default = 4096. + mssql.textlimit = 0 ; zero to pass through + + ; Valid range 0 - 2147483647. Default = 4096. + mssql.textsize = 0 ; zero to pass through + */ + function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') + { + $sql = "UPDATE $table SET $column=0x".bin2hex($val)." WHERE $where"; + return $this->Execute($sql) != false; + } + + // returns query ID if successful, otherwise false + function _query($sql,$inputarr) + { + $this->_errorMsg = false; + if (is_array($inputarr)) { + + # bind input params with sp_executesql: + # see http://www.quest-pipelines.com/newsletter-v3/0402_F.htm + # works only with sql server 7 and newer + if (!is_array($sql)) $sql = $this->Prepare($sql); + $params = ''; + $decl = ''; + $i = 0; + foreach($inputarr as $v) { + if ($decl) { + $decl .= ', '; + $params .= ', '; + } + if (is_string($v)) { + $len = strlen($v); + if ($len == 0) $len = 1; + + if ($len > 4000 ) { + // NVARCHAR is max 4000 chars. Let's use NTEXT + $decl .= "@P$i NTEXT"; + } else { + $decl .= "@P$i NVARCHAR($len)"; + } + + $params .= "@P$i=N". (strncmp($v,"'",1)==0? $v : $this->qstr($v)); + } else if (is_integer($v)) { + $decl .= "@P$i INT"; + $params .= "@P$i=".$v; + } else { + $decl .= "@P$i FLOAT"; + $params .= "@P$i=".$v; + } + $i += 1; + } + $decl = $this->qstr($decl); + if ($this->debug) ADOConnection::outp("sp_executesql N{$sql[1]},N$decl,$params"); + $rez = mssql_query("sp_executesql N{$sql[1]},N$decl,$params"); + + } else if (is_array($sql)) { + # PrepareSP() + $rez = mssql_execute($sql[1]); + + } else { + $rez = mssql_query($sql,$this->_connectionID); + } + return $rez; + } + + // returns true or false + function _close() + { + if ($this->transCnt) $this->RollbackTrans(); + $rez = @mssql_close($this->_connectionID); + $this->_connectionID = false; + return $rez; + } + + // mssql uses a default date like Dec 30 2000 12:00AM + function UnixDate($v) + { + return ADORecordSet_array_mssql::UnixDate($v); + } + + function UnixTimeStamp($v) + { + return ADORecordSet_array_mssql::UnixTimeStamp($v); + } } /*-------------------------------------------------------------------------------------- - Class Name: Recordset + Class Name: Recordset --------------------------------------------------------------------------------------*/ class ADORecordset_mssql extends ADORecordSet { - var $databaseType = "mssql"; - var $canSeek = true; - var $hasFetchAssoc; // see http://phplens.com/lens/lensforum/msgs.php?id=6083 - // _mths works only in non-localised system - - function ADORecordset_mssql($id,$mode=false) - { - // freedts check... - $this->hasFetchAssoc = function_exists('mssql_fetch_assoc'); - - if ($mode === false) { - global $ADODB_FETCH_MODE; - $mode = $ADODB_FETCH_MODE; - } - $this->fetchMode = $mode; - return $this->ADORecordSet($id,$mode); - } - - - function _initrs() - { - GLOBAL $ADODB_COUNTRECS; - $this->_numOfRows = ($ADODB_COUNTRECS)? @mssql_num_rows($this->_queryID):-1; - $this->_numOfFields = @mssql_num_fields($this->_queryID); - } - - - //Contributed by "Sven Axelsson" - // get next resultset - requires PHP 4.0.5 or later - function NextRecordSet() - { - if (!mssql_next_result($this->_queryID)) return false; - $this->_inited = false; - $this->bind = false; - $this->_currentRow = -1; - $this->Init(); - return true; - } - - /* Use associative array to get fields array */ - function Fields($colname) - { - if ($this->fetchMode != ADODB_FETCH_NUM) return $this->fields[$colname]; - if (!$this->bind) { - $this->bind = array(); - for ($i=0; $i < $this->_numOfFields; $i++) { - $o = $this->FetchField($i); - $this->bind[strtoupper($o->name)] = $i; - } - } - - return $this->fields[$this->bind[strtoupper($colname)]]; - } - - /* Returns: an object containing field information. - Get column information in the Recordset object. fetchField() can be used in order to obtain information about - fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by - fetchField() is retrieved. */ - - function FetchField($fieldOffset = -1) - { - if ($fieldOffset != -1) { - return @mssql_fetch_field($this->_queryID, $fieldOffset); - } - else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */ - return @mssql_fetch_field($this->_queryID); - } - return null; - } - - function _seek($row) - { - return @mssql_data_seek($this->_queryID, $row); - } - - // speedup - function MoveNext() - { - if ($this->EOF) return false; - - $this->_currentRow++; - - if ($this->fetchMode & ADODB_FETCH_ASSOC) { - if ($this->fetchMode & ADODB_FETCH_NUM) { - //ADODB_FETCH_BOTH mode - $this->fields = @mssql_fetch_array($this->_queryID); - } - else { - if ($this->hasFetchAssoc) {// only for PHP 4.2.0 or later - $this->fields = @mssql_fetch_assoc($this->_queryID); - } else { - $flds = @mssql_fetch_array($this->_queryID); - if (is_array($flds)) { - $fassoc = array(); - foreach($flds as $k => $v) { - if (is_numeric($k)) continue; - $fassoc[$k] = $v; - } - $this->fields = $fassoc; - } else - $this->fields = false; - } - } - - if (is_array($this->fields)) { - if (ADODB_ASSOC_CASE == 0) { - foreach($this->fields as $k=>$v) { - $this->fields[strtolower($k)] = $v; - } - } else if (ADODB_ASSOC_CASE == 1) { - foreach($this->fields as $k=>$v) { - $this->fields[strtoupper($k)] = $v; - } - } - } - } else { - $this->fields = @mssql_fetch_row($this->_queryID); - } - if ($this->fields) return true; - $this->EOF = true; - - return false; - } - - - // INSERT UPDATE DELETE returns false even if no error occurs in 4.0.4 - // also the date format has been changed from YYYY-mm-dd to dd MMM YYYY in 4.0.4. Idiot! - function _fetch($ignore_fields=false) - { - if ($this->fetchMode & ADODB_FETCH_ASSOC) { - if ($this->fetchMode & ADODB_FETCH_NUM) { - //ADODB_FETCH_BOTH mode - $this->fields = @mssql_fetch_array($this->_queryID); - } else { - if ($this->hasFetchAssoc) // only for PHP 4.2.0 or later - $this->fields = @mssql_fetch_assoc($this->_queryID); - else { - $this->fields = @mssql_fetch_array($this->_queryID); - if (is_array($$this->fields)) { - $fassoc = array(); - foreach($$this->fields as $k => $v) { - if (is_integer($k)) continue; - $fassoc[$k] = $v; - } - $this->fields = $fassoc; - } - } - } - - if (!$this->fields) { - } else if (ADODB_ASSOC_CASE == 0) { - foreach($this->fields as $k=>$v) { - $this->fields[strtolower($k)] = $v; - } - } else if (ADODB_ASSOC_CASE == 1) { - foreach($this->fields as $k=>$v) { - $this->fields[strtoupper($k)] = $v; - } - } - } else { - $this->fields = @mssql_fetch_row($this->_queryID); - } - return $this->fields; - } - - /* close() only needs to be called if you are worried about using too much memory while your script - is running. All associated result memory for the specified result identifier will automatically be freed. */ - - function _close() - { - $rez = mssql_free_result($this->_queryID); - $this->_queryID = false; - return $rez; - } - // mssql uses a default date like Dec 30 2000 12:00AM - function UnixDate($v) - { - return ADORecordSet_array_mssql::UnixDate($v); - } - - function UnixTimeStamp($v) - { - return ADORecordSet_array_mssql::UnixTimeStamp($v); - } + var $databaseType = "mssql"; + var $canSeek = true; + var $hasFetchAssoc; // see http://phplens.com/lens/lensforum/msgs.php?id=6083 + // _mths works only in non-localised system + + function ADORecordset_mssql($id,$mode=false) + { + // freedts check... + $this->hasFetchAssoc = function_exists('mssql_fetch_assoc'); + + if ($mode === false) { + global $ADODB_FETCH_MODE; + $mode = $ADODB_FETCH_MODE; + } + $this->fetchMode = $mode; + return $this->ADORecordSet($id,$mode); + } + + + function _initrs() + { + GLOBAL $ADODB_COUNTRECS; + $this->_numOfRows = ($ADODB_COUNTRECS)? @mssql_num_rows($this->_queryID):-1; + $this->_numOfFields = @mssql_num_fields($this->_queryID); + } + + + //Contributed by "Sven Axelsson" + // get next resultset - requires PHP 4.0.5 or later + function NextRecordSet() + { + if (!mssql_next_result($this->_queryID)) return false; + $this->_inited = false; + $this->bind = false; + $this->_currentRow = -1; + $this->Init(); + return true; + } + + /* Use associative array to get fields array */ + function Fields($colname) + { + if ($this->fetchMode != ADODB_FETCH_NUM) return $this->fields[$colname]; + if (!$this->bind) { + $this->bind = array(); + for ($i=0; $i < $this->_numOfFields; $i++) { + $o = $this->FetchField($i); + $this->bind[strtoupper($o->name)] = $i; + } + } + + return $this->fields[$this->bind[strtoupper($colname)]]; + } + + /* Returns: an object containing field information. + Get column information in the Recordset object. fetchField() can be used in order to obtain information about + fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by + fetchField() is retrieved. */ + + function FetchField($fieldOffset = -1) + { + if ($fieldOffset != -1) { + return @mssql_fetch_field($this->_queryID, $fieldOffset); + } + else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */ + return @mssql_fetch_field($this->_queryID); + } + return null; + } + + function _seek($row) + { + return @mssql_data_seek($this->_queryID, $row); + } + + // speedup + function MoveNext() + { + if ($this->EOF) return false; + + $this->_currentRow++; + + if ($this->fetchMode & ADODB_FETCH_ASSOC) { + if ($this->fetchMode & ADODB_FETCH_NUM) { + //ADODB_FETCH_BOTH mode + $this->fields = @mssql_fetch_array($this->_queryID); + } + else { + if ($this->hasFetchAssoc) {// only for PHP 4.2.0 or later + $this->fields = @mssql_fetch_assoc($this->_queryID); + } else { + $flds = @mssql_fetch_array($this->_queryID); + if (is_array($flds)) { + $fassoc = array(); + foreach($flds as $k => $v) { + if (is_numeric($k)) continue; + $fassoc[$k] = $v; + } + $this->fields = $fassoc; + } else + $this->fields = false; + } + } + + if (is_array($this->fields)) { + if (ADODB_ASSOC_CASE == 0) { + foreach($this->fields as $k=>$v) { + $this->fields[strtolower($k)] = $v; + } + } else if (ADODB_ASSOC_CASE == 1) { + foreach($this->fields as $k=>$v) { + $this->fields[strtoupper($k)] = $v; + } + } + } + } else { + $this->fields = @mssql_fetch_row($this->_queryID); + } + if ($this->fields) return true; + $this->EOF = true; + + return false; + } + + + // INSERT UPDATE DELETE returns false even if no error occurs in 4.0.4 + // also the date format has been changed from YYYY-mm-dd to dd MMM YYYY in 4.0.4. Idiot! + function _fetch($ignore_fields=false) + { + if ($this->fetchMode & ADODB_FETCH_ASSOC) { + if ($this->fetchMode & ADODB_FETCH_NUM) { + //ADODB_FETCH_BOTH mode + $this->fields = @mssql_fetch_array($this->_queryID); + } else { + if ($this->hasFetchAssoc) // only for PHP 4.2.0 or later + $this->fields = @mssql_fetch_assoc($this->_queryID); + else { + $this->fields = @mssql_fetch_array($this->_queryID); + if (is_array($$this->fields)) { + $fassoc = array(); + foreach($$this->fields as $k => $v) { + if (is_integer($k)) continue; + $fassoc[$k] = $v; + } + $this->fields = $fassoc; + } + } + } + + if (!$this->fields) { + } else if (ADODB_ASSOC_CASE == 0) { + foreach($this->fields as $k=>$v) { + $this->fields[strtolower($k)] = $v; + } + } else if (ADODB_ASSOC_CASE == 1) { + foreach($this->fields as $k=>$v) { + $this->fields[strtoupper($k)] = $v; + } + } + } else { + $this->fields = @mssql_fetch_row($this->_queryID); + } + return $this->fields; + } + + /* close() only needs to be called if you are worried about using too much memory while your script + is running. All associated result memory for the specified result identifier will automatically be freed. */ + + function _close() + { + $rez = mssql_free_result($this->_queryID); + $this->_queryID = false; + return $rez; + } + // mssql uses a default date like Dec 30 2000 12:00AM + function UnixDate($v) + { + return ADORecordSet_array_mssql::UnixDate($v); + } + + function UnixTimeStamp($v) + { + return ADORecordSet_array_mssql::UnixTimeStamp($v); + } } class ADORecordSet_array_mssql extends ADORecordSet_array { - function ADORecordSet_array_mssql($id=-1,$mode=false) - { - $this->ADORecordSet_array($id,$mode); - } - - // mssql uses a default date like Dec 30 2000 12:00AM - function UnixDate($v) - { - - if (is_numeric(substr($v,0,1)) && ADODB_PHPVER >= 0x4200) return parent::UnixDate($v); - - global $ADODB_mssql_mths,$ADODB_mssql_date_order; - - //Dec 30 2000 12:00AM - if ($ADODB_mssql_date_order == 'dmy') { - if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4})|" ,$v, $rr)) { - return parent::UnixDate($v); - } - if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; - - $theday = $rr[1]; - $themth = substr(strtoupper($rr[2]),0,3); - } else { - if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4})|" ,$v, $rr)) { - return parent::UnixDate($v); - } - if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; - - $theday = $rr[2]; - $themth = substr(strtoupper($rr[1]),0,3); - } - $themth = $ADODB_mssql_mths[$themth]; - if ($themth <= 0) return false; - // h-m-s-MM-DD-YY - return mktime(0,0,0,$themth,$theday,$rr[3]); - } - - function UnixTimeStamp($v) - { - - if (is_numeric(substr($v,0,1)) && ADODB_PHPVER >= 0x4200) return parent::UnixTimeStamp($v); - - global $ADODB_mssql_mths,$ADODB_mssql_date_order; - - //Dec 30 2000 12:00AM - if ($ADODB_mssql_date_order == 'dmy') { - if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|" - ,$v, $rr)) return parent::UnixTimeStamp($v); - if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; - - $theday = $rr[1]; - $themth = substr(strtoupper($rr[2]),0,3); - } else { - if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|" - ,$v, $rr)) return parent::UnixTimeStamp($v); - if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; - - $theday = $rr[2]; - $themth = substr(strtoupper($rr[1]),0,3); - } - - $themth = $ADODB_mssql_mths[$themth]; - if ($themth <= 0) return false; - - switch (strtoupper($rr[6])) { - case 'P': - if ($rr[4]<12) $rr[4] += 12; - break; - case 'A': - if ($rr[4]==12) $rr[4] = 0; - break; - default: - break; - } - // h-m-s-MM-DD-YY - return mktime($rr[4],$rr[5],0,$themth,$theday,$rr[3]); - } + function ADORecordSet_array_mssql($id=-1,$mode=false) + { + $this->ADORecordSet_array($id,$mode); + } + + // mssql uses a default date like Dec 30 2000 12:00AM + function UnixDate($v) + { + + if (is_numeric(substr($v,0,1)) && ADODB_PHPVER >= 0x4200) return parent::UnixDate($v); + + global $ADODB_mssql_mths,$ADODB_mssql_date_order; + + //Dec 30 2000 12:00AM + if ($ADODB_mssql_date_order == 'dmy') { + if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4})|" ,$v, $rr)) { + return parent::UnixDate($v); + } + if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; + + $theday = $rr[1]; + $themth = substr(strtoupper($rr[2]),0,3); + } else { + if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4})|" ,$v, $rr)) { + return parent::UnixDate($v); + } + if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; + + $theday = $rr[2]; + $themth = substr(strtoupper($rr[1]),0,3); + } + $themth = $ADODB_mssql_mths[$themth]; + if ($themth <= 0) return false; + // h-m-s-MM-DD-YY + return mktime(0,0,0,$themth,$theday,$rr[3]); + } + + function UnixTimeStamp($v) + { + + if (is_numeric(substr($v,0,1)) && ADODB_PHPVER >= 0x4200) return parent::UnixTimeStamp($v); + + global $ADODB_mssql_mths,$ADODB_mssql_date_order; + + //Dec 30 2000 12:00AM + if ($ADODB_mssql_date_order == 'dmy') { + if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|" + ,$v, $rr)) return parent::UnixTimeStamp($v); + if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; + + $theday = $rr[1]; + $themth = substr(strtoupper($rr[2]),0,3); + } else { + if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|" + ,$v, $rr)) return parent::UnixTimeStamp($v); + if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; + + $theday = $rr[2]; + $themth = substr(strtoupper($rr[1]),0,3); + } + + $themth = $ADODB_mssql_mths[$themth]; + if ($themth <= 0) return false; + + switch (strtoupper($rr[6])) { + case 'P': + if ($rr[4]<12) $rr[4] += 12; + break; + case 'A': + if ($rr[4]==12) $rr[4] = 0; + break; + default: + break; + } + // h-m-s-MM-DD-YY + return mktime($rr[4],$rr[5],0,$themth,$theday,$rr[3]); + } } /* Code Example 1: select object_name(constid) as constraint_name, - object_name(fkeyid) as table_name, + object_name(fkeyid) as table_name, col_name(fkeyid, fkey) as column_name, - object_name(rkeyid) as referenced_table_name, - col_name(rkeyid, rkey) as referenced_column_name + object_name(rkeyid) as referenced_table_name, + col_name(rkeyid, rkey) as referenced_column_name from sysforeignkeys where object_name(fkeyid) = x order by constraint_name, table_name, referenced_table_name, keyno Code Example 2: select constraint_name, - column_name, - ordinal_position + column_name, + ordinal_position from information_schema.key_column_usage where constraint_catalog = db_name() and table_name = x diff --git a/lib/WikiDB/adodb/drivers/adodb-mssqlnative.inc.php b/lib/WikiDB/adodb/drivers/adodb-mssqlnative.inc.php index 256aabd4a..2cae71138 100644 --- a/lib/WikiDB/adodb/drivers/adodb-mssqlnative.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-mssqlnative.inc.php @@ -11,7 +11,7 @@ Set tabs to 4 for best viewing. Native mssql driver. Requires mssql client. Works on Windows. http://www.microsoft.com/sql/technologies/php/default.mspx To configure for Unix, see - http://phpbuilder.com/columns/alberto20000919.php3 + http://phpbuilder.com/columns/alberto20000919.php3 $stream = sqlsrv_get_field($stmt, $index, SQLSRV_SQLTYPE_STREAM(SQLSRV_ENC_BINARY)); stream_filter_append($stream, "convert.iconv.ucs-2/utf-8"); // Voila, UTF-8 can be read directly from $stream @@ -21,23 +21,23 @@ Set tabs to 4 for best viewing. if (!defined('ADODB_DIR')) die(); if (!function_exists('sqlsrv_configure')) { - die("mssqlnative extension not installed"); + die("mssqlnative extension not installed"); } if (!function_exists('sqlsrv_set_error_handling')) { - function sqlsrv_set_error_handling($constant) { - sqlsrv_configure("WarningsReturnAsErrors", $constant); - } + function sqlsrv_set_error_handling($constant) { + sqlsrv_configure("WarningsReturnAsErrors", $constant); + } } if (!function_exists('sqlsrv_log_set_severity')) { - function sqlsrv_log_set_severity($constant) { - sqlsrv_configure("LogSeverity", $constant); - } + function sqlsrv_log_set_severity($constant) { + sqlsrv_configure("LogSeverity", $constant); + } } if (!function_exists('sqlsrv_log_set_subsystems')) { - function sqlsrv_log_set_subsystems($constant) { - sqlsrv_configure("LogSubsystems", $constant); - } + function sqlsrv_log_set_subsystems($constant) { + sqlsrv_configure("LogSubsystems", $constant); + } } @@ -68,13 +68,13 @@ if (!function_exists('sqlsrv_log_set_subsystems')) { // has datetime converstion to YYYY-MM-DD format, and also mssql_fetch_assoc if (ADODB_PHPVER >= 0x4300) { // docs say 4.2.0, but testing shows only since 4.3.0 does it work! - ini_set('mssql.datetimeconvert',0); + ini_set('mssql.datetimeconvert',0); } else { global $ADODB_mssql_mths; // array, months must be upper-case - $ADODB_mssql_date_order = 'mdy'; - $ADODB_mssql_mths = array( - 'JAN'=>1,'FEB'=>2,'MAR'=>3,'APR'=>4,'MAY'=>5,'JUN'=>6, - 'JUL'=>7,'AUG'=>8,'SEP'=>9,'OCT'=>10,'NOV'=>11,'DEC'=>12); + $ADODB_mssql_date_order = 'mdy'; + $ADODB_mssql_mths = array( + 'JAN'=>1,'FEB'=>2,'MAR'=>3,'APR'=>4,'MAY'=>5,'JUN'=>6, + 'JUL'=>7,'AUG'=>8,'SEP'=>9,'OCT'=>10,'NOV'=>11,'DEC'=>12); } //--------------------------------------------------------------------------- @@ -84,54 +84,54 @@ if (ADODB_PHPVER >= 0x4300) { function AutoDetect_MSSQL_Date_Order($conn) { global $ADODB_mssql_date_order; - $adate = $conn->GetOne('select getdate()'); - if ($adate) { - $anum = (int) $adate; - if ($anum > 0) { - if ($anum > 31) { - //ADOConnection::outp( "MSSQL: YYYY-MM-DD date format not supported currently"); - } else - $ADODB_mssql_date_order = 'dmy'; - } else - $ADODB_mssql_date_order = 'mdy'; - } + $adate = $conn->GetOne('select getdate()'); + if ($adate) { + $anum = (int) $adate; + if ($anum > 0) { + if ($anum > 31) { + //ADOConnection::outp( "MSSQL: YYYY-MM-DD date format not supported currently"); + } else + $ADODB_mssql_date_order = 'dmy'; + } else + $ADODB_mssql_date_order = 'mdy'; + } } class ADODB_mssqlnative extends ADOConnection { - var $databaseType = "mssqlnative"; - var $dataProvider = "mssqlnative"; - var $replaceQuote = "''"; // string to use to replace quotes - var $fmtDate = "'Y-m-d'"; - var $fmtTimeStamp = "'Y-m-d H:i:s'"; - var $hasInsertID = true; - var $substr = "substring"; - var $length = 'len'; - var $hasAffectedRows = true; - var $poorAffectedRows = false; - var $metaDatabasesSQL = "select name from sys.sysdatabases where name <> 'master'"; - var $metaTablesSQL="select name,case when type='U' then 'T' else 'V' end from sysobjects where (type='U' or type='V') and (name not in ('sysallocations','syscolumns','syscomments','sysdepends','sysfilegroups','sysfiles','sysfiles1','sysforeignkeys','sysfulltextcatalogs','sysindexes','sysindexkeys','sysmembers','sysobjects','syspermissions','sysprotects','sysreferences','systypes','sysusers','sysalternates','sysconstraints','syssegments','REFERENTIAL_CONSTRAINTS','CHECK_CONSTRAINTS','CONSTRAINT_TABLE_USAGE','CONSTRAINT_COLUMN_USAGE','VIEWS','VIEW_TABLE_USAGE','VIEW_COLUMN_USAGE','SCHEMATA','TABLES','TABLE_CONSTRAINTS','TABLE_PRIVILEGES','COLUMNS','COLUMN_DOMAIN_USAGE','COLUMN_PRIVILEGES','DOMAINS','DOMAIN_CONSTRAINTS','KEY_COLUMN_USAGE','dtproperties'))"; - var $metaColumnsSQL = # xtype==61 is datetime + var $databaseType = "mssqlnative"; + var $dataProvider = "mssqlnative"; + var $replaceQuote = "''"; // string to use to replace quotes + var $fmtDate = "'Y-m-d'"; + var $fmtTimeStamp = "'Y-m-d H:i:s'"; + var $hasInsertID = true; + var $substr = "substring"; + var $length = 'len'; + var $hasAffectedRows = true; + var $poorAffectedRows = false; + var $metaDatabasesSQL = "select name from sys.sysdatabases where name <> 'master'"; + var $metaTablesSQL="select name,case when type='U' then 'T' else 'V' end from sysobjects where (type='U' or type='V') and (name not in ('sysallocations','syscolumns','syscomments','sysdepends','sysfilegroups','sysfiles','sysfiles1','sysforeignkeys','sysfulltextcatalogs','sysindexes','sysindexkeys','sysmembers','sysobjects','syspermissions','sysprotects','sysreferences','systypes','sysusers','sysalternates','sysconstraints','syssegments','REFERENTIAL_CONSTRAINTS','CHECK_CONSTRAINTS','CONSTRAINT_TABLE_USAGE','CONSTRAINT_COLUMN_USAGE','VIEWS','VIEW_TABLE_USAGE','VIEW_COLUMN_USAGE','SCHEMATA','TABLES','TABLE_CONSTRAINTS','TABLE_PRIVILEGES','COLUMNS','COLUMN_DOMAIN_USAGE','COLUMN_PRIVILEGES','DOMAINS','DOMAIN_CONSTRAINTS','KEY_COLUMN_USAGE','dtproperties'))"; + var $metaColumnsSQL = # xtype==61 is datetime "select c.name,t.name,c.length, - (case when c.xusertype=61 then 0 else c.xprec end), - (case when c.xusertype=61 then 0 else c.xscale end) - from syscolumns c join systypes t on t.xusertype=c.xusertype join sysobjects o on o.id=c.id where o.name='%s'"; - var $hasTop = 'top'; // support mssql SELECT TOP 10 * FROM TABLE - var $hasGenID = true; - var $sysDate = 'convert(datetime,convert(char,GetDate(),102),102)'; - var $sysTimeStamp = 'GetDate()'; - var $maxParameterLen = 4000; - var $arrayClass = 'ADORecordSet_array_mssqlnative'; - var $uniqueSort = true; - var $leftOuter = '*='; - var $rightOuter = '=*'; - var $ansiOuter = true; // for mssql7 or later - var $identitySQL = 'select SCOPE_IDENTITY()'; // 'select SCOPE_IDENTITY'; # for mssql 2000 - var $uniqueOrderBy = true; - var $_bindInputArray = true; - var $_dropSeqSQL = "drop table %s"; - - function ADODB_mssqlnative() - { + (case when c.xusertype=61 then 0 else c.xprec end), + (case when c.xusertype=61 then 0 else c.xscale end) + from syscolumns c join systypes t on t.xusertype=c.xusertype join sysobjects o on o.id=c.id where o.name='%s'"; + var $hasTop = 'top'; // support mssql SELECT TOP 10 * FROM TABLE + var $hasGenID = true; + var $sysDate = 'convert(datetime,convert(char,GetDate(),102),102)'; + var $sysTimeStamp = 'GetDate()'; + var $maxParameterLen = 4000; + var $arrayClass = 'ADORecordSet_array_mssqlnative'; + var $uniqueSort = true; + var $leftOuter = '*='; + var $rightOuter = '=*'; + var $ansiOuter = true; // for mssql7 or later + var $identitySQL = 'select SCOPE_IDENTITY()'; // 'select SCOPE_IDENTITY'; # for mssql 2000 + var $uniqueOrderBy = true; + var $_bindInputArray = true; + var $_dropSeqSQL = "drop table %s"; + + function ADODB_mssqlnative() + { if ($this->debug) { error_log("
");
             sqlsrv_set_error_handling( SQLSRV_ERRORS_LOG_ALL );
@@ -144,237 +144,237 @@ class ADODB_mssqlnative extends ADOConnection {
             sqlsrv_log_set_subsystems(SQLSRV_LOG_SYSTEM_ALL);
             sqlsrv_configure('warnings_return_as_errors', 0);
         }
-	}
-
-	function ServerInfo()
-	{
-    	global $ADODB_FETCH_MODE;
-		if ($this->fetchMode === false) {
-			$savem = $ADODB_FETCH_MODE;
-			$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
-		} else
-			$savem = $this->SetFetchMode(ADODB_FETCH_NUM);
-		$arrServerInfo = sqlsrv_server_info($this->_connectionID);
-		$arr['description'] = $arrServerInfo['SQLServerName'].' connected to '.$arrServerInfo['CurrentDatabase'];
-		$arr['version'] = $arrServerInfo['SQLServerVersion'];//ADOConnection::_findvers($arr['description']);
-		return $arr;
-	}
-
-	function IfNull( $field, $ifNull )
-	{
-		return " ISNULL($field, $ifNull) "; // if MS SQL Server
-	}
-
-	function _insertid()
-	{
-	// SCOPE_IDENTITY()
-	// Returns the last IDENTITY value inserted into an IDENTITY column in
-	// the same scope. A scope is a module -- a stored procedure, trigger,
-	// function, or batch. Thus, two statements are in the same scope if
-	// they are in the same stored procedure, function, or batch.
-		return $this->GetOne($this->identitySQL);
-	}
-
-	function _affectedrows()
-	{
-	   return sqlsrv_rows_affected($this->_queryID);
-	}
-
-	function CreateSequence($seq='adodbseq',$start=1)
-	{
-		if($this->debug) error_log("
CreateSequence($seq,$start)"); + } + + function ServerInfo() + { + global $ADODB_FETCH_MODE; + if ($this->fetchMode === false) { + $savem = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + } else + $savem = $this->SetFetchMode(ADODB_FETCH_NUM); + $arrServerInfo = sqlsrv_server_info($this->_connectionID); + $arr['description'] = $arrServerInfo['SQLServerName'].' connected to '.$arrServerInfo['CurrentDatabase']; + $arr['version'] = $arrServerInfo['SQLServerVersion'];//ADOConnection::_findvers($arr['description']); + return $arr; + } + + function IfNull( $field, $ifNull ) + { + return " ISNULL($field, $ifNull) "; // if MS SQL Server + } + + function _insertid() + { + // SCOPE_IDENTITY() + // Returns the last IDENTITY value inserted into an IDENTITY column in + // the same scope. A scope is a module -- a stored procedure, trigger, + // function, or batch. Thus, two statements are in the same scope if + // they are in the same stored procedure, function, or batch. + return $this->GetOne($this->identitySQL); + } + + function _affectedrows() + { + return sqlsrv_rows_affected($this->_queryID); + } + + function CreateSequence($seq='adodbseq',$start=1) + { + if($this->debug) error_log("
CreateSequence($seq,$start)"); sqlsrv_begin_transaction($this->_connectionID); - $start -= 1; - $this->Execute("create table $seq (id int)");//was float(53) - $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)"); - if (!$ok) { + $start -= 1; + $this->Execute("create table $seq (id int)");//was float(53) + $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)"); + if (!$ok) { if($this->debug) error_log("
Error: ROLLBACK"); sqlsrv_rollback($this->_connectionID); - return false; - } + return false; + } sqlsrv_commit($this->_connectionID); - return true; - } + return true; + } - function GenID($seq='adodbseq',$start=1) - { + function GenID($seq='adodbseq',$start=1) + { if($this->debug) error_log("
GenID($seq,$start)"); sqlsrv_begin_transaction($this->_connectionID); - $ok = $this->Execute("update $seq with (tablock,holdlock) set id = id + 1"); - if (!$ok) { - $this->Execute("create table $seq (id int)"); - $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)"); - if (!$ok) { + $ok = $this->Execute("update $seq with (tablock,holdlock) set id = id + 1"); + if (!$ok) { + $this->Execute("create table $seq (id int)"); + $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)"); + if (!$ok) { if($this->debug) error_log("
Error: ROLLBACK"); sqlsrv_rollback($this->_connectionID); - return false; - } - sqlsrv_commit($this->_connectionID); - return $start; - } - $num = $this->GetOne("select id from $seq"); + return false; + } + sqlsrv_commit($this->_connectionID); + return $start; + } + $num = $this->GetOne("select id from $seq"); sqlsrv_commit($this->_connectionID); if($this->debug) error_log(" Returning: $num"); - return $num; - } - - // Format date column in sql string given an input format that understands Y M D - function SQLDate($fmt, $col=false) - { - if (!$col) $col = $this->sysTimeStamp; - $s = ''; - - $len = strlen($fmt); - for ($i=0; $i < $len; $i++) { - if ($s) $s .= '+'; - $ch = $fmt[$i]; - switch($ch) { - case 'Y': - case 'y': - $s .= "datename(yyyy,$col)"; - break; - case 'M': - $s .= "convert(char(3),$col,0)"; - break; - case 'm': - $s .= "replace(str(month($col),2),' ','0')"; - break; - case 'Q': - case 'q': - $s .= "datename(quarter,$col)"; - break; - case 'D': - case 'd': - $s .= "replace(str(day($col),2),' ','0')"; - break; - case 'h': - $s .= "substring(convert(char(14),$col,0),13,2)"; - break; - - case 'H': - $s .= "replace(str(datepart(hh,$col),2),' ','0')"; - break; - - case 'i': - $s .= "replace(str(datepart(mi,$col),2),' ','0')"; - break; - case 's': - $s .= "replace(str(datepart(ss,$col),2),' ','0')"; - break; - case 'a': - case 'A': - $s .= "substring(convert(char(19),$col,0),18,2)"; - break; - - default: - if ($ch == '\\') { - $i++; - $ch = substr($fmt,$i,1); - } - $s .= $this->qstr($ch); - break; - } - } - return $s; - } - - - function BeginTrans() - { - if ($this->transOff) return true; - $this->transCnt += 1; + return $num; + } + + // Format date column in sql string given an input format that understands Y M D + function SQLDate($fmt, $col=false) + { + if (!$col) $col = $this->sysTimeStamp; + $s = ''; + + $len = strlen($fmt); + for ($i=0; $i < $len; $i++) { + if ($s) $s .= '+'; + $ch = $fmt[$i]; + switch($ch) { + case 'Y': + case 'y': + $s .= "datename(yyyy,$col)"; + break; + case 'M': + $s .= "convert(char(3),$col,0)"; + break; + case 'm': + $s .= "replace(str(month($col),2),' ','0')"; + break; + case 'Q': + case 'q': + $s .= "datename(quarter,$col)"; + break; + case 'D': + case 'd': + $s .= "replace(str(day($col),2),' ','0')"; + break; + case 'h': + $s .= "substring(convert(char(14),$col,0),13,2)"; + break; + + case 'H': + $s .= "replace(str(datepart(hh,$col),2),' ','0')"; + break; + + case 'i': + $s .= "replace(str(datepart(mi,$col),2),' ','0')"; + break; + case 's': + $s .= "replace(str(datepart(ss,$col),2),' ','0')"; + break; + case 'a': + case 'A': + $s .= "substring(convert(char(19),$col,0),18,2)"; + break; + + default: + if ($ch == '\\') { + $i++; + $ch = substr($fmt,$i,1); + } + $s .= $this->qstr($ch); + break; + } + } + return $s; + } + + + function BeginTrans() + { + if ($this->transOff) return true; + $this->transCnt += 1; if ($this->debug) error_log('
begin transaction'); - sqlsrv_begin_transaction($this->_connectionID); - return true; - } + sqlsrv_begin_transaction($this->_connectionID); + return true; + } - function CommitTrans($ok=true) - { - if ($this->transOff) return true; + function CommitTrans($ok=true) + { + if ($this->transOff) return true; if ($this->debug) error_log('
commit transaction'); - if (!$ok) return $this->RollbackTrans(); - if ($this->transCnt) $this->transCnt -= 1; - sqlsrv_commit($this->_connectionID); - return true; - } - function RollbackTrans() - { - if ($this->transOff) return true; + if (!$ok) return $this->RollbackTrans(); + if ($this->transCnt) $this->transCnt -= 1; + sqlsrv_commit($this->_connectionID); + return true; + } + function RollbackTrans() + { + if ($this->transOff) return true; if ($this->debug) error_log('
rollback transaction'); - if ($this->transCnt) $this->transCnt -= 1; - sqlsrv_rollback($this->_connectionID); - return true; - } - - function SetTransactionMode( $transaction_mode ) - { - $this->_transmode = $transaction_mode; - if (empty($transaction_mode)) { - $this->Execute('SET TRANSACTION ISOLATION LEVEL READ COMMITTED'); - return; - } - if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode; - $this->Execute("SET TRANSACTION ".$transaction_mode); - } - - /* - Usage: - - $this->BeginTrans(); - $this->RowLock('table1,table2','table1.id=33 and table2.id=table1.id'); # lock row 33 for both tables - - # some operation on both tables table1 and table2 - - $this->CommitTrans(); - - See http://www.swynk.com/friends/achigrik/SQL70Locks.asp - */ - function RowLock($tables,$where,$col='top 1 null as ignore') - { - if (!$this->transCnt) $this->BeginTrans(); - return $this->GetOne("select $col from $tables with (ROWLOCK,HOLDLOCK) where $where"); - } - - function SelectDB($dbName) - { - $this->database = $dbName; - $this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions - if ($this->_connectionID) { + if ($this->transCnt) $this->transCnt -= 1; + sqlsrv_rollback($this->_connectionID); + return true; + } + + function SetTransactionMode( $transaction_mode ) + { + $this->_transmode = $transaction_mode; + if (empty($transaction_mode)) { + $this->Execute('SET TRANSACTION ISOLATION LEVEL READ COMMITTED'); + return; + } + if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode; + $this->Execute("SET TRANSACTION ".$transaction_mode); + } + + /* + Usage: + + $this->BeginTrans(); + $this->RowLock('table1,table2','table1.id=33 and table2.id=table1.id'); # lock row 33 for both tables + + # some operation on both tables table1 and table2 + + $this->CommitTrans(); + + See http://www.swynk.com/friends/achigrik/SQL70Locks.asp + */ + function RowLock($tables,$where,$col='top 1 null as ignore') + { + if (!$this->transCnt) $this->BeginTrans(); + return $this->GetOne("select $col from $tables with (ROWLOCK,HOLDLOCK) where $where"); + } + + function SelectDB($dbName) + { + $this->database = $dbName; + $this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions + if ($this->_connectionID) { $rs = $this->Execute('USE '.$dbName); if($rs) { return true; } else return false; - } - else return false; - } - - function ErrorMsg() - { - $retErrors = sqlsrv_errors(SQLSRV_ERR_ALL); - if($retErrors != null) { - foreach($retErrors as $arrError) { - $this->_errorMsg .= "SQLState: ".$arrError[ 'SQLSTATE']."\n"; - $this->_errorMsg .= "Error Code: ".$arrError[ 'code']."\n"; - $this->_errorMsg .= "Message: ".$arrError[ 'message']."\n"; - } - } else { - $this->_errorMsg = "No errors found"; - } - return $this->_errorMsg; - } - - function ErrorNo() - { - if ($this->_logsql && $this->_errorCode !== false) return $this->_errorCode; - $err = sqlsrv_errors(SQLSRV_ERR_ALL); + } + else return false; + } + + function ErrorMsg() + { + $retErrors = sqlsrv_errors(SQLSRV_ERR_ALL); + if($retErrors != null) { + foreach($retErrors as $arrError) { + $this->_errorMsg .= "SQLState: ".$arrError[ 'SQLSTATE']."\n"; + $this->_errorMsg .= "Error Code: ".$arrError[ 'code']."\n"; + $this->_errorMsg .= "Message: ".$arrError[ 'message']."\n"; + } + } else { + $this->_errorMsg = "No errors found"; + } + return $this->_errorMsg; + } + + function ErrorNo() + { + if ($this->_logsql && $this->_errorCode !== false) return $this->_errorCode; + $err = sqlsrv_errors(SQLSRV_ERR_ALL); if($err[0]) return $err[0]['code']; else return -1; - } + } - // returns true or false - function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) - { - if (!function_exists('sqlsrv_connect')) return null; + // returns true or false + function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) + { + if (!function_exists('sqlsrv_connect')) return null; $connectionInfo = array("Database"=>$argDatabasename,'UID'=>$argUsername,'PWD'=>$argPassword); if ($this->debug) error_log("
connecting... hostname: $argHostname params: ".var_export($connectionInfo,true)); //if ($this->debug) error_log("
_connectionID before: ".serialize($this->_connectionID)); @@ -384,24 +384,24 @@ class ADODB_mssqlnative extends ADOConnection { } //if ($this->debug) error_log(" _connectionID after: ".serialize($this->_connectionID)); //if ($this->debug) error_log("
defined functions:
".var_export(get_defined_functions(),true)."
"); - return true; - } + return true; + } - // returns true or false - function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) - { - //return null;//not implemented. NOTE: Persistent connections have no effect if PHP is used as a CGI program. (FastCGI!) + // returns true or false + function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) + { + //return null;//not implemented. NOTE: Persistent connections have no effect if PHP is used as a CGI program. (FastCGI!) return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename); - } + } - function Prepare($sql) - { - $stmt = sqlsrv_prepare( $this->_connectionID, $sql); - if (!$stmt) return $sql; - return array($sql,$stmt); - } + function Prepare($sql) + { + $stmt = sqlsrv_prepare( $this->_connectionID, $sql); + if (!$stmt) return $sql; + return array($sql,$stmt); + } - // returns concatenated string + // returns concatenated string // MSSQL requires integers to be cast as strings // automatically cast every datatype to VARCHAR(255) // @author David Rogers (introspectshun) @@ -422,43 +422,43 @@ class ADODB_mssqlnative extends ADOConnection { $s = implode('+',$arr); if (sizeof($arr) > 0) return "$s"; - return ''; + return ''; } - /* - Unfortunately, it appears that mssql cannot handle varbinary > 255 chars - So all your blobs must be of type "image". + /* + Unfortunately, it appears that mssql cannot handle varbinary > 255 chars + So all your blobs must be of type "image". - Remember to set in php.ini the following... + Remember to set in php.ini the following... - ; Valid range 0 - 2147483647. Default = 4096. - mssql.textlimit = 0 ; zero to pass through + ; Valid range 0 - 2147483647. Default = 4096. + mssql.textlimit = 0 ; zero to pass through - ; Valid range 0 - 2147483647. Default = 4096. - mssql.textsize = 0 ; zero to pass through - */ - function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') - { + ; Valid range 0 - 2147483647. Default = 4096. + mssql.textsize = 0 ; zero to pass through + */ + function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') + { - if (strtoupper($blobtype) == 'CLOB') { - $sql = "UPDATE $table SET $column='" . $val . "' WHERE $where"; - return $this->Execute($sql) != false; - } - $sql = "UPDATE $table SET $column=0x".bin2hex($val)." WHERE $where"; - return $this->Execute($sql) != false; - } + if (strtoupper($blobtype) == 'CLOB') { + $sql = "UPDATE $table SET $column='" . $val . "' WHERE $where"; + return $this->Execute($sql) != false; + } + $sql = "UPDATE $table SET $column=0x".bin2hex($val)." WHERE $where"; + return $this->Execute($sql) != false; + } - // returns query ID if successful, otherwise false - function _query($sql,$inputarr=false) - { - $this->_errorMsg = false; - if (is_array($inputarr)) { + // returns query ID if successful, otherwise false + function _query($sql,$inputarr=false) + { + $this->_errorMsg = false; + if (is_array($inputarr)) { $rez = sqlsrv_query($this->_connectionID,$sql,$inputarr); - } else if (is_array($sql)) { + } else if (is_array($sql)) { $rez = sqlsrv_query($this->_connectionID,$sql[1],$inputarr); - } else { - $rez = sqlsrv_query($this->_connectionID,$sql); - } + } else { + $rez = sqlsrv_query($this->_connectionID,$sql); + } if ($this->debug) error_log("
running query: ".var_export($sql,true)."
input array: ".var_export($inputarr,true)."
result: ".var_export($rez,true));//"
connection: ".serialize($this->_connectionID) //fix for returning true on anything besides select statements if (is_array($sql)) $sql = $sql[1]; @@ -469,112 +469,112 @@ class ADODB_mssqlnative extends ADOConnection { } //end fix if(!$rez) $rez = false; - return $rez; - } - - // returns true or false - function _close() - { - if ($this->transCnt) $this->RollbackTrans(); - $rez = @sqlsrv_close($this->_connectionID); - $this->_connectionID = false; - return $rez; - } - - // mssql uses a default date like Dec 30 2000 12:00AM - function UnixDate($v) - { - return ADORecordSet_array_mssql::UnixDate($v); - } - - function UnixTimeStamp($v) - { - return ADORecordSet_array_mssql::UnixTimeStamp($v); - } - - function &MetaIndexes($table,$primary=false) - { - $table = $this->qstr($table); - - $sql = "SELECT i.name AS ind_name, C.name AS col_name, USER_NAME(O.uid) AS Owner, c.colid, k.Keyno, - CASE WHEN I.indid BETWEEN 1 AND 254 AND (I.status & 2048 = 2048 OR I.Status = 16402 AND O.XType = 'V') THEN 1 ELSE 0 END AS IsPK, - CASE WHEN I.status & 2 = 2 THEN 1 ELSE 0 END AS IsUnique - FROM dbo.sysobjects o INNER JOIN dbo.sysindexes I ON o.id = i.id - INNER JOIN dbo.sysindexkeys K ON I.id = K.id AND I.Indid = K.Indid - INNER JOIN dbo.syscolumns c ON K.id = C.id AND K.colid = C.Colid - WHERE LEFT(i.name, 8) <> '_WA_Sys_' AND o.status >= 0 AND O.Name LIKE $table - ORDER BY O.name, I.Name, K.keyno"; - - global $ADODB_FETCH_MODE; - $save = $ADODB_FETCH_MODE; + return $rez; + } + + // returns true or false + function _close() + { + if ($this->transCnt) $this->RollbackTrans(); + $rez = @sqlsrv_close($this->_connectionID); + $this->_connectionID = false; + return $rez; + } + + // mssql uses a default date like Dec 30 2000 12:00AM + function UnixDate($v) + { + return ADORecordSet_array_mssql::UnixDate($v); + } + + function UnixTimeStamp($v) + { + return ADORecordSet_array_mssql::UnixTimeStamp($v); + } + + function &MetaIndexes($table,$primary=false) + { + $table = $this->qstr($table); + + $sql = "SELECT i.name AS ind_name, C.name AS col_name, USER_NAME(O.uid) AS Owner, c.colid, k.Keyno, + CASE WHEN I.indid BETWEEN 1 AND 254 AND (I.status & 2048 = 2048 OR I.Status = 16402 AND O.XType = 'V') THEN 1 ELSE 0 END AS IsPK, + CASE WHEN I.status & 2 = 2 THEN 1 ELSE 0 END AS IsUnique + FROM dbo.sysobjects o INNER JOIN dbo.sysindexes I ON o.id = i.id + INNER JOIN dbo.sysindexkeys K ON I.id = K.id AND I.Indid = K.Indid + INNER JOIN dbo.syscolumns c ON K.id = C.id AND K.colid = C.Colid + WHERE LEFT(i.name, 8) <> '_WA_Sys_' AND o.status >= 0 AND O.Name LIKE $table + ORDER BY O.name, I.Name, K.keyno"; + + global $ADODB_FETCH_MODE; + $save = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; if ($this->fetchMode !== FALSE) { - $savem = $this->SetFetchMode(FALSE); + $savem = $this->SetFetchMode(FALSE); } $rs = $this->Execute($sql); if (isset($savem)) { - $this->SetFetchMode($savem); + $this->SetFetchMode($savem); } $ADODB_FETCH_MODE = $save; if (!is_object($rs)) { - return FALSE; + return FALSE; } - $indexes = array(); - while ($row = $rs->FetchRow()) { - if (!$primary && $row[5]) continue; + $indexes = array(); + while ($row = $rs->FetchRow()) { + if (!$primary && $row[5]) continue; $indexes[$row[0]]['unique'] = $row[6]; $indexes[$row[0]]['columns'][] = $row[1]; - } + } return $indexes; - } + } - function MetaForeignKeys($table, $owner=false, $upper=false) - { - global $ADODB_FETCH_MODE; + function MetaForeignKeys($table, $owner=false, $upper=false) + { + global $ADODB_FETCH_MODE; - $save = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - $table = $this->qstr(strtoupper($table)); + $save = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + $table = $this->qstr(strtoupper($table)); - $sql = + $sql = "select object_name(constid) as constraint_name, - col_name(fkeyid, fkey) as column_name, - object_name(rkeyid) as referenced_table_name, - col_name(rkeyid, rkey) as referenced_column_name + col_name(fkeyid, fkey) as column_name, + object_name(rkeyid) as referenced_table_name, + col_name(rkeyid, rkey) as referenced_column_name from sysforeignkeys where upper(object_name(fkeyid)) = $table order by constraint_name, referenced_table_name, keyno"; - $constraints =& $this->GetArray($sql); + $constraints =& $this->GetArray($sql); - $ADODB_FETCH_MODE = $save; + $ADODB_FETCH_MODE = $save; - $arr = false; - foreach($constraints as $constr) { - //print_r($constr); - $arr[$constr[0]][$constr[2]][] = $constr[1].'='.$constr[3]; - } - if (!$arr) return false; + $arr = false; + foreach($constraints as $constr) { + //print_r($constr); + $arr[$constr[0]][$constr[2]][] = $constr[1].'='.$constr[3]; + } + if (!$arr) return false; - $arr2 = false; + $arr2 = false; - foreach($arr as $k => $v) { - foreach($v as $a => $b) { - if ($upper) $a = strtoupper($a); - $arr2[$a] = $b; - } - } - return $arr2; - } + foreach($arr as $k => $v) { + foreach($v as $a => $b) { + if ($upper) $a = strtoupper($a); + $arr2[$a] = $b; + } + } + return $arr2; + } - //From: Fernando Moreira - function MetaDatabases() - { - $this->SelectDB("master"); + //From: Fernando Moreira + function MetaDatabases() + { + $this->SelectDB("master"); $rs =& $this->Execute($this->metaDatabasesSQL); $rows = $rs->GetRows(); $ret = array(); @@ -586,188 +586,188 @@ class ADODB_mssqlnative extends ADOConnection { return $ret; else return false; - } - - // "Stein-Aksel Basma" - // tested with MSSQL 2000 - function &MetaPrimaryKeys($table) - { - global $ADODB_FETCH_MODE; - - $schema = ''; - $this->_findschema($table,$schema); - if (!$schema) $schema = $this->database; - if ($schema) $schema = "and k.table_catalog like '$schema%'"; - - $sql = "select distinct k.column_name,ordinal_position from information_schema.key_column_usage k, - information_schema.table_constraints tc - where tc.constraint_name = k.constraint_name and tc.constraint_type = - 'PRIMARY KEY' and k.table_name = '$table' $schema order by ordinal_position "; - - $savem = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - $a = $this->GetCol($sql); - $ADODB_FETCH_MODE = $savem; - - if ($a && sizeof($a)>0) return $a; - $false = false; - return $false; - } - - - function &MetaTables($ttype=false,$showSchema=false,$mask=false) - { - if ($mask) { - $save = $this->metaTablesSQL; - $mask = $this->qstr(($mask)); - $this->metaTablesSQL .= " AND name like $mask"; - } - $ret =& ADOConnection::MetaTables($ttype,$showSchema); - - if ($mask) { - $this->metaTablesSQL = $save; - } - return $ret; - } + } + + // "Stein-Aksel Basma" + // tested with MSSQL 2000 + function &MetaPrimaryKeys($table) + { + global $ADODB_FETCH_MODE; + + $schema = ''; + $this->_findschema($table,$schema); + if (!$schema) $schema = $this->database; + if ($schema) $schema = "and k.table_catalog like '$schema%'"; + + $sql = "select distinct k.column_name,ordinal_position from information_schema.key_column_usage k, + information_schema.table_constraints tc + where tc.constraint_name = k.constraint_name and tc.constraint_type = + 'PRIMARY KEY' and k.table_name = '$table' $schema order by ordinal_position "; + + $savem = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + $a = $this->GetCol($sql); + $ADODB_FETCH_MODE = $savem; + + if ($a && sizeof($a)>0) return $a; + $false = false; + return $false; + } + + + function &MetaTables($ttype=false,$showSchema=false,$mask=false) + { + if ($mask) { + $save = $this->metaTablesSQL; + $mask = $this->qstr(($mask)); + $this->metaTablesSQL .= " AND name like $mask"; + } + $ret =& ADOConnection::MetaTables($ttype,$showSchema); + + if ($mask) { + $this->metaTablesSQL = $save; + } + return $ret; + } } /*-------------------------------------------------------------------------------------- - Class Name: Recordset + Class Name: Recordset --------------------------------------------------------------------------------------*/ class ADORecordset_mssqlnative extends ADORecordSet { - var $databaseType = "mssqlnative"; - var $canSeek = false; - var $fieldOffset = 0; - // _mths works only in non-localised system + var $databaseType = "mssqlnative"; + var $canSeek = false; + var $fieldOffset = 0; + // _mths works only in non-localised system - function ADORecordset_mssqlnative($id,$mode=false) - { - if ($mode === false) { - global $ADODB_FETCH_MODE; - $mode = $ADODB_FETCH_MODE; + function ADORecordset_mssqlnative($id,$mode=false) + { + if ($mode === false) { + global $ADODB_FETCH_MODE; + $mode = $ADODB_FETCH_MODE; - } - $this->fetchMode = $mode; - return $this->ADORecordSet($id,$mode); - } + } + $this->fetchMode = $mode; + return $this->ADORecordSet($id,$mode); + } - function _initrs() - { - global $ADODB_COUNTRECS; + function _initrs() + { + global $ADODB_COUNTRECS; if ($this->connection->debug) error_log("(before) ADODB_COUNTRECS: {$ADODB_COUNTRECS} _numOfRows: {$this->_numOfRows} _numOfFields: {$this->_numOfFields}"); /*$retRowsAff = sqlsrv_rows_affected($this->_queryID);//"If you need to determine the number of rows a query will return before retrieving the actual results, appending a SELECT COUNT ... query would let you get that information, and then a call to next_result would move you to the "real" results." error_log("rowsaff: ".serialize($retRowsAff)); - $this->_numOfRows = ($ADODB_COUNTRECS)? $retRowsAff:-1;*/ + $this->_numOfRows = ($ADODB_COUNTRECS)? $retRowsAff:-1;*/ $this->_numOfRows = -1;//not supported $fieldmeta = sqlsrv_field_metadata($this->_queryID); $this->_numOfFields = ($fieldmeta)? count($fieldmeta):-1; if ($this->connection->debug) error_log("(after) _numOfRows: {$this->_numOfRows} _numOfFields: {$this->_numOfFields}"); - } - - - //Contributed by "Sven Axelsson" - // get next resultset - requires PHP 4.0.5 or later - function NextRecordSet() - { - if (!sqlsrv_next_result($this->_queryID)) return false; - $this->_inited = false; - $this->bind = false; - $this->_currentRow = -1; - $this->Init(); - return true; - } - - /* Use associative array to get fields array */ - function Fields($colname) - { - if ($this->fetchMode != ADODB_FETCH_NUM) return $this->fields[$colname]; - if (!$this->bind) { - $this->bind = array(); - for ($i=0; $i < $this->_numOfFields; $i++) { - $o = $this->FetchField($i); - $this->bind[strtoupper($o->name)] = $i; - } - } - - return $this->fields[$this->bind[strtoupper($colname)]]; - } - - /* Returns: an object containing field information. - Get column information in the Recordset object. fetchField() can be used in order to obtain information about - fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by - fetchField() is retrieved. */ - - function &FetchField($fieldOffset = -1) - { + } + + + //Contributed by "Sven Axelsson" + // get next resultset - requires PHP 4.0.5 or later + function NextRecordSet() + { + if (!sqlsrv_next_result($this->_queryID)) return false; + $this->_inited = false; + $this->bind = false; + $this->_currentRow = -1; + $this->Init(); + return true; + } + + /* Use associative array to get fields array */ + function Fields($colname) + { + if ($this->fetchMode != ADODB_FETCH_NUM) return $this->fields[$colname]; + if (!$this->bind) { + $this->bind = array(); + for ($i=0; $i < $this->_numOfFields; $i++) { + $o = $this->FetchField($i); + $this->bind[strtoupper($o->name)] = $i; + } + } + + return $this->fields[$this->bind[strtoupper($colname)]]; + } + + /* Returns: an object containing field information. + Get column information in the Recordset object. fetchField() can be used in order to obtain information about + fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by + fetchField() is retrieved. */ + + function &FetchField($fieldOffset = -1) + { if ($this->connection->debug) error_log("
fetchfield: $fieldOffset, fetch array:
".print_r($this->fields,true)."
backtrace: ".adodb_backtrace(false)); - if ($fieldOffset != -1) $this->fieldOffset = $fieldOffset; - $arrKeys = array_keys($this->fields); - if(array_key_exists($this->fieldOffset,$arrKeys) && !array_key_exists($arrKeys[$this->fieldOffset],$this->fields)) { - $f = false; - } else { - $f = $this->fields[ $arrKeys[$this->fieldOffset] ]; - if($fieldOffset == -1) $this->fieldOffset++; - } + if ($fieldOffset != -1) $this->fieldOffset = $fieldOffset; + $arrKeys = array_keys($this->fields); + if(array_key_exists($this->fieldOffset,$arrKeys) && !array_key_exists($arrKeys[$this->fieldOffset],$this->fields)) { + $f = false; + } else { + $f = $this->fields[ $arrKeys[$this->fieldOffset] ]; + if($fieldOffset == -1) $this->fieldOffset++; + } if (empty($f)) { $f = false;//PHP Notice: Only variable references should be returned by reference } - return $f; - } + return $f; + } - function _seek($row) - { - return false;//There is no support for cursors in the driver at this time. All data is returned via forward-only streams. - } + function _seek($row) + { + return false;//There is no support for cursors in the driver at this time. All data is returned via forward-only streams. + } - // speedup - function MoveNext() - { + // speedup + function MoveNext() + { if ($this->connection->debug) error_log("movenext()"); //if ($this->connection->debug) error_log("eof (beginning): ".$this->EOF); - if ($this->EOF) return false; + if ($this->EOF) return false; - $this->_currentRow++; + $this->_currentRow++; if ($this->connection->debug) error_log("_currentRow: ".$this->_currentRow); - if ($this->_fetch()) return true; - $this->EOF = true; + if ($this->_fetch()) return true; + $this->EOF = true; //if ($this->connection->debug) error_log("eof (end): ".$this->EOF); - return false; - } + return false; + } - // INSERT UPDATE DELETE returns false even if no error occurs in 4.0.4 - // also the date format has been changed from YYYY-mm-dd to dd MMM YYYY in 4.0.4. Idiot! - function _fetch($ignore_fields=false) - { + // INSERT UPDATE DELETE returns false even if no error occurs in 4.0.4 + // also the date format has been changed from YYYY-mm-dd to dd MMM YYYY in 4.0.4. Idiot! + function _fetch($ignore_fields=false) + { if ($this->connection->debug) error_log("_fetch()"); - if ($this->fetchMode & ADODB_FETCH_ASSOC) { - if ($this->fetchMode & ADODB_FETCH_NUM) { + if ($this->fetchMode & ADODB_FETCH_ASSOC) { + if ($this->fetchMode & ADODB_FETCH_NUM) { if ($this->connection->debug) error_log("fetch mode: both"); - $this->fields = @sqlsrv_fetch_array($this->_queryID,SQLSRV_FETCH_BOTH); - } else { + $this->fields = @sqlsrv_fetch_array($this->_queryID,SQLSRV_FETCH_BOTH); + } else { if ($this->connection->debug) error_log("fetch mode: assoc"); - $this->fields = @sqlsrv_fetch_array($this->_queryID,SQLSRV_FETCH_ASSOC); - } - - if (ADODB_ASSOC_CASE == 0) { - foreach($this->fields as $k=>$v) { - $this->fields[strtolower($k)] = $v; - } - } else if (ADODB_ASSOC_CASE == 1) { - foreach($this->fields as $k=>$v) { - $this->fields[strtoupper($k)] = $v; - } - } - } else { + $this->fields = @sqlsrv_fetch_array($this->_queryID,SQLSRV_FETCH_ASSOC); + } + + if (ADODB_ASSOC_CASE == 0) { + foreach($this->fields as $k=>$v) { + $this->fields[strtolower($k)] = $v; + } + } else if (ADODB_ASSOC_CASE == 1) { + foreach($this->fields as $k=>$v) { + $this->fields[strtoupper($k)] = $v; + } + } + } else { if ($this->connection->debug) error_log("fetch mode: num"); - $this->fields = @sqlsrv_fetch_array($this->_queryID,SQLSRV_FETCH_NUMERIC); - } + $this->fields = @sqlsrv_fetch_array($this->_queryID,SQLSRV_FETCH_NUMERIC); + } if(is_array($this->fields) && array_key_exists(1,$this->fields) && !array_key_exists(0,$this->fields)) {//fix fetch numeric keys since they're not 0 based $arrFixed = array(); foreach($this->fields as $key=>$value) { @@ -780,136 +780,136 @@ class ADORecordset_mssqlnative extends ADORecordSet { //if($this->connection->debug) error_log("
fixing non 0 based return array, old: ".print_r($this->fields,true)." new: ".print_r($arrFixed,true)); $this->fields = $arrFixed; } - if(is_array($this->fields)) { - foreach($this->fields as $key=>$value) { - if (is_object($value) && method_exists($value, 'format')) {//is DateTime object - $this->fields[$key] = $value->format("Y-m-d\TH:i:s\Z"); - } - } - } + if(is_array($this->fields)) { + foreach($this->fields as $key=>$value) { + if (is_object($value) && method_exists($value, 'format')) {//is DateTime object + $this->fields[$key] = $value->format("Y-m-d\TH:i:s\Z"); + } + } + } if($this->fields === null) $this->fields = false; if ($this->connection->debug) error_log("
after _fetch, fields:
".print_r($this->fields,true)." backtrace: ".adodb_backtrace(false));
-		return $this->fields;
-	}
+        return $this->fields;
+    }
 
     /*	close() only needs to be called if you are worried about using too much memory while your script
-		is running. All associated result memory for the specified result identifier will automatically be freed.	*/
-	function _close()
-	{
-		$rez = sqlsrv_free_stmt($this->_queryID);
-		$this->_queryID = false;
-		return $rez;
-	}
-
-	// mssql uses a default date like Dec 30 2000 12:00AM
-	function UnixDate($v)
-	{
-		return ADORecordSet_array_mssqlnative::UnixDate($v);
-	}
-
-	 function UnixTimeStamp($v)
-	{
-		return ADORecordSet_array_mssqlnative::UnixTimeStamp($v);
-	}
+        is running. All associated result memory for the specified result identifier will automatically be freed.	*/
+    function _close()
+    {
+        $rez = sqlsrv_free_stmt($this->_queryID);
+        $this->_queryID = false;
+        return $rez;
+    }
+
+    // mssql uses a default date like Dec 30 2000 12:00AM
+    function UnixDate($v)
+    {
+        return ADORecordSet_array_mssqlnative::UnixDate($v);
+    }
+
+     function UnixTimeStamp($v)
+    {
+        return ADORecordSet_array_mssqlnative::UnixTimeStamp($v);
+    }
 }
 
 
 class ADORecordSet_array_mssqlnative extends ADORecordSet_array {
-	function ADORecordSet_array_mssqlnative($id=-1,$mode=false)
-	{
-		$this->ADORecordSet_array($id,$mode);
-	}
-
-		// mssql uses a default date like Dec 30 2000 12:00AM
-	 function UnixDate($v)
-	{
-
-		if (is_numeric(substr($v,0,1)) && ADODB_PHPVER >= 0x4200) return parent::UnixDate($v);
-
-    	global $ADODB_mssql_mths,$ADODB_mssql_date_order;
-
-		//Dec 30 2000 12:00AM
-		if ($ADODB_mssql_date_order == 'dmy') {
-			if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4})|" ,$v, $rr)) {
-				return parent::UnixDate($v);
-			}
-			if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0;
-
-			$theday = $rr[1];
-			$themth =  substr(strtoupper($rr[2]),0,3);
-		} else {
-			if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4})|" ,$v, $rr)) {
-				return parent::UnixDate($v);
-			}
-			if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0;
-
-			$theday = $rr[2];
-			$themth = substr(strtoupper($rr[1]),0,3);
-		}
-		$themth = $ADODB_mssql_mths[$themth];
-		if ($themth <= 0) return false;
-		// h-m-s-MM-DD-YY
-		return  mktime(0,0,0,$themth,$theday,$rr[3]);
-	}
-
-	 function UnixTimeStamp($v)
-	{
-
-		if (is_numeric(substr($v,0,1)) && ADODB_PHPVER >= 0x4200) return parent::UnixTimeStamp($v);
-
-	    global $ADODB_mssql_mths,$ADODB_mssql_date_order;
-
-		//Dec 30 2000 12:00AM
-		 if ($ADODB_mssql_date_order == 'dmy') {
-			 if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|"
-			,$v, $rr)) return parent::UnixTimeStamp($v);
-			if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0;
-
-			$theday = $rr[1];
-			$themth =  substr(strtoupper($rr[2]),0,3);
-		} else {
-			if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|"
-			,$v, $rr)) return parent::UnixTimeStamp($v);
-			if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0;
-
-			$theday = $rr[2];
-			$themth = substr(strtoupper($rr[1]),0,3);
-		}
-
-		$themth = $ADODB_mssql_mths[$themth];
-		if ($themth <= 0) return false;
-
-		switch (strtoupper($rr[6])) {
-		case 'P':
-			if ($rr[4]<12) $rr[4] += 12;
-			break;
-		case 'A':
-			if ($rr[4]==12) $rr[4] = 0;
-			break;
-		default:
-			break;
-		}
-		// h-m-s-MM-DD-YY
-		return  mktime($rr[4],$rr[5],0,$themth,$theday,$rr[3]);
-	}
+    function ADORecordSet_array_mssqlnative($id=-1,$mode=false)
+    {
+        $this->ADORecordSet_array($id,$mode);
+    }
+
+        // mssql uses a default date like Dec 30 2000 12:00AM
+     function UnixDate($v)
+    {
+
+        if (is_numeric(substr($v,0,1)) && ADODB_PHPVER >= 0x4200) return parent::UnixDate($v);
+
+        global $ADODB_mssql_mths,$ADODB_mssql_date_order;
+
+        //Dec 30 2000 12:00AM
+        if ($ADODB_mssql_date_order == 'dmy') {
+            if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4})|" ,$v, $rr)) {
+                return parent::UnixDate($v);
+            }
+            if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0;
+
+            $theday = $rr[1];
+            $themth =  substr(strtoupper($rr[2]),0,3);
+        } else {
+            if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4})|" ,$v, $rr)) {
+                return parent::UnixDate($v);
+            }
+            if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0;
+
+            $theday = $rr[2];
+            $themth = substr(strtoupper($rr[1]),0,3);
+        }
+        $themth = $ADODB_mssql_mths[$themth];
+        if ($themth <= 0) return false;
+        // h-m-s-MM-DD-YY
+        return  mktime(0,0,0,$themth,$theday,$rr[3]);
+    }
+
+     function UnixTimeStamp($v)
+    {
+
+        if (is_numeric(substr($v,0,1)) && ADODB_PHPVER >= 0x4200) return parent::UnixTimeStamp($v);
+
+        global $ADODB_mssql_mths,$ADODB_mssql_date_order;
+
+        //Dec 30 2000 12:00AM
+         if ($ADODB_mssql_date_order == 'dmy') {
+             if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|"
+            ,$v, $rr)) return parent::UnixTimeStamp($v);
+            if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0;
+
+            $theday = $rr[1];
+            $themth =  substr(strtoupper($rr[2]),0,3);
+        } else {
+            if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|"
+            ,$v, $rr)) return parent::UnixTimeStamp($v);
+            if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0;
+
+            $theday = $rr[2];
+            $themth = substr(strtoupper($rr[1]),0,3);
+        }
+
+        $themth = $ADODB_mssql_mths[$themth];
+        if ($themth <= 0) return false;
+
+        switch (strtoupper($rr[6])) {
+        case 'P':
+            if ($rr[4]<12) $rr[4] += 12;
+            break;
+        case 'A':
+            if ($rr[4]==12) $rr[4] = 0;
+            break;
+        default:
+            break;
+        }
+        // h-m-s-MM-DD-YY
+        return  mktime($rr[4],$rr[5],0,$themth,$theday,$rr[3]);
+    }
 }
 
 /*
 Code Example 1:
 
 select 	object_name(constid) as constraint_name,
-       	object_name(fkeyid) as table_name,
+           object_name(fkeyid) as table_name,
         col_name(fkeyid, fkey) as column_name,
-	object_name(rkeyid) as referenced_table_name,
-   	col_name(rkeyid, rkey) as referenced_column_name
+    object_name(rkeyid) as referenced_table_name,
+       col_name(rkeyid, rkey) as referenced_column_name
 from sysforeignkeys
 where object_name(fkeyid) = x
 order by constraint_name, table_name, referenced_table_name,  keyno
 
 Code Example 2:
 select 	constraint_name,
-	column_name,
-	ordinal_position
+    column_name,
+    ordinal_position
 from information_schema.key_column_usage
 where constraint_catalog = db_name()
 and table_name = x
diff --git a/lib/WikiDB/adodb/drivers/adodb-mssqlpo.inc.php b/lib/WikiDB/adodb/drivers/adodb-mssqlpo.inc.php
index cf2e4ea9f..56d54c2f5 100644
--- a/lib/WikiDB/adodb/drivers/adodb-mssqlpo.inc.php
+++ b/lib/WikiDB/adodb/drivers/adodb-mssqlpo.inc.php
@@ -15,45 +15,45 @@
 
 
 /*
-	The big difference between mssqlpo and it's parent mssql is that mssqlpo supports
-	the more standard || string concatenation operator.
+    The big difference between mssqlpo and it's parent mssql is that mssqlpo supports
+    the more standard || string concatenation operator.
 */
 
 include_once(ADODB_DIR.'/drivers/adodb-mssql.inc.php');
 
 class ADODB_mssqlpo extends ADODB_mssql {
-	var $databaseType = "mssqlpo";
-	var $concat_operator = '||';
-
-	function ADODB_mssqlpo()
-	{
-		ADODB_mssql::ADODB_mssql();
-	}
-
-	function PrepareSP($sql)
-	{
-		if (!$this->_has_mssql_init) {
-			ADOConnection::outp( "PrepareSP: mssql_init only available since PHP 4.1.0");
-			return $sql;
-		}
-		if (is_string($sql)) $sql = str_replace('||','+',$sql);
-		$stmt = mssql_init($sql,$this->_connectionID);
-		if (!$stmt)  return $sql;
-		return array($sql,$stmt);
-	}
-
-	function _query($sql,$inputarr)
-	{
-		if (is_string($sql)) $sql = str_replace('||','+',$sql);
-		return ADODB_mssql::_query($sql,$inputarr);
-	}
+    var $databaseType = "mssqlpo";
+    var $concat_operator = '||';
+
+    function ADODB_mssqlpo()
+    {
+        ADODB_mssql::ADODB_mssql();
+    }
+
+    function PrepareSP($sql)
+    {
+        if (!$this->_has_mssql_init) {
+            ADOConnection::outp( "PrepareSP: mssql_init only available since PHP 4.1.0");
+            return $sql;
+        }
+        if (is_string($sql)) $sql = str_replace('||','+',$sql);
+        $stmt = mssql_init($sql,$this->_connectionID);
+        if (!$stmt)  return $sql;
+        return array($sql,$stmt);
+    }
+
+    function _query($sql,$inputarr)
+    {
+        if (is_string($sql)) $sql = str_replace('||','+',$sql);
+        return ADODB_mssql::_query($sql,$inputarr);
+    }
 }
 
 class ADORecordset_mssqlpo extends ADORecordset_mssql {
-	var $databaseType = "mssqlpo";
-	function ADORecordset_mssqlpo($id,$mode=false)
-	{
-		$this->ADORecordset_mssql($id,$mode);
-	}
+    var $databaseType = "mssqlpo";
+    function ADORecordset_mssqlpo($id,$mode=false)
+    {
+        $this->ADORecordset_mssql($id,$mode);
+    }
 }
 ?>
\ No newline at end of file
diff --git a/lib/WikiDB/adodb/drivers/adodb-mysql.inc.php b/lib/WikiDB/adodb/drivers/adodb-mysql.inc.php
index e325c3848..a8c4ca8d1 100644
--- a/lib/WikiDB/adodb/drivers/adodb-mysql.inc.php
+++ b/lib/WikiDB/adodb/drivers/adodb-mysql.inc.php
@@ -16,61 +16,61 @@ if (! defined("_ADODB_MYSQL_LAYER")) {
  define("_ADODB_MYSQL_LAYER", 1 );
 
 class ADODB_mysql extends ADOConnection {
-	var $databaseType = 'mysql';
-	var $dataProvider = 'mysql';
-	var $hasInsertID = true;
-	var $hasAffectedRows = true;
-	var $metaTablesSQL = "SHOW TABLES";
-	var $metaColumnsSQL = "SHOW COLUMNS FROM %s";
-	var $fmtTimeStamp = "'Y-m-d H:i:s'";
-	var $hasLimit = true;
-	var $hasMoveFirst = true;
-	var $hasGenID = true;
-	var $upperCase = 'upper';
-	var $isoDates = true; // accepts dates in ISO format
-	var $sysDate = 'CURDATE()';
-	var $sysTimeStamp = 'NOW()';
-	var $hasTransactions = false;
-	var $forceNewConnect = false;
-	var $poorAffectedRows = true;
-	var $clientFlags = 0;
-	var $substr = "substring";
-	var $nameQuote = '`';		/// string to use to quote identifiers and names
-
-	function ADODB_mysql()
-	{
-	}
-
-	function ServerInfo()
-	{
-		$arr['description'] = ADOConnection::GetOne("select version()");
-		$arr['version'] = ADOConnection::_findvers($arr['description']);
-		return $arr;
-	}
-
-	function IfNull( $field, $ifNull )
-	{
-		return " IFNULL($field, $ifNull) "; // if MySQL
-	}
-
-	function &MetaTables($ttype=false,$showSchema=false,$mask=false)
-	{
-		if ($mask) {
-			$save = $this->metaTablesSQL;
-			$mask = $this->qstr($mask);
-			$this->metaTablesSQL .= " like $mask";
-		}
-		$ret =& ADOConnection::MetaTables($ttype,$showSchema);
-
-		if ($mask) {
-			$this->metaTablesSQL = $save;
-		}
-		return $ret;
-	}
-
-
-	function &MetaIndexes ($table, $primary = FALSE, $owner=false)
-	{
+    var $databaseType = 'mysql';
+    var $dataProvider = 'mysql';
+    var $hasInsertID = true;
+    var $hasAffectedRows = true;
+    var $metaTablesSQL = "SHOW TABLES";
+    var $metaColumnsSQL = "SHOW COLUMNS FROM %s";
+    var $fmtTimeStamp = "'Y-m-d H:i:s'";
+    var $hasLimit = true;
+    var $hasMoveFirst = true;
+    var $hasGenID = true;
+    var $upperCase = 'upper';
+    var $isoDates = true; // accepts dates in ISO format
+    var $sysDate = 'CURDATE()';
+    var $sysTimeStamp = 'NOW()';
+    var $hasTransactions = false;
+    var $forceNewConnect = false;
+    var $poorAffectedRows = true;
+    var $clientFlags = 0;
+    var $substr = "substring";
+    var $nameQuote = '`';		/// string to use to quote identifiers and names
+
+    function ADODB_mysql()
+    {
+    }
+
+    function ServerInfo()
+    {
+        $arr['description'] = ADOConnection::GetOne("select version()");
+        $arr['version'] = ADOConnection::_findvers($arr['description']);
+        return $arr;
+    }
+
+    function IfNull( $field, $ifNull )
+    {
+        return " IFNULL($field, $ifNull) "; // if MySQL
+    }
+
+    function &MetaTables($ttype=false,$showSchema=false,$mask=false)
+    {
+        if ($mask) {
+            $save = $this->metaTablesSQL;
+            $mask = $this->qstr($mask);
+            $this->metaTablesSQL .= " like $mask";
+        }
+        $ret =& ADOConnection::MetaTables($ttype,$showSchema);
+
+        if ($mask) {
+            $this->metaTablesSQL = $save;
+        }
+        return $ret;
+    }
+
+
+    function &MetaIndexes ($table, $primary = FALSE, $owner=false)
+    {
         // save old fetch mode
         global $ADODB_FETCH_MODE;
 
@@ -118,553 +118,553 @@ class ADODB_mysql extends ADOConnection {
         }
 
         return $indexes;
-	}
-
-
-	// if magic quotes disabled, use mysql_real_escape_string()
-	function qstr($s,$magic_quotes=false)
-	{
-		if (!$magic_quotes) {
-
-			if (ADODB_PHPVER >= 0x4300) {
-				if (is_resource($this->_connectionID))
-					return "'".mysql_real_escape_string($s,$this->_connectionID)."'";
-			}
-			if ($this->replaceQuote[0] == '\\'){
-				$s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
-			}
-			return  "'".str_replace("'",$this->replaceQuote,$s)."'";
-		}
-
-		// undo magic quotes for "
-		$s = str_replace('\\"','"',$s);
-		return "'$s'";
-	}
-
-	function _insertid()
-	{
-		return mysql_insert_id($this->_connectionID);
-	}
-
-	function GetOne($sql,$inputarr=false)
-	{
-		$rs =& $this->SelectLimit($sql,1,-1,$inputarr);
-		if ($rs) {
-			$rs->Close();
-			if ($rs->EOF) return false;
-			return reset($rs->fields);
-		}
-
-		return false;
-	}
-
-	function _affectedrows()
-	{
+    }
+
+
+    // if magic quotes disabled, use mysql_real_escape_string()
+    function qstr($s,$magic_quotes=false)
+    {
+        if (!$magic_quotes) {
+
+            if (ADODB_PHPVER >= 0x4300) {
+                if (is_resource($this->_connectionID))
+                    return "'".mysql_real_escape_string($s,$this->_connectionID)."'";
+            }
+            if ($this->replaceQuote[0] == '\\'){
+                $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
+            }
+            return  "'".str_replace("'",$this->replaceQuote,$s)."'";
+        }
+
+        // undo magic quotes for "
+        $s = str_replace('\\"','"',$s);
+        return "'$s'";
+    }
+
+    function _insertid()
+    {
+        return mysql_insert_id($this->_connectionID);
+    }
+
+    function GetOne($sql,$inputarr=false)
+    {
+        $rs =& $this->SelectLimit($sql,1,-1,$inputarr);
+        if ($rs) {
+            $rs->Close();
+            if ($rs->EOF) return false;
+            return reset($rs->fields);
+        }
+
+        return false;
+    }
+
+    function _affectedrows()
+    {
             return mysql_affected_rows($this->_connectionID);
-	}
-
- 	// See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html
-	// Reference on Last_Insert_ID on the recommended way to simulate sequences
- 	var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
-	var $_genSeqSQL = "create table %s (id int not null)";
-	var $_genSeq2SQL = "insert into %s values (%s)";
-	var $_dropSeqSQL = "drop table %s";
-
-	function CreateSequence($seqname='adodbseq',$startID=1)
-	{
-		if (empty($this->_genSeqSQL)) return false;
-		$u = strtoupper($seqname);
-
-		$ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname));
-		if (!$ok) return false;
-		return $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
-	}
-
-
-	function GenID($seqname='adodbseq',$startID=1)
-	{
-		// post-nuke sets hasGenID to false
-		if (!$this->hasGenID) return false;
-
-		$savelog = $this->_logsql;
-		$this->_logsql = false;
-		$getnext = sprintf($this->_genIDSQL,$seqname);
-		$holdtransOK = $this->_transOK; // save the current status
-		$rs = @$this->Execute($getnext);
-		if (!$rs) {
-			if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset
-			$u = strtoupper($seqname);
-			$this->Execute(sprintf($this->_genSeqSQL,$seqname));
-			$this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
-			$rs = $this->Execute($getnext);
-		}
-		$this->genID = mysql_insert_id($this->_connectionID);
-
-		if ($rs) $rs->Close();
-
-		$this->_logsql = $savelog;
-		return $this->genID;
-	}
-
-  	function &MetaDatabases()
-	{
-		$qid = mysql_list_dbs($this->_connectionID);
-		$arr = array();
-		$i = 0;
-		$max = mysql_num_rows($qid);
-		while ($i < $max) {
-			$db = mysql_tablename($qid,$i);
-			if ($db != 'mysql') $arr[] = $db;
-			$i += 1;
-		}
-		return $arr;
-	}
-
-
-	// Format date column in sql string given an input format that understands Y M D
-	function SQLDate($fmt, $col=false)
-	{
-		if (!$col) $col = $this->sysTimeStamp;
-		$s = 'DATE_FORMAT('.$col.",'";
-		$concat = false;
-		$len = strlen($fmt);
-		for ($i=0; $i < $len; $i++) {
-			$ch = $fmt[$i];
-			switch($ch) {
-			case 'Y':
-			case 'y':
-				$s .= '%Y';
-				break;
-			case 'Q':
-			case 'q':
-				$s .= "'),Quarter($col)";
-
-				if ($len > $i+1) $s .= ",DATE_FORMAT($col,'";
-				else $s .= ",('";
-				$concat = true;
-				break;
-			case 'M':
-				$s .= '%b';
-				break;
-
-			case 'm':
-				$s .= '%m';
-				break;
-			case 'D':
-			case 'd':
-				$s .= '%d';
-				break;
-
-			case 'H':
-				$s .= '%H';
-				break;
-
-			case 'h':
-				$s .= '%I';
-				break;
-
-			case 'i':
-				$s .= '%i';
-				break;
-
-			case 's':
-				$s .= '%s';
-				break;
-
-			case 'a':
-			case 'A':
-				$s .= '%p';
-				break;
-
-			default:
-
-				if ($ch == '\\') {
-					$i++;
-					$ch = substr($fmt,$i,1);
-				}
-				$s .= $ch;
-				break;
-			}
-		}
-		$s.="')";
-		if ($concat) $s = "CONCAT($s)";
-		return $s;
-	}
-
-
-	// returns concatenated string
-	// much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator
-	function Concat()
-	{
-		$s = "";
-		$arr = func_get_args();
-
-		// suggestion by andrew005@mnogo.ru
-		$s = implode(',',$arr);
-		if (strlen($s) > 0) return "CONCAT($s)";
-		else return '';
-	}
-
-	function OffsetDate($dayFraction,$date=false)
-	{
-		if (!$date) $date = $this->sysDate;
-		return "from_unixtime(unix_timestamp($date)+($dayFraction)*24*3600)";
-	}
-
-	// returns true or false
-	function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
-	{
-		if (ADODB_PHPVER >= 0x4300)
-			$this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,
-												$this->forceNewConnect,$this->clientFlags);
-		else if (ADODB_PHPVER >= 0x4200)
-			$this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,
-												$this->forceNewConnect);
-		else
-			$this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword);
-
-		if ($this->_connectionID === false) return false;
-		if ($argDatabasename) return $this->SelectDB($argDatabasename);
-		return true;
-	}
-
-	// returns true or false
-	function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
-	{
-		if (ADODB_PHPVER >= 0x4300)
-			$this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword,$this->clientFlags);
-		else
-			$this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword);
-		if ($this->_connectionID === false) return false;
-		if ($this->autoRollback) $this->RollbackTrans();
-		if ($argDatabasename) return $this->SelectDB($argDatabasename);
-		return true;
-	}
-
-	function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
-	{
-		$this->forceNewConnect = true;
-		return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);
-	}
-
- 	function &MetaColumns($table)
-	{
-
-		if ($this->metaColumnsSQL) {
-		global $ADODB_FETCH_MODE;
-
-			$save = $ADODB_FETCH_MODE;
-			$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
-			if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
-
-			$rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
-
-			if (isset($savem)) $this->SetFetchMode($savem);
-			$ADODB_FETCH_MODE = $save;
-
-			if ($rs === false) return false;
-
-			$retarr = array();
-			while (!$rs->EOF){
-				$fld = new ADOFieldObject();
-				$fld->name = $rs->fields[0];
-				$type = $rs->fields[1];
-
-
-				// split type into type(length):
-				$fld->scale = null;
-				if (strpos($type,',') && preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
-					$fld->type = $query_array[1];
-					$fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
-					$fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
-				} elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
-					$fld->type = $query_array[1];
-					$fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
-				} else {
-					$fld->max_length = -1;
-					$fld->type = $type;
-				}
-				/*
-				// split type into type(length):
-				if (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
-					$fld->type = $query_array[1];
-					$fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
-				} else {
-					$fld->max_length = -1;
-					$fld->type = $type;
-				}*/
-				$fld->not_null = ($rs->fields[2] != 'YES');
-				$fld->primary_key = ($rs->fields[3] == 'PRI');
-				$fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
-				$fld->binary = (strpos($fld->type,'blob') !== false);
-
-				if (!$fld->binary) {
-					$d = $rs->fields[4];
-					if ($d != "" && $d != "NULL") {
-						$fld->has_default = true;
-						$fld->default_value = $d;
-					} else {
-						$fld->has_default = false;
-					}
-				}
-				if ($save == ADODB_FETCH_NUM) $retarr[] = $fld;
-				else $retarr[strtoupper($fld->name)] = $fld;
-				$rs->MoveNext();
-			}
-			$rs->Close();
-			return $retarr;
-		}
-		return false;
-	}
-
-	// returns true or false
-	function SelectDB($dbName)
-	{
-		$this->databaseName = $dbName;
-		if ($this->_connectionID) {
-			return @mysql_select_db($dbName,$this->_connectionID);
-		}
-		else return false;
-	}
-
-	// parameters use PostgreSQL convention, not MySQL
-	function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
-	{
-		$offsetStr =($offset>=0) ? "$offset," : '';
-
-		if ($secs)
-			$rs =& $this->CacheExecute($secs,$sql." LIMIT $offsetStr$nrows",$inputarr);
-		else
-			$rs =& $this->Execute($sql." LIMIT $offsetStr$nrows",$inputarr);
-		return $rs;
-	}
-
-
-	// returns queryID or false
-	function _query($sql,$inputarr)
-	{
-	//global $ADODB_COUNTRECS;
-		//if($ADODB_COUNTRECS)
-		return mysql_query($sql,$this->_connectionID);
-		//else return @mysql_unbuffered_query($sql,$this->_connectionID); // requires PHP >= 4.0.6
-	}
-
-	/*	Returns: the last error message from previous database operation	*/
-	function ErrorMsg()
-	{
-
-		if ($this->_logsql) return $this->_errorMsg;
-		if (empty($this->_connectionID)) $this->_errorMsg = @mysql_error();
-		else $this->_errorMsg = @mysql_error($this->_connectionID);
-		return $this->_errorMsg;
-	}
-
-	/*	Returns: the last error number from previous database operation	*/
-	function ErrorNo()
-	{
-		if ($this->_logsql) return $this->_errorCode;
-		if (empty($this->_connectionID))  return @mysql_errno();
-		else return @mysql_errno($this->_connectionID);
-	}
-
-
-
-	// returns true or false
-	function _close()
-	{
-		@mysql_close($this->_connectionID);
-		$this->_connectionID = false;
-	}
-
-
-	/*
-	* Maximum size of C field
-	*/
-	function CharMax()
-	{
-		return 255;
-	}
-
-	/*
-	* Maximum size of X field
-	*/
-	function TextMax()
-	{
-		return 4294967295;
-	}
+    }
+
+     // See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html
+    // Reference on Last_Insert_ID on the recommended way to simulate sequences
+     var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
+    var $_genSeqSQL = "create table %s (id int not null)";
+    var $_genSeq2SQL = "insert into %s values (%s)";
+    var $_dropSeqSQL = "drop table %s";
+
+    function CreateSequence($seqname='adodbseq',$startID=1)
+    {
+        if (empty($this->_genSeqSQL)) return false;
+        $u = strtoupper($seqname);
+
+        $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname));
+        if (!$ok) return false;
+        return $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
+    }
+
+
+    function GenID($seqname='adodbseq',$startID=1)
+    {
+        // post-nuke sets hasGenID to false
+        if (!$this->hasGenID) return false;
+
+        $savelog = $this->_logsql;
+        $this->_logsql = false;
+        $getnext = sprintf($this->_genIDSQL,$seqname);
+        $holdtransOK = $this->_transOK; // save the current status
+        $rs = @$this->Execute($getnext);
+        if (!$rs) {
+            if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset
+            $u = strtoupper($seqname);
+            $this->Execute(sprintf($this->_genSeqSQL,$seqname));
+            $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
+            $rs = $this->Execute($getnext);
+        }
+        $this->genID = mysql_insert_id($this->_connectionID);
+
+        if ($rs) $rs->Close();
+
+        $this->_logsql = $savelog;
+        return $this->genID;
+    }
+
+      function &MetaDatabases()
+    {
+        $qid = mysql_list_dbs($this->_connectionID);
+        $arr = array();
+        $i = 0;
+        $max = mysql_num_rows($qid);
+        while ($i < $max) {
+            $db = mysql_tablename($qid,$i);
+            if ($db != 'mysql') $arr[] = $db;
+            $i += 1;
+        }
+        return $arr;
+    }
+
+
+    // Format date column in sql string given an input format that understands Y M D
+    function SQLDate($fmt, $col=false)
+    {
+        if (!$col) $col = $this->sysTimeStamp;
+        $s = 'DATE_FORMAT('.$col.",'";
+        $concat = false;
+        $len = strlen($fmt);
+        for ($i=0; $i < $len; $i++) {
+            $ch = $fmt[$i];
+            switch($ch) {
+            case 'Y':
+            case 'y':
+                $s .= '%Y';
+                break;
+            case 'Q':
+            case 'q':
+                $s .= "'),Quarter($col)";
+
+                if ($len > $i+1) $s .= ",DATE_FORMAT($col,'";
+                else $s .= ",('";
+                $concat = true;
+                break;
+            case 'M':
+                $s .= '%b';
+                break;
+
+            case 'm':
+                $s .= '%m';
+                break;
+            case 'D':
+            case 'd':
+                $s .= '%d';
+                break;
+
+            case 'H':
+                $s .= '%H';
+                break;
+
+            case 'h':
+                $s .= '%I';
+                break;
+
+            case 'i':
+                $s .= '%i';
+                break;
+
+            case 's':
+                $s .= '%s';
+                break;
+
+            case 'a':
+            case 'A':
+                $s .= '%p';
+                break;
+
+            default:
+
+                if ($ch == '\\') {
+                    $i++;
+                    $ch = substr($fmt,$i,1);
+                }
+                $s .= $ch;
+                break;
+            }
+        }
+        $s.="')";
+        if ($concat) $s = "CONCAT($s)";
+        return $s;
+    }
+
+
+    // returns concatenated string
+    // much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator
+    function Concat()
+    {
+        $s = "";
+        $arr = func_get_args();
+
+        // suggestion by andrew005@mnogo.ru
+        $s = implode(',',$arr);
+        if (strlen($s) > 0) return "CONCAT($s)";
+        else return '';
+    }
+
+    function OffsetDate($dayFraction,$date=false)
+    {
+        if (!$date) $date = $this->sysDate;
+        return "from_unixtime(unix_timestamp($date)+($dayFraction)*24*3600)";
+    }
+
+    // returns true or false
+    function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
+    {
+        if (ADODB_PHPVER >= 0x4300)
+            $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,
+                                                $this->forceNewConnect,$this->clientFlags);
+        else if (ADODB_PHPVER >= 0x4200)
+            $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,
+                                                $this->forceNewConnect);
+        else
+            $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword);
+
+        if ($this->_connectionID === false) return false;
+        if ($argDatabasename) return $this->SelectDB($argDatabasename);
+        return true;
+    }
+
+    // returns true or false
+    function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
+    {
+        if (ADODB_PHPVER >= 0x4300)
+            $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword,$this->clientFlags);
+        else
+            $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword);
+        if ($this->_connectionID === false) return false;
+        if ($this->autoRollback) $this->RollbackTrans();
+        if ($argDatabasename) return $this->SelectDB($argDatabasename);
+        return true;
+    }
+
+    function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
+    {
+        $this->forceNewConnect = true;
+        return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);
+    }
+
+     function &MetaColumns($table)
+    {
+
+        if ($this->metaColumnsSQL) {
+        global $ADODB_FETCH_MODE;
+
+            $save = $ADODB_FETCH_MODE;
+            $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
+            if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
+
+            $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
+
+            if (isset($savem)) $this->SetFetchMode($savem);
+            $ADODB_FETCH_MODE = $save;
+
+            if ($rs === false) return false;
+
+            $retarr = array();
+            while (!$rs->EOF){
+                $fld = new ADOFieldObject();
+                $fld->name = $rs->fields[0];
+                $type = $rs->fields[1];
+
+
+                // split type into type(length):
+                $fld->scale = null;
+                if (strpos($type,',') && preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
+                    $fld->type = $query_array[1];
+                    $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
+                    $fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
+                } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
+                    $fld->type = $query_array[1];
+                    $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
+                } else {
+                    $fld->max_length = -1;
+                    $fld->type = $type;
+                }
+                /*
+                // split type into type(length):
+                if (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
+                    $fld->type = $query_array[1];
+                    $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
+                } else {
+                    $fld->max_length = -1;
+                    $fld->type = $type;
+                }*/
+                $fld->not_null = ($rs->fields[2] != 'YES');
+                $fld->primary_key = ($rs->fields[3] == 'PRI');
+                $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
+                $fld->binary = (strpos($fld->type,'blob') !== false);
+
+                if (!$fld->binary) {
+                    $d = $rs->fields[4];
+                    if ($d != "" && $d != "NULL") {
+                        $fld->has_default = true;
+                        $fld->default_value = $d;
+                    } else {
+                        $fld->has_default = false;
+                    }
+                }
+                if ($save == ADODB_FETCH_NUM) $retarr[] = $fld;
+                else $retarr[strtoupper($fld->name)] = $fld;
+                $rs->MoveNext();
+            }
+            $rs->Close();
+            return $retarr;
+        }
+        return false;
+    }
+
+    // returns true or false
+    function SelectDB($dbName)
+    {
+        $this->databaseName = $dbName;
+        if ($this->_connectionID) {
+            return @mysql_select_db($dbName,$this->_connectionID);
+        }
+        else return false;
+    }
+
+    // parameters use PostgreSQL convention, not MySQL
+    function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
+    {
+        $offsetStr =($offset>=0) ? "$offset," : '';
+
+        if ($secs)
+            $rs =& $this->CacheExecute($secs,$sql." LIMIT $offsetStr$nrows",$inputarr);
+        else
+            $rs =& $this->Execute($sql." LIMIT $offsetStr$nrows",$inputarr);
+        return $rs;
+    }
+
+
+    // returns queryID or false
+    function _query($sql,$inputarr)
+    {
+    //global $ADODB_COUNTRECS;
+        //if($ADODB_COUNTRECS)
+        return mysql_query($sql,$this->_connectionID);
+        //else return @mysql_unbuffered_query($sql,$this->_connectionID); // requires PHP >= 4.0.6
+    }
+
+    /*	Returns: the last error message from previous database operation	*/
+    function ErrorMsg()
+    {
+
+        if ($this->_logsql) return $this->_errorMsg;
+        if (empty($this->_connectionID)) $this->_errorMsg = @mysql_error();
+        else $this->_errorMsg = @mysql_error($this->_connectionID);
+        return $this->_errorMsg;
+    }
+
+    /*	Returns: the last error number from previous database operation	*/
+    function ErrorNo()
+    {
+        if ($this->_logsql) return $this->_errorCode;
+        if (empty($this->_connectionID))  return @mysql_errno();
+        else return @mysql_errno($this->_connectionID);
+    }
+
+
+
+    // returns true or false
+    function _close()
+    {
+        @mysql_close($this->_connectionID);
+        $this->_connectionID = false;
+    }
+
+
+    /*
+    * Maximum size of C field
+    */
+    function CharMax()
+    {
+        return 255;
+    }
+
+    /*
+    * Maximum size of X field
+    */
+    function TextMax()
+    {
+        return 4294967295;
+    }
 
 }
 
 /*--------------------------------------------------------------------------------------
-	 Class Name: Recordset
+     Class Name: Recordset
 --------------------------------------------------------------------------------------*/
 
 class ADORecordSet_mysql extends ADORecordSet{
 
-	var $databaseType = "mysql";
-	var $canSeek = true;
-
-	function ADORecordSet_mysql($queryID,$mode=false)
-	{
-		if ($mode === false) {
-			global $ADODB_FETCH_MODE;
-			$mode = $ADODB_FETCH_MODE;
-		}
-		switch ($mode)
-		{
-		case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break;
-		case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break;
-		default:
-		case ADODB_FETCH_DEFAULT:
-		case ADODB_FETCH_BOTH:$this->fetchMode = MYSQL_BOTH; break;
-		}
-
-		$this->ADORecordSet($queryID);
-	}
-
-	function _initrs()
-	{
-	//GLOBAL $ADODB_COUNTRECS;
-	//	$this->_numOfRows = ($ADODB_COUNTRECS) ? @mysql_num_rows($this->_queryID):-1;
-		$this->_numOfRows = @mysql_num_rows($this->_queryID);
-		$this->_numOfFields = @mysql_num_fields($this->_queryID);
-	}
-
-	function &FetchField($fieldOffset = -1)
-	{
-
-		if ($fieldOffset != -1) {
-			$o = @mysql_fetch_field($this->_queryID, $fieldOffset);
-			$f = @mysql_field_flags($this->_queryID,$fieldOffset);
-			$o->max_length = @mysql_field_len($this->_queryID,$fieldOffset); // suggested by: Jim Nicholson (jnich@att.com)
-			//$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
-			$o->binary = (strpos($f,'binary')!== false);
-		}
-		else if ($fieldOffset == -1) {	/*	The $fieldOffset argument is not provided thus its -1 	*/
-			$o = @mysql_fetch_field($this->_queryID);
-			$o->max_length = @mysql_field_len($this->_queryID); // suggested by: Jim Nicholson (jnich@att.com)
-			//$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
-		}
-
-		return $o;
-	}
-
-	function &GetRowAssoc($upper=true)
-	{
-		if ($this->fetchMode == MYSQL_ASSOC && !$upper) return $this->fields;
-		$row =& ADORecordSet::GetRowAssoc($upper);
-		return $row;
-	}
-
-	/* Use associative array to get fields array */
-	function Fields($colname)
-	{
-		// added @ by "Michael William Miller" 
-		if ($this->fetchMode != MYSQL_NUM) return @$this->fields[$colname];
-
-		if (!$this->bind) {
-			$this->bind = array();
-			for ($i=0; $i < $this->_numOfFields; $i++) {
-				$o = $this->FetchField($i);
-				$this->bind[strtoupper($o->name)] = $i;
-			}
-		}
-		 return $this->fields[$this->bind[strtoupper($colname)]];
-	}
-
-	function _seek($row)
-	{
-		if ($this->_numOfRows == 0) return false;
-		return @mysql_data_seek($this->_queryID,$row);
-	}
-
-
-	// 10% speedup to move MoveNext to child class
-	function MoveNext()
-	{
-	//global $ADODB_EXTENSION;if ($ADODB_EXTENSION) return adodb_movenext($this);
-
-		if ($this->EOF) return false;
-
-		$this->_currentRow++;
-		$this->fields = @mysql_fetch_array($this->_queryID,$this->fetchMode);
-		if (is_array($this->fields)) return true;
-
-		$this->EOF = true;
-
-		/* -- tested raising an error -- appears pointless
-		$conn = $this->connection;
-		if ($conn && $conn->raiseErrorFn && ($errno = $conn->ErrorNo())) {
-			$fn = $conn->raiseErrorFn;
-			$fn($conn->databaseType,'MOVENEXT',$errno,$conn->ErrorMsg().' ('.$this->sql.')',$conn->host,$conn->database);
-		}
-		*/
-		return false;
-	}
-
-	function _fetch()
-	{
-		$this->fields =  @mysql_fetch_array($this->_queryID,$this->fetchMode);
-		return is_array($this->fields);
-	}
-
-	function _close() {
-		@mysql_free_result($this->_queryID);
-		$this->_queryID = false;
-	}
-
-	function MetaType($t,$len=-1,$fieldobj=false)
-	{
-		if (is_object($t)) {
-			$fieldobj = $t;
-			$t = $fieldobj->type;
-			$len = $fieldobj->max_length;
-		}
-
-		$len = -1; // mysql max_length is not accurate
-		switch (strtoupper($t)) {
-		case 'STRING':
-		case 'CHAR':
-		case 'VARCHAR':
-		case 'TINYBLOB':
-		case 'TINYTEXT':
-		case 'ENUM':
-		case 'SET':
-			if ($len <= $this->blobSize) return 'C';
-
-		case 'TEXT':
-		case 'LONGTEXT':
-		case 'MEDIUMTEXT':
-			return 'X';
-
-		// php_mysql extension always returns 'blob' even if 'text'
-		// so we have to check whether binary...
-		case 'IMAGE':
-		case 'LONGBLOB':
-		case 'BLOB':
-		case 'MEDIUMBLOB':
-			return !empty($fieldobj->binary) ? 'B' : 'X';
-
-		case 'YEAR':
-		case 'DATE': return 'D';
-
-		case 'TIME':
-		case 'DATETIME':
-		case 'TIMESTAMP': return 'T';
-
-		case 'INT':
-		case 'INTEGER':
-		case 'BIGINT':
-		case 'TINYINT':
-		case 'MEDIUMINT':
-		case 'SMALLINT':
-
-			if (!empty($fieldobj->primary_key)) return 'R';
-			else return 'I';
-
-		default: return 'N';
-		}
-	}
+    var $databaseType = "mysql";
+    var $canSeek = true;
+
+    function ADORecordSet_mysql($queryID,$mode=false)
+    {
+        if ($mode === false) {
+            global $ADODB_FETCH_MODE;
+            $mode = $ADODB_FETCH_MODE;
+        }
+        switch ($mode)
+        {
+        case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break;
+        case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break;
+        default:
+        case ADODB_FETCH_DEFAULT:
+        case ADODB_FETCH_BOTH:$this->fetchMode = MYSQL_BOTH; break;
+        }
+
+        $this->ADORecordSet($queryID);
+    }
+
+    function _initrs()
+    {
+    //GLOBAL $ADODB_COUNTRECS;
+    //	$this->_numOfRows = ($ADODB_COUNTRECS) ? @mysql_num_rows($this->_queryID):-1;
+        $this->_numOfRows = @mysql_num_rows($this->_queryID);
+        $this->_numOfFields = @mysql_num_fields($this->_queryID);
+    }
+
+    function &FetchField($fieldOffset = -1)
+    {
+
+        if ($fieldOffset != -1) {
+            $o = @mysql_fetch_field($this->_queryID, $fieldOffset);
+            $f = @mysql_field_flags($this->_queryID,$fieldOffset);
+            $o->max_length = @mysql_field_len($this->_queryID,$fieldOffset); // suggested by: Jim Nicholson (jnich@att.com)
+            //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
+            $o->binary = (strpos($f,'binary')!== false);
+        }
+        else if ($fieldOffset == -1) {	/*	The $fieldOffset argument is not provided thus its -1 	*/
+            $o = @mysql_fetch_field($this->_queryID);
+            $o->max_length = @mysql_field_len($this->_queryID); // suggested by: Jim Nicholson (jnich@att.com)
+            //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
+        }
+
+        return $o;
+    }
+
+    function &GetRowAssoc($upper=true)
+    {
+        if ($this->fetchMode == MYSQL_ASSOC && !$upper) return $this->fields;
+        $row =& ADORecordSet::GetRowAssoc($upper);
+        return $row;
+    }
+
+    /* Use associative array to get fields array */
+    function Fields($colname)
+    {
+        // added @ by "Michael William Miller" 
+        if ($this->fetchMode != MYSQL_NUM) return @$this->fields[$colname];
+
+        if (!$this->bind) {
+            $this->bind = array();
+            for ($i=0; $i < $this->_numOfFields; $i++) {
+                $o = $this->FetchField($i);
+                $this->bind[strtoupper($o->name)] = $i;
+            }
+        }
+         return $this->fields[$this->bind[strtoupper($colname)]];
+    }
+
+    function _seek($row)
+    {
+        if ($this->_numOfRows == 0) return false;
+        return @mysql_data_seek($this->_queryID,$row);
+    }
+
+
+    // 10% speedup to move MoveNext to child class
+    function MoveNext()
+    {
+    //global $ADODB_EXTENSION;if ($ADODB_EXTENSION) return adodb_movenext($this);
+
+        if ($this->EOF) return false;
+
+        $this->_currentRow++;
+        $this->fields = @mysql_fetch_array($this->_queryID,$this->fetchMode);
+        if (is_array($this->fields)) return true;
+
+        $this->EOF = true;
+
+        /* -- tested raising an error -- appears pointless
+        $conn = $this->connection;
+        if ($conn && $conn->raiseErrorFn && ($errno = $conn->ErrorNo())) {
+            $fn = $conn->raiseErrorFn;
+            $fn($conn->databaseType,'MOVENEXT',$errno,$conn->ErrorMsg().' ('.$this->sql.')',$conn->host,$conn->database);
+        }
+        */
+        return false;
+    }
+
+    function _fetch()
+    {
+        $this->fields =  @mysql_fetch_array($this->_queryID,$this->fetchMode);
+        return is_array($this->fields);
+    }
+
+    function _close() {
+        @mysql_free_result($this->_queryID);
+        $this->_queryID = false;
+    }
+
+    function MetaType($t,$len=-1,$fieldobj=false)
+    {
+        if (is_object($t)) {
+            $fieldobj = $t;
+            $t = $fieldobj->type;
+            $len = $fieldobj->max_length;
+        }
+
+        $len = -1; // mysql max_length is not accurate
+        switch (strtoupper($t)) {
+        case 'STRING':
+        case 'CHAR':
+        case 'VARCHAR':
+        case 'TINYBLOB':
+        case 'TINYTEXT':
+        case 'ENUM':
+        case 'SET':
+            if ($len <= $this->blobSize) return 'C';
+
+        case 'TEXT':
+        case 'LONGTEXT':
+        case 'MEDIUMTEXT':
+            return 'X';
+
+        // php_mysql extension always returns 'blob' even if 'text'
+        // so we have to check whether binary...
+        case 'IMAGE':
+        case 'LONGBLOB':
+        case 'BLOB':
+        case 'MEDIUMBLOB':
+            return !empty($fieldobj->binary) ? 'B' : 'X';
+
+        case 'YEAR':
+        case 'DATE': return 'D';
+
+        case 'TIME':
+        case 'DATETIME':
+        case 'TIMESTAMP': return 'T';
+
+        case 'INT':
+        case 'INTEGER':
+        case 'BIGINT':
+        case 'TINYINT':
+        case 'MEDIUMINT':
+        case 'SMALLINT':
+
+            if (!empty($fieldobj->primary_key)) return 'R';
+            else return 'I';
+
+        default: return 'N';
+        }
+    }
 
 }
 }
diff --git a/lib/WikiDB/adodb/drivers/adodb-mysqli.inc.php b/lib/WikiDB/adodb/drivers/adodb-mysqli.inc.php
index ca6f2514c..385e782d2 100644
--- a/lib/WikiDB/adodb/drivers/adodb-mysqli.inc.php
+++ b/lib/WikiDB/adodb/drivers/adodb-mysqli.inc.php
@@ -16,809 +16,809 @@ if (! defined("_ADODB_MYSQL_LAYER")) {
  define("_ADODB_MYSQL_LAYER", 1 );
 
 class ADODB_mysqli extends ADOConnection {
-	var $databaseType = 'mysqli';
-	var $dataProvider = 'native';
-	var $hasInsertID = true;
-	var $hasAffectedRows = true;
-	var $metaTablesSQL = "SHOW TABLES";
-	var $metaColumnsSQL = "SHOW COLUMNS FROM %s";
-	var $fmtTimeStamp = "'Y-m-d H:i:s'";
-	var $hasLimit = true;
-	var $hasMoveFirst = true;
-	var $hasGenID = true;
-	var $upperCase = 'upper';
-	var $isoDates = true; // accepts dates in ISO format
-	var $sysDate = 'CURDATE()';
-	var $sysTimeStamp = 'NOW()';
-	var $hasTransactions = false;
-	var $forceNewConnect = false;
-	var $poorAffectedRows = true;
-	var $clientFlags = 0;
-	var $executeOnly = true;
-	var $substr = "substring";
-	var $nameQuote = '`';		/// string to use to quote identifiers and names
-	//var $_bindInputArray = true;
-
-	function ADODB_mysqli()
-	{
-	  if(!extension_loaded("mysqli"))
-	    {
-	      trigger_error("You must have the MySQLi extension.", E_USER_ERROR);
-	    }
-	}
-
-	function IfNull( $field, $ifNull )
-	{
-		return " IFNULL($field, $ifNull) "; // if MySQL
-	}
-
-	function ServerInfo()
-	{
-		$arr['description'] = $this->GetOne("select version()");
-		$arr['version'] = ADOConnection::_findvers($arr['description']);
-		return $arr;
-	}
-
-
-	function BeginTrans()
-	{
-		if ($this->transOff) return true;
-		$this->transCnt += 1;
-		$this->Execute('SET AUTOCOMMIT=0');
-		$this->Execute('BEGIN');
-		return true;
-	}
-
-	function CommitTrans($ok=true)
-	{
-		if ($this->transOff) return true;
-		if (!$ok) return $this->RollbackTrans();
-
-		if ($this->transCnt) $this->transCnt -= 1;
-		$this->Execute('COMMIT');
-		$this->Execute('SET AUTOCOMMIT=1');
-		return true;
-	}
-
-	function RollbackTrans()
-	{
-		if ($this->transOff) return true;
-		if ($this->transCnt) $this->transCnt -= 1;
-		$this->Execute('ROLLBACK');
-		$this->Execute('SET AUTOCOMMIT=1');
-		return true;
-	}
-
-	// if magic quotes disabled, use mysql_real_escape_string()
-	// From readme.htm:
-	// Quotes a string to be sent to the database. The $magic_quotes_enabled
-	// parameter may look funny, but the idea is if you are quoting a
-	// string extracted from a POST/GET variable, then
-	// pass get_magic_quotes_gpc() as the second parameter. This will
-	// ensure that the variable is not quoted twice, once by qstr and once
-	// by the magic_quotes_gpc.
-	//
-	//Eg. $s = $db->qstr(HTTP_GET_VARS['name'],get_magic_quotes_gpc());
-	function qstr($s, $magic_quotes = false)
-	{
-	  if (!$magic_quotes) {
-	    if (ADODB_PHPVER >= 0x5000) {
-	    //  $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID);
-	      return "'" . mysqli_real_escape_string($this->_connectionID, $s) . "'";
-	    }
-	    else
-	      {
-		trigger_error("phpver < 5 not implemented", E_USER_ERROR);
-	      }
-
-	    if ($this->replaceQuote[0] == '\\')
-	      {
-		$s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
-	      }
-	    return  "'".str_replace("'",$this->replaceQuote,$s)."'";
-	  }
-	  // undo magic quotes for "
-	  $s = str_replace('\\"','"',$s);
-	  return "'$s'";
-	}
-
-	function _insertid()
-	{
+    var $databaseType = 'mysqli';
+    var $dataProvider = 'native';
+    var $hasInsertID = true;
+    var $hasAffectedRows = true;
+    var $metaTablesSQL = "SHOW TABLES";
+    var $metaColumnsSQL = "SHOW COLUMNS FROM %s";
+    var $fmtTimeStamp = "'Y-m-d H:i:s'";
+    var $hasLimit = true;
+    var $hasMoveFirst = true;
+    var $hasGenID = true;
+    var $upperCase = 'upper';
+    var $isoDates = true; // accepts dates in ISO format
+    var $sysDate = 'CURDATE()';
+    var $sysTimeStamp = 'NOW()';
+    var $hasTransactions = false;
+    var $forceNewConnect = false;
+    var $poorAffectedRows = true;
+    var $clientFlags = 0;
+    var $executeOnly = true;
+    var $substr = "substring";
+    var $nameQuote = '`';		/// string to use to quote identifiers and names
+    //var $_bindInputArray = true;
+
+    function ADODB_mysqli()
+    {
+      if(!extension_loaded("mysqli"))
+        {
+          trigger_error("You must have the MySQLi extension.", E_USER_ERROR);
+        }
+    }
+
+    function IfNull( $field, $ifNull )
+    {
+        return " IFNULL($field, $ifNull) "; // if MySQL
+    }
+
+    function ServerInfo()
+    {
+        $arr['description'] = $this->GetOne("select version()");
+        $arr['version'] = ADOConnection::_findvers($arr['description']);
+        return $arr;
+    }
+
+
+    function BeginTrans()
+    {
+        if ($this->transOff) return true;
+        $this->transCnt += 1;
+        $this->Execute('SET AUTOCOMMIT=0');
+        $this->Execute('BEGIN');
+        return true;
+    }
+
+    function CommitTrans($ok=true)
+    {
+        if ($this->transOff) return true;
+        if (!$ok) return $this->RollbackTrans();
+
+        if ($this->transCnt) $this->transCnt -= 1;
+        $this->Execute('COMMIT');
+        $this->Execute('SET AUTOCOMMIT=1');
+        return true;
+    }
+
+    function RollbackTrans()
+    {
+        if ($this->transOff) return true;
+        if ($this->transCnt) $this->transCnt -= 1;
+        $this->Execute('ROLLBACK');
+        $this->Execute('SET AUTOCOMMIT=1');
+        return true;
+    }
+
+    // if magic quotes disabled, use mysql_real_escape_string()
+    // From readme.htm:
+    // Quotes a string to be sent to the database. The $magic_quotes_enabled
+    // parameter may look funny, but the idea is if you are quoting a
+    // string extracted from a POST/GET variable, then
+    // pass get_magic_quotes_gpc() as the second parameter. This will
+    // ensure that the variable is not quoted twice, once by qstr and once
+    // by the magic_quotes_gpc.
+    //
+    //Eg. $s = $db->qstr(HTTP_GET_VARS['name'],get_magic_quotes_gpc());
+    function qstr($s, $magic_quotes = false)
+    {
+      if (!$magic_quotes) {
+        if (ADODB_PHPVER >= 0x5000) {
+        //  $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID);
+          return "'" . mysqli_real_escape_string($this->_connectionID, $s) . "'";
+        }
+        else
+          {
+        trigger_error("phpver < 5 not implemented", E_USER_ERROR);
+          }
+
+        if ($this->replaceQuote[0] == '\\')
+          {
+        $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
+          }
+        return  "'".str_replace("'",$this->replaceQuote,$s)."'";
+      }
+      // undo magic quotes for "
+      $s = str_replace('\\"','"',$s);
+      return "'$s'";
+    }
+
+    function _insertid()
+    {
 //	  $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID);
-	  $result = @mysqli_insert_id($this->_connectionID);
-	  if ($result == -1){
-	      if ($this->debug) ADOConnection::outp("mysqli_insert_id() failed : "  . $this->ErrorMsg());
-	  }
-	  return $result;
-	}
-
-	// Only works for INSERT, UPDATE and DELETE query's
-	function _affectedrows()
-	{
-	//  $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID);
-	  $result =  @mysqli_affected_rows($this->_connectionID);
-	  if ($result == -1) {
-	      if ($this->debug) ADOConnection::outp("mysqli_affected_rows() failed : "  . $this->ErrorMsg());
-	  }
-	  return $result;
-	}
-
- 	// See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html
-	// Reference on Last_Insert_ID on the recommended way to simulate sequences
- 	var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
-	var $_genSeqSQL = "create table %s (id int not null)";
-	var $_genSeq2SQL = "insert into %s values (%s)";
-	var $_dropSeqSQL = "drop table %s";
-
-	function CreateSequence($seqname='adodbseq',$startID=1)
-	{
-		if (empty($this->_genSeqSQL)) return false;
-		$u = strtoupper($seqname);
-
-		$ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname));
-		if (!$ok) return false;
-		return $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
-	}
-
-	function GenID($seqname='adodbseq',$startID=1)
-	{
-		// post-nuke sets hasGenID to false
-		if (!$this->hasGenID) return false;
-
-		$getnext = sprintf($this->_genIDSQL,$seqname);
-		$holdtransOK = $this->_transOK; // save the current status
-		$rs = @$this->Execute($getnext);
-		if (!$rs) {
-			if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset
-			$u = strtoupper($seqname);
-			$this->Execute(sprintf($this->_genSeqSQL,$seqname));
-			$this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
-			$rs = $this->Execute($getnext);
-		}
-		$this->genID = mysqli_insert_id($this->_connectionID);
-
-		if ($rs) $rs->Close();
-
-		return $this->genID;
-	}
-
-  	function &MetaDatabases()
-	  {
-	    $query = "SHOW DATABASES";
-	    $ret =& $this->Execute($query);
-		return $ret;
-	  }
-
-
-	function &MetaIndexes ($table, $primary = FALSE)
-	{
-	        // save old fetch mode
-	        global $ADODB_FETCH_MODE;
-
-	        $save = $ADODB_FETCH_MODE;
-	        $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
-	        if ($this->fetchMode !== FALSE) {
-	               $savem = $this->SetFetchMode(FALSE);
-	        }
-
-	        // get index details
-	        $rs = $this->Execute(sprintf('SHOW INDEXES FROM %s',$table));
-
-	        // restore fetchmode
-	        if (isset($savem)) {
-	                $this->SetFetchMode($savem);
-	        }
-	        $ADODB_FETCH_MODE = $save;
-
-	        if (!is_object($rs)) {
-	                return FALSE;
-	        }
-
-	        $indexes = array ();
-
-	        // parse index data into array
-	        while ($row = $rs->FetchRow()) {
-	                if ($primary == FALSE AND $row[2] == 'PRIMARY') {
-	                        continue;
-	                }
-
-	                if (!isset($indexes[$row[2]])) {
-	                        $indexes[$row[2]] = array(
-	                                'unique' => ($row[1] == 0),
-	                                'columns' => array()
-	                        );
-	                }
-
-	                $indexes[$row[2]]['columns'][$row[3] - 1] = $row[4];
-	        }
-
-	        // sort columns by order in the index
-	        foreach ( array_keys ($indexes) as $index )
-	        {
-	                ksort ($indexes[$index]['columns']);
-	        }
-
-	        return $indexes;
-	}
-
-
-	// Format date column in sql string given an input format that understands Y M D
-	function SQLDate($fmt, $col=false)
-	{
-		if (!$col) $col = $this->sysTimeStamp;
-		$s = 'DATE_FORMAT('.$col.",'";
-		$concat = false;
-		$len = strlen($fmt);
-		for ($i=0; $i < $len; $i++) {
-			$ch = $fmt[$i];
-			switch($ch) {
-			case 'Y':
-			case 'y':
-				$s .= '%Y';
-				break;
-			case 'Q':
-			case 'q':
-				$s .= "'),Quarter($col)";
-
-				if ($len > $i+1) $s .= ",DATE_FORMAT($col,'";
-				else $s .= ",('";
-				$concat = true;
-				break;
-			case 'M':
-				$s .= '%b';
-				break;
-
-			case 'm':
-				$s .= '%m';
-				break;
-			case 'D':
-			case 'd':
-				$s .= '%d';
-				break;
-
-			case 'H':
-				$s .= '%H';
-				break;
-
-			case 'h':
-				$s .= '%I';
-				break;
-
-			case 'i':
-				$s .= '%i';
-				break;
-
-			case 's':
-				$s .= '%s';
-				break;
-
-			case 'a':
-			case 'A':
-				$s .= '%p';
-				break;
-
-			default:
-
-				if ($ch == '\\') {
-					$i++;
-					$ch = substr($fmt,$i,1);
-				}
-				$s .= $ch;
-				break;
-			}
-		}
-		$s.="')";
-		if ($concat) $s = "CONCAT($s)";
-		return $s;
-	}
-
-	// returns concatenated string
-	// much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator
-	function Concat()
-	{
-		$s = "";
-		$arr = func_get_args();
-
-		// suggestion by andrew005@mnogo.ru
-		$s = implode(',',$arr);
-		if (strlen($s) > 0) return "CONCAT($s)";
-		else return '';
-	}
-
-	// dayFraction is a day in floating point
-	function OffsetDate($dayFraction,$date=false)
-	{
-		if (!$date)
-		  $date = $this->sysDate;
-		return "from_unixtime(unix_timestamp($date)+($dayFraction)*24*3600)";
-	}
-
-	// returns true or false
-	// To add: parameter int $port,
-	//         parameter string $socket
-	function _connect($argHostname = NULL,
-			  $argUsername = NULL,
-			  $argPassword = NULL,
-			  $argDatabasename = NULL)
-	  {
-	    // @ means: error surpression on
-	    $this->_connectionID = @mysqli_init();
-
-	    if (is_null($this->_connectionID))
-	    {
-	      // mysqli_init only fails if insufficient memory
-	      if ($this->debug)
-		ADOConnection::outp("mysqli_init() failed : "  . $this->ErrorMsg());
-	      return false;
-	    }
-	    // Set connection options
-	    // Not implemented now
-	    // mysqli_options($this->_connection,,);
- 	    if (mysqli_real_connect($this->_connectionID,
- 				    $argHostname,
- 				    $argUsername,
- 				    $argPassword,
- 				    $argDatabasename))
- 	      {
- 		if ($argDatabasename)
-		  {
-		    return $this->SelectDB($argDatabasename);
-		  }
-
- 		return true;
- 	      }
- 	    else
-	      {
-		if ($this->debug)
-		  ADOConnection::outp("Could't connect : "  . $this->ErrorMsg());
-		return false;
-	      }
-	  }
-
-	// returns true or false
-	// How to force a persistent connection
-	function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
-	  {
-	    // not implemented in mysqli (yet)?
-	    $this->_connectionID = mysqli_connect($argHostname,
-						  $argUsername,
-						  $argPassword,
-						  $argDatabasename);
-	    if ($this->_connectionID === false) return false;
-	    //	    if ($this->autoRollback) $this->RollbackTrans();
-	    if ($argDatabasename) return $this->SelectDB($argDatabasename);
-	    return true;
-	  }
-
-	// When is this used? Close old connection first?
-	// In _connect(), check $this->forceNewConnect?
-	function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
-	  {
-	    $this->forceNewConnect = true;
-	    $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);
-	  }
-
- 	function &MetaColumns($table)
-	{
-	  if ($this->metaColumnsSQL) {
-	    global $ADODB_FETCH_MODE;
-	    $save = $ADODB_FETCH_MODE;
-	    $rs = false;
-	    switch($ADODB_FETCH_MODE)
-	      {
-	      case ADODB_FETCH_NUM:
-		$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
-		$rs = $this->Execute(sprintf($this->metaColumnsSQL,
-					     $table));
-
-		$ADODB_FETCH_MODE = $save;
-		if ($rs === false) break;
-		$retarr = array();
-		while (!$rs->EOF){
-		  $fld = new ADOFieldObject();
-		  $fld->name = $rs->fields[0];
-		  $fld->type = $rs->fields[1];
-		  // split type into type(length):
-		  if (preg_match("/^(.+)\((\d+)\)$/", $fld->type, $query_array))
-		    {
-		      $fld->type = $query_array[1];
-		      $fld->max_length = $query_array[2];
-		    }
-		  else
-		    {
-		      $fld->max_length = -1;
-		    }
-		  $fld->not_null = ($rs->fields[2] != 'YES');
-		  $fld->primary_key = ($rs->fields[3] == 'PRI');
-		  $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
-		  $fld->binary = (strpos($fld->type,'blob') !== false);
-		  if (!$fld->binary)
-		    {
-		      $d = $rs->fields[4];
-		      $d = $rs->fields['Default'];
-		      if ($d != "" && $d != "NULL")
-			{
-			  $fld->has_default = true;
-			  $fld->default_value = $d;
-			}
-		      else
-			{
-			  $fld->has_default = false;
-			}
-		    }
-		  $retarr[strtoupper($fld->name)] = $fld;
-		  $rs->MoveNext();
-		}
-		break;
-	      case ADODB_FETCH_ASSOC:
-	      case ADODB_FETCH_DEFAULT:
-	      case ADODB_FETCH_BOTH:
-		$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
-		$rs = $this->Execute(sprintf($this->metaColumnsSQL,
-					     $table));
-		$ADODB_FETCH_MODE = $save;
-		if ($rs === false) break;
-		$retarr = array();
-		while (!$rs->EOF){
-		  $fld = new ADOFieldObject();
-		  $fld->name = $rs->fields['Field'];
-		  $fld->type = $rs->fields['Type'];
-
-		  // split type into type(length):
-		  if (preg_match("/^(.+)\((\d+)\)$/", $fld->type, $query_array))
-		    {
-		      $fld->type = $query_array[1];
-		      $fld->max_length = $query_array[2];
-		    }
-		  else
-		    {
-		      $fld->max_length = -1;
-		    }
-		  $fld->not_null = ($rs->fields['Null'] != 'YES');
-		  $fld->primary_key = ($rs->fields['Key'] == 'PRI');
-		  $fld->auto_increment = (strpos($rs->fields['Extra'], 'auto_increment') !== false);
-		  $fld->binary = (strpos($fld->type,'blob') !== false);
-		  if (!$fld->binary)
-		    {
-		      $d = $rs->fields['Default'];
-		      if ($d != "" && $d != "NULL")
-			{
-			  $fld->has_default = true;
-			  $fld->default_value = $d;
-			}
-		      else
-			{
-			  $fld->has_default = false;
-			}
-		    }
-		  $retarr[strtoupper($fld->name)] = $fld;
-		  $rs->MoveNext();
-		}
-		break;
-	      default:
-	      }
-
-	    if ($rs === false) return false;
-	    $rs->Close();
-	    return $retarr;
-	  }
-	  return false;
-	}
-
-	// returns true or false
-	function SelectDB($dbName)
-	{
+      $result = @mysqli_insert_id($this->_connectionID);
+      if ($result == -1){
+          if ($this->debug) ADOConnection::outp("mysqli_insert_id() failed : "  . $this->ErrorMsg());
+      }
+      return $result;
+    }
+
+    // Only works for INSERT, UPDATE and DELETE query's
+    function _affectedrows()
+    {
+    //  $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID);
+      $result =  @mysqli_affected_rows($this->_connectionID);
+      if ($result == -1) {
+          if ($this->debug) ADOConnection::outp("mysqli_affected_rows() failed : "  . $this->ErrorMsg());
+      }
+      return $result;
+    }
+
+     // See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html
+    // Reference on Last_Insert_ID on the recommended way to simulate sequences
+     var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
+    var $_genSeqSQL = "create table %s (id int not null)";
+    var $_genSeq2SQL = "insert into %s values (%s)";
+    var $_dropSeqSQL = "drop table %s";
+
+    function CreateSequence($seqname='adodbseq',$startID=1)
+    {
+        if (empty($this->_genSeqSQL)) return false;
+        $u = strtoupper($seqname);
+
+        $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname));
+        if (!$ok) return false;
+        return $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
+    }
+
+    function GenID($seqname='adodbseq',$startID=1)
+    {
+        // post-nuke sets hasGenID to false
+        if (!$this->hasGenID) return false;
+
+        $getnext = sprintf($this->_genIDSQL,$seqname);
+        $holdtransOK = $this->_transOK; // save the current status
+        $rs = @$this->Execute($getnext);
+        if (!$rs) {
+            if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset
+            $u = strtoupper($seqname);
+            $this->Execute(sprintf($this->_genSeqSQL,$seqname));
+            $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
+            $rs = $this->Execute($getnext);
+        }
+        $this->genID = mysqli_insert_id($this->_connectionID);
+
+        if ($rs) $rs->Close();
+
+        return $this->genID;
+    }
+
+      function &MetaDatabases()
+      {
+        $query = "SHOW DATABASES";
+        $ret =& $this->Execute($query);
+        return $ret;
+      }
+
+
+    function &MetaIndexes ($table, $primary = FALSE)
+    {
+            // save old fetch mode
+            global $ADODB_FETCH_MODE;
+
+            $save = $ADODB_FETCH_MODE;
+            $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
+            if ($this->fetchMode !== FALSE) {
+                   $savem = $this->SetFetchMode(FALSE);
+            }
+
+            // get index details
+            $rs = $this->Execute(sprintf('SHOW INDEXES FROM %s',$table));
+
+            // restore fetchmode
+            if (isset($savem)) {
+                    $this->SetFetchMode($savem);
+            }
+            $ADODB_FETCH_MODE = $save;
+
+            if (!is_object($rs)) {
+                    return FALSE;
+            }
+
+            $indexes = array ();
+
+            // parse index data into array
+            while ($row = $rs->FetchRow()) {
+                    if ($primary == FALSE AND $row[2] == 'PRIMARY') {
+                            continue;
+                    }
+
+                    if (!isset($indexes[$row[2]])) {
+                            $indexes[$row[2]] = array(
+                                    'unique' => ($row[1] == 0),
+                                    'columns' => array()
+                            );
+                    }
+
+                    $indexes[$row[2]]['columns'][$row[3] - 1] = $row[4];
+            }
+
+            // sort columns by order in the index
+            foreach ( array_keys ($indexes) as $index )
+            {
+                    ksort ($indexes[$index]['columns']);
+            }
+
+            return $indexes;
+    }
+
+
+    // Format date column in sql string given an input format that understands Y M D
+    function SQLDate($fmt, $col=false)
+    {
+        if (!$col) $col = $this->sysTimeStamp;
+        $s = 'DATE_FORMAT('.$col.",'";
+        $concat = false;
+        $len = strlen($fmt);
+        for ($i=0; $i < $len; $i++) {
+            $ch = $fmt[$i];
+            switch($ch) {
+            case 'Y':
+            case 'y':
+                $s .= '%Y';
+                break;
+            case 'Q':
+            case 'q':
+                $s .= "'),Quarter($col)";
+
+                if ($len > $i+1) $s .= ",DATE_FORMAT($col,'";
+                else $s .= ",('";
+                $concat = true;
+                break;
+            case 'M':
+                $s .= '%b';
+                break;
+
+            case 'm':
+                $s .= '%m';
+                break;
+            case 'D':
+            case 'd':
+                $s .= '%d';
+                break;
+
+            case 'H':
+                $s .= '%H';
+                break;
+
+            case 'h':
+                $s .= '%I';
+                break;
+
+            case 'i':
+                $s .= '%i';
+                break;
+
+            case 's':
+                $s .= '%s';
+                break;
+
+            case 'a':
+            case 'A':
+                $s .= '%p';
+                break;
+
+            default:
+
+                if ($ch == '\\') {
+                    $i++;
+                    $ch = substr($fmt,$i,1);
+                }
+                $s .= $ch;
+                break;
+            }
+        }
+        $s.="')";
+        if ($concat) $s = "CONCAT($s)";
+        return $s;
+    }
+
+    // returns concatenated string
+    // much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator
+    function Concat()
+    {
+        $s = "";
+        $arr = func_get_args();
+
+        // suggestion by andrew005@mnogo.ru
+        $s = implode(',',$arr);
+        if (strlen($s) > 0) return "CONCAT($s)";
+        else return '';
+    }
+
+    // dayFraction is a day in floating point
+    function OffsetDate($dayFraction,$date=false)
+    {
+        if (!$date)
+          $date = $this->sysDate;
+        return "from_unixtime(unix_timestamp($date)+($dayFraction)*24*3600)";
+    }
+
+    // returns true or false
+    // To add: parameter int $port,
+    //         parameter string $socket
+    function _connect($argHostname = NULL,
+              $argUsername = NULL,
+              $argPassword = NULL,
+              $argDatabasename = NULL)
+      {
+        // @ means: error surpression on
+        $this->_connectionID = @mysqli_init();
+
+        if (is_null($this->_connectionID))
+        {
+          // mysqli_init only fails if insufficient memory
+          if ($this->debug)
+        ADOConnection::outp("mysqli_init() failed : "  . $this->ErrorMsg());
+          return false;
+        }
+        // Set connection options
+        // Not implemented now
+        // mysqli_options($this->_connection,,);
+         if (mysqli_real_connect($this->_connectionID,
+                     $argHostname,
+                     $argUsername,
+                     $argPassword,
+                     $argDatabasename))
+           {
+         if ($argDatabasename)
+          {
+            return $this->SelectDB($argDatabasename);
+          }
+
+         return true;
+           }
+         else
+          {
+        if ($this->debug)
+          ADOConnection::outp("Could't connect : "  . $this->ErrorMsg());
+        return false;
+          }
+      }
+
+    // returns true or false
+    // How to force a persistent connection
+    function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
+      {
+        // not implemented in mysqli (yet)?
+        $this->_connectionID = mysqli_connect($argHostname,
+                          $argUsername,
+                          $argPassword,
+                          $argDatabasename);
+        if ($this->_connectionID === false) return false;
+        //	    if ($this->autoRollback) $this->RollbackTrans();
+        if ($argDatabasename) return $this->SelectDB($argDatabasename);
+        return true;
+      }
+
+    // When is this used? Close old connection first?
+    // In _connect(), check $this->forceNewConnect?
+    function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
+      {
+        $this->forceNewConnect = true;
+        $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);
+      }
+
+     function &MetaColumns($table)
+    {
+      if ($this->metaColumnsSQL) {
+        global $ADODB_FETCH_MODE;
+        $save = $ADODB_FETCH_MODE;
+        $rs = false;
+        switch($ADODB_FETCH_MODE)
+          {
+          case ADODB_FETCH_NUM:
+        $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
+        $rs = $this->Execute(sprintf($this->metaColumnsSQL,
+                         $table));
+
+        $ADODB_FETCH_MODE = $save;
+        if ($rs === false) break;
+        $retarr = array();
+        while (!$rs->EOF){
+          $fld = new ADOFieldObject();
+          $fld->name = $rs->fields[0];
+          $fld->type = $rs->fields[1];
+          // split type into type(length):
+          if (preg_match("/^(.+)\((\d+)\)$/", $fld->type, $query_array))
+            {
+              $fld->type = $query_array[1];
+              $fld->max_length = $query_array[2];
+            }
+          else
+            {
+              $fld->max_length = -1;
+            }
+          $fld->not_null = ($rs->fields[2] != 'YES');
+          $fld->primary_key = ($rs->fields[3] == 'PRI');
+          $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
+          $fld->binary = (strpos($fld->type,'blob') !== false);
+          if (!$fld->binary)
+            {
+              $d = $rs->fields[4];
+              $d = $rs->fields['Default'];
+              if ($d != "" && $d != "NULL")
+            {
+              $fld->has_default = true;
+              $fld->default_value = $d;
+            }
+              else
+            {
+              $fld->has_default = false;
+            }
+            }
+          $retarr[strtoupper($fld->name)] = $fld;
+          $rs->MoveNext();
+        }
+        break;
+          case ADODB_FETCH_ASSOC:
+          case ADODB_FETCH_DEFAULT:
+          case ADODB_FETCH_BOTH:
+        $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
+        $rs = $this->Execute(sprintf($this->metaColumnsSQL,
+                         $table));
+        $ADODB_FETCH_MODE = $save;
+        if ($rs === false) break;
+        $retarr = array();
+        while (!$rs->EOF){
+          $fld = new ADOFieldObject();
+          $fld->name = $rs->fields['Field'];
+          $fld->type = $rs->fields['Type'];
+
+          // split type into type(length):
+          if (preg_match("/^(.+)\((\d+)\)$/", $fld->type, $query_array))
+            {
+              $fld->type = $query_array[1];
+              $fld->max_length = $query_array[2];
+            }
+          else
+            {
+              $fld->max_length = -1;
+            }
+          $fld->not_null = ($rs->fields['Null'] != 'YES');
+          $fld->primary_key = ($rs->fields['Key'] == 'PRI');
+          $fld->auto_increment = (strpos($rs->fields['Extra'], 'auto_increment') !== false);
+          $fld->binary = (strpos($fld->type,'blob') !== false);
+          if (!$fld->binary)
+            {
+              $d = $rs->fields['Default'];
+              if ($d != "" && $d != "NULL")
+            {
+              $fld->has_default = true;
+              $fld->default_value = $d;
+            }
+              else
+            {
+              $fld->has_default = false;
+            }
+            }
+          $retarr[strtoupper($fld->name)] = $fld;
+          $rs->MoveNext();
+        }
+        break;
+          default:
+          }
+
+        if ($rs === false) return false;
+        $rs->Close();
+        return $retarr;
+      }
+      return false;
+    }
+
+    // returns true or false
+    function SelectDB($dbName)
+    {
 //	    $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID);
-	    $this->databaseName = $dbName;
-	    if ($this->_connectionID) {
-        	$result = @mysqli_select_db($this->_connectionID, $dbName);
-			if (!$result) {
-		    	ADOConnection::outp("Select of database " . $dbName . " failed. " . $this->ErrorMsg());
-			}
-			return $result;
-		}
-	    return false;
-	}
-
-	// parameters use PostgreSQL convention, not MySQL
-	function &SelectLimit($sql,
-			      $nrows = -1,
-			      $offset = -1,
-			      $inputarr = false,
-			      $arg3 = false,
-			      $secs = 0)
-	{
-		$offsetStr = ($offset >= 0) ? "$offset," : '';
-
-		if ($secs)
-			$rs =& $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3);
-		else
-			$rs =& $this->Execute($sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3);
-
-		return $rs;
-	}
-
-
-	function Prepare($sql)
-	{
-		return $sql;
-
-		$stmt = mysqli_prepare($this->_connectionID,$sql);
-		if (!$stmt) return false;
-		return array($sql,$stmt);
-	}
-
-
-	// returns queryID or false
-	function _query($sql, $inputarr)
-	{
-	global $ADODB_COUNTRECS;
-
-		if (is_array($sql)) {
-			$stmt = $sql[1];
-			foreach($inputarr as $k => $v) {
-				if (is_string($v)) $a[] = MYSQLI_BIND_STRING;
-				else if (is_integer($v)) $a[] = MYSQLI_BIND_INT;
-				else $a[] = MYSQLI_BIND_DOUBLE;
-
-				$fnarr =& array_merge( array($stmt,$a) , $inputarr);
-				$ret = call_user_func_array('mysqli_bind_param',$fnarr);
-			}
-			$ret = mysqli_execute($stmt);
-			return $ret;
-		}
-		if (!$mysql_res =  mysqli_query($this->_connectionID, $sql, ($ADODB_COUNTRECS) ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT)) {
-		    if ($this->debug) ADOConnection::outp("Query: " . $sql . " failed. " . $this->ErrorMsg());
-		    return false;
-		}
-
-		return $mysql_res;
-	}
-
-	/*	Returns: the last error message from previous database operation	*/
-	function ErrorMsg()
-	  {
-	    if (empty($this->_connectionID))
-	      $this->_errorMsg = @mysqli_error();
-	    else
-	      $this->_errorMsg = @mysqli_error($this->_connectionID);
-	    return $this->_errorMsg;
-	  }
-
-	/*	Returns: the last error number from previous database operation	*/
-	function ErrorNo()
-	  {
-	    if (empty($this->_connectionID))
-	      return @mysqli_errno();
-	    else
-	      return @mysqli_errno($this->_connectionID);
-	  }
-
-	// returns true or false
-	function _close()
-	  {
-	    @mysqli_close($this->_connectionID);
-	    $this->_connectionID = false;
-	  }
-
-	/*
-	* Maximum size of C field
-	*/
-	function CharMax()
-	{
-		return 255;
-	}
-
-	/*
-	* Maximum size of X field
-	*/
-	function TextMax()
-	{
-	  return 4294967295;
-	}
+        $this->databaseName = $dbName;
+        if ($this->_connectionID) {
+            $result = @mysqli_select_db($this->_connectionID, $dbName);
+            if (!$result) {
+                ADOConnection::outp("Select of database " . $dbName . " failed. " . $this->ErrorMsg());
+            }
+            return $result;
+        }
+        return false;
+    }
+
+    // parameters use PostgreSQL convention, not MySQL
+    function &SelectLimit($sql,
+                  $nrows = -1,
+                  $offset = -1,
+                  $inputarr = false,
+                  $arg3 = false,
+                  $secs = 0)
+    {
+        $offsetStr = ($offset >= 0) ? "$offset," : '';
+
+        if ($secs)
+            $rs =& $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3);
+        else
+            $rs =& $this->Execute($sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3);
+
+        return $rs;
+    }
+
+
+    function Prepare($sql)
+    {
+        return $sql;
+
+        $stmt = mysqli_prepare($this->_connectionID,$sql);
+        if (!$stmt) return false;
+        return array($sql,$stmt);
+    }
+
+
+    // returns queryID or false
+    function _query($sql, $inputarr)
+    {
+    global $ADODB_COUNTRECS;
+
+        if (is_array($sql)) {
+            $stmt = $sql[1];
+            foreach($inputarr as $k => $v) {
+                if (is_string($v)) $a[] = MYSQLI_BIND_STRING;
+                else if (is_integer($v)) $a[] = MYSQLI_BIND_INT;
+                else $a[] = MYSQLI_BIND_DOUBLE;
+
+                $fnarr =& array_merge( array($stmt,$a) , $inputarr);
+                $ret = call_user_func_array('mysqli_bind_param',$fnarr);
+            }
+            $ret = mysqli_execute($stmt);
+            return $ret;
+        }
+        if (!$mysql_res =  mysqli_query($this->_connectionID, $sql, ($ADODB_COUNTRECS) ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT)) {
+            if ($this->debug) ADOConnection::outp("Query: " . $sql . " failed. " . $this->ErrorMsg());
+            return false;
+        }
+
+        return $mysql_res;
+    }
+
+    /*	Returns: the last error message from previous database operation	*/
+    function ErrorMsg()
+      {
+        if (empty($this->_connectionID))
+          $this->_errorMsg = @mysqli_error();
+        else
+          $this->_errorMsg = @mysqli_error($this->_connectionID);
+        return $this->_errorMsg;
+      }
+
+    /*	Returns: the last error number from previous database operation	*/
+    function ErrorNo()
+      {
+        if (empty($this->_connectionID))
+          return @mysqli_errno();
+        else
+          return @mysqli_errno($this->_connectionID);
+      }
+
+    // returns true or false
+    function _close()
+      {
+        @mysqli_close($this->_connectionID);
+        $this->_connectionID = false;
+      }
+
+    /*
+    * Maximum size of C field
+    */
+    function CharMax()
+    {
+        return 255;
+    }
+
+    /*
+    * Maximum size of X field
+    */
+    function TextMax()
+    {
+      return 4294967295;
+    }
 
 
 }
 
 /*--------------------------------------------------------------------------------------
-	 Class Name: Recordset
+     Class Name: Recordset
 --------------------------------------------------------------------------------------*/
 
 class ADORecordSet_mysqli extends ADORecordSet{
 
-	var $databaseType = "mysqli";
-	var $canSeek = true;
-
-	function ADORecordSet_mysqli($queryID, $mode = false)
-	{
-	  if ($mode === false)
-	    {
-	      global $ADODB_FETCH_MODE;
-	      $mode = $ADODB_FETCH_MODE;
-	    }
-	  switch ($mode)
-	    {
-	    case ADODB_FETCH_NUM:
-	      $this->fetchMode = MYSQLI_NUM;
-	      break;
-	    case ADODB_FETCH_ASSOC:
-	      $this->fetchMode = MYSQLI_ASSOC;
-	      break;
-	    case ADODB_FETCH_DEFAULT:
-	    case ADODB_FETCH_BOTH:
-	    default:
-	      $this->fetchMode = MYSQLI_ASSOC;
-	      break;
-	    }
-	  $this->ADORecordSet($queryID);
-	}
-
-	function _initrs()
-	{
-	    // mysqli_num_rows only return correct number, depens
-	    // on the use of mysql_store_result and mysql_use_result
-	    if (!$this->Connection->executeOnly) {
-			$this->_numOfRows = @mysqli_num_rows($this->_queryID);
-			$this->_numOfFields = @mysqli_num_fields($this->_queryID);
-	    }
-	    else {
-			$this->_numOfRows = 0;
-			$this->_numOfFields = 0;
-	    }
-	}
-
-	function &FetchField($fieldOffset = -1)
-	{
-	  $fieldnr = $fieldOffset;
-	  if ($fieldOffset != -1) {
-	    $fieldOffset = mysqi_field_seek($this->_queryID, $fieldnr);
-	  }
-	  $o = mysqli_fetch_field($this->_queryID);
-	  return $o;
-	}
-
-	function &GetRowAssoc($upper = true)
-	{
-	  if ($this->fetchMode == MYSQLI_ASSOC && !$upper)
-	    return $this->fields;
-	  $row =& ADORecordSet::GetRowAssoc($upper);
-	  return $row;
-	}
-
-	/* Use associative array to get fields array */
-	function Fields($colname)
-	{
-	  if ($this->fetchMode != MYSQLI_NUM)
-	    return @$this->fields[$colname];
-
-	  if (!$this->bind) {
-	    $this->bind = array();
-	    for ($i = 0; $i < $this->_numOfFields; $i++) {
-	      $o = $this->FetchField($i);
-	      $this->bind[strtoupper($o->name)] = $i;
-	    }
-	  }
-	  return $this->fields[$this->bind[strtoupper($colname)]];
-	}
-
-	function _seek($row)
-	{
-	  if ($this->_numOfRows == 0)
-	    return false;
-
-	  if ($row < 0)
-	    return false;
-
-	  mysqli_data_seek($this->_queryID, $row);
-	  $this->EOF = false;
-	  return true;
-	}
-
-	// 10% speedup to move MoveNext to child class
-	// This is the only implementation that works now (23-10-2003).
-	// Other functions return no or the wrong results.
-	function MoveNext()
-	{
-	  if ($this->EOF)
-	    return false;
-	  $this->_currentRow++;
-	  switch($this->fetchMode)
-	    {
-	    case MYSQLI_NUM:
-	      $this->fields = mysqli_fetch_array($this->_queryID);
-	      break;
-	    case MYSQLI_ASSOC:
-	    case MYSQLI_BOTH:
-	      $this->fields = mysqli_fetch_assoc($this->_queryID);
-	      break;
-	    default:
-	    }
-	  if (is_array($this->fields))
-	    return true;
-	  $this->EOF = true;
-	  return false;
-	}
-
-	function _fetch()
-	{
-	  // mysqli_fetch_array($this->_queryID, MYSQLI_NUM) does not
-	  // work (22-10-2003). But mysqli_fetch_array($this->_queryID) gives
-	  // int resulttype should default to MYSQLI_BOTH,but give MYSQLI_NUM.
-
-	  //	  $this->fields =  mysqli_fetch_fields($this->_queryID);
-	  //	  $this->fields =  mysqli_fetch_array($this->_queryID); //, $this->fetchMode);
-
-	  $this->fields =  mysqli_fetch_assoc($this->_queryID); // $this->fetchMode);
-	  return is_array($this->fields);
-	}
-
-	function _close()
-	{
-	  mysqli_free_result($this->_queryID);
-	  $this->_queryID = false;
-	}
-
-	function MetaType($t, $len = -1, $fieldobj = false)
-	{
-	  if (is_object($t))
-	    {
-	      $fieldobj = $t;
-	      $t = $fieldobj->type;
-	      $len = $fieldobj->max_length;
-	    }
-
-	  $len = -1; // mysql max_length is not accurate
-	  switch (strtoupper($t)) {
-	  case 'STRING':
-	  case 'CHAR':
-	  case 'VARCHAR':
-	  case 'TINYBLOB':
-	  case 'TINYTEXT':
-	  case 'ENUM':
-	  case 'SET':
-	    if ($len <= $this->blobSize) return 'C';
-
-	  case 'TEXT':
-	  case 'LONGTEXT':
-	  case 'MEDIUMTEXT':
-	    return 'X';
-
-	    // php_mysql extension always returns 'blob' even if 'text'
-	    // so we have to check whether binary...
-	  case 'IMAGE':
-	  case 'LONGBLOB':
-	  case 'BLOB':
-	  case 'MEDIUMBLOB':
-	    return !empty($fieldobj->binary) ? 'B' : 'X';
-	  case 'YEAR':
-	  case 'DATE':
-	    return 'D';
-
-	  case 'TIME':
-	  case 'DATETIME':
-	  case 'TIMESTAMP': return 'T';
-
-	  case 'INT':
-	  case 'INTEGER':
-	  case 'BIGINT':
-	  case 'TINYINT':
-	  case 'MEDIUMINT':
-	  case 'SMALLINT':
-
-	    if (!empty($fieldobj->primary_key)) return 'R';
-	    else return 'I';
-	    // Added floating-point types
-	    // Maybe not necessery.
-	  case 'FLOAT':
-	  case 'DOUBLE':
-	    //		case 'DOUBLE PRECISION':
-	  case 'DECIMAL':
-	  case 'DEC':
-	  case 'FIXED':
-	  default:
-	    return 'N';
-	  }
-	}
+    var $databaseType = "mysqli";
+    var $canSeek = true;
+
+    function ADORecordSet_mysqli($queryID, $mode = false)
+    {
+      if ($mode === false)
+        {
+          global $ADODB_FETCH_MODE;
+          $mode = $ADODB_FETCH_MODE;
+        }
+      switch ($mode)
+        {
+        case ADODB_FETCH_NUM:
+          $this->fetchMode = MYSQLI_NUM;
+          break;
+        case ADODB_FETCH_ASSOC:
+          $this->fetchMode = MYSQLI_ASSOC;
+          break;
+        case ADODB_FETCH_DEFAULT:
+        case ADODB_FETCH_BOTH:
+        default:
+          $this->fetchMode = MYSQLI_ASSOC;
+          break;
+        }
+      $this->ADORecordSet($queryID);
+    }
+
+    function _initrs()
+    {
+        // mysqli_num_rows only return correct number, depens
+        // on the use of mysql_store_result and mysql_use_result
+        if (!$this->Connection->executeOnly) {
+            $this->_numOfRows = @mysqli_num_rows($this->_queryID);
+            $this->_numOfFields = @mysqli_num_fields($this->_queryID);
+        }
+        else {
+            $this->_numOfRows = 0;
+            $this->_numOfFields = 0;
+        }
+    }
+
+    function &FetchField($fieldOffset = -1)
+    {
+      $fieldnr = $fieldOffset;
+      if ($fieldOffset != -1) {
+        $fieldOffset = mysqi_field_seek($this->_queryID, $fieldnr);
+      }
+      $o = mysqli_fetch_field($this->_queryID);
+      return $o;
+    }
+
+    function &GetRowAssoc($upper = true)
+    {
+      if ($this->fetchMode == MYSQLI_ASSOC && !$upper)
+        return $this->fields;
+      $row =& ADORecordSet::GetRowAssoc($upper);
+      return $row;
+    }
+
+    /* Use associative array to get fields array */
+    function Fields($colname)
+    {
+      if ($this->fetchMode != MYSQLI_NUM)
+        return @$this->fields[$colname];
+
+      if (!$this->bind) {
+        $this->bind = array();
+        for ($i = 0; $i < $this->_numOfFields; $i++) {
+          $o = $this->FetchField($i);
+          $this->bind[strtoupper($o->name)] = $i;
+        }
+      }
+      return $this->fields[$this->bind[strtoupper($colname)]];
+    }
+
+    function _seek($row)
+    {
+      if ($this->_numOfRows == 0)
+        return false;
+
+      if ($row < 0)
+        return false;
+
+      mysqli_data_seek($this->_queryID, $row);
+      $this->EOF = false;
+      return true;
+    }
+
+    // 10% speedup to move MoveNext to child class
+    // This is the only implementation that works now (23-10-2003).
+    // Other functions return no or the wrong results.
+    function MoveNext()
+    {
+      if ($this->EOF)
+        return false;
+      $this->_currentRow++;
+      switch($this->fetchMode)
+        {
+        case MYSQLI_NUM:
+          $this->fields = mysqli_fetch_array($this->_queryID);
+          break;
+        case MYSQLI_ASSOC:
+        case MYSQLI_BOTH:
+          $this->fields = mysqli_fetch_assoc($this->_queryID);
+          break;
+        default:
+        }
+      if (is_array($this->fields))
+        return true;
+      $this->EOF = true;
+      return false;
+    }
+
+    function _fetch()
+    {
+      // mysqli_fetch_array($this->_queryID, MYSQLI_NUM) does not
+      // work (22-10-2003). But mysqli_fetch_array($this->_queryID) gives
+      // int resulttype should default to MYSQLI_BOTH,but give MYSQLI_NUM.
+
+      //	  $this->fields =  mysqli_fetch_fields($this->_queryID);
+      //	  $this->fields =  mysqli_fetch_array($this->_queryID); //, $this->fetchMode);
+
+      $this->fields =  mysqli_fetch_assoc($this->_queryID); // $this->fetchMode);
+      return is_array($this->fields);
+    }
+
+    function _close()
+    {
+      mysqli_free_result($this->_queryID);
+      $this->_queryID = false;
+    }
+
+    function MetaType($t, $len = -1, $fieldobj = false)
+    {
+      if (is_object($t))
+        {
+          $fieldobj = $t;
+          $t = $fieldobj->type;
+          $len = $fieldobj->max_length;
+        }
+
+      $len = -1; // mysql max_length is not accurate
+      switch (strtoupper($t)) {
+      case 'STRING':
+      case 'CHAR':
+      case 'VARCHAR':
+      case 'TINYBLOB':
+      case 'TINYTEXT':
+      case 'ENUM':
+      case 'SET':
+        if ($len <= $this->blobSize) return 'C';
+
+      case 'TEXT':
+      case 'LONGTEXT':
+      case 'MEDIUMTEXT':
+        return 'X';
+
+        // php_mysql extension always returns 'blob' even if 'text'
+        // so we have to check whether binary...
+      case 'IMAGE':
+      case 'LONGBLOB':
+      case 'BLOB':
+      case 'MEDIUMBLOB':
+        return !empty($fieldobj->binary) ? 'B' : 'X';
+      case 'YEAR':
+      case 'DATE':
+        return 'D';
+
+      case 'TIME':
+      case 'DATETIME':
+      case 'TIMESTAMP': return 'T';
+
+      case 'INT':
+      case 'INTEGER':
+      case 'BIGINT':
+      case 'TINYINT':
+      case 'MEDIUMINT':
+      case 'SMALLINT':
+
+        if (!empty($fieldobj->primary_key)) return 'R';
+        else return 'I';
+        // Added floating-point types
+        // Maybe not necessery.
+      case 'FLOAT':
+      case 'DOUBLE':
+        //		case 'DOUBLE PRECISION':
+      case 'DECIMAL':
+      case 'DEC':
+      case 'FIXED':
+      default:
+        return 'N';
+      }
+    }
 
 
 }
diff --git a/lib/WikiDB/adodb/drivers/adodb-mysqlt.inc.php b/lib/WikiDB/adodb/drivers/adodb-mysqlt.inc.php
index 3f3633cd6..288f5f69e 100644
--- a/lib/WikiDB/adodb/drivers/adodb-mysqlt.inc.php
+++ b/lib/WikiDB/adodb/drivers/adodb-mysqlt.inc.php
@@ -18,59 +18,59 @@ include_once(ADODB_DIR."/drivers/adodb-mysql.inc.php");
 
 
 class ADODB_mysqlt extends ADODB_mysql {
-	var $databaseType = 'mysqlt';
-	var $ansiOuter = true; // for Version 3.23.17 or later
-	var $hasTransactions = true;
-
-	function BeginTrans()
-	{
-		if ($this->transOff) return true;
-		$this->transCnt += 1;
-		$this->Execute('SET AUTOCOMMIT=0');
-		$this->Execute('BEGIN');
-		return true;
-	}
-
-	function CommitTrans($ok=true)
-	{
-		if ($this->transOff) return true;
-		if (!$ok) return $this->RollbackTrans();
-
-		if ($this->transCnt) $this->transCnt -= 1;
-		$this->Execute('COMMIT');
-		$this->Execute('SET AUTOCOMMIT=1');
-		return true;
-	}
-
-	function RollbackTrans()
-	{
-		if ($this->transOff) return true;
-		if ($this->transCnt) $this->transCnt -= 1;
-		$this->Execute('ROLLBACK');
-		$this->Execute('SET AUTOCOMMIT=1');
-		return true;
-	}
+    var $databaseType = 'mysqlt';
+    var $ansiOuter = true; // for Version 3.23.17 or later
+    var $hasTransactions = true;
+
+    function BeginTrans()
+    {
+        if ($this->transOff) return true;
+        $this->transCnt += 1;
+        $this->Execute('SET AUTOCOMMIT=0');
+        $this->Execute('BEGIN');
+        return true;
+    }
+
+    function CommitTrans($ok=true)
+    {
+        if ($this->transOff) return true;
+        if (!$ok) return $this->RollbackTrans();
+
+        if ($this->transCnt) $this->transCnt -= 1;
+        $this->Execute('COMMIT');
+        $this->Execute('SET AUTOCOMMIT=1');
+        return true;
+    }
+
+    function RollbackTrans()
+    {
+        if ($this->transOff) return true;
+        if ($this->transCnt) $this->transCnt -= 1;
+        $this->Execute('ROLLBACK');
+        $this->Execute('SET AUTOCOMMIT=1');
+        return true;
+    }
 
 }
 
 class ADORecordSet_mysqlt extends ADORecordSet_mysql{
-	var $databaseType = "mysqlt";
+    var $databaseType = "mysqlt";
 
-	function ADORecordSet_mysqlt($queryID,$mode=false) {
-		return $this->ADORecordSet_mysql($queryID,$mode);
-	}
+    function ADORecordSet_mysqlt($queryID,$mode=false) {
+        return $this->ADORecordSet_mysql($queryID,$mode);
+    }
 
-	function MoveNext()
-	{
-		if ($this->EOF) return false;
+    function MoveNext()
+    {
+        if ($this->EOF) return false;
 
-		$this->_currentRow++;
-		// using & below slows things down by 20%!
-		$this->fields =  @mysql_fetch_array($this->_queryID,$this->fetchMode);
-		if ($this->fields) return true;
-		$this->EOF = true;
+        $this->_currentRow++;
+        // using & below slows things down by 20%!
+        $this->fields =  @mysql_fetch_array($this->_queryID,$this->fetchMode);
+        if ($this->fields) return true;
+        $this->EOF = true;
 
-		return false;
-	}
+        return false;
+    }
 }
 ?>
\ No newline at end of file
diff --git a/lib/WikiDB/adodb/drivers/adodb-netezza.inc.php b/lib/WikiDB/adodb/drivers/adodb-netezza.inc.php
index 435dc513d..500023fe6 100644
--- a/lib/WikiDB/adodb/drivers/adodb-netezza.inc.php
+++ b/lib/WikiDB/adodb/drivers/adodb-netezza.inc.php
@@ -20,149 +20,149 @@ include_once(ADODB_DIR.'/drivers/adodb-postgres64.inc.php');
 
 class ADODB_netezza extends ADODB_postgres64 {
     var $databaseType = 'netezza';
-	var $dataProvider = 'netezza';
-	var $hasInsertID = false;
-	var $_resultid = false;
-  	var $concat_operator='||';
-  	var $random = 'random';
-  	var $upperCase = 'upper';
-	var $metaDatabasesSQL = "select objname from _v_object_data where objtype='database' order by 1";
+    var $dataProvider = 'netezza';
+    var $hasInsertID = false;
+    var $_resultid = false;
+      var $concat_operator='||';
+      var $random = 'random';
+      var $upperCase = 'upper';
+    var $metaDatabasesSQL = "select objname from _v_object_data where objtype='database' order by 1";
     var $metaTablesSQL = "select objname from _v_object_data where objtype='table' order by 1";
-	var $isoDates = true; // accepts dates in ISO format
-	var $sysDate = "CURRENT_DATE";
-	var $sysTimeStamp = "CURRENT_TIMESTAMP";
-	var $blobEncodeType = 'C';
-	var $metaColumnsSQL = "SELECT attname, atttype FROM _v_relation_column_def WHERE name = '%s' AND attnum > 0 ORDER BY attnum";
-	var $metaColumnsSQL1 = "SELECT attname, atttype FROM _v_relation_column_def WHERE name = '%s' AND attnum > 0 ORDER BY attnum";
-	// netezza doesn't have keys. it does have distributions, so maybe this is
-	// something that can be pulled from the system tables
-	var $metaKeySQL = "";
-	var $hasAffectedRows = true;
-	var $hasLimit = true;
-	var $true = 't';		// string that represents TRUE for a database
-	var $false = 'f';		// string that represents FALSE for a database
-	var $fmtDate = "'Y-m-d'";	// used by DBDate() as the default date format used by the database
-	var $fmtTimeStamp = "'Y-m-d G:i:s'"; // used by DBTimeStamp as the default timestamp fmt.
-	var $ansiOuter = true;
-	var $autoRollback = true; // apparently pgsql does not autorollback properly before 4.3.4
-							// http://bugs.php.net/bug.php?id=25404
-
-
-	function ADODB_netezza()
-	{
-
-	}
-
-	function &MetaColumns($table,$upper=true)
-	{
-
-	// Changed this function to support Netezza which has no concept of keys
-	// could posisbly work on other things from the system table later.
-
-	global $ADODB_FETCH_MODE;
-
-		$table = strtolower($table);
-
-		$save = $ADODB_FETCH_MODE;
-		$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
-		if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
-
-		$rs =& $this->Execute(sprintf($this->metaColumnsSQL,$table,$table));
-		if (isset($savem)) $this->SetFetchMode($savem);
-		$ADODB_FETCH_MODE = $save;
-
-		if ($rs === false) return false;
-
-		$retarr = array();
-		while (!$rs->EOF) {
-			$fld = new ADOFieldObject();
-			$fld->name = $rs->fields[0];
-
-			// since we're returning type and length as one string,
-			// split them out here.
-
-			if ($first = strstr($rs->fields[1], "(")) {
-			 $fld->max_length = trim($first, "()");
-			} else {
-			 $fld->max_length = -1;
-			}
-
-			if ($first = strpos($rs->fields[1], "(")) {
-			 $fld->type = substr($rs->fields[1], 0, $first);
-			} else {
-			 $fld->type = $rs->fields[1];
-			}
-
-			switch ($fld->type) {
-			 case "byteint":
-			 case "boolean":
-			 $fld->max_length = 1;
-			 break;
-			 case "smallint":
-			 $fld->max_length = 2;
-			 break;
-			 case "integer":
-			 case "numeric":
-			 case "date":
-			 $fld->max_length = 4;
-			 break;
-			 case "bigint":
-			 case "time":
-			 case "timestamp":
-			 $fld->max_length = 8;
-			 break;
-			 case "timetz":
-			 case "time with time zone":
-			 $fld->max_length = 12;
-			 break;
-			}
-
-			if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld;
-			else $retarr[($upper) ? strtoupper($fld->name) : $fld->name] = $fld;
-
-			$rs->MoveNext();
-		}
-		$rs->Close();
-		return $retarr;
-
-	}
+    var $isoDates = true; // accepts dates in ISO format
+    var $sysDate = "CURRENT_DATE";
+    var $sysTimeStamp = "CURRENT_TIMESTAMP";
+    var $blobEncodeType = 'C';
+    var $metaColumnsSQL = "SELECT attname, atttype FROM _v_relation_column_def WHERE name = '%s' AND attnum > 0 ORDER BY attnum";
+    var $metaColumnsSQL1 = "SELECT attname, atttype FROM _v_relation_column_def WHERE name = '%s' AND attnum > 0 ORDER BY attnum";
+    // netezza doesn't have keys. it does have distributions, so maybe this is
+    // something that can be pulled from the system tables
+    var $metaKeySQL = "";
+    var $hasAffectedRows = true;
+    var $hasLimit = true;
+    var $true = 't';		// string that represents TRUE for a database
+    var $false = 'f';		// string that represents FALSE for a database
+    var $fmtDate = "'Y-m-d'";	// used by DBDate() as the default date format used by the database
+    var $fmtTimeStamp = "'Y-m-d G:i:s'"; // used by DBTimeStamp as the default timestamp fmt.
+    var $ansiOuter = true;
+    var $autoRollback = true; // apparently pgsql does not autorollback properly before 4.3.4
+                            // http://bugs.php.net/bug.php?id=25404
+
+
+    function ADODB_netezza()
+    {
+
+    }
+
+    function &MetaColumns($table,$upper=true)
+    {
+
+    // Changed this function to support Netezza which has no concept of keys
+    // could posisbly work on other things from the system table later.
+
+    global $ADODB_FETCH_MODE;
+
+        $table = strtolower($table);
+
+        $save = $ADODB_FETCH_MODE;
+        $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
+        if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
+
+        $rs =& $this->Execute(sprintf($this->metaColumnsSQL,$table,$table));
+        if (isset($savem)) $this->SetFetchMode($savem);
+        $ADODB_FETCH_MODE = $save;
+
+        if ($rs === false) return false;
+
+        $retarr = array();
+        while (!$rs->EOF) {
+            $fld = new ADOFieldObject();
+            $fld->name = $rs->fields[0];
+
+            // since we're returning type and length as one string,
+            // split them out here.
+
+            if ($first = strstr($rs->fields[1], "(")) {
+             $fld->max_length = trim($first, "()");
+            } else {
+             $fld->max_length = -1;
+            }
+
+            if ($first = strpos($rs->fields[1], "(")) {
+             $fld->type = substr($rs->fields[1], 0, $first);
+            } else {
+             $fld->type = $rs->fields[1];
+            }
+
+            switch ($fld->type) {
+             case "byteint":
+             case "boolean":
+             $fld->max_length = 1;
+             break;
+             case "smallint":
+             $fld->max_length = 2;
+             break;
+             case "integer":
+             case "numeric":
+             case "date":
+             $fld->max_length = 4;
+             break;
+             case "bigint":
+             case "time":
+             case "timestamp":
+             $fld->max_length = 8;
+             break;
+             case "timetz":
+             case "time with time zone":
+             $fld->max_length = 12;
+             break;
+            }
+
+            if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld;
+            else $retarr[($upper) ? strtoupper($fld->name) : $fld->name] = $fld;
+
+            $rs->MoveNext();
+        }
+        $rs->Close();
+        return $retarr;
+
+    }
 
 
 }
 
 /*--------------------------------------------------------------------------------------
-	 Class Name: Recordset
+     Class Name: Recordset
 --------------------------------------------------------------------------------------*/
 
 class ADORecordSet_netezza extends ADORecordSet_postgres64
 {
-	var $databaseType = "netezza";
-	var $canSeek = true;
-
-	function ADORecordSet_netezza($queryID,$mode=false)
-	{
-		if ($mode === false) {
-			global $ADODB_FETCH_MODE;
-			$mode = $ADODB_FETCH_MODE;
-		}
-		switch ($mode)
-		{
-		case ADODB_FETCH_NUM: $this->fetchMode = PGSQL_NUM; break;
-		case ADODB_FETCH_ASSOC:$this->fetchMode = PGSQL_ASSOC; break;
-		default:
-		case ADODB_FETCH_DEFAULT:
-		case ADODB_FETCH_BOTH:$this->fetchMode = PGSQL_BOTH; break;
-		}
-		$this->ADORecordSet($queryID);
-	}
-
-	// _initrs modified to disable blob handling
-	function _initrs()
-	{
-	global $ADODB_COUNTRECS;
-		$this->_numOfRows = ($ADODB_COUNTRECS)? @pg_numrows($this->_queryID):-1;
-		$this->_numOfFields = @pg_numfields($this->_queryID);
-	}
+    var $databaseType = "netezza";
+    var $canSeek = true;
+
+    function ADORecordSet_netezza($queryID,$mode=false)
+    {
+        if ($mode === false) {
+            global $ADODB_FETCH_MODE;
+            $mode = $ADODB_FETCH_MODE;
+        }
+        switch ($mode)
+        {
+        case ADODB_FETCH_NUM: $this->fetchMode = PGSQL_NUM; break;
+        case ADODB_FETCH_ASSOC:$this->fetchMode = PGSQL_ASSOC; break;
+        default:
+        case ADODB_FETCH_DEFAULT:
+        case ADODB_FETCH_BOTH:$this->fetchMode = PGSQL_BOTH; break;
+        }
+        $this->ADORecordSet($queryID);
+    }
+
+    // _initrs modified to disable blob handling
+    function _initrs()
+    {
+    global $ADODB_COUNTRECS;
+        $this->_numOfRows = ($ADODB_COUNTRECS)? @pg_numrows($this->_queryID):-1;
+        $this->_numOfFields = @pg_numfields($this->_queryID);
+    }
 
 }
 ?>
diff --git a/lib/WikiDB/adodb/drivers/adodb-oci8.inc.php b/lib/WikiDB/adodb/drivers/adodb-oci8.inc.php
index 505b62605..619109f9a 100644
--- a/lib/WikiDB/adodb/drivers/adodb-oci8.inc.php
+++ b/lib/WikiDB/adodb/drivers/adodb-oci8.inc.php
@@ -36,89 +36,89 @@ You can also modify the date format using the ALTER SESSION command.
 */
 
 class ADODB_oci8 extends ADOConnection {
-	var $databaseType = 'oci8';
-	var $dataProvider = 'oci8';
-	var $replaceQuote = "''"; // string to use to replace quotes
-	var $concat_operator='||';
-	var $sysDate = "TRUNC(SYSDATE)";
-	var $sysTimeStamp = 'SYSDATE';
-	var $metaDatabasesSQL = "SELECT USERNAME FROM ALL_USERS WHERE USERNAME NOT IN ('SYS','SYSTEM','DBSNMP','OUTLN') ORDER BY 1";
-	var $_stmt;
-	var $_commit = OCI_COMMIT_ON_SUCCESS;
-	var $_initdate = true; // init date to YYYY-MM-DD
-	var $metaTablesSQL = "select table_name,table_type from cat where table_type in ('TABLE','VIEW')";
-	var $metaColumnsSQL = "select cname,coltype,width, SCALE, PRECISION, NULLS, DEFAULTVAL from col where tname='%s' order by colno"; //changed by smondino@users.sourceforge. net
-	var $_bindInputArray = true;
-	var $hasGenID = true;
-	var $_genIDSQL = "SELECT (%s.nextval) FROM DUAL";
-	var $_genSeqSQL = "CREATE SEQUENCE %s START WITH %s";
-	var $_dropSeqSQL = "DROP SEQUENCE %s";
-	var $hasAffectedRows = true;
-	var $random = "abs(mod(DBMS_RANDOM.RANDOM,10000001)/10000000)";
-	var $noNullStrings = false;
-	var $connectSID = false;
-	var $_bind = false;
-	var $_hasOCIFetchStatement = false;
-	var $_getarray = false; // currently not working
-	var $leftOuter = '';  // oracle wierdness, $col = $value (+) for LEFT OUTER, $col (+)= $value for RIGHT OUTER
-	var $session_sharing_force_blob = false; // alter session on updateblob if set to true
-	var $firstrows = true; // enable first rows optimization on SelectLimit()
-	var $selectOffsetAlg1 = 100; // when to use 1st algorithm of selectlimit.
-	var $NLS_DATE_FORMAT = 'YYYY-MM-DD';  // To include time, use 'RRRR-MM-DD HH24:MI:SS'
- 	var $useDBDateFormatForTextInput=false;
-	var $datetime = false; // MetaType('DATE') returns 'D' (datetime==false) or 'T' (datetime == true)
-
-	// var $ansiOuter = true; // if oracle9
-
-	function ADODB_oci8()
-	{
-		$this->_hasOCIFetchStatement = ADODB_PHPVER >= 0x4200;
-	}
-
-	/*  Function &MetaColumns($table) added by smondino@users.sourceforge.net*/
-	function &MetaColumns($table)
-	{
-	global $ADODB_FETCH_MODE;
-
-		$save = $ADODB_FETCH_MODE;
-		$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
-		if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
-
-		$rs = $this->Execute(sprintf($this->metaColumnsSQL,strtoupper($table)));
-
-		if (isset($savem)) $this->SetFetchMode($savem);
-		$ADODB_FETCH_MODE = $save;
-		if (!$rs) return false;
-		$retarr = array();
-		while (!$rs->EOF) { //print_r($rs->fields);
-			$fld = new ADOFieldObject();
-	   		$fld->name = $rs->fields[0];
-	   		$fld->type = $rs->fields[1];
-	   		$fld->max_length = $rs->fields[2];
-			$fld->scale = $rs->fields[3];
-			if ($rs->fields[1] == 'NUMBER' && $rs->fields[3] == 0) {
-				$fld->type ='INT';
-	     		$fld->max_length = $rs->fields[4];
-	    	}
-		   	$fld->not_null = (strncmp($rs->fields[5], 'NOT',3) === 0);
-			$fld->binary = (strpos($fld->type,'BLOB') !== false);
-			$fld->default_value = $rs->fields[6];
-
-			if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld;
-			else $retarr[strtoupper($fld->name)] = $fld;
-			$rs->MoveNext();
-		}
-		$rs->Close();
-		return $retarr;
-	}
-
-	function Time()
-	{
-		$rs =& $this->Execute("select TO_CHAR($this->sysTimeStamp,'YYYY-MM-DD HH24:MI:SS') from dual");
-		if ($rs && !$rs->EOF) return $this->UnixTimeStamp(reset($rs->fields));
-
-		return false;
-	}
+    var $databaseType = 'oci8';
+    var $dataProvider = 'oci8';
+    var $replaceQuote = "''"; // string to use to replace quotes
+    var $concat_operator='||';
+    var $sysDate = "TRUNC(SYSDATE)";
+    var $sysTimeStamp = 'SYSDATE';
+    var $metaDatabasesSQL = "SELECT USERNAME FROM ALL_USERS WHERE USERNAME NOT IN ('SYS','SYSTEM','DBSNMP','OUTLN') ORDER BY 1";
+    var $_stmt;
+    var $_commit = OCI_COMMIT_ON_SUCCESS;
+    var $_initdate = true; // init date to YYYY-MM-DD
+    var $metaTablesSQL = "select table_name,table_type from cat where table_type in ('TABLE','VIEW')";
+    var $metaColumnsSQL = "select cname,coltype,width, SCALE, PRECISION, NULLS, DEFAULTVAL from col where tname='%s' order by colno"; //changed by smondino@users.sourceforge. net
+    var $_bindInputArray = true;
+    var $hasGenID = true;
+    var $_genIDSQL = "SELECT (%s.nextval) FROM DUAL";
+    var $_genSeqSQL = "CREATE SEQUENCE %s START WITH %s";
+    var $_dropSeqSQL = "DROP SEQUENCE %s";
+    var $hasAffectedRows = true;
+    var $random = "abs(mod(DBMS_RANDOM.RANDOM,10000001)/10000000)";
+    var $noNullStrings = false;
+    var $connectSID = false;
+    var $_bind = false;
+    var $_hasOCIFetchStatement = false;
+    var $_getarray = false; // currently not working
+    var $leftOuter = '';  // oracle wierdness, $col = $value (+) for LEFT OUTER, $col (+)= $value for RIGHT OUTER
+    var $session_sharing_force_blob = false; // alter session on updateblob if set to true
+    var $firstrows = true; // enable first rows optimization on SelectLimit()
+    var $selectOffsetAlg1 = 100; // when to use 1st algorithm of selectlimit.
+    var $NLS_DATE_FORMAT = 'YYYY-MM-DD';  // To include time, use 'RRRR-MM-DD HH24:MI:SS'
+     var $useDBDateFormatForTextInput=false;
+    var $datetime = false; // MetaType('DATE') returns 'D' (datetime==false) or 'T' (datetime == true)
+
+    // var $ansiOuter = true; // if oracle9
+
+    function ADODB_oci8()
+    {
+        $this->_hasOCIFetchStatement = ADODB_PHPVER >= 0x4200;
+    }
+
+    /*  Function &MetaColumns($table) added by smondino@users.sourceforge.net*/
+    function &MetaColumns($table)
+    {
+    global $ADODB_FETCH_MODE;
+
+        $save = $ADODB_FETCH_MODE;
+        $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
+        if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
+
+        $rs = $this->Execute(sprintf($this->metaColumnsSQL,strtoupper($table)));
+
+        if (isset($savem)) $this->SetFetchMode($savem);
+        $ADODB_FETCH_MODE = $save;
+        if (!$rs) return false;
+        $retarr = array();
+        while (!$rs->EOF) { //print_r($rs->fields);
+            $fld = new ADOFieldObject();
+               $fld->name = $rs->fields[0];
+               $fld->type = $rs->fields[1];
+               $fld->max_length = $rs->fields[2];
+            $fld->scale = $rs->fields[3];
+            if ($rs->fields[1] == 'NUMBER' && $rs->fields[3] == 0) {
+                $fld->type ='INT';
+                 $fld->max_length = $rs->fields[4];
+            }
+               $fld->not_null = (strncmp($rs->fields[5], 'NOT',3) === 0);
+            $fld->binary = (strpos($fld->type,'BLOB') !== false);
+            $fld->default_value = $rs->fields[6];
+
+            if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld;
+            else $retarr[strtoupper($fld->name)] = $fld;
+            $rs->MoveNext();
+        }
+        $rs->Close();
+        return $retarr;
+    }
+
+    function Time()
+    {
+        $rs =& $this->Execute("select TO_CHAR($this->sysTimeStamp,'YYYY-MM-DD HH24:MI:SS') from dual");
+        if ($rs && !$rs->EOF) return $this->UnixTimeStamp(reset($rs->fields));
+
+        return false;
+    }
 
 /*
 
@@ -135,1052 +135,1052 @@ class ADODB_oci8 extends ADOConnection {
     $conn->Connect($serveraddress,'scott,'tiger',$service_name);
 
   d. Server + SID
-  	$conn->connectSID = true;
-	$conn->Connect($serveraddress,'scott,'tiger',$SID);
+      $conn->connectSID = true;
+    $conn->Connect($serveraddress,'scott,'tiger',$SID);
 
 
 Example TNSName:
 ---------------
 NATSOFT.DOMAIN =
   (DESCRIPTION =
-	(ADDRESS_LIST =
-	  (ADDRESS = (PROTOCOL = TCP)(HOST = kermit)(PORT = 1523))
-	)
-	(CONNECT_DATA =
-	  (SERVICE_NAME = natsoft.domain)
-	)
+    (ADDRESS_LIST =
+      (ADDRESS = (PROTOCOL = TCP)(HOST = kermit)(PORT = 1523))
+    )
+    (CONNECT_DATA =
+      (SERVICE_NAME = natsoft.domain)
+    )
   )
 
   There are 3 connection modes, 0 = non-persistent, 1 = persistent, 2 = force new connection
 
 */
-	function _connect($argHostname, $argUsername, $argPassword, $argDatabasename,$mode=0)
-	{
-		if (!function_exists('OCIPLogon')) return false;
+    function _connect($argHostname, $argUsername, $argPassword, $argDatabasename,$mode=0)
+    {
+        if (!function_exists('OCIPLogon')) return false;
 
 
         $this->_errorMsg = false;
-		$this->_errorCode = false;
-
-		if($argHostname) { // added by Jorma Tuomainen 
-			if (empty($argDatabasename)) $argDatabasename = $argHostname;
-			else {
-				if(strpos($argHostname,":")) {
-					$argHostinfo=explode(":",$argHostname);
-				   	$argHostname=$argHostinfo[0];
-					$argHostport=$argHostinfo[1];
-			 	} else {
-					$argHostport="1521";
-	   			}
-
-				if ($this->connectSID) {
-					$argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname
-					.")(PORT=$argHostport))(CONNECT_DATA=(SID=$argDatabasename)))";
-				} else
-					$argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname
-					.")(PORT=$argHostport))(CONNECT_DATA=(SERVICE_NAME=$argDatabasename)))";
-			}
-		}
-
- 		//if ($argHostname) print "

Connect: 1st argument should be left blank for $this->databaseType

"; - if ($mode==1) { - $this->_connectionID = OCIPLogon($argUsername,$argPassword, $argDatabasename); - if ($this->_connectionID && $this->autoRollback) OCIrollback($this->_connectionID); - } else if ($mode==2) { - $this->_connectionID = OCINLogon($argUsername,$argPassword, $argDatabasename); - } else { - $this->_connectionID = OCILogon($argUsername,$argPassword, $argDatabasename); - } - if ($this->_connectionID === false) return false; - if ($this->_initdate) { - $this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='".$this->NLS_DATE_FORMAT."'"); - } - - // looks like: - // Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production With the Partitioning option JServer Release 8.1.7.0.0 - Production - // $vers = OCIServerVersion($this->_connectionID); - // if (strpos($vers,'8i') !== false) $this->ansiOuter = true; - return true; - } - - function ServerInfo() - { - $arr['compat'] = $this->GetOne('select value from sys.database_compatible_level'); - $arr['description'] = @OCIServerVersion($this->_connectionID); - $arr['version'] = ADOConnection::_findvers($arr['description']); - return $arr; - } - // returns true or false - function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) - { - return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename,1); - } - - - - // returns true or false - function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename) - { - return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename,2); - } - - function _affectedrows() - { - if (is_resource($this->_stmt)) return @OCIRowCount($this->_stmt); - return 0; - } - - function IfNull( $field, $ifNull ) - { - return " NVL($field, $ifNull) "; // if Oracle - } - - // format and return date string in database date format - function DBDate($d) - { - if (empty($d) && $d !== 0) return 'null'; - - if (is_string($d)) $d = ADORecordSet::UnixDate($d); - return "TO_DATE(".adodb_date($this->fmtDate,$d).",'".$this->NLS_DATE_FORMAT."')"; - } - - - // format and return date string in database timestamp format - function DBTimeStamp($ts) - { - if (empty($ts) && $ts !== 0) return 'null'; - if (is_string($ts)) $ts = ADORecordSet::UnixTimeStamp($ts); - return 'TO_DATE('.adodb_date($this->fmtTimeStamp,$ts).",'RRRR-MM-DD, HH:MI:SS AM')"; - } - - function RowLock($tables,$where) - { - if ($this->autoCommit) $this->BeginTrans(); - return $this->GetOne("select 1 as ignore from $tables where $where for update"); - } - - function &MetaTables($ttype=false,$showSchema=false,$mask=false) - { - if ($mask) { - $save = $this->metaTablesSQL; - $mask = $this->qstr(strtoupper($mask)); - $this->metaTablesSQL .= " AND table_name like $mask"; - } - $ret =& ADOConnection::MetaTables($ttype,$showSchema); - - if ($mask) { - $this->metaTablesSQL = $save; - } - return $ret; - } - - function BeginTrans() - { - if ($this->transOff) return true; - $this->transCnt += 1; - $this->autoCommit = false; - $this->_commit = OCI_DEFAULT; - return true; - } - - function CommitTrans($ok=true) - { - if ($this->transOff) return true; - if (!$ok) return $this->RollbackTrans(); - - if ($this->transCnt) $this->transCnt -= 1; - $ret = OCIcommit($this->_connectionID); - $this->_commit = OCI_COMMIT_ON_SUCCESS; - $this->autoCommit = true; - return $ret; - } - - function RollbackTrans() - { - if ($this->transOff) return true; - if ($this->transCnt) $this->transCnt -= 1; - $ret = OCIrollback($this->_connectionID); - $this->_commit = OCI_COMMIT_ON_SUCCESS; - $this->autoCommit = true; - return $ret; - } - - - function SelectDB($dbName) - { - return false; - } - - function ErrorMsg() - { - if ($this->_errorMsg !== false) return $this->_errorMsg; - - if (is_resource($this->_stmt)) $arr = @OCIerror($this->_stmt); - if (empty($arr)) { - $arr = @OCIerror($this->_connectionID); - if ($arr === false) $arr = @OCIError(); - if ($arr === false) return ''; - } - $this->_errorMsg = $arr['message']; - $this->_errorCode = $arr['code']; - return $this->_errorMsg; - } - - function ErrorNo() - { - if ($this->_errorCode !== false) return $this->_errorCode; - - if (is_resource($this->_stmt)) $arr = @OCIError($this->_stmt); - if (empty($arr)) { - $arr = @OCIError($this->_connectionID); - if ($arr == false) $arr = @OCIError(); - if ($arr == false) return ''; - } - - $this->_errorMsg = $arr['message']; - $this->_errorCode = $arr['code']; - - return $arr['code']; - } - - // Format date column in sql string given an input format that understands Y M D - function SQLDate($fmt, $col=false) - { - if (!$col) $col = $this->sysTimeStamp; - $s = 'TO_CHAR('.$col.",'"; - - $len = strlen($fmt); - for ($i=0; $i < $len; $i++) { - $ch = $fmt[$i]; - switch($ch) { - case 'Y': - case 'y': - $s .= 'YYYY'; - break; - case 'Q': - case 'q': - $s .= 'Q'; - break; - - case 'M': - $s .= 'Mon'; - break; - - case 'm': - $s .= 'MM'; - break; - case 'D': - case 'd': - $s .= 'DD'; - break; - - case 'H': - $s.= 'HH24'; - break; - - case 'h': - $s .= 'HH'; - break; - - case 'i': - $s .= 'MI'; - break; - - case 's': - $s .= 'SS'; - break; - - case 'a': - case 'A': - $s .= 'AM'; - break; - - default: - // handle escape characters... - if ($ch == '\\') { - $i++; - $ch = substr($fmt,$i,1); - } - if (strpos('-/.:;, ',$ch) !== false) $s .= $ch; - else $s .= '"'.$ch.'"'; - - } - } - return $s. "')"; - } - - - /* - This algorithm makes use of - - a. FIRST_ROWS hint - The FIRST_ROWS hint explicitly chooses the approach to optimize response time, - that is, minimum resource usage to return the first row. Results will be returned - as soon as they are identified. - - b. Uses rownum tricks to obtain only the required rows from a given offset. - As this uses complicated sql statements, we only use this if the $offset >= 100. - This idea by Tomas V V Cox. - - This implementation does not appear to work with oracle 8.0.5 or earlier. Comment - out this function then, and the slower SelectLimit() in the base class will be used. - */ - function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) - { - // seems that oracle only supports 1 hint comment in 8i - if ($this->firstrows) { - if (strpos($sql,'/*+') !== false) - $sql = str_replace('/*+ ','/*+FIRST_ROWS ',$sql); - else - $sql = preg_replace('/^[ \t\n]*select/i','SELECT /*+FIRST_ROWS*/',$sql); - } - - if ($offset < $this->selectOffsetAlg1) { - if ($nrows > 0) { - if ($offset > 0) $nrows += $offset; - //$inputarr['adodb_rownum'] = $nrows; - if ($this->databaseType == 'oci8po') { - $sql = "select * from ($sql) where rownum <= ?"; - } else { - $sql = "select * from ($sql) where rownum <= :adodb_offset"; - } - $inputarr['adodb_offset'] = $nrows; - $nrows = -1; - } - // note that $nrows = 0 still has to work ==> no rows returned - - $rs =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); - return $rs; - - } else { - // Algorithm by Tomas V V Cox, from PEAR DB oci8.php - - // Let Oracle return the name of the columns - $q_fields = "SELECT * FROM ($sql) WHERE NULL = NULL"; - if (!$stmt = OCIParse($this->_connectionID, $q_fields)) { - return false; - } - - if (is_array($inputarr)) { - foreach($inputarr as $k => $v) { - if (is_array($v)) { - if (sizeof($v) == 2) // suggested by g.giunta@libero. - OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1]); - else - OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1],$v[2]); - } else { - $len = -1; - if ($v === ' ') $len = 1; - if (isset($bindarr)) { // is prepared sql, so no need to ocibindbyname again - $bindarr[$k] = $v; - } else { // dynamic sql, so rebind every time - OCIBindByName($stmt,":$k",$inputarr[$k],$len); - } - } - } - } - - if (!OCIExecute($stmt, OCI_DEFAULT)) { - OCIFreeStatement($stmt); - return false; - } - - $ncols = OCINumCols($stmt); - for ( $i = 1; $i <= $ncols; $i++ ) { - $cols[] = '"'.OCIColumnName($stmt, $i).'"'; - } - $result = false; - - OCIFreeStatement($stmt); - $fields = implode(',', $cols); - $nrows += $offset; - $offset += 1; // in Oracle rownum starts at 1 - - if ($this->databaseType == 'oci8po') { - $sql = "SELECT $fields FROM". - "(SELECT rownum as adodb_rownum, $fields FROM". - " ($sql) WHERE rownum <= ?". - ") WHERE adodb_rownum >= ?"; - } else { - $sql = "SELECT $fields FROM". - "(SELECT rownum as adodb_rownum, $fields FROM". - " ($sql) WHERE rownum <= :adodb_nrows". - ") WHERE adodb_rownum >= :adodb_offset"; - } - $inputarr['adodb_nrows'] = $nrows; - $inputarr['adodb_offset'] = $offset; - - if ($secs2cache>0) $rs =& $this->CacheExecute($secs2cache, $sql,$inputarr); - else $rs =& $this->Execute($sql,$inputarr); - return $rs; - } - - } - - /** - * Usage: - * Store BLOBs and CLOBs - * - * Example: to store $var in a blob - * - * $conn->Execute('insert into TABLE (id,ablob) values(12,empty_blob())'); - * $conn->UpdateBlob('TABLE', 'ablob', $varHoldingBlob, 'ID=12', 'BLOB'); - * - * $blobtype supports 'BLOB' and 'CLOB', but you need to change to 'empty_clob()'. - * - * to get length of LOB: - * select DBMS_LOB.GETLENGTH(ablob) from TABLE - * - * If you are using CURSOR_SHARING = force, it appears this will case a segfault - * under oracle 8.1.7.0. Run: - * $db->Execute('ALTER SESSION SET CURSOR_SHARING=EXACT'); - * before UpdateBlob() then... - */ - - function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') - { - - //if (strlen($val) < 4000) return $this->Execute("UPDATE $table SET $column=:blob WHERE $where",array('blob'=>$val)) != false; - - switch(strtoupper($blobtype)) { - default: ADOConnection::outp("UpdateBlob: Unknown blobtype=$blobtype"); return false; - case 'BLOB': $type = OCI_B_BLOB; break; - case 'CLOB': $type = OCI_B_CLOB; break; - } - - if ($this->databaseType == 'oci8po') - $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO ?"; - else - $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO :blob"; - - $desc = OCINewDescriptor($this->_connectionID, OCI_D_LOB); - $arr['blob'] = array($desc,-1,$type); - if ($this->session_sharing_force_blob) $this->Execute('ALTER SESSION SET CURSOR_SHARING=EXACT'); - $commit = $this->autoCommit; - if ($commit) $this->BeginTrans(); - $rs = ADODB_oci8::Execute($sql,$arr); - if ($rez = !empty($rs)) $desc->save($val); - $desc->free(); - if ($commit) $this->CommitTrans(); - if ($this->session_sharing_force_blob) $this->Execute('ALTER SESSION SET CURSOR_SHARING=FORCE'); - - if ($rez) $rs->Close(); - return $rez; - } - - /** - * Usage: store file pointed to by $var in a blob - */ - function UpdateBlobFile($table,$column,$val,$where,$blobtype='BLOB') - { - switch(strtoupper($blobtype)) { - default: ADOConnection::outp( "UpdateBlob: Unknown blobtype=$blobtype"); return false; - case 'BLOB': $type = OCI_B_BLOB; break; - case 'CLOB': $type = OCI_B_CLOB; break; - } - - if ($this->databaseType == 'oci8po') - $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO ?"; - else - $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO :blob"; - - $desc = OCINewDescriptor($this->_connectionID, OCI_D_LOB); - $arr['blob'] = array($desc,-1,$type); - - $this->BeginTrans(); - $rs = ADODB_oci8::Execute($sql,$arr); - if ($rez = !empty($rs)) $desc->savefile($val); - $desc->free(); - $this->CommitTrans(); - - if ($rez) $rs->Close(); - return $rez; - } - - - /* - Example of usage: - - $stmt = $this->Prepare('insert into emp (empno, ename) values (:empno, :ename)'); - */ - function Prepare($sql,$cursor=false) - { - static $BINDNUM = 0; - - $stmt = OCIParse($this->_connectionID,$sql); - - if (!$stmt) return false; - - $BINDNUM += 1; - - if (@OCIStatementType($stmt) == 'BEGIN') { - return array($sql,$stmt,0,$BINDNUM, ($cursor) ? OCINewCursor($this->_connectionID) : false); - } - - return array($sql,$stmt,0,$BINDNUM); - } - - /* - Call an oracle stored procedure and return a cursor variable. - Convert the cursor variable into a recordset. - Concept by Robert Tuttle robert@ud.com - - Example: - Note: we return a cursor variable in :RS2 - $rs = $db->ExecuteCursor("BEGIN adodb.open_tab(:RS2); END;",'RS2'); - - $rs = $db->ExecuteCursor( - "BEGIN :RS2 = adodb.getdata(:VAR1); END;", - 'RS2', - array('VAR1' => 'Mr Bean')); - - */ - function &ExecuteCursor($sql,$cursorName='rs',$params=false) - { - $stmt = ADODB_oci8::Prepare($sql,true); # true to allocate OCINewCursor - - if (is_array($stmt) && sizeof($stmt) >= 5) { - $this->Parameter($stmt, $ignoreCur, $cursorName, false, -1, OCI_B_CURSOR); - if ($params) { - foreach($params as $k => $v) { - $this->Parameter($stmt,$params[$k], $k); - } - } - } - return $this->Execute($stmt); - } - - /* - Bind a variable -- very, very fast for executing repeated statements in oracle. - Better than using - for ($i = 0; $i < $max; $i++) { - $p1 = ?; $p2 = ?; $p3 = ?; - $this->Execute("insert into table (col0, col1, col2) values (:0, :1, :2)", - array($p1,$p2,$p3)); - } - - Usage: - $stmt = $DB->Prepare("insert into table (col0, col1, col2) values (:0, :1, :2)"); - $DB->Bind($stmt, $p1); - $DB->Bind($stmt, $p2); - $DB->Bind($stmt, $p3); - for ($i = 0; $i < $max; $i++) { - $p1 = ?; $p2 = ?; $p3 = ?; - $DB->Execute($stmt); - } - - Some timings: - ** Test table has 3 cols, and 1 index. Test to insert 1000 records - Time 0.6081s (1644.60 inserts/sec) with direct OCIParse/OCIExecute - Time 0.6341s (1577.16 inserts/sec) with ADOdb Prepare/Bind/Execute - Time 1.5533s ( 643.77 inserts/sec) with pure SQL using Execute - - Now if PHP only had batch/bulk updating like Java or PL/SQL... - - Note that the order of parameters differs from OCIBindByName, - because we default the names to :0, :1, :2 - */ - function Bind(&$stmt,&$var,$size=4000,$type=false,$name=false) - { - if (!is_array($stmt)) return false; + $this->_errorCode = false; + + if($argHostname) { // added by Jorma Tuomainen + if (empty($argDatabasename)) $argDatabasename = $argHostname; + else { + if(strpos($argHostname,":")) { + $argHostinfo=explode(":",$argHostname); + $argHostname=$argHostinfo[0]; + $argHostport=$argHostinfo[1]; + } else { + $argHostport="1521"; + } + + if ($this->connectSID) { + $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname + .")(PORT=$argHostport))(CONNECT_DATA=(SID=$argDatabasename)))"; + } else + $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname + .")(PORT=$argHostport))(CONNECT_DATA=(SERVICE_NAME=$argDatabasename)))"; + } + } + + //if ($argHostname) print "

Connect: 1st argument should be left blank for $this->databaseType

"; + if ($mode==1) { + $this->_connectionID = OCIPLogon($argUsername,$argPassword, $argDatabasename); + if ($this->_connectionID && $this->autoRollback) OCIrollback($this->_connectionID); + } else if ($mode==2) { + $this->_connectionID = OCINLogon($argUsername,$argPassword, $argDatabasename); + } else { + $this->_connectionID = OCILogon($argUsername,$argPassword, $argDatabasename); + } + if ($this->_connectionID === false) return false; + if ($this->_initdate) { + $this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='".$this->NLS_DATE_FORMAT."'"); + } + + // looks like: + // Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production With the Partitioning option JServer Release 8.1.7.0.0 - Production + // $vers = OCIServerVersion($this->_connectionID); + // if (strpos($vers,'8i') !== false) $this->ansiOuter = true; + return true; + } + + function ServerInfo() + { + $arr['compat'] = $this->GetOne('select value from sys.database_compatible_level'); + $arr['description'] = @OCIServerVersion($this->_connectionID); + $arr['version'] = ADOConnection::_findvers($arr['description']); + return $arr; + } + // returns true or false + function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) + { + return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename,1); + } + + + + // returns true or false + function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename) + { + return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename,2); + } + + function _affectedrows() + { + if (is_resource($this->_stmt)) return @OCIRowCount($this->_stmt); + return 0; + } + + function IfNull( $field, $ifNull ) + { + return " NVL($field, $ifNull) "; // if Oracle + } + + // format and return date string in database date format + function DBDate($d) + { + if (empty($d) && $d !== 0) return 'null'; + + if (is_string($d)) $d = ADORecordSet::UnixDate($d); + return "TO_DATE(".adodb_date($this->fmtDate,$d).",'".$this->NLS_DATE_FORMAT."')"; + } + + + // format and return date string in database timestamp format + function DBTimeStamp($ts) + { + if (empty($ts) && $ts !== 0) return 'null'; + if (is_string($ts)) $ts = ADORecordSet::UnixTimeStamp($ts); + return 'TO_DATE('.adodb_date($this->fmtTimeStamp,$ts).",'RRRR-MM-DD, HH:MI:SS AM')"; + } + + function RowLock($tables,$where) + { + if ($this->autoCommit) $this->BeginTrans(); + return $this->GetOne("select 1 as ignore from $tables where $where for update"); + } + + function &MetaTables($ttype=false,$showSchema=false,$mask=false) + { + if ($mask) { + $save = $this->metaTablesSQL; + $mask = $this->qstr(strtoupper($mask)); + $this->metaTablesSQL .= " AND table_name like $mask"; + } + $ret =& ADOConnection::MetaTables($ttype,$showSchema); + + if ($mask) { + $this->metaTablesSQL = $save; + } + return $ret; + } + + function BeginTrans() + { + if ($this->transOff) return true; + $this->transCnt += 1; + $this->autoCommit = false; + $this->_commit = OCI_DEFAULT; + return true; + } + + function CommitTrans($ok=true) + { + if ($this->transOff) return true; + if (!$ok) return $this->RollbackTrans(); + + if ($this->transCnt) $this->transCnt -= 1; + $ret = OCIcommit($this->_connectionID); + $this->_commit = OCI_COMMIT_ON_SUCCESS; + $this->autoCommit = true; + return $ret; + } + + function RollbackTrans() + { + if ($this->transOff) return true; + if ($this->transCnt) $this->transCnt -= 1; + $ret = OCIrollback($this->_connectionID); + $this->_commit = OCI_COMMIT_ON_SUCCESS; + $this->autoCommit = true; + return $ret; + } + + + function SelectDB($dbName) + { + return false; + } + + function ErrorMsg() + { + if ($this->_errorMsg !== false) return $this->_errorMsg; + + if (is_resource($this->_stmt)) $arr = @OCIerror($this->_stmt); + if (empty($arr)) { + $arr = @OCIerror($this->_connectionID); + if ($arr === false) $arr = @OCIError(); + if ($arr === false) return ''; + } + $this->_errorMsg = $arr['message']; + $this->_errorCode = $arr['code']; + return $this->_errorMsg; + } + + function ErrorNo() + { + if ($this->_errorCode !== false) return $this->_errorCode; + + if (is_resource($this->_stmt)) $arr = @OCIError($this->_stmt); + if (empty($arr)) { + $arr = @OCIError($this->_connectionID); + if ($arr == false) $arr = @OCIError(); + if ($arr == false) return ''; + } + + $this->_errorMsg = $arr['message']; + $this->_errorCode = $arr['code']; + + return $arr['code']; + } + + // Format date column in sql string given an input format that understands Y M D + function SQLDate($fmt, $col=false) + { + if (!$col) $col = $this->sysTimeStamp; + $s = 'TO_CHAR('.$col.",'"; + + $len = strlen($fmt); + for ($i=0; $i < $len; $i++) { + $ch = $fmt[$i]; + switch($ch) { + case 'Y': + case 'y': + $s .= 'YYYY'; + break; + case 'Q': + case 'q': + $s .= 'Q'; + break; + + case 'M': + $s .= 'Mon'; + break; + + case 'm': + $s .= 'MM'; + break; + case 'D': + case 'd': + $s .= 'DD'; + break; + + case 'H': + $s.= 'HH24'; + break; + + case 'h': + $s .= 'HH'; + break; + + case 'i': + $s .= 'MI'; + break; + + case 's': + $s .= 'SS'; + break; + + case 'a': + case 'A': + $s .= 'AM'; + break; + + default: + // handle escape characters... + if ($ch == '\\') { + $i++; + $ch = substr($fmt,$i,1); + } + if (strpos('-/.:;, ',$ch) !== false) $s .= $ch; + else $s .= '"'.$ch.'"'; + + } + } + return $s. "')"; + } + + + /* + This algorithm makes use of + + a. FIRST_ROWS hint + The FIRST_ROWS hint explicitly chooses the approach to optimize response time, + that is, minimum resource usage to return the first row. Results will be returned + as soon as they are identified. + + b. Uses rownum tricks to obtain only the required rows from a given offset. + As this uses complicated sql statements, we only use this if the $offset >= 100. + This idea by Tomas V V Cox. + + This implementation does not appear to work with oracle 8.0.5 or earlier. Comment + out this function then, and the slower SelectLimit() in the base class will be used. + */ + function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) + { + // seems that oracle only supports 1 hint comment in 8i + if ($this->firstrows) { + if (strpos($sql,'/*+') !== false) + $sql = str_replace('/*+ ','/*+FIRST_ROWS ',$sql); + else + $sql = preg_replace('/^[ \t\n]*select/i','SELECT /*+FIRST_ROWS*/',$sql); + } + + if ($offset < $this->selectOffsetAlg1) { + if ($nrows > 0) { + if ($offset > 0) $nrows += $offset; + //$inputarr['adodb_rownum'] = $nrows; + if ($this->databaseType == 'oci8po') { + $sql = "select * from ($sql) where rownum <= ?"; + } else { + $sql = "select * from ($sql) where rownum <= :adodb_offset"; + } + $inputarr['adodb_offset'] = $nrows; + $nrows = -1; + } + // note that $nrows = 0 still has to work ==> no rows returned + + $rs =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); + return $rs; + + } else { + // Algorithm by Tomas V V Cox, from PEAR DB oci8.php + + // Let Oracle return the name of the columns + $q_fields = "SELECT * FROM ($sql) WHERE NULL = NULL"; + if (!$stmt = OCIParse($this->_connectionID, $q_fields)) { + return false; + } + + if (is_array($inputarr)) { + foreach($inputarr as $k => $v) { + if (is_array($v)) { + if (sizeof($v) == 2) // suggested by g.giunta@libero. + OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1]); + else + OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1],$v[2]); + } else { + $len = -1; + if ($v === ' ') $len = 1; + if (isset($bindarr)) { // is prepared sql, so no need to ocibindbyname again + $bindarr[$k] = $v; + } else { // dynamic sql, so rebind every time + OCIBindByName($stmt,":$k",$inputarr[$k],$len); + } + } + } + } + + if (!OCIExecute($stmt, OCI_DEFAULT)) { + OCIFreeStatement($stmt); + return false; + } + + $ncols = OCINumCols($stmt); + for ( $i = 1; $i <= $ncols; $i++ ) { + $cols[] = '"'.OCIColumnName($stmt, $i).'"'; + } + $result = false; + + OCIFreeStatement($stmt); + $fields = implode(',', $cols); + $nrows += $offset; + $offset += 1; // in Oracle rownum starts at 1 + + if ($this->databaseType == 'oci8po') { + $sql = "SELECT $fields FROM". + "(SELECT rownum as adodb_rownum, $fields FROM". + " ($sql) WHERE rownum <= ?". + ") WHERE adodb_rownum >= ?"; + } else { + $sql = "SELECT $fields FROM". + "(SELECT rownum as adodb_rownum, $fields FROM". + " ($sql) WHERE rownum <= :adodb_nrows". + ") WHERE adodb_rownum >= :adodb_offset"; + } + $inputarr['adodb_nrows'] = $nrows; + $inputarr['adodb_offset'] = $offset; + + if ($secs2cache>0) $rs =& $this->CacheExecute($secs2cache, $sql,$inputarr); + else $rs =& $this->Execute($sql,$inputarr); + return $rs; + } + + } + + /** + * Usage: + * Store BLOBs and CLOBs + * + * Example: to store $var in a blob + * + * $conn->Execute('insert into TABLE (id,ablob) values(12,empty_blob())'); + * $conn->UpdateBlob('TABLE', 'ablob', $varHoldingBlob, 'ID=12', 'BLOB'); + * + * $blobtype supports 'BLOB' and 'CLOB', but you need to change to 'empty_clob()'. + * + * to get length of LOB: + * select DBMS_LOB.GETLENGTH(ablob) from TABLE + * + * If you are using CURSOR_SHARING = force, it appears this will case a segfault + * under oracle 8.1.7.0. Run: + * $db->Execute('ALTER SESSION SET CURSOR_SHARING=EXACT'); + * before UpdateBlob() then... + */ + + function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') + { + + //if (strlen($val) < 4000) return $this->Execute("UPDATE $table SET $column=:blob WHERE $where",array('blob'=>$val)) != false; + + switch(strtoupper($blobtype)) { + default: ADOConnection::outp("UpdateBlob: Unknown blobtype=$blobtype"); return false; + case 'BLOB': $type = OCI_B_BLOB; break; + case 'CLOB': $type = OCI_B_CLOB; break; + } + + if ($this->databaseType == 'oci8po') + $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO ?"; + else + $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO :blob"; + + $desc = OCINewDescriptor($this->_connectionID, OCI_D_LOB); + $arr['blob'] = array($desc,-1,$type); + if ($this->session_sharing_force_blob) $this->Execute('ALTER SESSION SET CURSOR_SHARING=EXACT'); + $commit = $this->autoCommit; + if ($commit) $this->BeginTrans(); + $rs = ADODB_oci8::Execute($sql,$arr); + if ($rez = !empty($rs)) $desc->save($val); + $desc->free(); + if ($commit) $this->CommitTrans(); + if ($this->session_sharing_force_blob) $this->Execute('ALTER SESSION SET CURSOR_SHARING=FORCE'); + + if ($rez) $rs->Close(); + return $rez; + } + + /** + * Usage: store file pointed to by $var in a blob + */ + function UpdateBlobFile($table,$column,$val,$where,$blobtype='BLOB') + { + switch(strtoupper($blobtype)) { + default: ADOConnection::outp( "UpdateBlob: Unknown blobtype=$blobtype"); return false; + case 'BLOB': $type = OCI_B_BLOB; break; + case 'CLOB': $type = OCI_B_CLOB; break; + } + + if ($this->databaseType == 'oci8po') + $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO ?"; + else + $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO :blob"; + + $desc = OCINewDescriptor($this->_connectionID, OCI_D_LOB); + $arr['blob'] = array($desc,-1,$type); + + $this->BeginTrans(); + $rs = ADODB_oci8::Execute($sql,$arr); + if ($rez = !empty($rs)) $desc->savefile($val); + $desc->free(); + $this->CommitTrans(); + + if ($rez) $rs->Close(); + return $rez; + } + + + /* + Example of usage: + + $stmt = $this->Prepare('insert into emp (empno, ename) values (:empno, :ename)'); + */ + function Prepare($sql,$cursor=false) + { + static $BINDNUM = 0; + + $stmt = OCIParse($this->_connectionID,$sql); + + if (!$stmt) return false; + + $BINDNUM += 1; + + if (@OCIStatementType($stmt) == 'BEGIN') { + return array($sql,$stmt,0,$BINDNUM, ($cursor) ? OCINewCursor($this->_connectionID) : false); + } + + return array($sql,$stmt,0,$BINDNUM); + } + + /* + Call an oracle stored procedure and return a cursor variable. + Convert the cursor variable into a recordset. + Concept by Robert Tuttle robert@ud.com + + Example: + Note: we return a cursor variable in :RS2 + $rs = $db->ExecuteCursor("BEGIN adodb.open_tab(:RS2); END;",'RS2'); + + $rs = $db->ExecuteCursor( + "BEGIN :RS2 = adodb.getdata(:VAR1); END;", + 'RS2', + array('VAR1' => 'Mr Bean')); + + */ + function &ExecuteCursor($sql,$cursorName='rs',$params=false) + { + $stmt = ADODB_oci8::Prepare($sql,true); # true to allocate OCINewCursor + + if (is_array($stmt) && sizeof($stmt) >= 5) { + $this->Parameter($stmt, $ignoreCur, $cursorName, false, -1, OCI_B_CURSOR); + if ($params) { + foreach($params as $k => $v) { + $this->Parameter($stmt,$params[$k], $k); + } + } + } + return $this->Execute($stmt); + } + + /* + Bind a variable -- very, very fast for executing repeated statements in oracle. + Better than using + for ($i = 0; $i < $max; $i++) { + $p1 = ?; $p2 = ?; $p3 = ?; + $this->Execute("insert into table (col0, col1, col2) values (:0, :1, :2)", + array($p1,$p2,$p3)); + } + + Usage: + $stmt = $DB->Prepare("insert into table (col0, col1, col2) values (:0, :1, :2)"); + $DB->Bind($stmt, $p1); + $DB->Bind($stmt, $p2); + $DB->Bind($stmt, $p3); + for ($i = 0; $i < $max; $i++) { + $p1 = ?; $p2 = ?; $p3 = ?; + $DB->Execute($stmt); + } + + Some timings: + ** Test table has 3 cols, and 1 index. Test to insert 1000 records + Time 0.6081s (1644.60 inserts/sec) with direct OCIParse/OCIExecute + Time 0.6341s (1577.16 inserts/sec) with ADOdb Prepare/Bind/Execute + Time 1.5533s ( 643.77 inserts/sec) with pure SQL using Execute + + Now if PHP only had batch/bulk updating like Java or PL/SQL... + + Note that the order of parameters differs from OCIBindByName, + because we default the names to :0, :1, :2 + */ + function Bind(&$stmt,&$var,$size=4000,$type=false,$name=false) + { + if (!is_array($stmt)) return false; if (($type == OCI_B_CURSOR) && sizeof($stmt) >= 5) { return OCIBindByName($stmt[1],":".$name,$stmt[4],$size,$type); } - if ($name == false) { - if ($type !== false) $rez = OCIBindByName($stmt[1],":".$name,$var,$size,$type); - else $rez = OCIBindByName($stmt[1],":".$stmt[2],$var,$size); // +1 byte for null terminator - $stmt[2] += 1; - } else if ($type == OCI_B_BLOB){ + if ($name == false) { + if ($type !== false) $rez = OCIBindByName($stmt[1],":".$name,$var,$size,$type); + else $rez = OCIBindByName($stmt[1],":".$stmt[2],$var,$size); // +1 byte for null terminator + $stmt[2] += 1; + } else if ($type == OCI_B_BLOB){ //we have to create a new Descriptor here $_blob = OCINewDescriptor($this->_connectionID, OCI_D_LOB); $rez = OCIBindByName($stmt[1], ":".$name, $_blob, -1, OCI_B_BLOB); $rez = $_blob; - } else { - if ($type !== false) $rez = OCIBindByName($stmt[1],":".$name,$var,$size,$type); - else $rez = OCIBindByName($stmt[1],":".$name,$var,$size); // +1 byte for null terminator - } - - return $rez; - } - - function Param($name) - { - return ':'.$name; - } - - /* - Usage: - $stmt = $db->Prepare('select * from table where id =:myid and group=:group'); - $db->Parameter($stmt,$id,'myid'); - $db->Parameter($stmt,$group,'group'); - $db->Execute($stmt); - - @param $stmt Statement returned by Prepare() or PrepareSP(). - @param $var PHP variable to bind to - @param $name Name of stored procedure variable name to bind to. - @param [$isOutput] Indicates direction of parameter 0/false=IN 1=OUT 2= IN/OUT. This is ignored in oci8. - @param [$maxLen] Holds an maximum length of the variable. - @param [$type] The data type of $var. Legal values depend on driver. - - See OCIBindByName documentation at php.net. - */ - function Parameter(&$stmt,&$var,$name,$isOutput=false,$maxLen=4000,$type=false) - { - if ($this->debug) { - $prefix = ($isOutput) ? 'Out' : 'In'; - $ztype = (empty($type)) ? 'false' : $type; - ADOConnection::outp( "{$prefix}Parameter(\$stmt, \$php_var='$var', \$name='$name', \$maxLen=$maxLen, \$type=$ztype);"); - } - return $this->Bind($stmt,$var,$maxLen,$type,$name); - } - - /* - returns query ID if successful, otherwise false - this version supports: - - 1. $db->execute('select * from table'); - - 2. $db->prepare('insert into table (a,b,c) values (:0,:1,:2)'); - $db->execute($prepared_statement, array(1,2,3)); - - 3. $db->execute('insert into table (a,b,c) values (:a,:b,:c)',array('a'=>1,'b'=>2,'c'=>3)); - - 4. $db->prepare('insert into table (a,b,c) values (:0,:1,:2)'); - $db->$bind($stmt,1); $db->bind($stmt,2); $db->bind($stmt,3); - $db->execute($stmt); - */ - function _query($sql,$inputarr) - { - - if (is_array($sql)) { // is prepared sql - $stmt = $sql[1]; - - // we try to bind to permanent array, so that OCIBindByName is persistent - // and carried out once only - note that max array element size is 4000 chars - if (is_array($inputarr)) { - $bindpos = $sql[3]; - if (isset($this->_bind[$bindpos])) { - // all tied up already - $bindarr = &$this->_bind[$bindpos]; - } else { - // one statement to bind them all - $bindarr = array(); - foreach($inputarr as $k => $v) { - $bindarr[$k] = $v; - OCIBindByName($stmt,":$k",$bindarr[$k],4000); - } - $this->_bind[$bindpos] = &$bindarr; - } - } - } else { - $stmt=OCIParse($this->_connectionID,$sql); - } - - $this->_stmt = $stmt; - if (!$stmt) return false; - - if (defined('ADODB_PREFETCH_ROWS')) @OCISetPrefetch($stmt,ADODB_PREFETCH_ROWS); - - if (is_array($inputarr)) { - foreach($inputarr as $k => $v) { - if (is_array($v)) { - if (sizeof($v) == 2) // suggested by g.giunta@libero. - OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1]); - else - OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1],$v[2]); - - if ($this->debug==99) echo "name=:$k",' var='.$inputarr[$k][0],' len='.$v[1],' type='.$v[2],'
'; - } else { - $len = -1; - if ($v === ' ') $len = 1; - if (isset($bindarr)) { // is prepared sql, so no need to ocibindbyname again - $bindarr[$k] = $v; - } else { // dynamic sql, so rebind every time - OCIBindByName($stmt,":$k",$inputarr[$k],$len); - } - } - } - } + } else { + if ($type !== false) $rez = OCIBindByName($stmt[1],":".$name,$var,$size,$type); + else $rez = OCIBindByName($stmt[1],":".$name,$var,$size); // +1 byte for null terminator + } + + return $rez; + } + + function Param($name) + { + return ':'.$name; + } + + /* + Usage: + $stmt = $db->Prepare('select * from table where id =:myid and group=:group'); + $db->Parameter($stmt,$id,'myid'); + $db->Parameter($stmt,$group,'group'); + $db->Execute($stmt); + + @param $stmt Statement returned by Prepare() or PrepareSP(). + @param $var PHP variable to bind to + @param $name Name of stored procedure variable name to bind to. + @param [$isOutput] Indicates direction of parameter 0/false=IN 1=OUT 2= IN/OUT. This is ignored in oci8. + @param [$maxLen] Holds an maximum length of the variable. + @param [$type] The data type of $var. Legal values depend on driver. + + See OCIBindByName documentation at php.net. + */ + function Parameter(&$stmt,&$var,$name,$isOutput=false,$maxLen=4000,$type=false) + { + if ($this->debug) { + $prefix = ($isOutput) ? 'Out' : 'In'; + $ztype = (empty($type)) ? 'false' : $type; + ADOConnection::outp( "{$prefix}Parameter(\$stmt, \$php_var='$var', \$name='$name', \$maxLen=$maxLen, \$type=$ztype);"); + } + return $this->Bind($stmt,$var,$maxLen,$type,$name); + } + + /* + returns query ID if successful, otherwise false + this version supports: + + 1. $db->execute('select * from table'); + + 2. $db->prepare('insert into table (a,b,c) values (:0,:1,:2)'); + $db->execute($prepared_statement, array(1,2,3)); + + 3. $db->execute('insert into table (a,b,c) values (:a,:b,:c)',array('a'=>1,'b'=>2,'c'=>3)); + + 4. $db->prepare('insert into table (a,b,c) values (:0,:1,:2)'); + $db->$bind($stmt,1); $db->bind($stmt,2); $db->bind($stmt,3); + $db->execute($stmt); + */ + function _query($sql,$inputarr) + { + + if (is_array($sql)) { // is prepared sql + $stmt = $sql[1]; + + // we try to bind to permanent array, so that OCIBindByName is persistent + // and carried out once only - note that max array element size is 4000 chars + if (is_array($inputarr)) { + $bindpos = $sql[3]; + if (isset($this->_bind[$bindpos])) { + // all tied up already + $bindarr = &$this->_bind[$bindpos]; + } else { + // one statement to bind them all + $bindarr = array(); + foreach($inputarr as $k => $v) { + $bindarr[$k] = $v; + OCIBindByName($stmt,":$k",$bindarr[$k],4000); + } + $this->_bind[$bindpos] = &$bindarr; + } + } + } else { + $stmt=OCIParse($this->_connectionID,$sql); + } + + $this->_stmt = $stmt; + if (!$stmt) return false; + + if (defined('ADODB_PREFETCH_ROWS')) @OCISetPrefetch($stmt,ADODB_PREFETCH_ROWS); + + if (is_array($inputarr)) { + foreach($inputarr as $k => $v) { + if (is_array($v)) { + if (sizeof($v) == 2) // suggested by g.giunta@libero. + OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1]); + else + OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1],$v[2]); + + if ($this->debug==99) echo "name=:$k",' var='.$inputarr[$k][0],' len='.$v[1],' type='.$v[2],'
'; + } else { + $len = -1; + if ($v === ' ') $len = 1; + if (isset($bindarr)) { // is prepared sql, so no need to ocibindbyname again + $bindarr[$k] = $v; + } else { // dynamic sql, so rebind every time + OCIBindByName($stmt,":$k",$inputarr[$k],$len); + } + } + } + } $this->_errorMsg = false; - $this->_errorCode = false; - if (OCIExecute($stmt,$this->_commit)) { + $this->_errorCode = false; + if (OCIExecute($stmt,$this->_commit)) { switch (@OCIStatementType($stmt)) { case "SELECT": - return $stmt; + return $stmt; case "BEGIN": if (is_array($sql) && !empty($sql[4])) { - $cursor = $sql[4]; - if (is_resource($cursor)) { - $ok = OCIExecute($cursor); - return $cursor; - } - return $stmt; + $cursor = $sql[4]; + if (is_resource($cursor)) { + $ok = OCIExecute($cursor); + return $cursor; + } + return $stmt; } else { - if (is_resource($stmt)) { - OCIFreeStatement($stmt); - return true; - } + if (is_resource($stmt)) { + OCIFreeStatement($stmt); + return true; + } return $stmt; } break; default : - // ociclose -- no because it could be used in a LOB? + // ociclose -- no because it could be used in a LOB? return true; } - } - return false; - } - - // returns true or false - function _close() - { - if (!$this->autoCommit) OCIRollback($this->_connectionID); - OCILogoff($this->_connectionID); - $this->_stmt = false; - $this->_connectionID = false; - } - - function MetaPrimaryKeys($table, $owner=false,$internalKey=false) - { - if ($internalKey) return array('ROWID'); - - // tested with oracle 8.1.7 - $table = strtoupper($table); - if ($owner) { - $owner_clause = "AND ((a.OWNER = b.OWNER) AND (a.OWNER = UPPER('$owner')))"; - $ptab = 'ALL_'; - } else { - $owner_clause = ''; - $ptab = 'USER_'; - } - $sql = " + } + return false; + } + + // returns true or false + function _close() + { + if (!$this->autoCommit) OCIRollback($this->_connectionID); + OCILogoff($this->_connectionID); + $this->_stmt = false; + $this->_connectionID = false; + } + + function MetaPrimaryKeys($table, $owner=false,$internalKey=false) + { + if ($internalKey) return array('ROWID'); + + // tested with oracle 8.1.7 + $table = strtoupper($table); + if ($owner) { + $owner_clause = "AND ((a.OWNER = b.OWNER) AND (a.OWNER = UPPER('$owner')))"; + $ptab = 'ALL_'; + } else { + $owner_clause = ''; + $ptab = 'USER_'; + } + $sql = " SELECT /*+ RULE */ distinct b.column_name FROM {$ptab}CONSTRAINTS a - , {$ptab}CONS_COLUMNS b + , {$ptab}CONS_COLUMNS b WHERE ( UPPER(b.table_name) = ('$table')) - AND (UPPER(a.table_name) = ('$table') and a.constraint_type = 'P') - $owner_clause - AND (a.constraint_name = b.constraint_name)"; - - $rs = $this->Execute($sql); - if ($rs && !$rs->EOF) { - $arr =& $rs->GetArray(); - $a = array(); - foreach($arr as $v) { - $a[] = reset($v); - } - return $a; - } - else return false; - } - - // http://gis.mit.edu/classes/11.521/sqlnotes/referential_integrity.html - function MetaForeignKeys($table, $owner=false) - { - global $ADODB_FETCH_MODE; - - $save = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - $table = $this->qstr(strtoupper($table)); - if (!$owner) { - $owner = $this->user; - $tabp = 'user_'; - } else - $tabp = 'all_'; - - $owner = ' and owner='.$this->qstr(strtoupper($owner)); - - $sql = + AND (UPPER(a.table_name) = ('$table') and a.constraint_type = 'P') + $owner_clause + AND (a.constraint_name = b.constraint_name)"; + + $rs = $this->Execute($sql); + if ($rs && !$rs->EOF) { + $arr =& $rs->GetArray(); + $a = array(); + foreach($arr as $v) { + $a[] = reset($v); + } + return $a; + } + else return false; + } + + // http://gis.mit.edu/classes/11.521/sqlnotes/referential_integrity.html + function MetaForeignKeys($table, $owner=false) + { + global $ADODB_FETCH_MODE; + + $save = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + $table = $this->qstr(strtoupper($table)); + if (!$owner) { + $owner = $this->user; + $tabp = 'user_'; + } else + $tabp = 'all_'; + + $owner = ' and owner='.$this->qstr(strtoupper($owner)); + + $sql = "select constraint_name,r_owner,r_constraint_name - from {$tabp}constraints - where constraint_type = 'R' and table_name = $table $owner"; - - $constraints =& $this->GetArray($sql); - $arr = false; - foreach($constraints as $constr) { - $cons = $this->qstr($constr[0]); - $rowner = $this->qstr($constr[1]); - $rcons = $this->qstr($constr[2]); - $cols = $this->GetArray("select column_name from {$tabp}cons_columns where constraint_name=$cons $owner order by position"); - $tabcol = $this->GetArray("select table_name,column_name from {$tabp}cons_columns where owner=$rowner and constraint_name=$rcons order by position"); - - if ($cols && $tabcol) - for ($i=0, $max=sizeof($cols); $i < $max; $i++) { - $arr[$tabcol[$i][0]] = $cols[$i][0].'='.$tabcol[$i][1]; - } - } - $ADODB_FETCH_MODE = $save; - - return $arr; - } - - - function CharMax() - { - return 4000; - } - - function TextMax() - { - return 4000; - } - - /** - * Quotes a string. - * An example is $db->qstr("Don't bother",magic_quotes_runtime()); - * - * @param s the string to quote - * @param [magic_quotes] if $s is GET/POST var, set to get_magic_quotes_gpc(). - * This undoes the stupidity of magic quotes for GPC. - * - * @return quoted string to be sent back to database - */ - function qstr($s,$magic_quotes=false) - { - $nofixquotes=false; - - if (is_array($s)) adodb_backtrace(); - if ($this->noNullStrings && strlen($s)==0)$s = ' '; - if (!$magic_quotes) { - if ($this->replaceQuote[0] == '\\'){ - $s = str_replace('\\','\\\\',$s); - } - return "'".str_replace("'",$this->replaceQuote,$s)."'"; - } - - // undo magic quotes for " - $s = str_replace('\\"','"',$s); - - if ($this->replaceQuote == "\\'") // ' already quoted, no need to change anything - return "'$s'"; - else {// change \' to '' for sybase/mssql - $s = str_replace('\\\\','\\',$s); - return "'".str_replace("\\'",$this->replaceQuote,$s)."'"; - } - } + from {$tabp}constraints + where constraint_type = 'R' and table_name = $table $owner"; + + $constraints =& $this->GetArray($sql); + $arr = false; + foreach($constraints as $constr) { + $cons = $this->qstr($constr[0]); + $rowner = $this->qstr($constr[1]); + $rcons = $this->qstr($constr[2]); + $cols = $this->GetArray("select column_name from {$tabp}cons_columns where constraint_name=$cons $owner order by position"); + $tabcol = $this->GetArray("select table_name,column_name from {$tabp}cons_columns where owner=$rowner and constraint_name=$rcons order by position"); + + if ($cols && $tabcol) + for ($i=0, $max=sizeof($cols); $i < $max; $i++) { + $arr[$tabcol[$i][0]] = $cols[$i][0].'='.$tabcol[$i][1]; + } + } + $ADODB_FETCH_MODE = $save; + + return $arr; + } + + + function CharMax() + { + return 4000; + } + + function TextMax() + { + return 4000; + } + + /** + * Quotes a string. + * An example is $db->qstr("Don't bother",magic_quotes_runtime()); + * + * @param s the string to quote + * @param [magic_quotes] if $s is GET/POST var, set to get_magic_quotes_gpc(). + * This undoes the stupidity of magic quotes for GPC. + * + * @return quoted string to be sent back to database + */ + function qstr($s,$magic_quotes=false) + { + $nofixquotes=false; + + if (is_array($s)) adodb_backtrace(); + if ($this->noNullStrings && strlen($s)==0)$s = ' '; + if (!$magic_quotes) { + if ($this->replaceQuote[0] == '\\'){ + $s = str_replace('\\','\\\\',$s); + } + return "'".str_replace("'",$this->replaceQuote,$s)."'"; + } + + // undo magic quotes for " + $s = str_replace('\\"','"',$s); + + if ($this->replaceQuote == "\\'") // ' already quoted, no need to change anything + return "'$s'"; + else {// change \' to '' for sybase/mssql + $s = str_replace('\\\\','\\',$s); + return "'".str_replace("\\'",$this->replaceQuote,$s)."'"; + } + } } /*-------------------------------------------------------------------------------------- - Class Name: Recordset + Class Name: Recordset --------------------------------------------------------------------------------------*/ class ADORecordset_oci8 extends ADORecordSet { - var $databaseType = 'oci8'; - var $bind=false; - var $_fieldobjs; - //var $_arr = false; - - function ADORecordset_oci8($queryID,$mode=false) - { - if ($mode === false) { - global $ADODB_FETCH_MODE; - $mode = $ADODB_FETCH_MODE; - } - switch ($mode) - { - default: - case ADODB_FETCH_NUM: $this->fetchMode = OCI_NUM+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; - case ADODB_FETCH_ASSOC:$this->fetchMode = OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; - case ADODB_FETCH_DEFAULT: - case ADODB_FETCH_BOTH:$this->fetchMode = OCI_NUM+OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; - } - - $this->_queryID = $queryID; - } - - - function Init() - { - if ($this->_inited) return; - - $this->_inited = true; - if ($this->_queryID) { - - $this->_currentRow = 0; - @$this->_initrs(); - $this->EOF = !$this->_fetch(); - - /* - // based on idea by Gaetano Giunta to detect unusual oracle errors - // see http://phplens.com/lens/lensforum/msgs.php?id=6771 - $err = OCIError($this->_queryID); - if ($err && $this->connection->debug) ADOConnection::outp($err); - */ - - if (!is_array($this->fields)) { - $this->_numOfRows = 0; - $this->fields = array(); - } - } else { - $this->fields = array(); - $this->_numOfRows = 0; - $this->_numOfFields = 0; - $this->EOF = true; - } - } - - function _initrs() - { - $this->_numOfRows = -1; - $this->_numOfFields = OCInumcols($this->_queryID); - if ($this->_numOfFields>0) { - $this->_fieldobjs = array(); - $max = $this->_numOfFields; - for ($i=0;$i<$max; $i++) $this->_fieldobjs[] = $this->_FetchField($i); - } - } - - /* Returns: an object containing field information. - Get column information in the Recordset object. fetchField() can be used in order to obtain information about - fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by - fetchField() is retrieved. */ - - function &_FetchField($fieldOffset = -1) - { - $fld = new ADOFieldObject; - $fieldOffset += 1; - $fld->name =OCIcolumnname($this->_queryID, $fieldOffset); - $fld->type = OCIcolumntype($this->_queryID, $fieldOffset); - $fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset); - if ($fld->type == 'NUMBER') { - $p = OCIColumnPrecision($this->_queryID, $fieldOffset); - $sc = OCIColumnScale($this->_queryID, $fieldOffset); - if ($p != 0 && $sc == 0) $fld->type = 'INT'; - //echo " $this->name ($p.$sc) "; - } - return $fld; - } - - /* For some reason, OCIcolumnname fails when called after _initrs() so we cache it */ - function &FetchField($fieldOffset = -1) - { - return $this->_fieldobjs[$fieldOffset]; - } - - - // 10% speedup to move MoveNext to child class - function MoveNext() - { - //global $ADODB_EXTENSION;if ($ADODB_EXTENSION) return @adodb_movenext($this); - - if ($this->EOF) return false; - - $this->_currentRow++; - if(@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) - return true; - $this->EOF = true; - - return false; - } - - /* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */ - function &GetArrayLimit($nrows,$offset=-1) - { - if ($offset <= 0) { - $arr =& $this->GetArray($nrows); - return $arr; - } - for ($i=1; $i < $offset; $i++) - if (!@OCIFetch($this->_queryID)) return array(); - - if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) return array(); - $results = array(); - $cnt = 0; - while (!$this->EOF && $nrows != $cnt) { - $results[$cnt++] = $this->fields; - $this->MoveNext(); - } - - return $results; - } - - - /* Use associative array to get fields array */ - function Fields($colname) - { - if (!$this->bind) { - $this->bind = array(); - for ($i=0; $i < $this->_numOfFields; $i++) { - $o = $this->FetchField($i); - $this->bind[strtoupper($o->name)] = $i; - } - } - - return $this->fields[$this->bind[strtoupper($colname)]]; - } - - - - function _seek($row) - { - return false; - } - - function _fetch() - { - return @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode); - } - - /* close() only needs to be called if you are worried about using too much memory while your script - is running. All associated result memory for the specified result identifier will automatically be freed. */ - - function _close() - { - if ($this->connection->_stmt === $this->_queryID) $this->connection->_stmt = false; - OCIFreeStatement($this->_queryID); - $this->_queryID = false; - - } - - function MetaType($t,$len=-1) - { - if (is_object($t)) { - $fieldobj = $t; - $t = $fieldobj->type; - $len = $fieldobj->max_length; - } - switch (strtoupper($t)) { - case 'VARCHAR': - case 'VARCHAR2': - case 'CHAR': - case 'VARBINARY': - case 'BINARY': - case 'NCHAR': - case 'NVARCHAR': - case 'NVARCHAR2': - if (isset($this) && $len <= $this->blobSize) return 'C'; - - case 'NCLOB': - case 'LONG': - case 'LONG VARCHAR': - case 'CLOB': - return 'X'; - - case 'LONG RAW': - case 'LONG VARBINARY': - case 'BLOB': - return 'B'; - - case 'DATE': - return ($this->connection->datetime) ? 'T' : 'D'; - - - case 'TIMESTAMP': return 'T'; - - case 'INT': - case 'SMALLINT': - case 'INTEGER': - return 'I'; - - default: return 'N'; - } - } + var $databaseType = 'oci8'; + var $bind=false; + var $_fieldobjs; + //var $_arr = false; + + function ADORecordset_oci8($queryID,$mode=false) + { + if ($mode === false) { + global $ADODB_FETCH_MODE; + $mode = $ADODB_FETCH_MODE; + } + switch ($mode) + { + default: + case ADODB_FETCH_NUM: $this->fetchMode = OCI_NUM+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; + case ADODB_FETCH_ASSOC:$this->fetchMode = OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; + case ADODB_FETCH_DEFAULT: + case ADODB_FETCH_BOTH:$this->fetchMode = OCI_NUM+OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; + } + + $this->_queryID = $queryID; + } + + + function Init() + { + if ($this->_inited) return; + + $this->_inited = true; + if ($this->_queryID) { + + $this->_currentRow = 0; + @$this->_initrs(); + $this->EOF = !$this->_fetch(); + + /* + // based on idea by Gaetano Giunta to detect unusual oracle errors + // see http://phplens.com/lens/lensforum/msgs.php?id=6771 + $err = OCIError($this->_queryID); + if ($err && $this->connection->debug) ADOConnection::outp($err); + */ + + if (!is_array($this->fields)) { + $this->_numOfRows = 0; + $this->fields = array(); + } + } else { + $this->fields = array(); + $this->_numOfRows = 0; + $this->_numOfFields = 0; + $this->EOF = true; + } + } + + function _initrs() + { + $this->_numOfRows = -1; + $this->_numOfFields = OCInumcols($this->_queryID); + if ($this->_numOfFields>0) { + $this->_fieldobjs = array(); + $max = $this->_numOfFields; + for ($i=0;$i<$max; $i++) $this->_fieldobjs[] = $this->_FetchField($i); + } + } + + /* Returns: an object containing field information. + Get column information in the Recordset object. fetchField() can be used in order to obtain information about + fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by + fetchField() is retrieved. */ + + function &_FetchField($fieldOffset = -1) + { + $fld = new ADOFieldObject; + $fieldOffset += 1; + $fld->name =OCIcolumnname($this->_queryID, $fieldOffset); + $fld->type = OCIcolumntype($this->_queryID, $fieldOffset); + $fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset); + if ($fld->type == 'NUMBER') { + $p = OCIColumnPrecision($this->_queryID, $fieldOffset); + $sc = OCIColumnScale($this->_queryID, $fieldOffset); + if ($p != 0 && $sc == 0) $fld->type = 'INT'; + //echo " $this->name ($p.$sc) "; + } + return $fld; + } + + /* For some reason, OCIcolumnname fails when called after _initrs() so we cache it */ + function &FetchField($fieldOffset = -1) + { + return $this->_fieldobjs[$fieldOffset]; + } + + + // 10% speedup to move MoveNext to child class + function MoveNext() + { + //global $ADODB_EXTENSION;if ($ADODB_EXTENSION) return @adodb_movenext($this); + + if ($this->EOF) return false; + + $this->_currentRow++; + if(@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) + return true; + $this->EOF = true; + + return false; + } + + /* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */ + function &GetArrayLimit($nrows,$offset=-1) + { + if ($offset <= 0) { + $arr =& $this->GetArray($nrows); + return $arr; + } + for ($i=1; $i < $offset; $i++) + if (!@OCIFetch($this->_queryID)) return array(); + + if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) return array(); + $results = array(); + $cnt = 0; + while (!$this->EOF && $nrows != $cnt) { + $results[$cnt++] = $this->fields; + $this->MoveNext(); + } + + return $results; + } + + + /* Use associative array to get fields array */ + function Fields($colname) + { + if (!$this->bind) { + $this->bind = array(); + for ($i=0; $i < $this->_numOfFields; $i++) { + $o = $this->FetchField($i); + $this->bind[strtoupper($o->name)] = $i; + } + } + + return $this->fields[$this->bind[strtoupper($colname)]]; + } + + + + function _seek($row) + { + return false; + } + + function _fetch() + { + return @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode); + } + + /* close() only needs to be called if you are worried about using too much memory while your script + is running. All associated result memory for the specified result identifier will automatically be freed. */ + + function _close() + { + if ($this->connection->_stmt === $this->_queryID) $this->connection->_stmt = false; + OCIFreeStatement($this->_queryID); + $this->_queryID = false; + + } + + function MetaType($t,$len=-1) + { + if (is_object($t)) { + $fieldobj = $t; + $t = $fieldobj->type; + $len = $fieldobj->max_length; + } + switch (strtoupper($t)) { + case 'VARCHAR': + case 'VARCHAR2': + case 'CHAR': + case 'VARBINARY': + case 'BINARY': + case 'NCHAR': + case 'NVARCHAR': + case 'NVARCHAR2': + if (isset($this) && $len <= $this->blobSize) return 'C'; + + case 'NCLOB': + case 'LONG': + case 'LONG VARCHAR': + case 'CLOB': + return 'X'; + + case 'LONG RAW': + case 'LONG VARBINARY': + case 'BLOB': + return 'B'; + + case 'DATE': + return ($this->connection->datetime) ? 'T' : 'D'; + + + case 'TIMESTAMP': return 'T'; + + case 'INT': + case 'SMALLINT': + case 'INTEGER': + return 'I'; + + default: return 'N'; + } + } } ?> diff --git a/lib/WikiDB/adodb/drivers/adodb-oci805.inc.php b/lib/WikiDB/adodb/drivers/adodb-oci805.inc.php index 08ff26801..48da9ad31 100644 --- a/lib/WikiDB/adodb/drivers/adodb-oci805.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-oci805.inc.php @@ -15,42 +15,42 @@ include_once(ADODB_DIR.'/drivers/adodb-oci8.inc.php'); class ADODB_oci805 extends ADODB_oci8 { - var $databaseType = "oci805"; - var $connectSID = true; + var $databaseType = "oci805"; + var $connectSID = true; - function ADODB_oci805() - { - $this->ADODB_oci8(); - } + function ADODB_oci805() + { + $this->ADODB_oci8(); + } - function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) - { - // seems that oracle only supports 1 hint comment in 8i - if (strpos($sql,'/*+') !== false) - $sql = str_replace('/*+ ','/*+FIRST_ROWS ',$sql); - else - $sql = preg_replace('/^[ \t\n]*select/i','SELECT /*+FIRST_ROWS*/',$sql); + function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) + { + // seems that oracle only supports 1 hint comment in 8i + if (strpos($sql,'/*+') !== false) + $sql = str_replace('/*+ ','/*+FIRST_ROWS ',$sql); + else + $sql = preg_replace('/^[ \t\n]*select/i','SELECT /*+FIRST_ROWS*/',$sql); - /* - The following is only available from 8.1.5 because order by in inline views not - available before then... - http://www.jlcomp.demon.co.uk/faq/top_sql.html - if ($nrows > 0) { - if ($offset > 0) $nrows += $offset; - $sql = "select * from ($sql) where rownum <= $nrows"; - $nrows = -1; - } - */ + /* + The following is only available from 8.1.5 because order by in inline views not + available before then... + http://www.jlcomp.demon.co.uk/faq/top_sql.html + if ($nrows > 0) { + if ($offset > 0) $nrows += $offset; + $sql = "select * from ($sql) where rownum <= $nrows"; + $nrows = -1; + } + */ - return ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); - } + return ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); + } } class ADORecordset_oci805 extends ADORecordset_oci8 { - var $databaseType = "oci805"; - function ADORecordset_oci805($id,$mode=false) - { - $this->ADORecordset_oci8($id,$mode); - } + var $databaseType = "oci805"; + function ADORecordset_oci805($id,$mode=false) + { + $this->ADORecordset_oci8($id,$mode); + } } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/drivers/adodb-oci8po.inc.php b/lib/WikiDB/adodb/drivers/adodb-oci8po.inc.php index 9d7e356df..520cdf506 100644 --- a/lib/WikiDB/adodb/drivers/adodb-oci8po.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-oci8po.inc.php @@ -20,171 +20,171 @@ V4.22 15 Apr 2004 (c) 2000-2004 John Lim. All rights reserved. include_once(ADODB_DIR.'/drivers/adodb-oci8.inc.php'); class ADODB_oci8po extends ADODB_oci8 { - var $databaseType = 'oci8po'; - var $dataProvider = 'oci8'; - var $metaColumnsSQL = "select lower(cname),coltype,width, SCALE, PRECISION, NULLS, DEFAULTVAL from col where tname='%s' order by colno"; //changed by smondino@users.sourceforge. net - var $metaTablesSQL = "select lower(table_name),table_type from cat where table_type in ('TABLE','VIEW')"; - - function ADODB_oci8po() - { - $this->ADODB_oci8(); - } - - function Param($name) - { - return '?'; - } - - function Prepare($sql,$cursor=false) - { - $sqlarr = explode('?',$sql); - $sql = $sqlarr[0]; - for ($i = 1, $max = sizeof($sqlarr); $i < $max; $i++) { - $sql .= ':'.($i-1) . $sqlarr[$i]; - } - return ADODB_oci8::Prepare($sql,$cursor); - } - - // emulate handling of parameters ? ?, replacing with :bind0 :bind1 - function _query($sql,$inputarr) - { - if (is_array($inputarr)) { - $i = 0; - if (is_array($sql)) { - foreach($inputarr as $v) { - $arr['bind'.$i++] = $v; - } - } else { - $sqlarr = explode('?',$sql); - $sql = $sqlarr[0]; - foreach($inputarr as $k => $v) { - $sql .= ":$k" . $sqlarr[++$i]; - } - } - } - return ADODB_oci8::_query($sql,$inputarr); - } + var $databaseType = 'oci8po'; + var $dataProvider = 'oci8'; + var $metaColumnsSQL = "select lower(cname),coltype,width, SCALE, PRECISION, NULLS, DEFAULTVAL from col where tname='%s' order by colno"; //changed by smondino@users.sourceforge. net + var $metaTablesSQL = "select lower(table_name),table_type from cat where table_type in ('TABLE','VIEW')"; + + function ADODB_oci8po() + { + $this->ADODB_oci8(); + } + + function Param($name) + { + return '?'; + } + + function Prepare($sql,$cursor=false) + { + $sqlarr = explode('?',$sql); + $sql = $sqlarr[0]; + for ($i = 1, $max = sizeof($sqlarr); $i < $max; $i++) { + $sql .= ':'.($i-1) . $sqlarr[$i]; + } + return ADODB_oci8::Prepare($sql,$cursor); + } + + // emulate handling of parameters ? ?, replacing with :bind0 :bind1 + function _query($sql,$inputarr) + { + if (is_array($inputarr)) { + $i = 0; + if (is_array($sql)) { + foreach($inputarr as $v) { + $arr['bind'.$i++] = $v; + } + } else { + $sqlarr = explode('?',$sql); + $sql = $sqlarr[0]; + foreach($inputarr as $k => $v) { + $sql .= ":$k" . $sqlarr[++$i]; + } + } + } + return ADODB_oci8::_query($sql,$inputarr); + } } /*-------------------------------------------------------------------------------------- - Class Name: Recordset + Class Name: Recordset --------------------------------------------------------------------------------------*/ class ADORecordset_oci8po extends ADORecordset_oci8 { - var $databaseType = 'oci8po'; - - function ADORecordset_oci8po($queryID,$mode=false) - { - $this->ADORecordset_oci8($queryID,$mode); - } - - function Fields($colname) - { - if ($this->fetchMode & OCI_ASSOC) return $this->fields[$colname]; - - if (!$this->bind) { - $this->bind = array(); - for ($i=0; $i < $this->_numOfFields; $i++) { - $o = $this->FetchField($i); - $this->bind[strtoupper($o->name)] = $i; - } - } - return $this->fields[$this->bind[strtoupper($colname)]]; - } - - // lowercase field names... - function &_FetchField($fieldOffset = -1) - { - $fld = new ADOFieldObject; - $fieldOffset += 1; - $fld->name = strtolower(OCIcolumnname($this->_queryID, $fieldOffset)); - $fld->type = OCIcolumntype($this->_queryID, $fieldOffset); - $fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset); - if ($fld->type == 'NUMBER') { - //$p = OCIColumnPrecision($this->_queryID, $fieldOffset); - $sc = OCIColumnScale($this->_queryID, $fieldOffset); - if ($sc == 0) $fld->type = 'INT'; - } - return $fld; - } - - // 10% speedup to move MoveNext to child class - function MoveNext() - { - - if (!$this->EOF) { - $this->_currentRow++; - if(@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) { - global $ADODB_ANSI_PADDING_OFF; - - if ($this->fetchMode & OCI_ASSOC) $this->_updatefields(); - if (!empty($ADODB_ANSI_PADDING_OFF)) { - foreach($this->fields as $k => $v) { - if (is_string($v)) $this->fields[$k] = rtrim($v); - } - } - return true; - } - $this->EOF = true; - } - return false; - } - - /* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */ - function &GetArrayLimit($nrows,$offset=-1) - { - if ($offset <= 0) return $this->GetArray($nrows); - for ($i=1; $i < $offset; $i++) - if (!@OCIFetch($this->_queryID)) return array(); - - if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) return array(); - if ($this->fetchMode & OCI_ASSOC) $this->_updatefields(); - $results = array(); - $cnt = 0; - while (!$this->EOF && $nrows != $cnt) { - $results[$cnt++] = $this->fields; - $this->MoveNext(); - } - - return $results; - } - - // Create associative array - function _updatefields() - { - if (ADODB_ASSOC_CASE == 2) return; // native - - $arr = array(); - $lowercase = (ADODB_ASSOC_CASE == 0); - - foreach($this->fields as $k => $v) { - if (is_integer($k)) $arr[$k] = $v; - else { - if ($lowercase) - $arr[strtolower($k)] = $v; - else - $arr[strtoupper($k)] = $v; - } - } - $this->fields = $arr; - } - - function _fetch() - { - $ret = @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode); - if ($ret) { - global $ADODB_ANSI_PADDING_OFF; - - if ($this->fetchMode & OCI_ASSOC) $this->_updatefields(); - if (!empty($ADODB_ANSI_PADDING_OFF)) { - foreach($this->fields as $k => $v) { - if (is_string($v)) $this->fields[$k] = rtrim($v); - } - } - } - return $ret; - } + var $databaseType = 'oci8po'; + + function ADORecordset_oci8po($queryID,$mode=false) + { + $this->ADORecordset_oci8($queryID,$mode); + } + + function Fields($colname) + { + if ($this->fetchMode & OCI_ASSOC) return $this->fields[$colname]; + + if (!$this->bind) { + $this->bind = array(); + for ($i=0; $i < $this->_numOfFields; $i++) { + $o = $this->FetchField($i); + $this->bind[strtoupper($o->name)] = $i; + } + } + return $this->fields[$this->bind[strtoupper($colname)]]; + } + + // lowercase field names... + function &_FetchField($fieldOffset = -1) + { + $fld = new ADOFieldObject; + $fieldOffset += 1; + $fld->name = strtolower(OCIcolumnname($this->_queryID, $fieldOffset)); + $fld->type = OCIcolumntype($this->_queryID, $fieldOffset); + $fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset); + if ($fld->type == 'NUMBER') { + //$p = OCIColumnPrecision($this->_queryID, $fieldOffset); + $sc = OCIColumnScale($this->_queryID, $fieldOffset); + if ($sc == 0) $fld->type = 'INT'; + } + return $fld; + } + + // 10% speedup to move MoveNext to child class + function MoveNext() + { + + if (!$this->EOF) { + $this->_currentRow++; + if(@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) { + global $ADODB_ANSI_PADDING_OFF; + + if ($this->fetchMode & OCI_ASSOC) $this->_updatefields(); + if (!empty($ADODB_ANSI_PADDING_OFF)) { + foreach($this->fields as $k => $v) { + if (is_string($v)) $this->fields[$k] = rtrim($v); + } + } + return true; + } + $this->EOF = true; + } + return false; + } + + /* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */ + function &GetArrayLimit($nrows,$offset=-1) + { + if ($offset <= 0) return $this->GetArray($nrows); + for ($i=1; $i < $offset; $i++) + if (!@OCIFetch($this->_queryID)) return array(); + + if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) return array(); + if ($this->fetchMode & OCI_ASSOC) $this->_updatefields(); + $results = array(); + $cnt = 0; + while (!$this->EOF && $nrows != $cnt) { + $results[$cnt++] = $this->fields; + $this->MoveNext(); + } + + return $results; + } + + // Create associative array + function _updatefields() + { + if (ADODB_ASSOC_CASE == 2) return; // native + + $arr = array(); + $lowercase = (ADODB_ASSOC_CASE == 0); + + foreach($this->fields as $k => $v) { + if (is_integer($k)) $arr[$k] = $v; + else { + if ($lowercase) + $arr[strtolower($k)] = $v; + else + $arr[strtoupper($k)] = $v; + } + } + $this->fields = $arr; + } + + function _fetch() + { + $ret = @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode); + if ($ret) { + global $ADODB_ANSI_PADDING_OFF; + + if ($this->fetchMode & OCI_ASSOC) $this->_updatefields(); + if (!empty($ADODB_ANSI_PADDING_OFF)) { + foreach($this->fields as $k => $v) { + if (is_string($v)) $this->fields[$k] = rtrim($v); + } + } + } + return $ret; + } } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/drivers/adodb-odbc.inc.php b/lib/WikiDB/adodb/drivers/adodb-odbc.inc.php index b78d532bc..72a6dbedd 100644 --- a/lib/WikiDB/adodb/drivers/adodb-odbc.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-odbc.inc.php @@ -17,278 +17,278 @@ Set tabs to 4 for best viewing. class ADODB_odbc extends ADOConnection { - var $databaseType = "odbc"; - var $fmtDate = "'Y-m-d'"; - var $fmtTimeStamp = "'Y-m-d, h:i:sA'"; - var $replaceQuote = "''"; // string to use to replace quotes - var $dataProvider = "odbc"; - var $hasAffectedRows = true; - var $binmode = ODBC_BINMODE_RETURN; - var $useFetchArray = false; // setting this to true will make array elements in FETCH_ASSOC mode case-sensitive - // breaking backward-compat - //var $longreadlen = 8000; // default number of chars to return for a Blob/Long field - var $_bindInputArray = false; - var $curmode = SQL_CUR_USE_DRIVER; // See sqlext.h, SQL_CUR_DEFAULT == SQL_CUR_USE_DRIVER == 2L - var $_genSeqSQL = "create table %s (id integer)"; - var $_autocommit = true; - var $_haserrorfunctions = true; - var $_has_stupid_odbc_fetch_api_change = true; - var $_lastAffectedRows = 0; - - function ADODB_odbc() - { - $this->_haserrorfunctions = ADODB_PHPVER >= 0x4050; - $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200; - } - - function ServerInfo() - { - - if (!empty($this->host) && ADODB_PHPVER >= 0x4300) { - $dsn = strtoupper($this->host); - $first = true; - $found = false; - - if (!function_exists('odbc_data_source')) return false; - - while(true) { - - $rez = odbc_data_source($this->_connectionID, - $first ? SQL_FETCH_FIRST : SQL_FETCH_NEXT); - $first = false; - if (!is_array($rez)) break; - if (strtoupper($rez['server']) == $dsn) { - $found = true; - break; - } - } - if (!$found) return ADOConnection::ServerInfo(); - if (!isset($rez['version'])) $rez['version'] = ''; - return $rez; - } else { - return ADOConnection::ServerInfo(); - } - } - - - function CreateSequence($seqname='adodbseq',$start=1) - { - if (empty($this->_genSeqSQL)) return false; - $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname)); - if (!$ok) return false; - $start -= 1; - return $this->Execute("insert into $seqname values($start)"); - } - - var $_dropSeqSQL = 'drop table %s'; - function DropSequence($seqname) - { - if (empty($this->_dropSeqSQL)) return false; - return $this->Execute(sprintf($this->_dropSeqSQL,$seqname)); - } - - /* - This algorithm is not very efficient, but works even if table locking - is not available. - - Will return false if unable to generate an ID after $MAXLOOPS attempts. - */ - function GenID($seq='adodbseq',$start=1) - { - // if you have to modify the parameter below, your database is overloaded, - // or you need to implement generation of id's yourself! - $MAXLOOPS = 100; - //$this->debug=1; - while (--$MAXLOOPS>=0) { - $num = $this->GetOne("select id from $seq"); - if ($num === false) { - $this->Execute(sprintf($this->_genSeqSQL ,$seq)); - $start -= 1; - $num = '0'; - $ok = $this->Execute("insert into $seq values($start)"); - if (!$ok) return false; - } - $this->Execute("update $seq set id=id+1 where id=$num"); - - if ($this->affected_rows() > 0) { - $num += 1; - $this->genID = $num; - return $num; - } - } - if ($fn = $this->raiseErrorFn) { - $fn($this->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts",$seq,$num); - } - return false; - } - - - function ErrorMsg() - { - if ($this->_haserrorfunctions) { - if ($this->_errorMsg !== false) return $this->_errorMsg; - if (empty($this->_connectionID)) return @odbc_errormsg(); - return @odbc_errormsg($this->_connectionID); - } else return ADOConnection::ErrorMsg(); - } - - function ErrorNo() - { - - if ($this->_haserrorfunctions) { - if ($this->_errorCode !== false) { - // bug in 4.0.6, error number can be corrupted string (should be 6 digits) - return (strlen($this->_errorCode)<=2) ? 0 : $this->_errorCode; - } - - if (empty($this->_connectionID)) $e = @odbc_error(); - else $e = @odbc_error($this->_connectionID); - - // bug in 4.0.6, error number can be corrupted string (should be 6 digits) - // so we check and patch - if (strlen($e)<=2) return 0; - return $e; - } else return ADOConnection::ErrorNo(); - } - - - // returns true or false - function _connect($argDSN, $argUsername, $argPassword, $argDatabasename) - { - global $php_errormsg; - - if (!function_exists('odbc_connect')) return false; - - if ($this->debug && $argDatabasename && $this->databaseType != 'vfp') { - ADOConnection::outp("For odbc Connect(), $argDatabasename is not used. Place dsn in 1st parameter."); - } - $php_errormsg = ''; - if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword); - else $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword,$this->curmode); - $this->_errorMsg = $php_errormsg; - if (isset($this->connectStmt)) $this->Execute($this->connectStmt); - - //if ($this->_connectionID) odbc_autocommit($this->_connectionID,true); - return $this->_connectionID != false; - } - - // returns true or false - function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename) - { - global $php_errormsg; - - if (!function_exists('odbc_connect')) return false; - - $php_errormsg = ''; - if ($this->debug && $argDatabasename) { - ADOConnection::outp("For odbc PConnect(), $argDatabasename is not used. Place dsn in 1st parameter."); - } - // print "dsn=$argDSN u=$argUsername p=$argPassword
"; flush(); - if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword); - else $this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword,$this->curmode); - - $this->_errorMsg = $php_errormsg; - if ($this->_connectionID && $this->autoRollback) @odbc_rollback($this->_connectionID); - if (isset($this->connectStmt)) $this->Execute($this->connectStmt); - - return $this->_connectionID != false; - } - - function BeginTrans() - { - if (!$this->hasTransactions) return false; - if ($this->transOff) return true; - $this->transCnt += 1; - $this->_autocommit = false; - return odbc_autocommit($this->_connectionID,false); - } - - function CommitTrans($ok=true) - { - if ($this->transOff) return true; - if (!$ok) return $this->RollbackTrans(); - if ($this->transCnt) $this->transCnt -= 1; - $this->_autocommit = true; - $ret = odbc_commit($this->_connectionID); - odbc_autocommit($this->_connectionID,true); - return $ret; - } - - function RollbackTrans() - { - if ($this->transOff) return true; - if ($this->transCnt) $this->transCnt -= 1; - $this->_autocommit = true; - $ret = odbc_rollback($this->_connectionID); - odbc_autocommit($this->_connectionID,true); - return $ret; - } - - function MetaPrimaryKeys($table) - { - global $ADODB_FETCH_MODE; - - $savem = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - $qid = @odbc_primarykeys($this->_connectionID,'','',$table); - - if (!$qid) { - $ADODB_FETCH_MODE = $savem; - return false; - } - $rs = new ADORecordSet_odbc($qid); - $ADODB_FETCH_MODE = $savem; - - if (!$rs) return false; - $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; - - $arr =& $rs->GetArray(); - $rs->Close(); - //print_r($arr); - $arr2 = array(); - for ($i=0; $i < sizeof($arr); $i++) { - if ($arr[$i][3]) $arr2[] = $arr[$i][3]; - } - return $arr2; - } - - - - function &MetaTables($ttype=false) - { - global $ADODB_FETCH_MODE; - - $savem = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - $qid = odbc_tables($this->_connectionID); - - $rs = new ADORecordSet_odbc($qid); - - $ADODB_FETCH_MODE = $savem; - if (!$rs) return false; - - $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; - - $arr =& $rs->GetArray(); - //print_r($arr); - - $rs->Close(); - $arr2 = array(); - - if ($ttype) { - $isview = strncmp($ttype,'V',1) === 0; - } - for ($i=0; $i < sizeof($arr); $i++) { - if (!$arr[$i][2]) continue; - $type = $arr[$i][3]; - if ($ttype) { - if ($isview) { - if (strncmp($type,'V',1) === 0) $arr2[] = $arr[$i][2]; - } else if (strncmp($type,'SYS',3) !== 0) $arr2[] = $arr[$i][2]; - } else if (strncmp($type,'SYS',3) !== 0) $arr2[] = $arr[$i][2]; - } - return $arr2; - } + var $databaseType = "odbc"; + var $fmtDate = "'Y-m-d'"; + var $fmtTimeStamp = "'Y-m-d, h:i:sA'"; + var $replaceQuote = "''"; // string to use to replace quotes + var $dataProvider = "odbc"; + var $hasAffectedRows = true; + var $binmode = ODBC_BINMODE_RETURN; + var $useFetchArray = false; // setting this to true will make array elements in FETCH_ASSOC mode case-sensitive + // breaking backward-compat + //var $longreadlen = 8000; // default number of chars to return for a Blob/Long field + var $_bindInputArray = false; + var $curmode = SQL_CUR_USE_DRIVER; // See sqlext.h, SQL_CUR_DEFAULT == SQL_CUR_USE_DRIVER == 2L + var $_genSeqSQL = "create table %s (id integer)"; + var $_autocommit = true; + var $_haserrorfunctions = true; + var $_has_stupid_odbc_fetch_api_change = true; + var $_lastAffectedRows = 0; + + function ADODB_odbc() + { + $this->_haserrorfunctions = ADODB_PHPVER >= 0x4050; + $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200; + } + + function ServerInfo() + { + + if (!empty($this->host) && ADODB_PHPVER >= 0x4300) { + $dsn = strtoupper($this->host); + $first = true; + $found = false; + + if (!function_exists('odbc_data_source')) return false; + + while(true) { + + $rez = odbc_data_source($this->_connectionID, + $first ? SQL_FETCH_FIRST : SQL_FETCH_NEXT); + $first = false; + if (!is_array($rez)) break; + if (strtoupper($rez['server']) == $dsn) { + $found = true; + break; + } + } + if (!$found) return ADOConnection::ServerInfo(); + if (!isset($rez['version'])) $rez['version'] = ''; + return $rez; + } else { + return ADOConnection::ServerInfo(); + } + } + + + function CreateSequence($seqname='adodbseq',$start=1) + { + if (empty($this->_genSeqSQL)) return false; + $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname)); + if (!$ok) return false; + $start -= 1; + return $this->Execute("insert into $seqname values($start)"); + } + + var $_dropSeqSQL = 'drop table %s'; + function DropSequence($seqname) + { + if (empty($this->_dropSeqSQL)) return false; + return $this->Execute(sprintf($this->_dropSeqSQL,$seqname)); + } + + /* + This algorithm is not very efficient, but works even if table locking + is not available. + + Will return false if unable to generate an ID after $MAXLOOPS attempts. + */ + function GenID($seq='adodbseq',$start=1) + { + // if you have to modify the parameter below, your database is overloaded, + // or you need to implement generation of id's yourself! + $MAXLOOPS = 100; + //$this->debug=1; + while (--$MAXLOOPS>=0) { + $num = $this->GetOne("select id from $seq"); + if ($num === false) { + $this->Execute(sprintf($this->_genSeqSQL ,$seq)); + $start -= 1; + $num = '0'; + $ok = $this->Execute("insert into $seq values($start)"); + if (!$ok) return false; + } + $this->Execute("update $seq set id=id+1 where id=$num"); + + if ($this->affected_rows() > 0) { + $num += 1; + $this->genID = $num; + return $num; + } + } + if ($fn = $this->raiseErrorFn) { + $fn($this->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts",$seq,$num); + } + return false; + } + + + function ErrorMsg() + { + if ($this->_haserrorfunctions) { + if ($this->_errorMsg !== false) return $this->_errorMsg; + if (empty($this->_connectionID)) return @odbc_errormsg(); + return @odbc_errormsg($this->_connectionID); + } else return ADOConnection::ErrorMsg(); + } + + function ErrorNo() + { + + if ($this->_haserrorfunctions) { + if ($this->_errorCode !== false) { + // bug in 4.0.6, error number can be corrupted string (should be 6 digits) + return (strlen($this->_errorCode)<=2) ? 0 : $this->_errorCode; + } + + if (empty($this->_connectionID)) $e = @odbc_error(); + else $e = @odbc_error($this->_connectionID); + + // bug in 4.0.6, error number can be corrupted string (should be 6 digits) + // so we check and patch + if (strlen($e)<=2) return 0; + return $e; + } else return ADOConnection::ErrorNo(); + } + + + // returns true or false + function _connect($argDSN, $argUsername, $argPassword, $argDatabasename) + { + global $php_errormsg; + + if (!function_exists('odbc_connect')) return false; + + if ($this->debug && $argDatabasename && $this->databaseType != 'vfp') { + ADOConnection::outp("For odbc Connect(), $argDatabasename is not used. Place dsn in 1st parameter."); + } + $php_errormsg = ''; + if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword); + else $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword,$this->curmode); + $this->_errorMsg = $php_errormsg; + if (isset($this->connectStmt)) $this->Execute($this->connectStmt); + + //if ($this->_connectionID) odbc_autocommit($this->_connectionID,true); + return $this->_connectionID != false; + } + + // returns true or false + function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename) + { + global $php_errormsg; + + if (!function_exists('odbc_connect')) return false; + + $php_errormsg = ''; + if ($this->debug && $argDatabasename) { + ADOConnection::outp("For odbc PConnect(), $argDatabasename is not used. Place dsn in 1st parameter."); + } + // print "dsn=$argDSN u=$argUsername p=$argPassword
"; flush(); + if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword); + else $this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword,$this->curmode); + + $this->_errorMsg = $php_errormsg; + if ($this->_connectionID && $this->autoRollback) @odbc_rollback($this->_connectionID); + if (isset($this->connectStmt)) $this->Execute($this->connectStmt); + + return $this->_connectionID != false; + } + + function BeginTrans() + { + if (!$this->hasTransactions) return false; + if ($this->transOff) return true; + $this->transCnt += 1; + $this->_autocommit = false; + return odbc_autocommit($this->_connectionID,false); + } + + function CommitTrans($ok=true) + { + if ($this->transOff) return true; + if (!$ok) return $this->RollbackTrans(); + if ($this->transCnt) $this->transCnt -= 1; + $this->_autocommit = true; + $ret = odbc_commit($this->_connectionID); + odbc_autocommit($this->_connectionID,true); + return $ret; + } + + function RollbackTrans() + { + if ($this->transOff) return true; + if ($this->transCnt) $this->transCnt -= 1; + $this->_autocommit = true; + $ret = odbc_rollback($this->_connectionID); + odbc_autocommit($this->_connectionID,true); + return $ret; + } + + function MetaPrimaryKeys($table) + { + global $ADODB_FETCH_MODE; + + $savem = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + $qid = @odbc_primarykeys($this->_connectionID,'','',$table); + + if (!$qid) { + $ADODB_FETCH_MODE = $savem; + return false; + } + $rs = new ADORecordSet_odbc($qid); + $ADODB_FETCH_MODE = $savem; + + if (!$rs) return false; + $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; + + $arr =& $rs->GetArray(); + $rs->Close(); + //print_r($arr); + $arr2 = array(); + for ($i=0; $i < sizeof($arr); $i++) { + if ($arr[$i][3]) $arr2[] = $arr[$i][3]; + } + return $arr2; + } + + + + function &MetaTables($ttype=false) + { + global $ADODB_FETCH_MODE; + + $savem = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + $qid = odbc_tables($this->_connectionID); + + $rs = new ADORecordSet_odbc($qid); + + $ADODB_FETCH_MODE = $savem; + if (!$rs) return false; + + $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; + + $arr =& $rs->GetArray(); + //print_r($arr); + + $rs->Close(); + $arr2 = array(); + + if ($ttype) { + $isview = strncmp($ttype,'V',1) === 0; + } + for ($i=0; $i < sizeof($arr); $i++) { + if (!$arr[$i][2]) continue; + $type = $arr[$i][3]; + if ($ttype) { + if ($isview) { + if (strncmp($type,'V',1) === 0) $arr2[] = $arr[$i][2]; + } else if (strncmp($type,'SYS',3) !== 0) $arr2[] = $arr[$i][2]; + } else if (strncmp($type,'SYS',3) !== 0) $arr2[] = $arr[$i][2]; + } + return $arr2; + } /* / SQL data type codes / @@ -316,394 +316,394 @@ class ADODB_odbc extends ADOConnection { #define SQL_UNICODE_VARCHAR (-96) #define SQL_UNICODE_LONGVARCHAR (-97) */ - function ODBCTypes($t) - { - switch ((integer)$t) { - case 1: - case 12: - case 0: - case -95: - case -96: - return 'C'; - case -97: - case -1: //text - return 'X'; - case -4: //image - return 'B'; - - case 91: - case 11: - return 'D'; - - case 92: - case 93: - case 9: return 'T'; - case 4: - case 5: - case -6: - return 'I'; - - case -11: // uniqidentifier - return 'R'; - case -7: //bit - return 'L'; - - default: - return 'N'; - } - } - - function &MetaColumns($table) - { - global $ADODB_FETCH_MODE; - - $table = strtoupper($table); - $schema = false; - $this->_findschema($table,$schema); - - $savem = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - - if (false) { // after testing, confirmed that the following does not work becoz of a bug - $qid2 = odbc_tables($this->_connectionID); - $rs = new ADORecordSet_odbc($qid2); - $ADODB_FETCH_MODE = $savem; - if (!$rs) return false; - $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; - $rs->_fetch(); - - while (!$rs->EOF) { - if ($table == strtoupper($rs->fields[2])) { - $q = $rs->fields[0]; - $o = $rs->fields[1]; - break; - } - $rs->MoveNext(); - } - $rs->Close(); - - $qid = odbc_columns($this->_connectionID,$q,$o,strtoupper($table),'%'); - } else switch ($this->databaseType) { - case 'access': - case 'vfp': - case 'db2': - $qid = odbc_columns($this->_connectionID); - break; - - default: - $qid = @odbc_columns($this->_connectionID,'%','%',strtoupper($table),'%'); - if (empty($qid)) $qid = odbc_columns($this->_connectionID); - break; - } - if (empty($qid)) return false; - - $rs = new ADORecordSet_odbc($qid); - $ADODB_FETCH_MODE = $savem; - - if (!$rs) return false; - - $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; - $rs->_fetch(); - $retarr = array(); - - /* - $rs->fields indices - 0 TABLE_QUALIFIER - 1 TABLE_SCHEM - 2 TABLE_NAME - 3 COLUMN_NAME - 4 DATA_TYPE - 5 TYPE_NAME - 6 PRECISION - 7 LENGTH - 8 SCALE - 9 RADIX - 10 NULLABLE - 11 REMARKS - */ - while (!$rs->EOF) { - //adodb_pr($rs->fields); - if (strtoupper($rs->fields[2]) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) { - $fld = new ADOFieldObject(); - $fld->name = $rs->fields[3]; - $fld->type = $this->ODBCTypes($rs->fields[4]); - - // ref: http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraccgen/html/msdn_odk.asp - // access uses precision to store length for char/varchar - if ($fld->type == 'C' or $fld->type == 'X') { - if ($this->databaseType == 'access') - $fld->max_length = $rs->fields[6]; - else if ($rs->fields[4] <= -95) // UNICODE - $fld->max_length = $rs->fields[7]/2; - else - $fld->max_length = $rs->fields[7]; - } else - $fld->max_length = $rs->fields[7]; - $fld->not_null = !empty($rs->fields[10]); - $fld->scale = $rs->fields[8]; - $retarr[strtoupper($fld->name)] = $fld; - } else if (sizeof($retarr)>0) - break; - $rs->MoveNext(); - } - $rs->Close(); //-- crashes 4.03pl1 -- why? - - return $retarr; - } - - function Prepare($sql) - { - if (! $this->_bindInputArray) return $sql; // no binding - $stmt = odbc_prepare($this->_connectionID,$sql); - if (!$stmt) { - // we don't know whether odbc driver is parsing prepared stmts, so just return sql - return $sql; - } - return array($sql,$stmt,false); - } - - /* returns queryID or false */ - function _query($sql,$inputarr=false) - { - GLOBAL $php_errormsg; - $php_errormsg = ''; - $this->_error = ''; - - if ($inputarr) { - if (is_array($sql)) { - $stmtid = $sql[1]; - } else { - $stmtid = odbc_prepare($this->_connectionID,$sql); - - if ($stmtid == false) { - $this->_errorMsg = $php_errormsg; - return false; - } - } - - if (! odbc_execute($stmtid,$inputarr)) { - //@odbc_free_result($stmtid); - if ($this->_haserrorfunctions) { - $this->_errorMsg = odbc_errormsg(); - $this->_errorCode = odbc_error(); - } - return false; - } - - } else if (is_array($sql)) { - $stmtid = $sql[1]; - if (!odbc_execute($stmtid)) { - //@odbc_free_result($stmtid); - if ($this->_haserrorfunctions) { - $this->_errorMsg = odbc_errormsg(); - $this->_errorCode = odbc_error(); - } - return false; - } - } else - $stmtid = odbc_exec($this->_connectionID,$sql); - - $this->_lastAffectedRows = 0; - if ($stmtid) { - if (@odbc_num_fields($stmtid) == 0) { - $this->_lastAffectedRows = odbc_num_rows($stmtid); - $stmtid = true; - } else { - $this->_lastAffectedRows = 0; - odbc_binmode($stmtid,$this->binmode); - odbc_longreadlen($stmtid,$this->maxblobsize); - } - - if ($this->_haserrorfunctions) { - $this->_errorMsg = ''; - $this->_errorCode = 0; - } else - $this->_errorMsg = $php_errormsg; - } else { - if ($this->_haserrorfunctions) { - $this->_errorMsg = odbc_errormsg(); - $this->_errorCode = odbc_error(); - } else - $this->_errorMsg = $php_errormsg; - } - return $stmtid; - } - - /* - Insert a null into the blob field of the table first. - Then use UpdateBlob to store the blob. - - Usage: - - $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); - $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); - */ - function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') - { - return $this->Execute("UPDATE $table SET $column=? WHERE $where",array($val)) != false; - } - - // returns true or false - function _close() - { - $ret = @odbc_close($this->_connectionID); - $this->_connectionID = false; - return $ret; - } - - function _affectedrows() - { - return $this->_lastAffectedRows; - } + function ODBCTypes($t) + { + switch ((integer)$t) { + case 1: + case 12: + case 0: + case -95: + case -96: + return 'C'; + case -97: + case -1: //text + return 'X'; + case -4: //image + return 'B'; + + case 91: + case 11: + return 'D'; + + case 92: + case 93: + case 9: return 'T'; + case 4: + case 5: + case -6: + return 'I'; + + case -11: // uniqidentifier + return 'R'; + case -7: //bit + return 'L'; + + default: + return 'N'; + } + } + + function &MetaColumns($table) + { + global $ADODB_FETCH_MODE; + + $table = strtoupper($table); + $schema = false; + $this->_findschema($table,$schema); + + $savem = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + + if (false) { // after testing, confirmed that the following does not work becoz of a bug + $qid2 = odbc_tables($this->_connectionID); + $rs = new ADORecordSet_odbc($qid2); + $ADODB_FETCH_MODE = $savem; + if (!$rs) return false; + $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; + $rs->_fetch(); + + while (!$rs->EOF) { + if ($table == strtoupper($rs->fields[2])) { + $q = $rs->fields[0]; + $o = $rs->fields[1]; + break; + } + $rs->MoveNext(); + } + $rs->Close(); + + $qid = odbc_columns($this->_connectionID,$q,$o,strtoupper($table),'%'); + } else switch ($this->databaseType) { + case 'access': + case 'vfp': + case 'db2': + $qid = odbc_columns($this->_connectionID); + break; + + default: + $qid = @odbc_columns($this->_connectionID,'%','%',strtoupper($table),'%'); + if (empty($qid)) $qid = odbc_columns($this->_connectionID); + break; + } + if (empty($qid)) return false; + + $rs = new ADORecordSet_odbc($qid); + $ADODB_FETCH_MODE = $savem; + + if (!$rs) return false; + + $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change; + $rs->_fetch(); + $retarr = array(); + + /* + $rs->fields indices + 0 TABLE_QUALIFIER + 1 TABLE_SCHEM + 2 TABLE_NAME + 3 COLUMN_NAME + 4 DATA_TYPE + 5 TYPE_NAME + 6 PRECISION + 7 LENGTH + 8 SCALE + 9 RADIX + 10 NULLABLE + 11 REMARKS + */ + while (!$rs->EOF) { + //adodb_pr($rs->fields); + if (strtoupper($rs->fields[2]) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) { + $fld = new ADOFieldObject(); + $fld->name = $rs->fields[3]; + $fld->type = $this->ODBCTypes($rs->fields[4]); + + // ref: http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraccgen/html/msdn_odk.asp + // access uses precision to store length for char/varchar + if ($fld->type == 'C' or $fld->type == 'X') { + if ($this->databaseType == 'access') + $fld->max_length = $rs->fields[6]; + else if ($rs->fields[4] <= -95) // UNICODE + $fld->max_length = $rs->fields[7]/2; + else + $fld->max_length = $rs->fields[7]; + } else + $fld->max_length = $rs->fields[7]; + $fld->not_null = !empty($rs->fields[10]); + $fld->scale = $rs->fields[8]; + $retarr[strtoupper($fld->name)] = $fld; + } else if (sizeof($retarr)>0) + break; + $rs->MoveNext(); + } + $rs->Close(); //-- crashes 4.03pl1 -- why? + + return $retarr; + } + + function Prepare($sql) + { + if (! $this->_bindInputArray) return $sql; // no binding + $stmt = odbc_prepare($this->_connectionID,$sql); + if (!$stmt) { + // we don't know whether odbc driver is parsing prepared stmts, so just return sql + return $sql; + } + return array($sql,$stmt,false); + } + + /* returns queryID or false */ + function _query($sql,$inputarr=false) + { + GLOBAL $php_errormsg; + $php_errormsg = ''; + $this->_error = ''; + + if ($inputarr) { + if (is_array($sql)) { + $stmtid = $sql[1]; + } else { + $stmtid = odbc_prepare($this->_connectionID,$sql); + + if ($stmtid == false) { + $this->_errorMsg = $php_errormsg; + return false; + } + } + + if (! odbc_execute($stmtid,$inputarr)) { + //@odbc_free_result($stmtid); + if ($this->_haserrorfunctions) { + $this->_errorMsg = odbc_errormsg(); + $this->_errorCode = odbc_error(); + } + return false; + } + + } else if (is_array($sql)) { + $stmtid = $sql[1]; + if (!odbc_execute($stmtid)) { + //@odbc_free_result($stmtid); + if ($this->_haserrorfunctions) { + $this->_errorMsg = odbc_errormsg(); + $this->_errorCode = odbc_error(); + } + return false; + } + } else + $stmtid = odbc_exec($this->_connectionID,$sql); + + $this->_lastAffectedRows = 0; + if ($stmtid) { + if (@odbc_num_fields($stmtid) == 0) { + $this->_lastAffectedRows = odbc_num_rows($stmtid); + $stmtid = true; + } else { + $this->_lastAffectedRows = 0; + odbc_binmode($stmtid,$this->binmode); + odbc_longreadlen($stmtid,$this->maxblobsize); + } + + if ($this->_haserrorfunctions) { + $this->_errorMsg = ''; + $this->_errorCode = 0; + } else + $this->_errorMsg = $php_errormsg; + } else { + if ($this->_haserrorfunctions) { + $this->_errorMsg = odbc_errormsg(); + $this->_errorCode = odbc_error(); + } else + $this->_errorMsg = $php_errormsg; + } + return $stmtid; + } + + /* + Insert a null into the blob field of the table first. + Then use UpdateBlob to store the blob. + + Usage: + + $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); + $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); + */ + function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') + { + return $this->Execute("UPDATE $table SET $column=? WHERE $where",array($val)) != false; + } + + // returns true or false + function _close() + { + $ret = @odbc_close($this->_connectionID); + $this->_connectionID = false; + return $ret; + } + + function _affectedrows() + { + return $this->_lastAffectedRows; + } } /*-------------------------------------------------------------------------------------- - Class Name: Recordset + Class Name: Recordset --------------------------------------------------------------------------------------*/ class ADORecordSet_odbc extends ADORecordSet { - var $bind = false; - var $databaseType = "odbc"; - var $dataProvider = "odbc"; - var $useFetchArray; - var $_has_stupid_odbc_fetch_api_change; - - function ADORecordSet_odbc($id,$mode=false) - { - if ($mode === false) { - global $ADODB_FETCH_MODE; - $mode = $ADODB_FETCH_MODE; - } - $this->fetchMode = $mode; - - $this->_queryID = $id; - - // the following is required for mysql odbc driver in 4.3.1 -- why? - $this->EOF = false; - $this->_currentRow = -1; - //$this->ADORecordSet($id); - } - - - // returns the field object - function &FetchField($fieldOffset = -1) - { - - $off=$fieldOffset+1; // offsets begin at 1 - - $o= new ADOFieldObject(); - $o->name = @odbc_field_name($this->_queryID,$off); - $o->type = @odbc_field_type($this->_queryID,$off); - $o->max_length = @odbc_field_len($this->_queryID,$off); - if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name); - else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name); - return $o; - } - - /* Use associative array to get fields array */ - function Fields($colname) - { - if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname]; - if (!$this->bind) { - $this->bind = array(); - for ($i=0; $i < $this->_numOfFields; $i++) { - $o = $this->FetchField($i); - $this->bind[strtoupper($o->name)] = $i; - } - } - - return $this->fields[$this->bind[strtoupper($colname)]]; - } - - - function _initrs() - { - global $ADODB_COUNTRECS; - $this->_numOfRows = ($ADODB_COUNTRECS) ? @odbc_num_rows($this->_queryID) : -1; - $this->_numOfFields = @odbc_num_fields($this->_queryID); - // some silly drivers such as db2 as/400 and intersystems cache return _numOfRows = 0 - if ($this->_numOfRows == 0) $this->_numOfRows = -1; - //$this->useFetchArray = $this->connection->useFetchArray; - $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200; - } - - function _seek($row) - { - return false; - } - - // speed up SelectLimit() by switching to ADODB_FETCH_NUM as ADODB_FETCH_ASSOC is emulated - function &GetArrayLimit($nrows,$offset=-1) - { - if ($offset <= 0) { - $rs =& $this->GetArray($nrows); - return $rs; - } - $savem = $this->fetchMode; - $this->fetchMode = ADODB_FETCH_NUM; - $this->Move($offset); - $this->fetchMode = $savem; - - if ($this->fetchMode & ADODB_FETCH_ASSOC) { - $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE); - } - - $results = array(); - $cnt = 0; - while (!$this->EOF && $nrows != $cnt) { - $results[$cnt++] = $this->fields; - $this->MoveNext(); - } - - return $results; - } - - - function MoveNext() - { - if ($this->_numOfRows != 0 && !$this->EOF) { - $this->_currentRow++; - $row = 0; - if ($this->_has_stupid_odbc_fetch_api_change) - $rez = @odbc_fetch_into($this->_queryID,$this->fields); - else - $rez = @odbc_fetch_into($this->_queryID,$row,$this->fields); - if ($rez) { - if ($this->fetchMode & ADODB_FETCH_ASSOC) { - $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE); - } - return true; - } - } - $this->fields = false; - $this->EOF = true; - return false; - } - - function _fetch() - { - $row = 0; - if ($this->_has_stupid_odbc_fetch_api_change) - $rez = @odbc_fetch_into($this->_queryID,$this->fields,$row); - else - $rez = @odbc_fetch_into($this->_queryID,$row,$this->fields); - - if ($rez) { - if ($this->fetchMode & ADODB_FETCH_ASSOC) { - $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE); - } - return true; - } - $this->fields = false; - return false; - } - - function _close() - { - return @odbc_free_result($this->_queryID); - } + var $bind = false; + var $databaseType = "odbc"; + var $dataProvider = "odbc"; + var $useFetchArray; + var $_has_stupid_odbc_fetch_api_change; + + function ADORecordSet_odbc($id,$mode=false) + { + if ($mode === false) { + global $ADODB_FETCH_MODE; + $mode = $ADODB_FETCH_MODE; + } + $this->fetchMode = $mode; + + $this->_queryID = $id; + + // the following is required for mysql odbc driver in 4.3.1 -- why? + $this->EOF = false; + $this->_currentRow = -1; + //$this->ADORecordSet($id); + } + + + // returns the field object + function &FetchField($fieldOffset = -1) + { + + $off=$fieldOffset+1; // offsets begin at 1 + + $o= new ADOFieldObject(); + $o->name = @odbc_field_name($this->_queryID,$off); + $o->type = @odbc_field_type($this->_queryID,$off); + $o->max_length = @odbc_field_len($this->_queryID,$off); + if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name); + else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name); + return $o; + } + + /* Use associative array to get fields array */ + function Fields($colname) + { + if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname]; + if (!$this->bind) { + $this->bind = array(); + for ($i=0; $i < $this->_numOfFields; $i++) { + $o = $this->FetchField($i); + $this->bind[strtoupper($o->name)] = $i; + } + } + + return $this->fields[$this->bind[strtoupper($colname)]]; + } + + + function _initrs() + { + global $ADODB_COUNTRECS; + $this->_numOfRows = ($ADODB_COUNTRECS) ? @odbc_num_rows($this->_queryID) : -1; + $this->_numOfFields = @odbc_num_fields($this->_queryID); + // some silly drivers such as db2 as/400 and intersystems cache return _numOfRows = 0 + if ($this->_numOfRows == 0) $this->_numOfRows = -1; + //$this->useFetchArray = $this->connection->useFetchArray; + $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200; + } + + function _seek($row) + { + return false; + } + + // speed up SelectLimit() by switching to ADODB_FETCH_NUM as ADODB_FETCH_ASSOC is emulated + function &GetArrayLimit($nrows,$offset=-1) + { + if ($offset <= 0) { + $rs =& $this->GetArray($nrows); + return $rs; + } + $savem = $this->fetchMode; + $this->fetchMode = ADODB_FETCH_NUM; + $this->Move($offset); + $this->fetchMode = $savem; + + if ($this->fetchMode & ADODB_FETCH_ASSOC) { + $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE); + } + + $results = array(); + $cnt = 0; + while (!$this->EOF && $nrows != $cnt) { + $results[$cnt++] = $this->fields; + $this->MoveNext(); + } + + return $results; + } + + + function MoveNext() + { + if ($this->_numOfRows != 0 && !$this->EOF) { + $this->_currentRow++; + $row = 0; + if ($this->_has_stupid_odbc_fetch_api_change) + $rez = @odbc_fetch_into($this->_queryID,$this->fields); + else + $rez = @odbc_fetch_into($this->_queryID,$row,$this->fields); + if ($rez) { + if ($this->fetchMode & ADODB_FETCH_ASSOC) { + $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE); + } + return true; + } + } + $this->fields = false; + $this->EOF = true; + return false; + } + + function _fetch() + { + $row = 0; + if ($this->_has_stupid_odbc_fetch_api_change) + $rez = @odbc_fetch_into($this->_queryID,$this->fields,$row); + else + $rez = @odbc_fetch_into($this->_queryID,$row,$this->fields); + + if ($rez) { + if ($this->fetchMode & ADODB_FETCH_ASSOC) { + $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE); + } + return true; + } + $this->fields = false; + return false; + } + + function _close() + { + return @odbc_free_result($this->_queryID); + } } diff --git a/lib/WikiDB/adodb/drivers/adodb-odbc_mssql.inc.php b/lib/WikiDB/adodb/drivers/adodb-odbc_mssql.inc.php index af4bfc4ea..e81c26b55 100644 --- a/lib/WikiDB/adodb/drivers/adodb-odbc_mssql.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-odbc_mssql.inc.php @@ -13,227 +13,227 @@ Set tabs to 4 for best viewing. */ if (!defined('_ADODB_ODBC_LAYER')) { - include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); + include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); } class ADODB_odbc_mssql extends ADODB_odbc { - var $databaseType = 'odbc_mssql'; - var $fmtDate = "'Y-m-d'"; - var $fmtTimeStamp = "'Y-m-d h:i:sA'"; - var $_bindInputArray = true; - var $metaTablesSQL="select name,case when type='U' then 'T' else 'V' end from sysobjects where (type='U' or type='V') and (name not in ('sysallocations','syscolumns','syscomments','sysdepends','sysfilegroups','sysfiles','sysfiles1','sysforeignkeys','sysfulltextcatalogs','sysindexes','sysindexkeys','sysmembers','sysobjects','syspermissions','sysprotects','sysreferences','systypes','sysusers','sysalternates','sysconstraints','syssegments','REFERENTIAL_CONSTRAINTS','CHECK_CONSTRAINTS','CONSTRAINT_TABLE_USAGE','CONSTRAINT_COLUMN_USAGE','VIEWS','VIEW_TABLE_USAGE','VIEW_COLUMN_USAGE','SCHEMATA','TABLES','TABLE_CONSTRAINTS','TABLE_PRIVILEGES','COLUMNS','COLUMN_DOMAIN_USAGE','COLUMN_PRIVILEGES','DOMAINS','DOMAIN_CONSTRAINTS','KEY_COLUMN_USAGE'))"; - var $metaColumnsSQL = "select c.name,t.name,c.length from syscolumns c join systypes t on t.xusertype=c.xusertype join sysobjects o on o.id=c.id where o.name='%s'"; - var $hasTop = 'top'; // support mssql/interbase SELECT TOP 10 * FROM TABLE - var $sysDate = 'GetDate()'; - var $sysTimeStamp = 'GetDate()'; - var $leftOuter = '*='; - var $rightOuter = '=*'; - var $upperCase = 'upper'; - var $substr = 'substring'; - var $length = 'len'; - var $ansiOuter = true; // for mssql7 or later - var $identitySQL = 'select @@IDENTITY'; // 'select SCOPE_IDENTITY'; # for mssql 2000 - var $hasInsertID = true; - var $connectStmt = 'SET CONCAT_NULL_YIELDS_NULL OFF'; # When SET CONCAT_NULL_YIELDS_NULL is ON, - # concatenating a null value with a string yields a NULL result - - function ADODB_odbc_mssql() - { - $this->ADODB_odbc(); - $this->curmode = SQL_CUR_USE_ODBC; - } - - // crashes php... - function ServerInfo() - { - global $ADODB_FETCH_MODE; - $save = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - $row = $this->GetRow("execute sp_server_info 2"); - $ADODB_FETCH_MODE = $save; - if (!is_array($row)) return false; - $arr['description'] = $row[2]; - $arr['version'] = ADOConnection::_findvers($arr['description']); - return $arr; - } - - function IfNull( $field, $ifNull ) - { - return " ISNULL($field, $ifNull) "; // if MS SQL Server - } - - function _insertid() - { - // SCOPE_IDENTITY() - // Returns the last IDENTITY value inserted into an IDENTITY column in - // the same scope. A scope is a module -- a stored procedure, trigger, - // function, or batch. Thus, two statements are in the same scope if - // they are in the same stored procedure, function, or batch. - return $this->GetOne($this->identitySQL); - } - - - function MetaForeignKeys($table, $owner=false, $upper=false) - { - global $ADODB_FETCH_MODE; - - $save = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - $table = $this->qstr(strtoupper($table)); - - $sql = + var $databaseType = 'odbc_mssql'; + var $fmtDate = "'Y-m-d'"; + var $fmtTimeStamp = "'Y-m-d h:i:sA'"; + var $_bindInputArray = true; + var $metaTablesSQL="select name,case when type='U' then 'T' else 'V' end from sysobjects where (type='U' or type='V') and (name not in ('sysallocations','syscolumns','syscomments','sysdepends','sysfilegroups','sysfiles','sysfiles1','sysforeignkeys','sysfulltextcatalogs','sysindexes','sysindexkeys','sysmembers','sysobjects','syspermissions','sysprotects','sysreferences','systypes','sysusers','sysalternates','sysconstraints','syssegments','REFERENTIAL_CONSTRAINTS','CHECK_CONSTRAINTS','CONSTRAINT_TABLE_USAGE','CONSTRAINT_COLUMN_USAGE','VIEWS','VIEW_TABLE_USAGE','VIEW_COLUMN_USAGE','SCHEMATA','TABLES','TABLE_CONSTRAINTS','TABLE_PRIVILEGES','COLUMNS','COLUMN_DOMAIN_USAGE','COLUMN_PRIVILEGES','DOMAINS','DOMAIN_CONSTRAINTS','KEY_COLUMN_USAGE'))"; + var $metaColumnsSQL = "select c.name,t.name,c.length from syscolumns c join systypes t on t.xusertype=c.xusertype join sysobjects o on o.id=c.id where o.name='%s'"; + var $hasTop = 'top'; // support mssql/interbase SELECT TOP 10 * FROM TABLE + var $sysDate = 'GetDate()'; + var $sysTimeStamp = 'GetDate()'; + var $leftOuter = '*='; + var $rightOuter = '=*'; + var $upperCase = 'upper'; + var $substr = 'substring'; + var $length = 'len'; + var $ansiOuter = true; // for mssql7 or later + var $identitySQL = 'select @@IDENTITY'; // 'select SCOPE_IDENTITY'; # for mssql 2000 + var $hasInsertID = true; + var $connectStmt = 'SET CONCAT_NULL_YIELDS_NULL OFF'; # When SET CONCAT_NULL_YIELDS_NULL is ON, + # concatenating a null value with a string yields a NULL result + + function ADODB_odbc_mssql() + { + $this->ADODB_odbc(); + $this->curmode = SQL_CUR_USE_ODBC; + } + + // crashes php... + function ServerInfo() + { + global $ADODB_FETCH_MODE; + $save = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + $row = $this->GetRow("execute sp_server_info 2"); + $ADODB_FETCH_MODE = $save; + if (!is_array($row)) return false; + $arr['description'] = $row[2]; + $arr['version'] = ADOConnection::_findvers($arr['description']); + return $arr; + } + + function IfNull( $field, $ifNull ) + { + return " ISNULL($field, $ifNull) "; // if MS SQL Server + } + + function _insertid() + { + // SCOPE_IDENTITY() + // Returns the last IDENTITY value inserted into an IDENTITY column in + // the same scope. A scope is a module -- a stored procedure, trigger, + // function, or batch. Thus, two statements are in the same scope if + // they are in the same stored procedure, function, or batch. + return $this->GetOne($this->identitySQL); + } + + + function MetaForeignKeys($table, $owner=false, $upper=false) + { + global $ADODB_FETCH_MODE; + + $save = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + $table = $this->qstr(strtoupper($table)); + + $sql = "select object_name(constid) as constraint_name, - col_name(fkeyid, fkey) as column_name, - object_name(rkeyid) as referenced_table_name, - col_name(rkeyid, rkey) as referenced_column_name + col_name(fkeyid, fkey) as column_name, + object_name(rkeyid) as referenced_table_name, + col_name(rkeyid, rkey) as referenced_column_name from sysforeignkeys where upper(object_name(fkeyid)) = $table order by constraint_name, referenced_table_name, keyno"; - $constraints =& $this->GetArray($sql); - - $ADODB_FETCH_MODE = $save; - - $arr = false; - foreach($constraints as $constr) { - //print_r($constr); - $arr[$constr[0]][$constr[2]][] = $constr[1].'='.$constr[3]; - } - if (!$arr) return false; - - $arr2 = false; - - foreach($arr as $k => $v) { - foreach($v as $a => $b) { - if ($upper) $a = strtoupper($a); - $arr2[$a] = $b; - } - } - return $arr2; - } - - function &MetaTables($ttype=false,$showSchema=false,$mask=false) - { - if ($mask) {$this->debug=1; - $save = $this->metaTablesSQL; - $mask = $this->qstr($mask); - $this->metaTablesSQL .= " AND name like $mask"; - } - $ret =& ADOConnection::MetaTables($ttype,$showSchema); - - if ($mask) { - $this->metaTablesSQL = $save; - } - return $ret; - } - - function &MetaColumns($table) - { - return ADOConnection::MetaColumns($table); - } - - function _query($sql,$inputarr) - { - if (is_string($sql)) $sql = str_replace('||','+',$sql); - return ADODB_odbc::_query($sql,$inputarr); - } - - // "Stein-Aksel Basma" - // tested with MSSQL 2000 - function &MetaPrimaryKeys($table) - { - $sql = "select k.column_name from information_schema.key_column_usage k, - information_schema.table_constraints tc - where tc.constraint_name = k.constraint_name and tc.constraint_type = - 'PRIMARY KEY' and k.table_name = '$table'"; - - $a = $this->GetCol($sql); - if ($a && sizeof($a)>0) return $a; - return false; - } - - function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) - { - if ($nrows > 0 && $offset <= 0) { - $sql = preg_replace( - '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop." $nrows ",$sql); - $rs =& $this->Execute($sql,$inputarr); - } else - $rs =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); - - return $rs; - } - - // Format date column in sql string given an input format that understands Y M D - function SQLDate($fmt, $col=false) - { - if (!$col) $col = $this->sysTimeStamp; - $s = ''; - - $len = strlen($fmt); - for ($i=0; $i < $len; $i++) { - if ($s) $s .= '+'; - $ch = $fmt[$i]; - switch($ch) { - case 'Y': - case 'y': - $s .= "datename(yyyy,$col)"; - break; - case 'M': - $s .= "convert(char(3),$col,0)"; - break; - case 'm': - $s .= "replace(str(month($col),2),' ','0')"; - break; - case 'Q': - case 'q': - $s .= "datename(quarter,$col)"; - break; - case 'D': - case 'd': - $s .= "replace(str(day($col),2),' ','0')"; - break; - case 'h': - $s .= "substring(convert(char(14),$col,0),13,2)"; - break; - - case 'H': - $s .= "replace(str(datepart(hh,$col),2),' ','0')"; - break; - - case 'i': - $s .= "replace(str(datepart(mi,$col),2),' ','0')"; - break; - case 's': - $s .= "replace(str(datepart(ss,$col),2),' ','0')"; - break; - case 'a': - case 'A': - $s .= "substring(convert(char(19),$col,0),18,2)"; - break; - - default: - if ($ch == '\\') { - $i++; - $ch = substr($fmt,$i,1); - } - $s .= $this->qstr($ch); - break; - } - } - return $s; - } + $constraints =& $this->GetArray($sql); + + $ADODB_FETCH_MODE = $save; + + $arr = false; + foreach($constraints as $constr) { + //print_r($constr); + $arr[$constr[0]][$constr[2]][] = $constr[1].'='.$constr[3]; + } + if (!$arr) return false; + + $arr2 = false; + + foreach($arr as $k => $v) { + foreach($v as $a => $b) { + if ($upper) $a = strtoupper($a); + $arr2[$a] = $b; + } + } + return $arr2; + } + + function &MetaTables($ttype=false,$showSchema=false,$mask=false) + { + if ($mask) {$this->debug=1; + $save = $this->metaTablesSQL; + $mask = $this->qstr($mask); + $this->metaTablesSQL .= " AND name like $mask"; + } + $ret =& ADOConnection::MetaTables($ttype,$showSchema); + + if ($mask) { + $this->metaTablesSQL = $save; + } + return $ret; + } + + function &MetaColumns($table) + { + return ADOConnection::MetaColumns($table); + } + + function _query($sql,$inputarr) + { + if (is_string($sql)) $sql = str_replace('||','+',$sql); + return ADODB_odbc::_query($sql,$inputarr); + } + + // "Stein-Aksel Basma" + // tested with MSSQL 2000 + function &MetaPrimaryKeys($table) + { + $sql = "select k.column_name from information_schema.key_column_usage k, + information_schema.table_constraints tc + where tc.constraint_name = k.constraint_name and tc.constraint_type = + 'PRIMARY KEY' and k.table_name = '$table'"; + + $a = $this->GetCol($sql); + if ($a && sizeof($a)>0) return $a; + return false; + } + + function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) + { + if ($nrows > 0 && $offset <= 0) { + $sql = preg_replace( + '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop." $nrows ",$sql); + $rs =& $this->Execute($sql,$inputarr); + } else + $rs =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); + + return $rs; + } + + // Format date column in sql string given an input format that understands Y M D + function SQLDate($fmt, $col=false) + { + if (!$col) $col = $this->sysTimeStamp; + $s = ''; + + $len = strlen($fmt); + for ($i=0; $i < $len; $i++) { + if ($s) $s .= '+'; + $ch = $fmt[$i]; + switch($ch) { + case 'Y': + case 'y': + $s .= "datename(yyyy,$col)"; + break; + case 'M': + $s .= "convert(char(3),$col,0)"; + break; + case 'm': + $s .= "replace(str(month($col),2),' ','0')"; + break; + case 'Q': + case 'q': + $s .= "datename(quarter,$col)"; + break; + case 'D': + case 'd': + $s .= "replace(str(day($col),2),' ','0')"; + break; + case 'h': + $s .= "substring(convert(char(14),$col,0),13,2)"; + break; + + case 'H': + $s .= "replace(str(datepart(hh,$col),2),' ','0')"; + break; + + case 'i': + $s .= "replace(str(datepart(mi,$col),2),' ','0')"; + break; + case 's': + $s .= "replace(str(datepart(ss,$col),2),' ','0')"; + break; + case 'a': + case 'A': + $s .= "substring(convert(char(19),$col,0),18,2)"; + break; + + default: + if ($ch == '\\') { + $i++; + $ch = substr($fmt,$i,1); + } + $s .= $this->qstr($ch); + break; + } + } + return $s; + } } class ADORecordSet_odbc_mssql extends ADORecordSet_odbc { - var $databaseType = 'odbc_mssql'; + var $databaseType = 'odbc_mssql'; - function ADORecordSet_odbc_mssql($id,$mode=false) - { - return $this->ADORecordSet_odbc($id,$mode); - } + function ADORecordSet_odbc_mssql($id,$mode=false) + { + return $this->ADORecordSet_odbc($id,$mode); + } } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/drivers/adodb-odbc_oracle.inc.php b/lib/WikiDB/adodb/drivers/adodb-odbc_oracle.inc.php index 4f71668e3..14d23b1cf 100644 --- a/lib/WikiDB/adodb/drivers/adodb-odbc_oracle.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-odbc_oracle.inc.php @@ -12,104 +12,104 @@ Set tabs to 4 for best viewing. */ if (!defined('_ADODB_ODBC_LAYER')) { - include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); + include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); } class ADODB_odbc_oracle extends ADODB_odbc { - var $databaseType = 'odbc_oracle'; - var $replaceQuote = "''"; // string to use to replace quotes - var $concat_operator='||'; - var $fmtDate = "'Y-m-d 00:00:00'"; - var $fmtTimeStamp = "'Y-m-d h:i:sA'"; - var $metaTablesSQL = 'select table_name from cat'; - var $metaColumnsSQL = "select cname,coltype,width from col where tname='%s' order by colno"; - var $sysDate = "TRUNC(SYSDATE)"; - var $sysTimeStamp = 'SYSDATE'; - - //var $_bindInputArray = false; - - function ADODB_odbc_oracle() - { - $this->ADODB_odbc(); - } - - function &MetaTables() - { - if ($this->metaTablesSQL) { - $rs = $this->Execute($this->metaTablesSQL); - if ($rs === false) return false; - $arr = $rs->GetArray(); - $arr2 = array(); - for ($i=0; $i < sizeof($arr); $i++) { - $arr2[] = $arr[$i][0]; - } - $rs->Close(); - return $arr2; - } - return false; - } - - function &MetaColumns($table) - { - if (!empty($this->metaColumnsSQL)) { - - $rs = $this->Execute(sprintf($this->metaColumnsSQL,strtoupper($table))); - if ($rs === false) return false; - - $retarr = array(); - while (!$rs->EOF) { //print_r($rs->fields); - $fld = new ADOFieldObject(); - $fld->name = $rs->fields[0]; - $fld->type = $rs->fields[1]; - $fld->max_length = $rs->fields[2]; - - - if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld; - else $retarr[strtoupper($fld->name)] = $fld; - - $rs->MoveNext(); - } - $rs->Close(); - return $retarr; - } - return false; - } - - // returns true or false - function _connect($argDSN, $argUsername, $argPassword, $argDatabasename) - { - global $php_errormsg; - - $php_errormsg = ''; - $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword,SQL_CUR_USE_ODBC ); - $this->_errorMsg = $php_errormsg; - - $this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'"); - //if ($this->_connectionID) odbc_autocommit($this->_connectionID,true); - return $this->_connectionID != false; - } - // returns true or false - function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename) - { - global $php_errormsg; - $php_errormsg = ''; - $this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword,SQL_CUR_USE_ODBC ); - $this->_errorMsg = $php_errormsg; - - $this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'"); - //if ($this->_connectionID) odbc_autocommit($this->_connectionID,true); - return $this->_connectionID != false; - } + var $databaseType = 'odbc_oracle'; + var $replaceQuote = "''"; // string to use to replace quotes + var $concat_operator='||'; + var $fmtDate = "'Y-m-d 00:00:00'"; + var $fmtTimeStamp = "'Y-m-d h:i:sA'"; + var $metaTablesSQL = 'select table_name from cat'; + var $metaColumnsSQL = "select cname,coltype,width from col where tname='%s' order by colno"; + var $sysDate = "TRUNC(SYSDATE)"; + var $sysTimeStamp = 'SYSDATE'; + + //var $_bindInputArray = false; + + function ADODB_odbc_oracle() + { + $this->ADODB_odbc(); + } + + function &MetaTables() + { + if ($this->metaTablesSQL) { + $rs = $this->Execute($this->metaTablesSQL); + if ($rs === false) return false; + $arr = $rs->GetArray(); + $arr2 = array(); + for ($i=0; $i < sizeof($arr); $i++) { + $arr2[] = $arr[$i][0]; + } + $rs->Close(); + return $arr2; + } + return false; + } + + function &MetaColumns($table) + { + if (!empty($this->metaColumnsSQL)) { + + $rs = $this->Execute(sprintf($this->metaColumnsSQL,strtoupper($table))); + if ($rs === false) return false; + + $retarr = array(); + while (!$rs->EOF) { //print_r($rs->fields); + $fld = new ADOFieldObject(); + $fld->name = $rs->fields[0]; + $fld->type = $rs->fields[1]; + $fld->max_length = $rs->fields[2]; + + + if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld; + else $retarr[strtoupper($fld->name)] = $fld; + + $rs->MoveNext(); + } + $rs->Close(); + return $retarr; + } + return false; + } + + // returns true or false + function _connect($argDSN, $argUsername, $argPassword, $argDatabasename) + { + global $php_errormsg; + + $php_errormsg = ''; + $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword,SQL_CUR_USE_ODBC ); + $this->_errorMsg = $php_errormsg; + + $this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'"); + //if ($this->_connectionID) odbc_autocommit($this->_connectionID,true); + return $this->_connectionID != false; + } + // returns true or false + function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename) + { + global $php_errormsg; + $php_errormsg = ''; + $this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword,SQL_CUR_USE_ODBC ); + $this->_errorMsg = $php_errormsg; + + $this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'"); + //if ($this->_connectionID) odbc_autocommit($this->_connectionID,true); + return $this->_connectionID != false; + } } class ADORecordSet_odbc_oracle extends ADORecordSet_odbc { - var $databaseType = 'odbc_oracle'; + var $databaseType = 'odbc_oracle'; - function ADORecordSet_odbc_oracle($id,$mode=false) - { - return $this->ADORecordSet_odbc($id,$mode); - } + function ADORecordSet_odbc_oracle($id,$mode=false) + { + return $this->ADORecordSet_odbc($id,$mode); + } } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/drivers/adodb-odbtp.inc.php b/lib/WikiDB/adodb/drivers/adodb-odbtp.inc.php index 0ff01a109..56b630be7 100644 --- a/lib/WikiDB/adodb/drivers/adodb-odbtp.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-odbtp.inc.php @@ -12,617 +12,617 @@ V4.22 15 Apr 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights rese define("_ADODB_ODBTP_LAYER", 2 ); class ADODB_odbtp extends ADOConnection{ - var $databaseType = "odbtp"; - var $dataProvider = "odbtp"; - var $fmtDate = "'Y-m-d'"; - var $fmtTimeStamp = "'Y-m-d, h:i:sA'"; - var $replaceQuote = "''"; // string to use to replace quotes - var $odbc_driver = 0; - var $hasAffectedRows = true; - var $hasInsertID = false; - var $hasGenID = true; - var $hasMoveFirst = true; - - var $_genSeqSQL = "create table %s (seq_name char(30) not null unique , seq_value integer not null)"; - var $_dropSeqSQL = "delete from adodb_seq where seq_name = '%s'"; - var $_autocommit = true; - var $_bindInputArray = false; - var $_useUnicodeSQL = false; - var $_canPrepareSP = false; - - function ADODB_odbtp() - { - } - - function ServerInfo() - { - return array('description' => @odbtp_get_attr( ODB_ATTR_DBMSNAME, $this->_connectionID), - 'version' => @odbtp_get_attr( ODB_ATTR_DBMSVER, $this->_connectionID)); - } - - function ErrorMsg() - { - if (empty($this->_connectionID)) return @odbtp_last_error(); - return @odbtp_last_error($this->_connectionID); - } - - function ErrorNo() - { - if (empty($this->_connectionID)) return @odbtp_last_error_state(); - return @odbtp_last_error_state($this->_connectionID); - } - - function _insertid() - { - // SCOPE_IDENTITY() - // Returns the last IDENTITY value inserted into an IDENTITY column in - // the same scope. A scope is a module -- a stored procedure, trigger, - // function, or batch. Thus, two statements are in the same scope if - // they are in the same stored procedure, function, or batch. - return $this->GetOne($this->identitySQL); - } - - function _affectedrows() - { - if ($this->_queryID) { - return @odbtp_affected_rows ($this->_queryID); - } else - return 0; - } - - function CreateSequence($seqname='adodbseq',$start=1) - { - //verify existence - $num = $this->GetOne("select seq_value from adodb_seq"); - $seqtab='adodb_seq'; - if( $this->odbc_driver == ODB_DRIVER_FOXPRO ) { - $path = @odbtp_get_attr( ODB_ATTR_DATABASENAME, $this->_connectionID ); - //if using vfp dbc file - if( !strcasecmp(strrchr($path, '.'), '.dbc') ) + var $databaseType = "odbtp"; + var $dataProvider = "odbtp"; + var $fmtDate = "'Y-m-d'"; + var $fmtTimeStamp = "'Y-m-d, h:i:sA'"; + var $replaceQuote = "''"; // string to use to replace quotes + var $odbc_driver = 0; + var $hasAffectedRows = true; + var $hasInsertID = false; + var $hasGenID = true; + var $hasMoveFirst = true; + + var $_genSeqSQL = "create table %s (seq_name char(30) not null unique , seq_value integer not null)"; + var $_dropSeqSQL = "delete from adodb_seq where seq_name = '%s'"; + var $_autocommit = true; + var $_bindInputArray = false; + var $_useUnicodeSQL = false; + var $_canPrepareSP = false; + + function ADODB_odbtp() + { + } + + function ServerInfo() + { + return array('description' => @odbtp_get_attr( ODB_ATTR_DBMSNAME, $this->_connectionID), + 'version' => @odbtp_get_attr( ODB_ATTR_DBMSVER, $this->_connectionID)); + } + + function ErrorMsg() + { + if (empty($this->_connectionID)) return @odbtp_last_error(); + return @odbtp_last_error($this->_connectionID); + } + + function ErrorNo() + { + if (empty($this->_connectionID)) return @odbtp_last_error_state(); + return @odbtp_last_error_state($this->_connectionID); + } + + function _insertid() + { + // SCOPE_IDENTITY() + // Returns the last IDENTITY value inserted into an IDENTITY column in + // the same scope. A scope is a module -- a stored procedure, trigger, + // function, or batch. Thus, two statements are in the same scope if + // they are in the same stored procedure, function, or batch. + return $this->GetOne($this->identitySQL); + } + + function _affectedrows() + { + if ($this->_queryID) { + return @odbtp_affected_rows ($this->_queryID); + } else + return 0; + } + + function CreateSequence($seqname='adodbseq',$start=1) + { + //verify existence + $num = $this->GetOne("select seq_value from adodb_seq"); + $seqtab='adodb_seq'; + if( $this->odbc_driver == ODB_DRIVER_FOXPRO ) { + $path = @odbtp_get_attr( ODB_ATTR_DATABASENAME, $this->_connectionID ); + //if using vfp dbc file + if( !strcasecmp(strrchr($path, '.'), '.dbc') ) $path = substr($path,0,strrpos($path,'\/')); - $seqtab = $path . '/' . $seqtab; + $seqtab = $path . '/' . $seqtab; + } + if($num == false) { + if (empty($this->_genSeqSQL)) return false; + $ok = $this->Execute(sprintf($this->_genSeqSQL ,$seqtab)); + } + $num = $this->GetOne("select seq_value from adodb_seq where seq_name='$seqname'"); + if ($num) { + return false; } - if($num == false) { - if (empty($this->_genSeqSQL)) return false; - $ok = $this->Execute(sprintf($this->_genSeqSQL ,$seqtab)); - } - $num = $this->GetOne("select seq_value from adodb_seq where seq_name='$seqname'"); - if ($num) { - return false; - } - $start -= 1; - return $this->Execute("insert into adodb_seq values('$seqname',$start)"); - } - - function DropSequence($seqname) - { - if (empty($this->_dropSeqSQL)) return false; - return $this->Execute(sprintf($this->_dropSeqSQL,$seqname)); - } - - function GenID($seq='adodbseq',$start=1) - { - $seqtab='adodb_seq'; - if( $this->odbc_driver == ODB_DRIVER_FOXPRO ) { - $path = @odbtp_get_attr( ODB_ATTR_DATABASENAME, $this->_connectionID ); - //if using vfp dbc file - if( !strcasecmp(strrchr($path, '.'), '.dbc') ) + $start -= 1; + return $this->Execute("insert into adodb_seq values('$seqname',$start)"); + } + + function DropSequence($seqname) + { + if (empty($this->_dropSeqSQL)) return false; + return $this->Execute(sprintf($this->_dropSeqSQL,$seqname)); + } + + function GenID($seq='adodbseq',$start=1) + { + $seqtab='adodb_seq'; + if( $this->odbc_driver == ODB_DRIVER_FOXPRO ) { + $path = @odbtp_get_attr( ODB_ATTR_DATABASENAME, $this->_connectionID ); + //if using vfp dbc file + if( !strcasecmp(strrchr($path, '.'), '.dbc') ) $path = substr($path,0,strrpos($path,'\/')); - $seqtab = $path . '/' . $seqtab; + $seqtab = $path . '/' . $seqtab; } - $MAXLOOPS = 100; - while (--$MAXLOOPS>=0) { - $num = $this->GetOne("select seq_value from adodb_seq where seq_name='$seq'"); - if ($num === false) { - //verify if abodb_seq table exist - $ok = $this->GetOne("select seq_value from adodb_seq "); - if(!$ok) { - //creating the sequence table adodb_seq - $this->Execute(sprintf($this->_genSeqSQL ,$seqtab)); - } - $start -= 1; - $num = '0'; - $ok = $this->Execute("insert into adodb_seq values('$seq',$start)"); - if (!$ok) return false; - } - $ok = $this->Execute("update adodb_seq set seq_value=seq_value+1 where seq_name='$seq'"); - if($ok) { - $num += 1; - $this->genID = $num; - return $num; - } - } - if ($fn = $this->raiseErrorFn) { - $fn($this->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts",$seq,$num); - } - return false; - } - - //example for $UserOrDSN - //for visual fox : DRIVER={Microsoft Visual FoxPro Driver};SOURCETYPE=DBF;SOURCEDB=c:\YourDbfFileDir;EXCLUSIVE=NO; - //for visual fox dbc: DRIVER={Microsoft Visual FoxPro Driver};SOURCETYPE=DBC;SOURCEDB=c:\YourDbcFileDir\mydb.dbc;EXCLUSIVE=NO; - //for access : DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\path_to_access_db\base_test.mdb;UID=root;PWD=; - //for mssql : DRIVER={SQL Server};SERVER=myserver;UID=myuid;PWD=mypwd;DATABASE=OdbtpTest; - //if uid & pwd can be separate + $MAXLOOPS = 100; + while (--$MAXLOOPS>=0) { + $num = $this->GetOne("select seq_value from adodb_seq where seq_name='$seq'"); + if ($num === false) { + //verify if abodb_seq table exist + $ok = $this->GetOne("select seq_value from adodb_seq "); + if(!$ok) { + //creating the sequence table adodb_seq + $this->Execute(sprintf($this->_genSeqSQL ,$seqtab)); + } + $start -= 1; + $num = '0'; + $ok = $this->Execute("insert into adodb_seq values('$seq',$start)"); + if (!$ok) return false; + } + $ok = $this->Execute("update adodb_seq set seq_value=seq_value+1 where seq_name='$seq'"); + if($ok) { + $num += 1; + $this->genID = $num; + return $num; + } + } + if ($fn = $this->raiseErrorFn) { + $fn($this->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts",$seq,$num); + } + return false; + } + + //example for $UserOrDSN + //for visual fox : DRIVER={Microsoft Visual FoxPro Driver};SOURCETYPE=DBF;SOURCEDB=c:\YourDbfFileDir;EXCLUSIVE=NO; + //for visual fox dbc: DRIVER={Microsoft Visual FoxPro Driver};SOURCETYPE=DBC;SOURCEDB=c:\YourDbcFileDir\mydb.dbc;EXCLUSIVE=NO; + //for access : DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\path_to_access_db\base_test.mdb;UID=root;PWD=; + //for mssql : DRIVER={SQL Server};SERVER=myserver;UID=myuid;PWD=mypwd;DATABASE=OdbtpTest; + //if uid & pwd can be separate function _connect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='') - { - $this->_connectionID = @odbtp_connect($HostOrInterface,$UserOrDSN,$argPassword,$argDatabase); - if ($this->_connectionID === false) - { - $this->_errorMsg = $this->ErrorMsg() ; - return false; - } - $this->odbc_driver = @odbtp_get_attr(ODB_ATTR_DRIVER, $this->_connectionID); - - // Set driver specific attributes - switch( $this->odbc_driver ) { - case ODB_DRIVER_MSSQL: - $this->fmtDate = "'Y-m-d'"; - $this->fmtTimeStamp = "'Y-m-d h:i:sA'"; - $this->sysDate = 'convert(datetime,convert(char,GetDate(),102),102)'; - $this->sysTimeStamp = 'GetDate()'; - $this->ansiOuter = true; - $this->leftOuter = '*='; - $this->rightOuter = '=*'; + { + $this->_connectionID = @odbtp_connect($HostOrInterface,$UserOrDSN,$argPassword,$argDatabase); + if ($this->_connectionID === false) + { + $this->_errorMsg = $this->ErrorMsg() ; + return false; + } + $this->odbc_driver = @odbtp_get_attr(ODB_ATTR_DRIVER, $this->_connectionID); + + // Set driver specific attributes + switch( $this->odbc_driver ) { + case ODB_DRIVER_MSSQL: + $this->fmtDate = "'Y-m-d'"; + $this->fmtTimeStamp = "'Y-m-d h:i:sA'"; + $this->sysDate = 'convert(datetime,convert(char,GetDate(),102),102)'; + $this->sysTimeStamp = 'GetDate()'; + $this->ansiOuter = true; + $this->leftOuter = '*='; + $this->rightOuter = '=*'; $this->hasTop = 'top'; - $this->hasInsertID = true; - $this->hasTransactions = true; - $this->_bindInputArray = true; - $this->_canSelectDb = true; - $this->substr = "substring"; - $this->length = 'len'; - $this->upperCase = 'upper'; - $this->identitySQL = 'select @@IDENTITY'; - $this->metaDatabasesSQL = "select name from master..sysdatabases where name <> 'master'"; - break; - case ODB_DRIVER_JET: - $this->fmtDate = "#Y-m-d#"; - $this->fmtTimeStamp = "#Y-m-d h:i:sA#"; - $this->sysDate = "FORMAT(NOW,'yyyy-mm-dd')"; - $this->sysTimeStamp = 'NOW'; + $this->hasInsertID = true; + $this->hasTransactions = true; + $this->_bindInputArray = true; + $this->_canSelectDb = true; + $this->substr = "substring"; + $this->length = 'len'; + $this->upperCase = 'upper'; + $this->identitySQL = 'select @@IDENTITY'; + $this->metaDatabasesSQL = "select name from master..sysdatabases where name <> 'master'"; + break; + case ODB_DRIVER_JET: + $this->fmtDate = "#Y-m-d#"; + $this->fmtTimeStamp = "#Y-m-d h:i:sA#"; + $this->sysDate = "FORMAT(NOW,'yyyy-mm-dd')"; + $this->sysTimeStamp = 'NOW'; $this->hasTop = 'top'; - $this->hasTransactions = false; - $this->_canPrepareSP = true; // For MS Access only. - - // Can't rebind ODB_CHAR to ODB_WCHAR if row cache enabled. - if ($this->_useUnicodeSQL) - odbtp_use_row_cache($this->_connectionID, FALSE, 0); - break; - case ODB_DRIVER_FOXPRO: - $this->fmtDate = "{^Y-m-d}"; - $this->fmtTimeStamp = "{^Y-m-d, h:i:sA}"; - $this->sysDate = 'date()'; - $this->sysTimeStamp = 'datetime()'; - $this->ansiOuter = true; + $this->hasTransactions = false; + $this->_canPrepareSP = true; // For MS Access only. + + // Can't rebind ODB_CHAR to ODB_WCHAR if row cache enabled. + if ($this->_useUnicodeSQL) + odbtp_use_row_cache($this->_connectionID, FALSE, 0); + break; + case ODB_DRIVER_FOXPRO: + $this->fmtDate = "{^Y-m-d}"; + $this->fmtTimeStamp = "{^Y-m-d, h:i:sA}"; + $this->sysDate = 'date()'; + $this->sysTimeStamp = 'datetime()'; + $this->ansiOuter = true; $this->hasTop = 'top'; - $this->hasTransactions = false; - $this->replaceQuote = "'+chr(39)+'"; - $this->true = '.T.'; - $this->false = '.F.'; - $this->upperCase = 'upper'; - break; - case ODB_DRIVER_ORACLE: - $this->fmtDate = "'Y-m-d 00:00:00'"; - $this->fmtTimeStamp = "'Y-m-d h:i:sA'"; - $this->sysDate = 'TRUNC(SYSDATE)'; - $this->sysTimeStamp = 'SYSDATE'; - $this->hasTransactions = true; - $this->_bindInputArray = true; - $this->concat_operator = '||'; - break; - case ODB_DRIVER_SYBASE: - $this->fmtDate = "'Y-m-d'"; - $this->fmtTimeStamp = "'Y-m-d H:i:s'"; - $this->sysDate = 'GetDate()'; - $this->sysTimeStamp = 'GetDate()'; - $this->leftOuter = '*='; - $this->rightOuter = '=*'; - $this->hasInsertID = true; - $this->hasTransactions = true; - $this->upperCase = 'upper'; - $this->identitySQL = 'select @@IDENTITY'; - break; - default: - if( @odbtp_get_attr(ODB_ATTR_TXNCAPABLE, $this->_connectionID) ) - $this->hasTransactions = true; - else - $this->hasTransactions = false; - } + $this->hasTransactions = false; + $this->replaceQuote = "'+chr(39)+'"; + $this->true = '.T.'; + $this->false = '.F.'; + $this->upperCase = 'upper'; + break; + case ODB_DRIVER_ORACLE: + $this->fmtDate = "'Y-m-d 00:00:00'"; + $this->fmtTimeStamp = "'Y-m-d h:i:sA'"; + $this->sysDate = 'TRUNC(SYSDATE)'; + $this->sysTimeStamp = 'SYSDATE'; + $this->hasTransactions = true; + $this->_bindInputArray = true; + $this->concat_operator = '||'; + break; + case ODB_DRIVER_SYBASE: + $this->fmtDate = "'Y-m-d'"; + $this->fmtTimeStamp = "'Y-m-d H:i:s'"; + $this->sysDate = 'GetDate()'; + $this->sysTimeStamp = 'GetDate()'; + $this->leftOuter = '*='; + $this->rightOuter = '=*'; + $this->hasInsertID = true; + $this->hasTransactions = true; + $this->upperCase = 'upper'; + $this->identitySQL = 'select @@IDENTITY'; + break; + default: + if( @odbtp_get_attr(ODB_ATTR_TXNCAPABLE, $this->_connectionID) ) + $this->hasTransactions = true; + else + $this->hasTransactions = false; + } @odbtp_set_attr(ODB_ATTR_FULLCOLINFO, TRUE, $this->_connectionID ); - if ($this->_useUnicodeSQL ) - @odbtp_set_attr(ODB_ATTR_UNICODESQL, TRUE, $this->_connectionID); + if ($this->_useUnicodeSQL ) + @odbtp_set_attr(ODB_ATTR_UNICODESQL, TRUE, $this->_connectionID); return true; - } - - function _pconnect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='') - { - return $this->_connect($HostOrInterface, $UserOrDSN, $argPassword, $argDatabase); - } - - function SelectDB($dbName) - { - if (!@odbtp_select_db($dbName, $this->_connectionID)) { - return false; - } - $this->databaseName = $dbName; - return true; - } - - function &MetaTables($ttype='',$showSchema=false,$mask=false) - { - global $ADODB_FETCH_MODE; - - $savem = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - $arr =& $this->GetArray("||SQLTables||||$ttype"); - $ADODB_FETCH_MODE = $savem; - - $arr2 = array(); - for ($i=0; $i < sizeof($arr); $i++) { - if ($arr[$i][3] == 'SYSTEM TABLE' ) continue; - if ($arr[$i][2]) - $arr2[] = $showSchema ? $arr[$i][1].'.'.$arr[$i][2] : $arr[$i][2]; - } - return $arr2; - } - - function &MetaColumns($table,$upper=true) - { - global $ADODB_FETCH_MODE; - - $schema = false; - $this->_findschema($table,$schema); - if ($upper) $table = strtoupper($table); - - $savem = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - $rs = $this->Execute( "||SQLColumns||$schema|$table" ); - $ADODB_FETCH_MODE = $savem; - - if (!$rs) return false; - - while (!$rs->EOF) { - //print_r($rs->fields); - if (strtoupper($rs->fields[2]) == $table) { - $fld = new ADOFieldObject(); - $fld->name = $rs->fields[3]; - $fld->type = $rs->fields[5]; - $fld->max_length = $rs->fields[6]; - $fld->not_null = !empty($rs->fields[9]); - $fld->scale = $rs->fields[7]; - if (!is_null($rs->fields[12])) { - $fld->has_default = true; - $fld->default_value = $rs->fields[12]; - } - $retarr[strtoupper($fld->name)] = $fld; - } else if (sizeof($retarr)>0) - break; - $rs->MoveNext(); - } - $rs->Close(); - - return $retarr; - } - - function &MetaPrimaryKeys($table, $owner='') - { - global $ADODB_FETCH_MODE; - - $savem = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - $arr =& $this->GetArray("||SQLPrimaryKeys||$owner|$table"); - $ADODB_FETCH_MODE = $savem; - - //print_r($arr); - $arr2 = array(); - for ($i=0; $i < sizeof($arr); $i++) { - if ($arr[$i][3]) $arr2[] = $arr[$i][3]; - } - return $arr2; - } - - function &MetaForeignKeys($table, $owner='', $upper=false) - { - global $ADODB_FETCH_MODE; - - $savem = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - $constraints =& $this->GetArray("||SQLForeignKeys|||||$owner|$table"); - $ADODB_FETCH_MODE = $savem; - - $arr = false; - foreach($constraints as $constr) { - //print_r($constr); - $arr[$constr[11]][$constr[2]][] = $constr[7].'='.$constr[3]; - } - if (!$arr) return false; - - $arr2 = array(); - - foreach($arr as $k => $v) { - foreach($v as $a => $b) { - if ($upper) $a = strtoupper($a); - $arr2[$a] = $b; - } - } - return $arr2; - } - - function BeginTrans() - { - if (!$this->hasTransactions) return false; - if ($this->transOff) return true; - $this->transCnt += 1; - $this->_autocommit = false; - $rs = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS,ODB_TXN_READUNCOMMITTED,$this->_connectionID); - if(!$rs) return false; - else return true; - } - - function CommitTrans($ok=true) - { - if ($this->transOff) return true; - if (!$ok) return $this->RollbackTrans(); - if ($this->transCnt) $this->transCnt -= 1; - $this->_autocommit = true; - if( ($ret = odbtp_commit($this->_connectionID)) ) - $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off - return $ret; - } - - function RollbackTrans() - { - if ($this->transOff) return true; - if ($this->transCnt) $this->transCnt -= 1; - $this->_autocommit = true; - if( ($ret = odbtp_rollback($this->_connectionID)) ) - $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off - return $ret; - } - - function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) - { - // TOP requires ORDER BY for Visual FoxPro - if( $this->odbc_driver == ODB_DRIVER_FOXPRO ) { - if (!preg_match('/ORDER[ \t\r\n]+BY/is',$sql)) $sql .= ' ORDER BY 1'; - } - return ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); - } - - function Prepare($sql) - { - if (! $this->_bindInputArray) return $sql; // no binding - $stmt = odbtp_prepare($sql,$this->_connectionID); - if (!$stmt) { - // print "Prepare Error for ($sql) ".$this->ErrorMsg()."
"; - return $sql; - } - return array($sql,$stmt,false); - } - - function PrepareSP($sql) - { - if (!$this->_canPrepareSP) return $sql; // Can't prepare procedures - - $stmt = odbtp_prepare_proc($sql,$this->_connectionID); - if (!$stmt) return false; - return array($sql,$stmt); - } - - /* - Usage: - $stmt = $db->PrepareSP('SP_RUNSOMETHING'); -- takes 2 params, @myid and @group - - # note that the parameter does not have @ in front! - $db->Parameter($stmt,$id,'myid'); - $db->Parameter($stmt,$group,'group',false,64); - $db->Parameter($stmt,$group,'photo',false,100000,ODB_BINARY); - $db->Execute($stmt); - - @param $stmt Statement returned by Prepare() or PrepareSP(). - @param $var PHP variable to bind to. Can set to null (for isNull support). - @param $name Name of stored procedure variable name to bind to. - @param [$isOutput] Indicates direction of parameter 0/false=IN 1=OUT 2= IN/OUT. This is ignored in odbtp. - @param [$maxLen] Holds an maximum length of the variable. - @param [$type] The data type of $var. Legal values depend on driver. - - See odbtp_attach_param documentation at http://odbtp.sourceforge.net. - */ - function Parameter(&$stmt, &$var, $name, $isOutput=false, $maxLen=0, $type=0) - { - if ( $this->odbc_driver == ODB_DRIVER_JET ) { - $name = '['.$name.']'; - if( !$type && $this->_useUnicodeSQL - && @odbtp_param_bindtype($stmt[1], $name) == ODB_CHAR ) - { - $type = ODB_WCHAR; - } - } - else { - $name = '@'.$name; - } - return odbtp_attach_param($stmt[1], $name, $var, $type, $maxLen); - } - - /* - Insert a null into the blob field of the table first. - Then use UpdateBlob to store the blob. - - Usage: - - $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); - $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); - */ - - function UpdateBlob($table,$column,$val,$where,$blobtype='image') - { - $sql = "UPDATE $table SET $column = ? WHERE $where"; - if( !($stmt = odbtp_prepare($sql, $this->_connectionID)) ) - return false; - if( !odbtp_input( $stmt, 1, ODB_BINARY, 1000000, $blobtype ) ) - return false; - if( !odbtp_set( $stmt, 1, $val ) ) - return false; - return odbtp_execute( $stmt ) != false; - } - - function IfNull( $field, $ifNull ) - { - switch( $this->odbc_driver ) { - case ODB_DRIVER_MSSQL: - return " ISNULL($field, $ifNull) "; - case ODB_DRIVER_JET: - return " IIF(IsNull($field), $ifNull, $field) "; - } - return " CASE WHEN $field is null THEN $ifNull ELSE $field END "; - } - - function _query($sql,$inputarr=false) - { - if ($inputarr) { - if (is_array($sql)) { - $stmtid = $sql[1]; - } else { - $stmtid = odbtp_prepare($sql,$this->_connectionID); - if ($stmtid == false) { - $this->_errorMsg = $php_errormsg; - return false; - } - } - $num_params = odbtp_num_params( $stmtid ); - for( $param = 1; $param <= $num_params; $param++ ) { - @odbtp_input( $stmtid, $param ); - @odbtp_set( $stmtid, $param, $inputarr[$param-1] ); - } - if (! odbtp_execute($stmtid) ) { - return false; - } - } else if (is_array($sql)) { - $stmtid = $sql[1]; - if (!odbtp_execute($stmtid)) { - return false; - } - } else { - $stmtid = @odbtp_query($sql,$this->_connectionID); - } - $this->_lastAffectedRows = 0; - if ($stmtid) { - $this->_lastAffectedRows = @odbtp_affected_rows($stmtid); - } + } + + function _pconnect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='') + { + return $this->_connect($HostOrInterface, $UserOrDSN, $argPassword, $argDatabase); + } + + function SelectDB($dbName) + { + if (!@odbtp_select_db($dbName, $this->_connectionID)) { + return false; + } + $this->databaseName = $dbName; + return true; + } + + function &MetaTables($ttype='',$showSchema=false,$mask=false) + { + global $ADODB_FETCH_MODE; + + $savem = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + $arr =& $this->GetArray("||SQLTables||||$ttype"); + $ADODB_FETCH_MODE = $savem; + + $arr2 = array(); + for ($i=0; $i < sizeof($arr); $i++) { + if ($arr[$i][3] == 'SYSTEM TABLE' ) continue; + if ($arr[$i][2]) + $arr2[] = $showSchema ? $arr[$i][1].'.'.$arr[$i][2] : $arr[$i][2]; + } + return $arr2; + } + + function &MetaColumns($table,$upper=true) + { + global $ADODB_FETCH_MODE; + + $schema = false; + $this->_findschema($table,$schema); + if ($upper) $table = strtoupper($table); + + $savem = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + $rs = $this->Execute( "||SQLColumns||$schema|$table" ); + $ADODB_FETCH_MODE = $savem; + + if (!$rs) return false; + + while (!$rs->EOF) { + //print_r($rs->fields); + if (strtoupper($rs->fields[2]) == $table) { + $fld = new ADOFieldObject(); + $fld->name = $rs->fields[3]; + $fld->type = $rs->fields[5]; + $fld->max_length = $rs->fields[6]; + $fld->not_null = !empty($rs->fields[9]); + $fld->scale = $rs->fields[7]; + if (!is_null($rs->fields[12])) { + $fld->has_default = true; + $fld->default_value = $rs->fields[12]; + } + $retarr[strtoupper($fld->name)] = $fld; + } else if (sizeof($retarr)>0) + break; + $rs->MoveNext(); + } + $rs->Close(); + + return $retarr; + } + + function &MetaPrimaryKeys($table, $owner='') + { + global $ADODB_FETCH_MODE; + + $savem = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + $arr =& $this->GetArray("||SQLPrimaryKeys||$owner|$table"); + $ADODB_FETCH_MODE = $savem; + + //print_r($arr); + $arr2 = array(); + for ($i=0; $i < sizeof($arr); $i++) { + if ($arr[$i][3]) $arr2[] = $arr[$i][3]; + } + return $arr2; + } + + function &MetaForeignKeys($table, $owner='', $upper=false) + { + global $ADODB_FETCH_MODE; + + $savem = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + $constraints =& $this->GetArray("||SQLForeignKeys|||||$owner|$table"); + $ADODB_FETCH_MODE = $savem; + + $arr = false; + foreach($constraints as $constr) { + //print_r($constr); + $arr[$constr[11]][$constr[2]][] = $constr[7].'='.$constr[3]; + } + if (!$arr) return false; + + $arr2 = array(); + + foreach($arr as $k => $v) { + foreach($v as $a => $b) { + if ($upper) $a = strtoupper($a); + $arr2[$a] = $b; + } + } + return $arr2; + } + + function BeginTrans() + { + if (!$this->hasTransactions) return false; + if ($this->transOff) return true; + $this->transCnt += 1; + $this->_autocommit = false; + $rs = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS,ODB_TXN_READUNCOMMITTED,$this->_connectionID); + if(!$rs) return false; + else return true; + } + + function CommitTrans($ok=true) + { + if ($this->transOff) return true; + if (!$ok) return $this->RollbackTrans(); + if ($this->transCnt) $this->transCnt -= 1; + $this->_autocommit = true; + if( ($ret = odbtp_commit($this->_connectionID)) ) + $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off + return $ret; + } + + function RollbackTrans() + { + if ($this->transOff) return true; + if ($this->transCnt) $this->transCnt -= 1; + $this->_autocommit = true; + if( ($ret = odbtp_rollback($this->_connectionID)) ) + $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off + return $ret; + } + + function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) + { + // TOP requires ORDER BY for Visual FoxPro + if( $this->odbc_driver == ODB_DRIVER_FOXPRO ) { + if (!preg_match('/ORDER[ \t\r\n]+BY/is',$sql)) $sql .= ' ORDER BY 1'; + } + return ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); + } + + function Prepare($sql) + { + if (! $this->_bindInputArray) return $sql; // no binding + $stmt = odbtp_prepare($sql,$this->_connectionID); + if (!$stmt) { + // print "Prepare Error for ($sql) ".$this->ErrorMsg()."
"; + return $sql; + } + return array($sql,$stmt,false); + } + + function PrepareSP($sql) + { + if (!$this->_canPrepareSP) return $sql; // Can't prepare procedures + + $stmt = odbtp_prepare_proc($sql,$this->_connectionID); + if (!$stmt) return false; + return array($sql,$stmt); + } + + /* + Usage: + $stmt = $db->PrepareSP('SP_RUNSOMETHING'); -- takes 2 params, @myid and @group + + # note that the parameter does not have @ in front! + $db->Parameter($stmt,$id,'myid'); + $db->Parameter($stmt,$group,'group',false,64); + $db->Parameter($stmt,$group,'photo',false,100000,ODB_BINARY); + $db->Execute($stmt); + + @param $stmt Statement returned by Prepare() or PrepareSP(). + @param $var PHP variable to bind to. Can set to null (for isNull support). + @param $name Name of stored procedure variable name to bind to. + @param [$isOutput] Indicates direction of parameter 0/false=IN 1=OUT 2= IN/OUT. This is ignored in odbtp. + @param [$maxLen] Holds an maximum length of the variable. + @param [$type] The data type of $var. Legal values depend on driver. + + See odbtp_attach_param documentation at http://odbtp.sourceforge.net. + */ + function Parameter(&$stmt, &$var, $name, $isOutput=false, $maxLen=0, $type=0) + { + if ( $this->odbc_driver == ODB_DRIVER_JET ) { + $name = '['.$name.']'; + if( !$type && $this->_useUnicodeSQL + && @odbtp_param_bindtype($stmt[1], $name) == ODB_CHAR ) + { + $type = ODB_WCHAR; + } + } + else { + $name = '@'.$name; + } + return odbtp_attach_param($stmt[1], $name, $var, $type, $maxLen); + } + + /* + Insert a null into the blob field of the table first. + Then use UpdateBlob to store the blob. + + Usage: + + $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); + $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); + */ + + function UpdateBlob($table,$column,$val,$where,$blobtype='image') + { + $sql = "UPDATE $table SET $column = ? WHERE $where"; + if( !($stmt = odbtp_prepare($sql, $this->_connectionID)) ) + return false; + if( !odbtp_input( $stmt, 1, ODB_BINARY, 1000000, $blobtype ) ) + return false; + if( !odbtp_set( $stmt, 1, $val ) ) + return false; + return odbtp_execute( $stmt ) != false; + } + + function IfNull( $field, $ifNull ) + { + switch( $this->odbc_driver ) { + case ODB_DRIVER_MSSQL: + return " ISNULL($field, $ifNull) "; + case ODB_DRIVER_JET: + return " IIF(IsNull($field), $ifNull, $field) "; + } + return " CASE WHEN $field is null THEN $ifNull ELSE $field END "; + } + + function _query($sql,$inputarr=false) + { + if ($inputarr) { + if (is_array($sql)) { + $stmtid = $sql[1]; + } else { + $stmtid = odbtp_prepare($sql,$this->_connectionID); + if ($stmtid == false) { + $this->_errorMsg = $php_errormsg; + return false; + } + } + $num_params = odbtp_num_params( $stmtid ); + for( $param = 1; $param <= $num_params; $param++ ) { + @odbtp_input( $stmtid, $param ); + @odbtp_set( $stmtid, $param, $inputarr[$param-1] ); + } + if (! odbtp_execute($stmtid) ) { + return false; + } + } else if (is_array($sql)) { + $stmtid = $sql[1]; + if (!odbtp_execute($stmtid)) { + return false; + } + } else { + $stmtid = @odbtp_query($sql,$this->_connectionID); + } + $this->_lastAffectedRows = 0; + if ($stmtid) { + $this->_lastAffectedRows = @odbtp_affected_rows($stmtid); + } return $stmtid; - } - - function _close() - { - $ret = @odbtp_close($this->_connectionID); - $this->_connectionID = false; - return $ret; - } + } + + function _close() + { + $ret = @odbtp_close($this->_connectionID); + $this->_connectionID = false; + return $ret; + } } class ADORecordSet_odbtp extends ADORecordSet { - var $databaseType = 'odbtp'; - var $canSeek = true; - - function ADORecordSet_odbtp($queryID,$mode=false) - { - if ($mode === false) { - global $ADODB_FETCH_MODE; - $mode = $ADODB_FETCH_MODE; - } - $this->fetchMode = $mode; - $this->ADORecordSet($queryID); - } - - function _initrs() - { - $this->_numOfFields = @odbtp_num_fields($this->_queryID); - if (!($this->_numOfRows = @odbtp_num_rows($this->_queryID))) - $this->_numOfRows = -1; - } - - function &FetchField($fieldOffset = 0) - { - $off=$fieldOffset; // offsets begin at 0 - $o= new ADOFieldObject(); - $o->name = @odbtp_field_name($this->_queryID,$off); - $o->type = @odbtp_field_type($this->_queryID,$off); + var $databaseType = 'odbtp'; + var $canSeek = true; + + function ADORecordSet_odbtp($queryID,$mode=false) + { + if ($mode === false) { + global $ADODB_FETCH_MODE; + $mode = $ADODB_FETCH_MODE; + } + $this->fetchMode = $mode; + $this->ADORecordSet($queryID); + } + + function _initrs() + { + $this->_numOfFields = @odbtp_num_fields($this->_queryID); + if (!($this->_numOfRows = @odbtp_num_rows($this->_queryID))) + $this->_numOfRows = -1; + } + + function &FetchField($fieldOffset = 0) + { + $off=$fieldOffset; // offsets begin at 0 + $o= new ADOFieldObject(); + $o->name = @odbtp_field_name($this->_queryID,$off); + $o->type = @odbtp_field_type($this->_queryID,$off); $o->max_length = @odbtp_field_length($this->_queryID,$off); - if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name); - else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name); - return $o; - } - - function _seek($row) - { - return @odbtp_data_seek($this->_queryID, $row); - } - - function fields($colname) - { - if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname]; - - if (!$this->bind) { - $this->bind = array(); - for ($i=0; $i < $this->_numOfFields; $i++) { - $name = @odbtp_field_name( $this->_queryID, $i ); - $this->bind[strtoupper($name)] = $i; - } - } - return $this->fields[$this->bind[strtoupper($colname)]]; - } - - function _fetch_odbtp($type=0) - { - switch ($this->fetchMode) { - case ADODB_FETCH_NUM: - $this->fields = @odbtp_fetch_row($this->_queryID, $type); - break; - case ADODB_FETCH_ASSOC: - $this->fields = @odbtp_fetch_assoc($this->_queryID, $type); - break; + if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name); + else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name); + return $o; + } + + function _seek($row) + { + return @odbtp_data_seek($this->_queryID, $row); + } + + function fields($colname) + { + if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname]; + + if (!$this->bind) { + $this->bind = array(); + for ($i=0; $i < $this->_numOfFields; $i++) { + $name = @odbtp_field_name( $this->_queryID, $i ); + $this->bind[strtoupper($name)] = $i; + } + } + return $this->fields[$this->bind[strtoupper($colname)]]; + } + + function _fetch_odbtp($type=0) + { + switch ($this->fetchMode) { + case ADODB_FETCH_NUM: + $this->fields = @odbtp_fetch_row($this->_queryID, $type); + break; + case ADODB_FETCH_ASSOC: + $this->fields = @odbtp_fetch_assoc($this->_queryID, $type); + break; default: - $this->fields = @odbtp_fetch_array($this->_queryID, $type); - } - return is_array($this->fields); - } + $this->fields = @odbtp_fetch_array($this->_queryID, $type); + } + return is_array($this->fields); + } - function _fetch() - { - return $this->_fetch_odbtp(); - } + function _fetch() + { + return $this->_fetch_odbtp(); + } - function MoveFirst() - { - if (!$this->_fetch_odbtp(ODB_FETCH_FIRST)) return false; - $this->EOF = false; - $this->_currentRow = 0; - return true; + function MoveFirst() + { + if (!$this->_fetch_odbtp(ODB_FETCH_FIRST)) return false; + $this->EOF = false; + $this->_currentRow = 0; + return true; } function MoveLast() { - if (!$this->_fetch_odbtp(ODB_FETCH_LAST)) return false; - $this->EOF = false; - $this->_currentRow = $this->_numOfRows - 1; - return true; - } - - function NextRecordSet() - { - if (!@odbtp_next_result($this->_queryID)) return false; - $this->_inited = false; - $this->bind = false; - $this->_currentRow = -1; - $this->Init(); - return true; - } - - function _close() - { - return @odbtp_free_query($this->_queryID); - } + if (!$this->_fetch_odbtp(ODB_FETCH_LAST)) return false; + $this->EOF = false; + $this->_currentRow = $this->_numOfRows - 1; + return true; + } + + function NextRecordSet() + { + if (!@odbtp_next_result($this->_queryID)) return false; + $this->_inited = false; + $this->bind = false; + $this->_currentRow = -1; + $this->Init(); + return true; + } + + function _close() + { + return @odbtp_free_query($this->_queryID); + } } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/drivers/adodb-odbtp_unicode.inc.php b/lib/WikiDB/adodb/drivers/adodb-odbtp_unicode.inc.php index e9656cb44..3af1d2d0f 100644 --- a/lib/WikiDB/adodb/drivers/adodb-odbtp_unicode.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-odbtp_unicode.inc.php @@ -21,39 +21,39 @@ V4.22 15 Apr 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights rese */ if (!defined('_ADODB_ODBTP_LAYER')) { - include(ADODB_DIR."/drivers/adodb-odbtp.inc.php"); + include(ADODB_DIR."/drivers/adodb-odbtp.inc.php"); } class ADODB_odbtp_unicode extends ADODB_odbtp { - var $databaseType = "odbtp_unicode"; - var $_useUnicodeSQL = true; + var $databaseType = "odbtp_unicode"; + var $_useUnicodeSQL = true; - function ADODB_odbtp_unicode() - { - $this->ADODB_odbtp(); - } + function ADODB_odbtp_unicode() + { + $this->ADODB_odbtp(); + } } class ADORecordSet_odbtp_unicode extends ADORecordSet_odbtp { - var $databaseType = 'odbtp_unicode'; - - function ADORecordSet_odbtp_unicode($queryID,$mode=false) - { - $this->ADORecordSet_odbtp($queryID, $mode); - } - - function _initrs() - { - $this->_numOfFields = @odbtp_num_fields($this->_queryID); - if (!($this->_numOfRows = @odbtp_num_rows($this->_queryID))) - $this->_numOfRows = -1; - - if ($this->connection->odbc_driver == ODB_DRIVER_JET) { - for ($f = 0; $f < $this->_numOfFields; $f++) { - if (odbtp_field_bindtype($this->_queryID, $f) == ODB_CHAR) - odbtp_bind_field($this->_queryID, $f, ODB_WCHAR); - } - } - } + var $databaseType = 'odbtp_unicode'; + + function ADORecordSet_odbtp_unicode($queryID,$mode=false) + { + $this->ADORecordSet_odbtp($queryID, $mode); + } + + function _initrs() + { + $this->_numOfFields = @odbtp_num_fields($this->_queryID); + if (!($this->_numOfRows = @odbtp_num_rows($this->_queryID))) + $this->_numOfRows = -1; + + if ($this->connection->odbc_driver == ODB_DRIVER_JET) { + for ($f = 0; $f < $this->_numOfFields; $f++) { + if (odbtp_field_bindtype($this->_queryID, $f) == ODB_CHAR) + odbtp_bind_field($this->_queryID, $f, ODB_WCHAR); + } + } + } } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/drivers/adodb-oracle.inc.php b/lib/WikiDB/adodb/drivers/adodb-oracle.inc.php index 828bea661..9faf7d60f 100644 --- a/lib/WikiDB/adodb/drivers/adodb-oracle.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-oracle.inc.php @@ -14,152 +14,152 @@ V4.22 15 Apr 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights rese */ class ADODB_oracle extends ADOConnection { - var $databaseType = "oracle"; - var $replaceQuote = "''"; // string to use to replace quotes - var $concat_operator='||'; - var $_curs; - var $_initdate = true; // init date to YYYY-MM-DD - var $metaTablesSQL = 'select table_name from cat'; - var $metaColumnsSQL = "select cname,coltype,width from col where tname='%s' order by colno"; - var $sysDate = "TO_DATE(TO_CHAR(SYSDATE,'YYYY-MM-DD'),'YYYY-MM-DD')"; - var $sysTimeStamp = 'SYSDATE'; - var $connectSID = true; - - function ADODB_oracle() - { - } - - // format and return date string in database date format - function DBDate($d) - { - if (is_string($d)) $d = ADORecordSet::UnixDate($d); - return 'TO_DATE('.adodb_date($this->fmtDate,$d).",'YYYY-MM-DD')"; - } - - // format and return date string in database timestamp format - function DBTimeStamp($ts) - { - if (is_string($ts)) $d = ADORecordSet::UnixTimeStamp($ts); - return 'TO_DATE('.adodb_date($this->fmtTimeStamp,$ts).",'RRRR-MM-DD, HH:MI:SS AM')"; - } - - - function BeginTrans() - { - $this->autoCommit = false; - ora_commitoff($this->_connectionID); - return true; - } - - - function CommitTrans($ok=true) - { - if (!$ok) return $this->RollbackTrans(); - $ret = ora_commit($this->_connectionID); - ora_commiton($this->_connectionID); - return $ret; - } - - - function RollbackTrans() - { - $ret = ora_rollback($this->_connectionID); - ora_commiton($this->_connectionID); - return $ret; - } - - - /* there seems to be a bug in the oracle extension -- always returns ORA-00000 - no error */ - function ErrorMsg() - { - $this->_errorMsg = @ora_error($this->_curs); - if (!$this->_errorMsg) $this->_errorMsg = @ora_error($this->_connectionID); - return $this->_errorMsg; - } - - - function ErrorNo() - { - $err = @ora_errorcode($this->_curs); - if (!$err) return @ora_errorcode($this->_connectionID); - } - - - - // returns true or false - function _connect($argHostname, $argUsername, $argPassword, $argDatabasename, $mode=0) - { + var $databaseType = "oracle"; + var $replaceQuote = "''"; // string to use to replace quotes + var $concat_operator='||'; + var $_curs; + var $_initdate = true; // init date to YYYY-MM-DD + var $metaTablesSQL = 'select table_name from cat'; + var $metaColumnsSQL = "select cname,coltype,width from col where tname='%s' order by colno"; + var $sysDate = "TO_DATE(TO_CHAR(SYSDATE,'YYYY-MM-DD'),'YYYY-MM-DD')"; + var $sysTimeStamp = 'SYSDATE'; + var $connectSID = true; + + function ADODB_oracle() + { + } + + // format and return date string in database date format + function DBDate($d) + { + if (is_string($d)) $d = ADORecordSet::UnixDate($d); + return 'TO_DATE('.adodb_date($this->fmtDate,$d).",'YYYY-MM-DD')"; + } + + // format and return date string in database timestamp format + function DBTimeStamp($ts) + { + if (is_string($ts)) $d = ADORecordSet::UnixTimeStamp($ts); + return 'TO_DATE('.adodb_date($this->fmtTimeStamp,$ts).",'RRRR-MM-DD, HH:MI:SS AM')"; + } + + + function BeginTrans() + { + $this->autoCommit = false; + ora_commitoff($this->_connectionID); + return true; + } + + + function CommitTrans($ok=true) + { + if (!$ok) return $this->RollbackTrans(); + $ret = ora_commit($this->_connectionID); + ora_commiton($this->_connectionID); + return $ret; + } + + + function RollbackTrans() + { + $ret = ora_rollback($this->_connectionID); + ora_commiton($this->_connectionID); + return $ret; + } + + + /* there seems to be a bug in the oracle extension -- always returns ORA-00000 - no error */ + function ErrorMsg() + { + $this->_errorMsg = @ora_error($this->_curs); + if (!$this->_errorMsg) $this->_errorMsg = @ora_error($this->_connectionID); + return $this->_errorMsg; + } + + + function ErrorNo() + { + $err = @ora_errorcode($this->_curs); + if (!$err) return @ora_errorcode($this->_connectionID); + } + + + + // returns true or false + function _connect($argHostname, $argUsername, $argPassword, $argDatabasename, $mode=0) + { // G. Giunta 2003/08/13 - This looks danegrously suspicious: why should we want to set // the oracle home to the host name of remote DB? // if ($argHostname) putenv("ORACLE_HOME=$argHostname"); - if($argHostname) { // code copied from version submitted for oci8 by Jorma Tuomainen - if (empty($argDatabasename)) $argDatabasename = $argHostname; - else { - if(strpos($argHostname,":")) { - $argHostinfo=explode(":",$argHostname); - $argHostname=$argHostinfo[0]; - $argHostport=$argHostinfo[1]; - } else { - $argHostport="1521"; - } + if($argHostname) { // code copied from version submitted for oci8 by Jorma Tuomainen + if (empty($argDatabasename)) $argDatabasename = $argHostname; + else { + if(strpos($argHostname,":")) { + $argHostinfo=explode(":",$argHostname); + $argHostname=$argHostinfo[0]; + $argHostport=$argHostinfo[1]; + } else { + $argHostport="1521"; + } - if ($this->connectSID) { - $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname - .")(PORT=$argHostport))(CONNECT_DATA=(SID=$argDatabasename)))"; - } else - $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname - .")(PORT=$argHostport))(CONNECT_DATA=(SERVICE_NAME=$argDatabasename)))"; - } + if ($this->connectSID) { + $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname + .")(PORT=$argHostport))(CONNECT_DATA=(SID=$argDatabasename)))"; + } else + $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname + .")(PORT=$argHostport))(CONNECT_DATA=(SERVICE_NAME=$argDatabasename)))"; + } - } + } - if ($argDatabasename) $argUsername .= "@$argDatabasename"; + if ($argDatabasename) $argUsername .= "@$argDatabasename"; - //if ($argHostname) print "

Connect: 1st argument should be left blank for $this->databaseType

"; - if ($mode = 1) - $this->_connectionID = ora_plogon($argUsername,$argPassword); - else - $this->_connectionID = ora_logon($argUsername,$argPassword); - if ($this->_connectionID === false) return false; - if ($this->autoCommit) ora_commiton($this->_connectionID); - if ($this->_initdate) { - $rs = $this->_query("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD'"); - if ($rs) ora_close($rs); - } + //if ($argHostname) print "

Connect: 1st argument should be left blank for $this->databaseType

"; + if ($mode = 1) + $this->_connectionID = ora_plogon($argUsername,$argPassword); + else + $this->_connectionID = ora_logon($argUsername,$argPassword); + if ($this->_connectionID === false) return false; + if ($this->autoCommit) ora_commiton($this->_connectionID); + if ($this->_initdate) { + $rs = $this->_query("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD'"); + if ($rs) ora_close($rs); + } - return true; - } + return true; + } - // returns true or false - function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) - { - return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename, 1); - } + // returns true or false + function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) + { + return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename, 1); + } - // returns query ID if successful, otherwise false - function _query($sql,$inputarr=false) - { - $curs = ora_open($this->_connectionID); + // returns query ID if successful, otherwise false + function _query($sql,$inputarr=false) + { + $curs = ora_open($this->_connectionID); - if ($curs === false) return false; - $this->_curs = $curs; - if (!ora_parse($curs,$sql)) return false; - if (ora_exec($curs)) return $curs; + if ($curs === false) return false; + $this->_curs = $curs; + if (!ora_parse($curs,$sql)) return false; + if (ora_exec($curs)) return $curs; - @ora_close($curs); - return false; - } + @ora_close($curs); + return false; + } - // returns true or false - function _close() - { - return @ora_logoff($this->_connectionID); - } + // returns true or false + function _close() + { + return @ora_logoff($this->_connectionID); + } @@ -167,131 +167,131 @@ class ADODB_oracle extends ADOConnection { /*-------------------------------------------------------------------------------------- - Class Name: Recordset + Class Name: Recordset --------------------------------------------------------------------------------------*/ class ADORecordset_oracle extends ADORecordSet { - var $databaseType = "oracle"; - var $bind = false; - - function ADORecordset_oracle($queryID,$mode=false) - { - - if ($mode === false) { - global $ADODB_FETCH_MODE; - $mode = $ADODB_FETCH_MODE; - } - $this->fetchMode = $mode; - - $this->_queryID = $queryID; - - $this->_inited = true; - $this->fields = array(); - if ($queryID) { - $this->_currentRow = 0; - $this->EOF = !$this->_fetch(); - @$this->_initrs(); - } else { - $this->_numOfRows = 0; - $this->_numOfFields = 0; - $this->EOF = true; - } - - return $this->_queryID; - } - - - - /* Returns: an object containing field information. - Get column information in the Recordset object. fetchField() can be used in order to obtain information about - fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by - fetchField() is retrieved. */ - - function FetchField($fieldOffset = -1) - { - $fld = new ADOFieldObject; - $fld->name = ora_columnname($this->_queryID, $fieldOffset); - $fld->type = ora_columntype($this->_queryID, $fieldOffset); - $fld->max_length = ora_columnsize($this->_queryID, $fieldOffset); - return $fld; - } - - /* Use associative array to get fields array */ - function Fields($colname) - { - if (!$this->bind) { - $this->bind = array(); - for ($i=0; $i < $this->_numOfFields; $i++) { - $o = $this->FetchField($i); - $this->bind[strtoupper($o->name)] = $i; - } - } - - return $this->fields[$this->bind[strtoupper($colname)]]; - } + var $databaseType = "oracle"; + var $bind = false; + + function ADORecordset_oracle($queryID,$mode=false) + { + + if ($mode === false) { + global $ADODB_FETCH_MODE; + $mode = $ADODB_FETCH_MODE; + } + $this->fetchMode = $mode; + + $this->_queryID = $queryID; + + $this->_inited = true; + $this->fields = array(); + if ($queryID) { + $this->_currentRow = 0; + $this->EOF = !$this->_fetch(); + @$this->_initrs(); + } else { + $this->_numOfRows = 0; + $this->_numOfFields = 0; + $this->EOF = true; + } + + return $this->_queryID; + } + + + + /* Returns: an object containing field information. + Get column information in the Recordset object. fetchField() can be used in order to obtain information about + fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by + fetchField() is retrieved. */ + + function FetchField($fieldOffset = -1) + { + $fld = new ADOFieldObject; + $fld->name = ora_columnname($this->_queryID, $fieldOffset); + $fld->type = ora_columntype($this->_queryID, $fieldOffset); + $fld->max_length = ora_columnsize($this->_queryID, $fieldOffset); + return $fld; + } + + /* Use associative array to get fields array */ + function Fields($colname) + { + if (!$this->bind) { + $this->bind = array(); + for ($i=0; $i < $this->_numOfFields; $i++) { + $o = $this->FetchField($i); + $this->bind[strtoupper($o->name)] = $i; + } + } + + return $this->fields[$this->bind[strtoupper($colname)]]; + } function _initrs() { - $this->_numOfRows = -1; - $this->_numOfFields = @ora_numcols($this->_queryID); + $this->_numOfRows = -1; + $this->_numOfFields = @ora_numcols($this->_queryID); } function _seek($row) { - return false; + return false; } function _fetch($ignore_fields=false) { - if ($this->fetchMode & ADODB_FETCH_ASSOC) - return @ora_fetch_into($this->_queryID,$this->fields,ORA_FETCHINTO_NULLS|ORA_FETCHINTO_ASSOC); - else - return @ora_fetch_into($this->_queryID,$this->fields,ORA_FETCHINTO_NULLS); + if ($this->fetchMode & ADODB_FETCH_ASSOC) + return @ora_fetch_into($this->_queryID,$this->fields,ORA_FETCHINTO_NULLS|ORA_FETCHINTO_ASSOC); + else + return @ora_fetch_into($this->_queryID,$this->fields,ORA_FETCHINTO_NULLS); } /* close() only needs to be called if you are worried about using too much memory while your script - is running. All associated result memory for the specified result identifier will automatically be freed. */ + is running. All associated result memory for the specified result identifier will automatically be freed. */ function _close() { - return @ora_close($this->_queryID); + return @ora_close($this->_queryID); } - function MetaType($t,$len=-1) - { - if (is_object($t)) { - $fieldobj = $t; - $t = $fieldobj->type; - $len = $fieldobj->max_length; - } - - switch (strtoupper($t)) { - case 'VARCHAR': - case 'VARCHAR2': - case 'CHAR': - case 'VARBINARY': - case 'BINARY': - if ($len <= $this->blobSize) return 'C'; - case 'LONG': - case 'LONG VARCHAR': - case 'CLOB': - return 'X'; - case 'LONG RAW': - case 'LONG VARBINARY': - case 'BLOB': - return 'B'; - - case 'DATE': return 'D'; - - //case 'T': return 'T'; - - case 'BIT': return 'L'; - case 'INT': - case 'SMALLINT': - case 'INTEGER': return 'I'; - default: return 'N'; - } - } + function MetaType($t,$len=-1) + { + if (is_object($t)) { + $fieldobj = $t; + $t = $fieldobj->type; + $len = $fieldobj->max_length; + } + + switch (strtoupper($t)) { + case 'VARCHAR': + case 'VARCHAR2': + case 'CHAR': + case 'VARBINARY': + case 'BINARY': + if ($len <= $this->blobSize) return 'C'; + case 'LONG': + case 'LONG VARCHAR': + case 'CLOB': + return 'X'; + case 'LONG RAW': + case 'LONG VARBINARY': + case 'BLOB': + return 'B'; + + case 'DATE': return 'D'; + + //case 'T': return 'T'; + + case 'BIT': return 'L'; + case 'INT': + case 'SMALLINT': + case 'INTEGER': return 'I'; + default: return 'N'; + } + } } ?> diff --git a/lib/WikiDB/adodb/drivers/adodb-postgres64.inc.php b/lib/WikiDB/adodb/drivers/adodb-postgres64.inc.php index 167489ffe..0b4529d8b 100644 --- a/lib/WikiDB/adodb/drivers/adodb-postgres64.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-postgres64.inc.php @@ -9,8 +9,8 @@ Original version derived from Alberto Cerezal (acerezalp@dbnet.es) - DBNet Informatica & Comunicaciones. 08 Nov 2000 jlim - Minor corrections, removing mysql stuff 09 Nov 2000 jlim - added insertid support suggested by "Christopher Kings-Lynne" - jlim - changed concat operator to || and data types to MetaType to match documented pgsql types - see http://www.postgresql.org/devel-corner/docs/postgres/datatype.htm + jlim - changed concat operator to || and data types to MetaType to match documented pgsql types + see http://www.postgresql.org/devel-corner/docs/postgres/datatype.htm 22 Nov 2000 jlim - added changes to FetchField() and MetaTables() contributed by "raser" 27 Nov 2000 jlim - added changes to _connect/_pconnect from ideas by "Lennie" 15 Dec 2000 jlim - added changes suggested by Additional code changes by "Eric G. Werk" egw@netguide.dk. @@ -19,499 +19,499 @@ See http://www.varlena.com/varlena/GeneralBits/47.php - -- What indexes are on my table? - select * from pg_indexes where tablename = 'tablename'; - - -- What triggers are on my table? - select c.relname as "Table", t.tgname as "Trigger Name", - t.tgconstrname as "Constraint Name", t.tgenabled as "Enabled", - t.tgisconstraint as "Is Constraint", cc.relname as "Referenced Table", - p.proname as "Function Name" - from pg_trigger t, pg_class c, pg_class cc, pg_proc p - where t.tgfoid = p.oid and t.tgrelid = c.oid - and t.tgconstrrelid = cc.oid - and c.relname = 'tablename'; - - -- What constraints are on my table? - select r.relname as "Table", c.conname as "Constraint Name", - contype as "Constraint Type", conkey as "Key Columns", - confkey as "Foreign Columns", consrc as "Source" - from pg_class r, pg_constraint c - where r.oid = c.conrelid - and relname = 'tablename'; + -- What indexes are on my table? + select * from pg_indexes where tablename = 'tablename'; + + -- What triggers are on my table? + select c.relname as "Table", t.tgname as "Trigger Name", + t.tgconstrname as "Constraint Name", t.tgenabled as "Enabled", + t.tgisconstraint as "Is Constraint", cc.relname as "Referenced Table", + p.proname as "Function Name" + from pg_trigger t, pg_class c, pg_class cc, pg_proc p + where t.tgfoid = p.oid and t.tgrelid = c.oid + and t.tgconstrrelid = cc.oid + and c.relname = 'tablename'; + + -- What constraints are on my table? + select r.relname as "Table", c.conname as "Constraint Name", + contype as "Constraint Type", conkey as "Key Columns", + confkey as "Foreign Columns", consrc as "Source" + from pg_class r, pg_constraint c + where r.oid = c.conrelid + and relname = 'tablename'; */ function adodb_addslashes($s) { - $len = strlen($s); - if ($len == 0) return "''"; - if (strncmp($s,"'",1) === 0 && substr(s,$len-1) == "'") return $s; // already quoted + $len = strlen($s); + if ($len == 0) return "''"; + if (strncmp($s,"'",1) === 0 && substr(s,$len-1) == "'") return $s; // already quoted - return "'".addslashes($s)."'"; + return "'".addslashes($s)."'"; } class ADODB_postgres64 extends ADOConnection{ - var $databaseType = 'postgres64'; - var $dataProvider = 'postgres'; - var $hasInsertID = true; - var $_resultid = false; - var $concat_operator='||'; - var $metaDatabasesSQL = "select datname from pg_database where datname not in ('template0','template1') order by 1"; + var $databaseType = 'postgres64'; + var $dataProvider = 'postgres'; + var $hasInsertID = true; + var $_resultid = false; + var $concat_operator='||'; + var $metaDatabasesSQL = "select datname from pg_database where datname not in ('template0','template1') order by 1"; var $metaTablesSQL = "select tablename,'T' from pg_tables where tablename not like 'pg\_%' union select viewname,'V' from pg_views where viewname not like 'pg\_%'"; - //"select tablename from pg_tables where tablename not like 'pg_%' order by 1"; - var $isoDates = true; // accepts dates in ISO format - var $sysDate = "CURRENT_DATE"; - var $sysTimeStamp = "CURRENT_TIMESTAMP"; - var $blobEncodeType = 'C'; - var $metaColumnsSQL = "SELECT a.attname,t.typname,a.attlen,a.atttypmod,a.attnotnull,a.atthasdef,a.attnum - FROM pg_class c, pg_attribute a,pg_type t - WHERE relkind = 'r' AND (c.relname='%s' or c.relname = lower('%s')) and a.attname not like '....%%' + //"select tablename from pg_tables where tablename not like 'pg_%' order by 1"; + var $isoDates = true; // accepts dates in ISO format + var $sysDate = "CURRENT_DATE"; + var $sysTimeStamp = "CURRENT_TIMESTAMP"; + var $blobEncodeType = 'C'; + var $metaColumnsSQL = "SELECT a.attname,t.typname,a.attlen,a.atttypmod,a.attnotnull,a.atthasdef,a.attnum + FROM pg_class c, pg_attribute a,pg_type t + WHERE relkind = 'r' AND (c.relname='%s' or c.relname = lower('%s')) and a.attname not like '....%%' AND a.attnum > 0 AND a.atttypid = t.oid AND a.attrelid = c.oid ORDER BY a.attnum"; - var $metaColumnsSQL1 = "SELECT a.attname, t.typname, a.attlen, a.atttypmod, a.attnotnull, a.atthasdef, a.attnum + var $metaColumnsSQL1 = "SELECT a.attname, t.typname, a.attlen, a.atttypmod, a.attnotnull, a.atthasdef, a.attnum FROM pg_class c, pg_attribute a, pg_type t, pg_namespace n WHERE relkind = 'r' AND (c.relname='%s' or c.relname = lower('%s')) and c.relnamespace=n.oid and n.nspname='%s' - and a.attname not like '....%%' AND a.attnum > 0 - AND a.atttypid = t.oid AND a.attrelid = c.oid ORDER BY a.attnum"; - - // get primary key etc -- from Freek Dijkstra - var $metaKeySQL = "SELECT ic.relname AS index_name, a.attname AS column_name,i.indisunique AS unique_key, i.indisprimary AS primary_key - FROM pg_class bc, pg_class ic, pg_index i, pg_attribute a WHERE bc.oid = i.indrelid AND ic.oid = i.indexrelid AND (i.indkey[0] = a.attnum OR i.indkey[1] = a.attnum OR i.indkey[2] = a.attnum OR i.indkey[3] = a.attnum OR i.indkey[4] = a.attnum OR i.indkey[5] = a.attnum OR i.indkey[6] = a.attnum OR i.indkey[7] = a.attnum) AND a.attrelid = bc.oid AND bc.relname = '%s'"; - - var $hasAffectedRows = true; - var $hasLimit = false; // set to true for pgsql 7 only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10 - // below suggested by Freek Dijkstra - var $true = 't'; // string that represents TRUE for a database - var $false = 'f'; // string that represents FALSE for a database - var $fmtDate = "'Y-m-d'"; // used by DBDate() as the default date format used by the database - var $fmtTimeStamp = "'Y-m-d G:i:s'"; // used by DBTimeStamp as the default timestamp fmt. - var $hasMoveFirst = true; - var $hasGenID = true; - var $_genIDSQL = "SELECT NEXTVAL('%s')"; - var $_genSeqSQL = "CREATE SEQUENCE %s START %s"; - var $_dropSeqSQL = "DROP SEQUENCE %s"; - var $metaDefaultsSQL = "SELECT d.adnum as num, d.adsrc as def from pg_attrdef d, pg_class c where d.adrelid=c.oid and c.relname='%s' order by d.adnum"; - var $random = 'random()'; /// random function - var $autoRollback = true; // apparently pgsql does not autorollback properly before 4.3.4 - // http://bugs.php.net/bug.php?id=25404 - - var $_bindInputArray = false; // requires postgresql 7.3+ and ability to modify database - - // The last (fmtTimeStamp is not entirely correct: - // PostgreSQL also has support for time zones, - // and writes these time in this format: "2001-03-01 18:59:26+02". - // There is no code for the "+02" time zone information, so I just left that out. - // I'm not familiar enough with both ADODB as well as Postgres - // to know what the concequences are. The other values are correct (wheren't in 0.94) - // -- Freek Dijkstra - - function ADODB_postgres64() - { - // changes the metaColumnsSQL, adds columns: attnum[6] - } - - function ServerInfo() - { - if (isset($this->version)) return $this->version; - - $arr['description'] = $this->GetOne("select version()"); - $arr['version'] = ADOConnection::_findvers($arr['description']); - $this->version = $arr; - return $arr; - } + and a.attname not like '....%%' AND a.attnum > 0 + AND a.atttypid = t.oid AND a.attrelid = c.oid ORDER BY a.attnum"; + + // get primary key etc -- from Freek Dijkstra + var $metaKeySQL = "SELECT ic.relname AS index_name, a.attname AS column_name,i.indisunique AS unique_key, i.indisprimary AS primary_key + FROM pg_class bc, pg_class ic, pg_index i, pg_attribute a WHERE bc.oid = i.indrelid AND ic.oid = i.indexrelid AND (i.indkey[0] = a.attnum OR i.indkey[1] = a.attnum OR i.indkey[2] = a.attnum OR i.indkey[3] = a.attnum OR i.indkey[4] = a.attnum OR i.indkey[5] = a.attnum OR i.indkey[6] = a.attnum OR i.indkey[7] = a.attnum) AND a.attrelid = bc.oid AND bc.relname = '%s'"; + + var $hasAffectedRows = true; + var $hasLimit = false; // set to true for pgsql 7 only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10 + // below suggested by Freek Dijkstra + var $true = 't'; // string that represents TRUE for a database + var $false = 'f'; // string that represents FALSE for a database + var $fmtDate = "'Y-m-d'"; // used by DBDate() as the default date format used by the database + var $fmtTimeStamp = "'Y-m-d G:i:s'"; // used by DBTimeStamp as the default timestamp fmt. + var $hasMoveFirst = true; + var $hasGenID = true; + var $_genIDSQL = "SELECT NEXTVAL('%s')"; + var $_genSeqSQL = "CREATE SEQUENCE %s START %s"; + var $_dropSeqSQL = "DROP SEQUENCE %s"; + var $metaDefaultsSQL = "SELECT d.adnum as num, d.adsrc as def from pg_attrdef d, pg_class c where d.adrelid=c.oid and c.relname='%s' order by d.adnum"; + var $random = 'random()'; /// random function + var $autoRollback = true; // apparently pgsql does not autorollback properly before 4.3.4 + // http://bugs.php.net/bug.php?id=25404 + + var $_bindInputArray = false; // requires postgresql 7.3+ and ability to modify database + + // The last (fmtTimeStamp is not entirely correct: + // PostgreSQL also has support for time zones, + // and writes these time in this format: "2001-03-01 18:59:26+02". + // There is no code for the "+02" time zone information, so I just left that out. + // I'm not familiar enough with both ADODB as well as Postgres + // to know what the concequences are. The other values are correct (wheren't in 0.94) + // -- Freek Dijkstra + + function ADODB_postgres64() + { + // changes the metaColumnsSQL, adds columns: attnum[6] + } + + function ServerInfo() + { + if (isset($this->version)) return $this->version; + + $arr['description'] = $this->GetOne("select version()"); + $arr['version'] = ADOConnection::_findvers($arr['description']); + $this->version = $arr; + return $arr; + } /* - function IfNull( $field, $ifNull ) - { - return " NULLIF($field, $ifNull) "; // if PGSQL - } + function IfNull( $field, $ifNull ) + { + return " NULLIF($field, $ifNull) "; // if PGSQL + } */ - // get the last id - never tested - function pg_insert_id($tablename,$fieldname) - { - $result=pg_exec($this->_connectionID, "SELECT last_value FROM ${tablename}_${fieldname}_seq"); - if ($result) { - $arr = @pg_fetch_row($result,0); - pg_freeresult($result); - if (isset($arr[0])) return $arr[0]; - } - return false; - } + // get the last id - never tested + function pg_insert_id($tablename,$fieldname) + { + $result=pg_exec($this->_connectionID, "SELECT last_value FROM ${tablename}_${fieldname}_seq"); + if ($result) { + $arr = @pg_fetch_row($result,0); + pg_freeresult($result); + if (isset($arr[0])) return $arr[0]; + } + return false; + } /* Warning from http://www.php.net/manual/function.pg-getlastoid.php: Using a OID as a unique identifier is not generally wise. Unless you are very careful, you might end up with a tuple having a different OID if a database must be reloaded. */ - function _insertid() - { - if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') return false; - return pg_getlastoid($this->_resultid); - } + function _insertid() + { + if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') return false; + return pg_getlastoid($this->_resultid); + } // I get this error with PHP before 4.0.6 - jlim // Warning: This compilation does not support pg_cmdtuples() in d:/inetpub/wwwroot/php/adodb/adodb-postgres.inc.php on line 44 function _affectedrows() { - if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') return false; - return pg_cmdtuples($this->_resultid); + if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') return false; + return pg_cmdtuples($this->_resultid); } - // returns true/false - function BeginTrans() - { - if ($this->transOff) return true; - $this->transCnt += 1; - return @pg_Exec($this->_connectionID, "begin"); - } - - function RowLock($tables,$where) - { - if (!$this->transCnt) $this->BeginTrans(); - return $this->GetOne("select 1 as ignore from $tables where $where for update"); - } - - // returns true/false. - function CommitTrans($ok=true) - { - if ($this->transOff) return true; - if (!$ok) return $this->RollbackTrans(); - - $this->transCnt -= 1; - return @pg_Exec($this->_connectionID, "commit"); - } - - // returns true/false - function RollbackTrans() - { - if ($this->transOff) return true; - $this->transCnt -= 1; - return @pg_Exec($this->_connectionID, "rollback"); - } - - function &MetaTables($ttype=false,$showSchema=false,$mask=false) - { - if ($mask) { - $save = $this->metaTablesSQL; - $mask = $this->qstr(strtolower($mask)); - $this->metaTablesSQL = " + // returns true/false + function BeginTrans() + { + if ($this->transOff) return true; + $this->transCnt += 1; + return @pg_Exec($this->_connectionID, "begin"); + } + + function RowLock($tables,$where) + { + if (!$this->transCnt) $this->BeginTrans(); + return $this->GetOne("select 1 as ignore from $tables where $where for update"); + } + + // returns true/false. + function CommitTrans($ok=true) + { + if ($this->transOff) return true; + if (!$ok) return $this->RollbackTrans(); + + $this->transCnt -= 1; + return @pg_Exec($this->_connectionID, "commit"); + } + + // returns true/false + function RollbackTrans() + { + if ($this->transOff) return true; + $this->transCnt -= 1; + return @pg_Exec($this->_connectionID, "rollback"); + } + + function &MetaTables($ttype=false,$showSchema=false,$mask=false) + { + if ($mask) { + $save = $this->metaTablesSQL; + $mask = $this->qstr(strtolower($mask)); + $this->metaTablesSQL = " select tablename,'T' from pg_tables where tablename like $mask union select viewname,'V' from pg_views where viewname like $mask"; - } - $ret =& ADOConnection::MetaTables($ttype,$showSchema); - - if ($mask) { - $this->metaTablesSQL = $save; - } - return $ret; - } - - /* - // if magic quotes disabled, use pg_escape_string() - function qstr($s,$magic_quotes=false) - { - if (!$magic_quotes) { - if (ADODB_PHPVER >= 0x4200) { - return "'".pg_escape_string($s)."'"; - } - if ($this->replaceQuote[0] == '\\'){ - $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s); - } - return "'".str_replace("'",$this->replaceQuote,$s)."'"; - } - - // undo magic quotes for " - $s = str_replace('\\"','"',$s); - return "'$s'"; - } - */ - - - // Format date column in sql string given an input format that understands Y M D - function SQLDate($fmt, $col=false) - { - if (!$col) $col = $this->sysTimeStamp; - $s = 'TO_CHAR('.$col.",'"; - - $len = strlen($fmt); - for ($i=0; $i < $len; $i++) { - $ch = $fmt[$i]; - switch($ch) { - case 'Y': - case 'y': - $s .= 'YYYY'; - break; - case 'Q': - case 'q': - $s .= 'Q'; - break; - - case 'M': - $s .= 'Mon'; - break; - - case 'm': - $s .= 'MM'; - break; - case 'D': - case 'd': - $s .= 'DD'; - break; - - case 'H': - $s.= 'HH24'; - break; - - case 'h': - $s .= 'HH'; - break; - - case 'i': - $s .= 'MI'; - break; - - case 's': - $s .= 'SS'; - break; - - case 'a': - case 'A': - $s .= 'AM'; - break; - - default: - // handle escape characters... - if ($ch == '\\') { - $i++; - $ch = substr($fmt,$i,1); - } - if (strpos('-/.:;, ',$ch) !== false) $s .= $ch; - else $s .= '"'.$ch.'"'; - - } - } - return $s. "')"; - } - - - - /* - * Load a Large Object from a file - * - the procedure stores the object id in the table and imports the object using - * postgres proprietary blob handling routines - * - * contributed by Mattia Rossi mattia@technologist.com - * modified for safe mode by juraj chlebec - */ - function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB') - { - pg_exec ($this->_connectionID, "begin"); - - $fd = fopen($path,'r'); - $contents = fread($fd,filesize($path)); - fclose($fd); - - $oid = pg_lo_create($this->_connectionID); - $handle = pg_lo_open($this->_connectionID, $oid, 'w'); - pg_lo_write($handle, $contents); - pg_lo_close($handle); - - // $oid = pg_lo_import ($path); - pg_exec($this->_connectionID, "commit"); - $rs = ADOConnection::UpdateBlob($table,$column,$oid,$where,$blobtype); - $rez = !empty($rs); - return $rez; - } - - /* - * If an OID is detected, then we use pg_lo_* to open the oid file and read the - * real blob from the db using the oid supplied as a parameter. If you are storing - * blobs using bytea, we autodetect and process it so this function is not needed. - * - * contributed by Mattia Rossi mattia@technologist.com - * - * see http://www.postgresql.org/idocs/index.php?largeobjects.html - */ - function BlobDecode( $blob) - { - if (strlen($blob) > 24) return $blob; - - @pg_exec($this->_connectionID,"begin"); - $fd = @pg_lo_open($this->_connectionID,$blob,"r"); - if ($fd === false) { - @pg_exec($this->_connectionID,"commit"); - return $blob; - } - $realblob = @pg_loreadall($fd); - @pg_loclose($fd); - @pg_exec($this->_connectionID,"commit"); - return $realblob; - } - - /* - See http://www.postgresql.org/idocs/index.php?datatype-binary.html - - NOTE: SQL string literals (input strings) must be preceded with two backslashes - due to the fact that they must pass through two parsers in the PostgreSQL - backend. - */ - function BlobEncode($blob) - { - if (ADODB_PHPVER >= 0x4200) return pg_escape_bytea($blob); - - /*92=backslash, 0=null, 39=single-quote*/ - $badch = array(chr(92),chr(0),chr(39)); # \ null ' - $fixch = array('\\\\134','\\\\000','\\\\047'); - return adodb_str_replace($badch,$fixch,$blob); - - // note that there is a pg_escape_bytea function only for php 4.2.0 or later - } - - function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') - { - // do not use bind params which uses qstr(), as blobencode() already quotes data - return $this->Execute("UPDATE $table SET $column='".$this->BlobEncode($val)."'::bytea WHERE $where"); - } - - function OffsetDate($dayFraction,$date=false) - { - if (!$date) $date = $this->sysDate; - return "($date+interval'$dayFraction days')"; - } - - - // for schema support, pass in the $table param "$schema.$tabname". - // converts field names to lowercase, $upper is ignored - function &MetaColumns($table,$upper=true) - { - global $ADODB_FETCH_MODE; - - $schema = false; - $this->_findschema($table,$schema); - - $table = strtolower($table); - - $save = $ADODB_FETCH_MODE; - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); - - if ($schema) $rs =& $this->Execute(sprintf($this->metaColumnsSQL1,$table,$table,$schema)); - else $rs =& $this->Execute(sprintf($this->metaColumnsSQL,$table,$table)); - if (isset($savem)) $this->SetFetchMode($savem); - $ADODB_FETCH_MODE = $save; - - if ($rs === false) return false; - - if (!empty($this->metaKeySQL)) { - // If we want the primary keys, we have to issue a separate query - // Of course, a modified version of the metaColumnsSQL query using a - // LEFT JOIN would have been much more elegant, but postgres does - // not support OUTER JOINS. So here is the clumsy way. - - $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; - - $rskey = $this->Execute(sprintf($this->metaKeySQL,($table))); - // fetch all result in once for performance. - $keys =& $rskey->GetArray(); - if (isset($savem)) $this->SetFetchMode($savem); - $ADODB_FETCH_MODE = $save; - - $rskey->Close(); - unset($rskey); - } - - $rsdefa = array(); - if (!empty($this->metaDefaultsSQL)) { - $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; - $sql = sprintf($this->metaDefaultsSQL, ($table)); - $rsdef = $this->Execute($sql); - if (isset($savem)) $this->SetFetchMode($savem); - $ADODB_FETCH_MODE = $save; - - if ($rsdef) { - while (!$rsdef->EOF) { - $num = $rsdef->fields['num']; - $s = $rsdef->fields['def']; - if (substr($s, 0, 1) == "'") { /* quoted strings hack... for now... fixme */ - $s = substr($s, 1); - $s = substr($s, 0, strlen($s) - 1); - } - - $rsdefa[$num] = $s; - $rsdef->MoveNext(); - } - } else { - ADOConnection::outp( "==> SQL => " . $sql); - } - unset($rsdef); - } - - $retarr = array(); - while (!$rs->EOF) { - $fld = new ADOFieldObject(); - $fld->name = $rs->fields[0]; - $fld->type = $rs->fields[1]; - $fld->max_length = $rs->fields[2]; - if ($fld->max_length <= 0) $fld->max_length = $rs->fields[3]-4; - if ($fld->max_length <= 0) $fld->max_length = -1; - - // dannym - // 5 hasdefault; 6 num-of-column - $fld->has_default = ($rs->fields[5] == 't'); - if ($fld->has_default) { - $fld->default_value = $rsdefa[$rs->fields[6]]; - } - - //Freek - if ($rs->fields[4] == $this->true) { - $fld->not_null = true; - } - - // Freek - if (is_array($keys)) { - foreach($keys as $key) { - if ($fld->name == $key['column_name'] AND $key['primary_key'] == $this->true) - $fld->primary_key = true; - if ($fld->name == $key['column_name'] AND $key['unique_key'] == $this->true) - $fld->unique = true; // What name is more compatible? - } - } - - if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld; - else $retarr[($upper) ? strtoupper($fld->name) : $fld->name] = $fld; - - $rs->MoveNext(); - } - $rs->Close(); - return $retarr; - - } - - function &MetaIndexes ($table, $primary = FALSE) + } + $ret =& ADOConnection::MetaTables($ttype,$showSchema); + + if ($mask) { + $this->metaTablesSQL = $save; + } + return $ret; + } + + /* + // if magic quotes disabled, use pg_escape_string() + function qstr($s,$magic_quotes=false) + { + if (!$magic_quotes) { + if (ADODB_PHPVER >= 0x4200) { + return "'".pg_escape_string($s)."'"; + } + if ($this->replaceQuote[0] == '\\'){ + $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s); + } + return "'".str_replace("'",$this->replaceQuote,$s)."'"; + } + + // undo magic quotes for " + $s = str_replace('\\"','"',$s); + return "'$s'"; + } + */ + + + // Format date column in sql string given an input format that understands Y M D + function SQLDate($fmt, $col=false) + { + if (!$col) $col = $this->sysTimeStamp; + $s = 'TO_CHAR('.$col.",'"; + + $len = strlen($fmt); + for ($i=0; $i < $len; $i++) { + $ch = $fmt[$i]; + switch($ch) { + case 'Y': + case 'y': + $s .= 'YYYY'; + break; + case 'Q': + case 'q': + $s .= 'Q'; + break; + + case 'M': + $s .= 'Mon'; + break; + + case 'm': + $s .= 'MM'; + break; + case 'D': + case 'd': + $s .= 'DD'; + break; + + case 'H': + $s.= 'HH24'; + break; + + case 'h': + $s .= 'HH'; + break; + + case 'i': + $s .= 'MI'; + break; + + case 's': + $s .= 'SS'; + break; + + case 'a': + case 'A': + $s .= 'AM'; + break; + + default: + // handle escape characters... + if ($ch == '\\') { + $i++; + $ch = substr($fmt,$i,1); + } + if (strpos('-/.:;, ',$ch) !== false) $s .= $ch; + else $s .= '"'.$ch.'"'; + + } + } + return $s. "')"; + } + + + + /* + * Load a Large Object from a file + * - the procedure stores the object id in the table and imports the object using + * postgres proprietary blob handling routines + * + * contributed by Mattia Rossi mattia@technologist.com + * modified for safe mode by juraj chlebec + */ + function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB') + { + pg_exec ($this->_connectionID, "begin"); + + $fd = fopen($path,'r'); + $contents = fread($fd,filesize($path)); + fclose($fd); + + $oid = pg_lo_create($this->_connectionID); + $handle = pg_lo_open($this->_connectionID, $oid, 'w'); + pg_lo_write($handle, $contents); + pg_lo_close($handle); + + // $oid = pg_lo_import ($path); + pg_exec($this->_connectionID, "commit"); + $rs = ADOConnection::UpdateBlob($table,$column,$oid,$where,$blobtype); + $rez = !empty($rs); + return $rez; + } + + /* + * If an OID is detected, then we use pg_lo_* to open the oid file and read the + * real blob from the db using the oid supplied as a parameter. If you are storing + * blobs using bytea, we autodetect and process it so this function is not needed. + * + * contributed by Mattia Rossi mattia@technologist.com + * + * see http://www.postgresql.org/idocs/index.php?largeobjects.html + */ + function BlobDecode( $blob) + { + if (strlen($blob) > 24) return $blob; + + @pg_exec($this->_connectionID,"begin"); + $fd = @pg_lo_open($this->_connectionID,$blob,"r"); + if ($fd === false) { + @pg_exec($this->_connectionID,"commit"); + return $blob; + } + $realblob = @pg_loreadall($fd); + @pg_loclose($fd); + @pg_exec($this->_connectionID,"commit"); + return $realblob; + } + + /* + See http://www.postgresql.org/idocs/index.php?datatype-binary.html + + NOTE: SQL string literals (input strings) must be preceded with two backslashes + due to the fact that they must pass through two parsers in the PostgreSQL + backend. + */ + function BlobEncode($blob) + { + if (ADODB_PHPVER >= 0x4200) return pg_escape_bytea($blob); + + /*92=backslash, 0=null, 39=single-quote*/ + $badch = array(chr(92),chr(0),chr(39)); # \ null ' + $fixch = array('\\\\134','\\\\000','\\\\047'); + return adodb_str_replace($badch,$fixch,$blob); + + // note that there is a pg_escape_bytea function only for php 4.2.0 or later + } + + function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') + { + // do not use bind params which uses qstr(), as blobencode() already quotes data + return $this->Execute("UPDATE $table SET $column='".$this->BlobEncode($val)."'::bytea WHERE $where"); + } + + function OffsetDate($dayFraction,$date=false) + { + if (!$date) $date = $this->sysDate; + return "($date+interval'$dayFraction days')"; + } + + + // for schema support, pass in the $table param "$schema.$tabname". + // converts field names to lowercase, $upper is ignored + function &MetaColumns($table,$upper=true) + { + global $ADODB_FETCH_MODE; + + $schema = false; + $this->_findschema($table,$schema); + + $table = strtolower($table); + + $save = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); + + if ($schema) $rs =& $this->Execute(sprintf($this->metaColumnsSQL1,$table,$table,$schema)); + else $rs =& $this->Execute(sprintf($this->metaColumnsSQL,$table,$table)); + if (isset($savem)) $this->SetFetchMode($savem); + $ADODB_FETCH_MODE = $save; + + if ($rs === false) return false; + + if (!empty($this->metaKeySQL)) { + // If we want the primary keys, we have to issue a separate query + // Of course, a modified version of the metaColumnsSQL query using a + // LEFT JOIN would have been much more elegant, but postgres does + // not support OUTER JOINS. So here is the clumsy way. + + $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; + + $rskey = $this->Execute(sprintf($this->metaKeySQL,($table))); + // fetch all result in once for performance. + $keys =& $rskey->GetArray(); + if (isset($savem)) $this->SetFetchMode($savem); + $ADODB_FETCH_MODE = $save; + + $rskey->Close(); + unset($rskey); + } + + $rsdefa = array(); + if (!empty($this->metaDefaultsSQL)) { + $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; + $sql = sprintf($this->metaDefaultsSQL, ($table)); + $rsdef = $this->Execute($sql); + if (isset($savem)) $this->SetFetchMode($savem); + $ADODB_FETCH_MODE = $save; + + if ($rsdef) { + while (!$rsdef->EOF) { + $num = $rsdef->fields['num']; + $s = $rsdef->fields['def']; + if (substr($s, 0, 1) == "'") { /* quoted strings hack... for now... fixme */ + $s = substr($s, 1); + $s = substr($s, 0, strlen($s) - 1); + } + + $rsdefa[$num] = $s; + $rsdef->MoveNext(); + } + } else { + ADOConnection::outp( "==> SQL => " . $sql); + } + unset($rsdef); + } + + $retarr = array(); + while (!$rs->EOF) { + $fld = new ADOFieldObject(); + $fld->name = $rs->fields[0]; + $fld->type = $rs->fields[1]; + $fld->max_length = $rs->fields[2]; + if ($fld->max_length <= 0) $fld->max_length = $rs->fields[3]-4; + if ($fld->max_length <= 0) $fld->max_length = -1; + + // dannym + // 5 hasdefault; 6 num-of-column + $fld->has_default = ($rs->fields[5] == 't'); + if ($fld->has_default) { + $fld->default_value = $rsdefa[$rs->fields[6]]; + } + + //Freek + if ($rs->fields[4] == $this->true) { + $fld->not_null = true; + } + + // Freek + if (is_array($keys)) { + foreach($keys as $key) { + if ($fld->name == $key['column_name'] AND $key['primary_key'] == $this->true) + $fld->primary_key = true; + if ($fld->name == $key['column_name'] AND $key['unique_key'] == $this->true) + $fld->unique = true; // What name is more compatible? + } + } + + if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld; + else $retarr[($upper) ? strtoupper($fld->name) : $fld->name] = $fld; + + $rs->MoveNext(); + } + $rs->Close(); + return $retarr; + + } + + function &MetaIndexes ($table, $primary = FALSE) { global $ADODB_FETCH_MODE; - $schema = false; - $this->_findschema($table,$schema); + $schema = false; + $this->_findschema($table,$schema); - if ($schema) { // requires pgsql 7.3+ - pg_namespace used. - $sql = ' + if ($schema) { // requires pgsql 7.3+ - pg_namespace used. + $sql = ' SELECT c.relname as "Name", i.indisunique as "Unique", i.indkey as "Columns" FROM pg_catalog.pg_class c JOIN pg_catalog.pg_index i ON i.indexrelid=c.oid JOIN pg_catalog.pg_class c2 ON c2.oid=i.indrelid - ,pg_namespace n + ,pg_namespace n WHERE c2.relname=\'%s\' and c.relnamespace=c2.relnamespace and c.relnamespace=n.oid and n.nspname=\'%s\' AND i.indisprimary=false'; - } else { - $sql = ' + } else { + $sql = ' SELECT c.relname as "Name", i.indisunique as "Unique", i.indkey as "Columns" FROM pg_catalog.pg_class c JOIN pg_catalog.pg_index i ON i.indexrelid=c.oid JOIN pg_catalog.pg_class c2 ON c2.oid=i.indrelid WHERE c2.relname=\'%s\''; - } + } if ($primary == FALSE) { $sql .= ' AND i.indisprimary=false;'; @@ -553,401 +553,401 @@ WHERE c2.relname=\'%s\''; return $indexes; } - // returns true or false - // - // examples: - // $db->Connect("host=host1 user=user1 password=secret port=4341"); - // $db->Connect('host1','user1','secret'); - function _connect($str,$user='',$pwd='',$db='',$ctype=0) - { - - if (!function_exists('pg_pconnect')) return false; - - $this->_errorMsg = false; - - if ($user || $pwd || $db) { - $user = adodb_addslashes($user); - $pwd = adodb_addslashes($pwd); - if (strlen($db) == 0) $db = 'template1'; - $db = adodb_addslashes($db); - if ($str) { - $host = explode(":", $str); - if ($host[0]) $str = "host=".adodb_addslashes($host[0]); - else $str = 'host=localhost'; - if (isset($host[1])) $str .= " port=$host[1]"; - } - if ($user) $str .= " user=".$user; - if ($pwd) $str .= " password=".$pwd; - if ($db) $str .= " dbname=".$db; - } - - //if ($user) $linea = "user=$user host=$linea password=$pwd dbname=$db port=5432"; - - if ($ctype === 1) { // persistent - $this->_connectionID = pg_pconnect($str); - } else { - if ($ctype === -1) { // nconnect, we trick pgsql ext by changing the connection str - static $ncnt; - - if (empty($ncnt)) $ncnt = 1; - else $ncnt += 1; - - $str .= str_repeat(' ',$ncnt); - } - $this->_connectionID = pg_connect($str); - } - if ($this->_connectionID === false) return false; - $this->Execute("set datestyle='ISO'"); - return true; - } - - function _nconnect($argHostname, $argUsername, $argPassword, $argDatabaseName) - { - return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabaseName,-1); - } - - // returns true or false - // - // examples: - // $db->PConnect("host=host1 user=user1 password=secret port=4341"); - // $db->PConnect('host1','user1','secret'); - function _pconnect($str,$user='',$pwd='',$db='') - { - return $this->_connect($str,$user,$pwd,$db,1); - } - - - // returns queryID or false - function _query($sql,$inputarr) - { - - if ($inputarr) { - /* - It appears that PREPARE/EXECUTE is slower for many queries. - - For query executed 1000 times: - "select id,firstname,lastname from adoxyz - where firstname not like ? and lastname not like ? and id = ?" - - with plan = 1.51861286163 secs - no plan = 1.26903700829 secs - - - - */ - $plan = 'P'.md5($sql); - - $execp = ''; - foreach($inputarr as $v) { - if ($execp) $execp .= ','; - if (is_string($v)) { - if (strncmp($v,"'",1) !== 0) $execp .= $this->qstr($v); - } else { - $execp .= $v; - } - } - - if ($execp) $exsql = "EXECUTE $plan ($execp)"; - else $exsql = "EXECUTE $plan"; - - $rez = @pg_exec($this->_connectionID,$exsql); - if (!$rez) { - # Perhaps plan does not exist? Prepare/compile plan. - $params = ''; - foreach($inputarr as $v) { - if ($params) $params .= ','; - if (is_string($v)) { - $params .= 'VARCHAR'; - } else if (is_integer($v)) { - $params .= 'INTEGER'; - } else { - $params .= "REAL"; - } - } - $sqlarr = explode('?',$sql); - //print_r($sqlarr); - $sql = ''; - $i = 1; - foreach($sqlarr as $v) { - $sql .= $v.' $'.$i; - $i++; - } - $s = "PREPARE $plan ($params) AS ".substr($sql,0,strlen($sql)-2); - //adodb_pr($s); - pg_exec($this->_connectionID,$s); - echo $this->ErrorMsg(); - } - - $rez = pg_exec($this->_connectionID,$exsql); - } else { - $this->_errorMsg = false; - //adodb_backtrace(); - $rez = pg_exec($this->_connectionID,$sql); - } - // check if no data returned, then no need to create real recordset - if ($rez && pg_numfields($rez) <= 0) { - if (is_resource($this->_resultid) && get_resource_type($this->_resultid) === 'pgsql result') { - pg_freeresult($this->_resultid); - } - $this->_resultid = $rez; - return true; - } - - return $rez; - } - - - /* Returns: the last error message from previous database operation */ - function ErrorMsg() - { - if ($this->_errorMsg !== false) return $this->_errorMsg; - if (ADODB_PHPVER >= 0x4300) { - if (!empty($this->_resultid)) { - $this->_errorMsg = @pg_result_error($this->_resultid); - if ($this->_errorMsg) return $this->_errorMsg; - } - - if (!empty($this->_connectionID)) { - $this->_errorMsg = @pg_last_error($this->_connectionID); - } else $this->_errorMsg = @pg_last_error(); - } else { - if (empty($this->_connectionID)) $this->_errorMsg = @pg_errormessage(); - else $this->_errorMsg = @pg_errormessage($this->_connectionID); - } - return $this->_errorMsg; - } - - function ErrorNo() - { - $e = $this->ErrorMsg(); - return strlen($e) ? $e : 0; - } - - // returns true or false - function _close() - { - if ($this->transCnt) $this->RollbackTrans(); - if ($this->_resultid) { - @pg_freeresult($this->_resultid); - $this->_resultid = false; - } - @pg_close($this->_connectionID); - $this->_connectionID = false; - return true; - } - - - /* - * Maximum size of C field - */ - function CharMax() - { - return 1000000000; // should be 1 Gb? - } - - /* - * Maximum size of X field - */ - function TextMax() - { - return 1000000000; // should be 1 Gb? - } + // returns true or false + // + // examples: + // $db->Connect("host=host1 user=user1 password=secret port=4341"); + // $db->Connect('host1','user1','secret'); + function _connect($str,$user='',$pwd='',$db='',$ctype=0) + { + + if (!function_exists('pg_pconnect')) return false; + + $this->_errorMsg = false; + + if ($user || $pwd || $db) { + $user = adodb_addslashes($user); + $pwd = adodb_addslashes($pwd); + if (strlen($db) == 0) $db = 'template1'; + $db = adodb_addslashes($db); + if ($str) { + $host = explode(":", $str); + if ($host[0]) $str = "host=".adodb_addslashes($host[0]); + else $str = 'host=localhost'; + if (isset($host[1])) $str .= " port=$host[1]"; + } + if ($user) $str .= " user=".$user; + if ($pwd) $str .= " password=".$pwd; + if ($db) $str .= " dbname=".$db; + } + + //if ($user) $linea = "user=$user host=$linea password=$pwd dbname=$db port=5432"; + + if ($ctype === 1) { // persistent + $this->_connectionID = pg_pconnect($str); + } else { + if ($ctype === -1) { // nconnect, we trick pgsql ext by changing the connection str + static $ncnt; + + if (empty($ncnt)) $ncnt = 1; + else $ncnt += 1; + + $str .= str_repeat(' ',$ncnt); + } + $this->_connectionID = pg_connect($str); + } + if ($this->_connectionID === false) return false; + $this->Execute("set datestyle='ISO'"); + return true; + } + + function _nconnect($argHostname, $argUsername, $argPassword, $argDatabaseName) + { + return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabaseName,-1); + } + + // returns true or false + // + // examples: + // $db->PConnect("host=host1 user=user1 password=secret port=4341"); + // $db->PConnect('host1','user1','secret'); + function _pconnect($str,$user='',$pwd='',$db='') + { + return $this->_connect($str,$user,$pwd,$db,1); + } + + + // returns queryID or false + function _query($sql,$inputarr) + { + + if ($inputarr) { + /* + It appears that PREPARE/EXECUTE is slower for many queries. + + For query executed 1000 times: + "select id,firstname,lastname from adoxyz + where firstname not like ? and lastname not like ? and id = ?" + + with plan = 1.51861286163 secs + no plan = 1.26903700829 secs + + + + */ + $plan = 'P'.md5($sql); + + $execp = ''; + foreach($inputarr as $v) { + if ($execp) $execp .= ','; + if (is_string($v)) { + if (strncmp($v,"'",1) !== 0) $execp .= $this->qstr($v); + } else { + $execp .= $v; + } + } + + if ($execp) $exsql = "EXECUTE $plan ($execp)"; + else $exsql = "EXECUTE $plan"; + + $rez = @pg_exec($this->_connectionID,$exsql); + if (!$rez) { + # Perhaps plan does not exist? Prepare/compile plan. + $params = ''; + foreach($inputarr as $v) { + if ($params) $params .= ','; + if (is_string($v)) { + $params .= 'VARCHAR'; + } else if (is_integer($v)) { + $params .= 'INTEGER'; + } else { + $params .= "REAL"; + } + } + $sqlarr = explode('?',$sql); + //print_r($sqlarr); + $sql = ''; + $i = 1; + foreach($sqlarr as $v) { + $sql .= $v.' $'.$i; + $i++; + } + $s = "PREPARE $plan ($params) AS ".substr($sql,0,strlen($sql)-2); + //adodb_pr($s); + pg_exec($this->_connectionID,$s); + echo $this->ErrorMsg(); + } + + $rez = pg_exec($this->_connectionID,$exsql); + } else { + $this->_errorMsg = false; + //adodb_backtrace(); + $rez = pg_exec($this->_connectionID,$sql); + } + // check if no data returned, then no need to create real recordset + if ($rez && pg_numfields($rez) <= 0) { + if (is_resource($this->_resultid) && get_resource_type($this->_resultid) === 'pgsql result') { + pg_freeresult($this->_resultid); + } + $this->_resultid = $rez; + return true; + } + + return $rez; + } + + + /* Returns: the last error message from previous database operation */ + function ErrorMsg() + { + if ($this->_errorMsg !== false) return $this->_errorMsg; + if (ADODB_PHPVER >= 0x4300) { + if (!empty($this->_resultid)) { + $this->_errorMsg = @pg_result_error($this->_resultid); + if ($this->_errorMsg) return $this->_errorMsg; + } + + if (!empty($this->_connectionID)) { + $this->_errorMsg = @pg_last_error($this->_connectionID); + } else $this->_errorMsg = @pg_last_error(); + } else { + if (empty($this->_connectionID)) $this->_errorMsg = @pg_errormessage(); + else $this->_errorMsg = @pg_errormessage($this->_connectionID); + } + return $this->_errorMsg; + } + + function ErrorNo() + { + $e = $this->ErrorMsg(); + return strlen($e) ? $e : 0; + } + + // returns true or false + function _close() + { + if ($this->transCnt) $this->RollbackTrans(); + if ($this->_resultid) { + @pg_freeresult($this->_resultid); + $this->_resultid = false; + } + @pg_close($this->_connectionID); + $this->_connectionID = false; + return true; + } + + + /* + * Maximum size of C field + */ + function CharMax() + { + return 1000000000; // should be 1 Gb? + } + + /* + * Maximum size of X field + */ + function TextMax() + { + return 1000000000; // should be 1 Gb? + } } /*-------------------------------------------------------------------------------------- - Class Name: Recordset + Class Name: Recordset --------------------------------------------------------------------------------------*/ class ADORecordSet_postgres64 extends ADORecordSet{ - var $_blobArr; - var $databaseType = "postgres64"; - var $canSeek = true; - function ADORecordSet_postgres64($queryID,$mode=false) - { - if ($mode === false) { - global $ADODB_FETCH_MODE; - $mode = $ADODB_FETCH_MODE; - } - switch ($mode) - { - case ADODB_FETCH_NUM: $this->fetchMode = PGSQL_NUM; break; - case ADODB_FETCH_ASSOC:$this->fetchMode = PGSQL_ASSOC; break; - default: - case ADODB_FETCH_DEFAULT: - case ADODB_FETCH_BOTH:$this->fetchMode = PGSQL_BOTH; break; - } - $this->ADORecordSet($queryID); - } - - function &GetRowAssoc($upper=true) - { - if ($this->fetchMode == PGSQL_ASSOC && !$upper) return $this->fields; - $row =& ADORecordSet::GetRowAssoc($upper); - return $row; - } - - function _initrs() - { - global $ADODB_COUNTRECS; - $qid = $this->_queryID; - $this->_numOfRows = ($ADODB_COUNTRECS)? @pg_numrows($qid):-1; - $this->_numOfFields = @pg_numfields($qid); - - // cache types for blob decode check - for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { - if (pg_fieldtype($qid,$i) == 'bytea') { - $this->_blobArr[$i] = pg_fieldname($qid,$off); - } - } - } - - /* Use associative array to get fields array */ - function Fields($colname) - { - if ($this->fetchMode != PGSQL_NUM) return @$this->fields[$colname]; - - if (!$this->bind) { - $this->bind = array(); - for ($i=0; $i < $this->_numOfFields; $i++) { - $o = $this->FetchField($i); - $this->bind[strtoupper($o->name)] = $i; - } - } - return $this->fields[$this->bind[strtoupper($colname)]]; - } - - function &FetchField($fieldOffset = 0) - { - $off=$fieldOffset; // offsets begin at 0 - - $o= new ADOFieldObject(); - $o->name = @pg_fieldname($this->_queryID,$off); - $o->type = @pg_fieldtype($this->_queryID,$off); - $o->max_length = @pg_fieldsize($this->_queryID,$off); - return $o; - } - - function _seek($row) - { - return @pg_fetch_row($this->_queryID,$row); - } - - function _decode($blob) - { - eval('$realblob="'.adodb_str_replace(array('"','$'),array('\"','\$'),$blob).'";'); - return $realblob; - } - - function _fixblobs() - { - if ($this->fetchMode == PGSQL_NUM || $this->fetchMode == PGSQL_BOTH) { - foreach($this->_blobArr as $k => $v) { - $this->fields[$k] = ADORecordSet_postgres64::_decode($this->fields[$k]); - } - } - if ($this->fetchMode == PGSQL_ASSOC || $this->fetchMode == PGSQL_BOTH) { - foreach($this->_blobArr as $k => $v) { - $this->fields[$v] = ADORecordSet_postgres64::_decode($this->fields[$v]); - } - } - } - - // 10% speedup to move MoveNext to child class - function MoveNext() - { - if (!$this->EOF) { - $this->_currentRow++; - if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) { - $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode); - if (is_array($this->fields) && $this->fields) { - if ($this->fields && isset($this->_blobArr)) $this->_fixblobs(); - return true; - } - } - $this->fields = false; - $this->EOF = true; - } - return false; - } - - function _fetch() - { - - if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0) - return false; - - $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode); - - if ($this->fields && isset($this->_blobArr)) $this->_fixblobs(); - - return (is_array($this->fields)); - } - - function _close() - { - return @pg_freeresult($this->_queryID); - } - - function MetaType($t,$len=-1,$fieldobj=false) - { - if (is_object($t)) { - $fieldobj = $t; - $t = $fieldobj->type; - $len = $fieldobj->max_length; - } - switch (strtoupper($t)) { - case 'MONEY': // stupid, postgres expects money to be a string - case 'INTERVAL': - case 'CHAR': - case 'CHARACTER': - case 'VARCHAR': - case 'NAME': - case 'BPCHAR': - case '_VARCHAR': - if ($len <= $this->blobSize) return 'C'; - - case 'TEXT': - return 'X'; - - case 'IMAGE': // user defined type - case 'BLOB': // user defined type - case 'BIT': // This is a bit string, not a single bit, so don't return 'L' - case 'VARBIT': - case 'BYTEA': - return 'B'; - - case 'BOOL': - case 'BOOLEAN': - return 'L'; - - case 'DATE': - return 'D'; - - case 'TIME': - case 'DATETIME': - case 'TIMESTAMP': - case 'TIMESTAMPTZ': - return 'T'; - - case 'SMALLINT': - case 'BIGINT': - case 'INTEGER': - case 'INT8': - case 'INT4': - case 'INT2': - if (isset($fieldobj) && - empty($fieldobj->primary_key) && empty($fieldobj->unique)) return 'I'; - - case 'OID': - case 'SERIAL': - return 'R'; - - default: - return 'N'; - } - } + var $_blobArr; + var $databaseType = "postgres64"; + var $canSeek = true; + function ADORecordSet_postgres64($queryID,$mode=false) + { + if ($mode === false) { + global $ADODB_FETCH_MODE; + $mode = $ADODB_FETCH_MODE; + } + switch ($mode) + { + case ADODB_FETCH_NUM: $this->fetchMode = PGSQL_NUM; break; + case ADODB_FETCH_ASSOC:$this->fetchMode = PGSQL_ASSOC; break; + default: + case ADODB_FETCH_DEFAULT: + case ADODB_FETCH_BOTH:$this->fetchMode = PGSQL_BOTH; break; + } + $this->ADORecordSet($queryID); + } + + function &GetRowAssoc($upper=true) + { + if ($this->fetchMode == PGSQL_ASSOC && !$upper) return $this->fields; + $row =& ADORecordSet::GetRowAssoc($upper); + return $row; + } + + function _initrs() + { + global $ADODB_COUNTRECS; + $qid = $this->_queryID; + $this->_numOfRows = ($ADODB_COUNTRECS)? @pg_numrows($qid):-1; + $this->_numOfFields = @pg_numfields($qid); + + // cache types for blob decode check + for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { + if (pg_fieldtype($qid,$i) == 'bytea') { + $this->_blobArr[$i] = pg_fieldname($qid,$off); + } + } + } + + /* Use associative array to get fields array */ + function Fields($colname) + { + if ($this->fetchMode != PGSQL_NUM) return @$this->fields[$colname]; + + if (!$this->bind) { + $this->bind = array(); + for ($i=0; $i < $this->_numOfFields; $i++) { + $o = $this->FetchField($i); + $this->bind[strtoupper($o->name)] = $i; + } + } + return $this->fields[$this->bind[strtoupper($colname)]]; + } + + function &FetchField($fieldOffset = 0) + { + $off=$fieldOffset; // offsets begin at 0 + + $o= new ADOFieldObject(); + $o->name = @pg_fieldname($this->_queryID,$off); + $o->type = @pg_fieldtype($this->_queryID,$off); + $o->max_length = @pg_fieldsize($this->_queryID,$off); + return $o; + } + + function _seek($row) + { + return @pg_fetch_row($this->_queryID,$row); + } + + function _decode($blob) + { + eval('$realblob="'.adodb_str_replace(array('"','$'),array('\"','\$'),$blob).'";'); + return $realblob; + } + + function _fixblobs() + { + if ($this->fetchMode == PGSQL_NUM || $this->fetchMode == PGSQL_BOTH) { + foreach($this->_blobArr as $k => $v) { + $this->fields[$k] = ADORecordSet_postgres64::_decode($this->fields[$k]); + } + } + if ($this->fetchMode == PGSQL_ASSOC || $this->fetchMode == PGSQL_BOTH) { + foreach($this->_blobArr as $k => $v) { + $this->fields[$v] = ADORecordSet_postgres64::_decode($this->fields[$v]); + } + } + } + + // 10% speedup to move MoveNext to child class + function MoveNext() + { + if (!$this->EOF) { + $this->_currentRow++; + if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) { + $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode); + if (is_array($this->fields) && $this->fields) { + if ($this->fields && isset($this->_blobArr)) $this->_fixblobs(); + return true; + } + } + $this->fields = false; + $this->EOF = true; + } + return false; + } + + function _fetch() + { + + if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0) + return false; + + $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode); + + if ($this->fields && isset($this->_blobArr)) $this->_fixblobs(); + + return (is_array($this->fields)); + } + + function _close() + { + return @pg_freeresult($this->_queryID); + } + + function MetaType($t,$len=-1,$fieldobj=false) + { + if (is_object($t)) { + $fieldobj = $t; + $t = $fieldobj->type; + $len = $fieldobj->max_length; + } + switch (strtoupper($t)) { + case 'MONEY': // stupid, postgres expects money to be a string + case 'INTERVAL': + case 'CHAR': + case 'CHARACTER': + case 'VARCHAR': + case 'NAME': + case 'BPCHAR': + case '_VARCHAR': + if ($len <= $this->blobSize) return 'C'; + + case 'TEXT': + return 'X'; + + case 'IMAGE': // user defined type + case 'BLOB': // user defined type + case 'BIT': // This is a bit string, not a single bit, so don't return 'L' + case 'VARBIT': + case 'BYTEA': + return 'B'; + + case 'BOOL': + case 'BOOLEAN': + return 'L'; + + case 'DATE': + return 'D'; + + case 'TIME': + case 'DATETIME': + case 'TIMESTAMP': + case 'TIMESTAMPTZ': + return 'T'; + + case 'SMALLINT': + case 'BIGINT': + case 'INTEGER': + case 'INT8': + case 'INT4': + case 'INT2': + if (isset($fieldobj) && + empty($fieldobj->primary_key) && empty($fieldobj->unique)) return 'I'; + + case 'OID': + case 'SERIAL': + return 'R'; + + default: + return 'N'; + } + } } ?> diff --git a/lib/WikiDB/adodb/drivers/adodb-postgres7.inc.php b/lib/WikiDB/adodb/drivers/adodb-postgres7.inc.php index 8848815ce..68ea531b2 100644 --- a/lib/WikiDB/adodb/drivers/adodb-postgres7.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-postgres7.inc.php @@ -14,79 +14,79 @@ include_once(ADODB_DIR."/drivers/adodb-postgres64.inc.php"); class ADODB_postgres7 extends ADODB_postgres64 { - var $databaseType = 'postgres7'; - var $hasLimit = true; // set to true for pgsql 6.5+ only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10 - var $ansiOuter = true; - var $charSet = true; //set to true for Postgres 7 and above - PG client supports encodings - - function ADODB_postgres7() - { - $this->ADODB_postgres64(); - } - - - // the following should be compat with postgresql 7.2, - // which makes obsolete the LIMIT limit,offset syntax - function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0) - { - $offsetStr = ($offset >= 0) ? " OFFSET $offset" : ''; - $limitStr = ($nrows >= 0) ? " LIMIT $nrows" : ''; - if ($secs2cache) - $rs =& $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr); - else - $rs =& $this->Execute($sql."$limitStr$offsetStr",$inputarr); - - return $rs; - } - /* - function Prepare($sql) - { - $info = $this->ServerInfo(); - if ($info['version']>=7.3) { - return array($sql,false); - } - return $sql; - } - */ - - // from Edward Jaramilla, improved version - works on pg 7.4 + var $databaseType = 'postgres7'; + var $hasLimit = true; // set to true for pgsql 6.5+ only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10 + var $ansiOuter = true; + var $charSet = true; //set to true for Postgres 7 and above - PG client supports encodings + + function ADODB_postgres7() + { + $this->ADODB_postgres64(); + } + + + // the following should be compat with postgresql 7.2, + // which makes obsolete the LIMIT limit,offset syntax + function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0) + { + $offsetStr = ($offset >= 0) ? " OFFSET $offset" : ''; + $limitStr = ($nrows >= 0) ? " LIMIT $nrows" : ''; + if ($secs2cache) + $rs =& $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr); + else + $rs =& $this->Execute($sql."$limitStr$offsetStr",$inputarr); + + return $rs; + } + /* + function Prepare($sql) + { + $info = $this->ServerInfo(); + if ($info['version']>=7.3) { + return array($sql,false); + } + return $sql; + } + */ + + // from Edward Jaramilla, improved version - works on pg 7.4 function MetaForeignKeys($table, $owner=false, $upper=false) { - $sql = 'SELECT t.tgargs as args - FROM - pg_trigger t,pg_class c,pg_proc p - WHERE - t.tgenabled AND - t.tgrelid = c.oid AND - t.tgfoid = p.oid AND - p.proname = \'RI_FKey_check_ins\' AND - c.relname = \''.strtolower($table).'\' - ORDER BY - t.tgrelid'; - - $rs = $this->Execute($sql); - - if ($rs && !$rs->EOF) { - $arr =& $rs->GetArray(); - $a = array(); - foreach($arr as $v) - { - $data = explode(chr(0), $v['args']); - if ($upper) { - $a[strtoupper($data[2])][] = strtoupper($data[4].'='.$data[5]); - } else { - $a[$data[2]][] = $data[4].'='.$data[5]; - } - } - return $a; - } - return false; + $sql = 'SELECT t.tgargs as args + FROM + pg_trigger t,pg_class c,pg_proc p + WHERE + t.tgenabled AND + t.tgrelid = c.oid AND + t.tgfoid = p.oid AND + p.proname = \'RI_FKey_check_ins\' AND + c.relname = \''.strtolower($table).'\' + ORDER BY + t.tgrelid'; + + $rs = $this->Execute($sql); + + if ($rs && !$rs->EOF) { + $arr =& $rs->GetArray(); + $a = array(); + foreach($arr as $v) + { + $data = explode(chr(0), $v['args']); + if ($upper) { + $a[strtoupper($data[2])][] = strtoupper($data[4].'='.$data[5]); + } else { + $a[$data[2]][] = $data[4].'='.$data[5]; + } + } + return $a; + } + return false; } function xMetaForeignKeys($table, $owner=false, $upper=false) - { + { $sql = ' SELECT t.tgargs as args @@ -103,10 +103,10 @@ SELECT t.tgargs as args ORDER BY t.tgrelid'; $rs = $this->Execute($sql); - if ($rs && !$rs->EOF) { - $arr =& $rs->GetArray(); - $a = array(); - foreach($arr as $v) { + if ($rs && !$rs->EOF) { + $arr =& $rs->GetArray(); + $a = array(); + foreach($arr as $v) { $data = explode(chr(0), $v['args']); if ($upper) { $a[] = array(strtoupper($data[2]) => strtoupper($data[4].'='.$data[5])); @@ -114,76 +114,76 @@ SELECT t.tgargs as args $a[] = array($data[2] => $data[4].'='.$data[5]); } - } - return $a; - } - else return false; + } + return $a; + } + else return false; } - // this is a set of functions for managing client encoding - very important if the encodings - // of your database and your output target (i.e. HTML) don't match - //for instance, you may have UNICODE database and server it on-site as WIN1251 etc. - // GetCharSet - get the name of the character set the client is using now - // the functions should work with Postgres 7.0 and above, the set of charsets supported - // depends on compile flags of postgres distribution - if no charsets were compiled into the server - // it will return 'SQL_ANSI' always - function GetCharSet() - { - //we will use ADO's builtin property charSet - $this->charSet = @pg_client_encoding($this->_connectionID); - if (!$this->charSet) { - return false; - } else { - return $this->charSet; - } - } - - // SetCharSet - switch the client encoding - function SetCharSet($charset_name) - { - $this->GetCharSet(); - if ($this->charSet !== $charset_name) { - $if = pg_set_client_encoding($this->_connectionID, $charset_name); - if ($if == "0" & $this->GetCharSet() == $charset_name) { - return true; - } else return false; - } else return true; - } + // this is a set of functions for managing client encoding - very important if the encodings + // of your database and your output target (i.e. HTML) don't match + //for instance, you may have UNICODE database and server it on-site as WIN1251 etc. + // GetCharSet - get the name of the character set the client is using now + // the functions should work with Postgres 7.0 and above, the set of charsets supported + // depends on compile flags of postgres distribution - if no charsets were compiled into the server + // it will return 'SQL_ANSI' always + function GetCharSet() + { + //we will use ADO's builtin property charSet + $this->charSet = @pg_client_encoding($this->_connectionID); + if (!$this->charSet) { + return false; + } else { + return $this->charSet; + } + } + + // SetCharSet - switch the client encoding + function SetCharSet($charset_name) + { + $this->GetCharSet(); + if ($this->charSet !== $charset_name) { + $if = pg_set_client_encoding($this->_connectionID, $charset_name); + if ($if == "0" & $this->GetCharSet() == $charset_name) { + return true; + } else return false; + } else return true; + } } /*-------------------------------------------------------------------------------------- - Class Name: Recordset + Class Name: Recordset --------------------------------------------------------------------------------------*/ class ADORecordSet_postgres7 extends ADORecordSet_postgres64{ - var $databaseType = "postgres7"; - - - function ADORecordSet_postgres7($queryID,$mode=false) - { - $this->ADORecordSet_postgres64($queryID,$mode); - } - - // 10% speedup to move MoveNext to child class - function MoveNext() - { - if (!$this->EOF) { - $this->_currentRow++; - if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) { - $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode); - - if (is_array($this->fields)) { - if ($this->fields && isset($this->_blobArr)) $this->_fixblobs(); - return true; - } - } - $this->fields = false; - $this->EOF = true; - } - return false; - } + var $databaseType = "postgres7"; + + + function ADORecordSet_postgres7($queryID,$mode=false) + { + $this->ADORecordSet_postgres64($queryID,$mode); + } + + // 10% speedup to move MoveNext to child class + function MoveNext() + { + if (!$this->EOF) { + $this->_currentRow++; + if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) { + $this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode); + + if (is_array($this->fields)) { + if ($this->fields && isset($this->_blobArr)) $this->_fixblobs(); + return true; + } + } + $this->fields = false; + $this->EOF = true; + } + return false; + } } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/drivers/adodb-proxy.inc.php b/lib/WikiDB/adodb/drivers/adodb-proxy.inc.php index 34a91cc80..1da931787 100644 --- a/lib/WikiDB/adodb/drivers/adodb-proxy.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-proxy.inc.php @@ -10,21 +10,21 @@ V4.22 15 Apr 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights rese */ if (! defined("_ADODB_PROXY_LAYER")) { - define("_ADODB_PROXY_LAYER", 1 ); - include(ADODB_DIR."/drivers/adodb-csv.inc.php"); + define("_ADODB_PROXY_LAYER", 1 ); + include(ADODB_DIR."/drivers/adodb-csv.inc.php"); - class ADODB_proxy extends ADODB_csv { - var $databaseType = 'proxy'; - var $databaseProvider = 'csv'; - } - class ADORecordset_proxy extends ADORecordset_csv { - var $databaseType = "proxy"; + class ADODB_proxy extends ADODB_csv { + var $databaseType = 'proxy'; + var $databaseProvider = 'csv'; + } + class ADORecordset_proxy extends ADORecordset_csv { + var $databaseType = "proxy"; - function ADORecordset_proxy($id,$mode=false) - { - $this->ADORecordset($id,$mode); - } - }; + function ADORecordset_proxy($id,$mode=false) + { + $this->ADORecordset($id,$mode); + } + }; } // define ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/drivers/adodb-sapdb.inc.php b/lib/WikiDB/adodb/drivers/adodb-sapdb.inc.php index 2ea565560..b28181387 100644 --- a/lib/WikiDB/adodb/drivers/adodb-sapdb.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-sapdb.inc.php @@ -13,50 +13,50 @@ Set tabs to 4 for best viewing. */ if (!defined('_ADODB_ODBC_LAYER')) { - include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); + include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); } if (!defined('ADODB_SAPDB')){ define('ADODB_SAPDB',1); class ADODB_SAPDB extends ADODB_odbc { - var $databaseType = "sapdb"; - var $concat_operator = '||'; - var $sysDate = 'DATE'; - var $sysTimeStamp = 'TIMESTAMP'; - var $fmtDate = "\\D\\A\\T\\E('Y-m-d')"; /// used by DBDate() as the default date format used by the database - var $fmtTimeStamp = "\\T\\I\\M\\E\\S\\T\\A\\M\\P('Y-m-d','H:i:s')"; /// used by DBTimeStamp as the default timestamp fmt. + var $databaseType = "sapdb"; + var $concat_operator = '||'; + var $sysDate = 'DATE'; + var $sysTimeStamp = 'TIMESTAMP'; + var $fmtDate = "\\D\\A\\T\\E('Y-m-d')"; /// used by DBDate() as the default date format used by the database + var $fmtTimeStamp = "\\T\\I\\M\\E\\S\\T\\A\\M\\P('Y-m-d','H:i:s')"; /// used by DBTimeStamp as the default timestamp fmt. - function ADODB_SAPDB() - { - //if (strncmp(PHP_OS,'WIN',3) === 0) $this->curmode = SQL_CUR_USE_ODBC; - $this->ADODB_odbc(); - } + function ADODB_SAPDB() + { + //if (strncmp(PHP_OS,'WIN',3) === 0) $this->curmode = SQL_CUR_USE_ODBC; + $this->ADODB_odbc(); + } - /* - SelectLimit implementation problems: + /* + SelectLimit implementation problems: - The following will return random 10 rows as order by performed after "WHERE rowno<10" - which is not ideal... + The following will return random 10 rows as order by performed after "WHERE rowno<10" + which is not ideal... - select * from table where rowno < 10 order by 1 + select * from table where rowno < 10 order by 1 - This means that we have to use the adoconnection base class SelectLimit when - there is an "order by". + This means that we have to use the adoconnection base class SelectLimit when + there is an "order by". - See http://listserv.sap.com/pipermail/sapdb.general/2002-January/010405.html - */ + See http://listserv.sap.com/pipermail/sapdb.general/2002-January/010405.html + */ }; class ADORecordSet_sapdb extends ADORecordSet_odbc { - var $databaseType = "sapdb"; + var $databaseType = "sapdb"; - function ADORecordSet_sapdb($id,$mode=false) - { - $this->ADORecordSet_odbc($id,$mode); - } + function ADORecordSet_sapdb($id,$mode=false) + { + $this->ADORecordSet_odbc($id,$mode); + } } } //define diff --git a/lib/WikiDB/adodb/drivers/adodb-sqlanywhere.inc.php b/lib/WikiDB/adodb/drivers/adodb-sqlanywhere.inc.php index 15bbfa4d7..b99bea645 100644 --- a/lib/WikiDB/adodb/drivers/adodb-sqlanywhere.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-sqlanywhere.inc.php @@ -10,32 +10,32 @@ Set tabs to 4 for best viewing. Latest version is available at http://php.weblogs.com/ 21.02.2002 - Wade Johnson wade@wadejohnson.de - Extended ODBC class for Sybase SQLAnywhere. + Extended ODBC class for Sybase SQLAnywhere. 1) Added support to retrieve the last row insert ID on tables with - primary key column using autoincrement function. + primary key column using autoincrement function. 2) Added blob support. Usage: - a) create blob variable on db server: + a) create blob variable on db server: - $dbconn->create_blobvar($blobVarName); + $dbconn->create_blobvar($blobVarName); - b) load blob var from file. $filename must be complete path + b) load blob var from file. $filename must be complete path - $dbcon->load_blobvar_from_file($blobVarName, $filename); + $dbcon->load_blobvar_from_file($blobVarName, $filename); - c) Use the $blobVarName in SQL insert or update statement in the values - clause: + c) Use the $blobVarName in SQL insert or update statement in the values + clause: - $recordSet = $dbconn->Execute('INSERT INTO tabname (idcol, blobcol) ' - . - 'VALUES (\'test\', ' . $blobVarName . ')'); + $recordSet = $dbconn->Execute('INSERT INTO tabname (idcol, blobcol) ' + . + 'VALUES (\'test\', ' . $blobVarName . ')'); - instead of loading blob from a file, you can also load from - an unformatted (raw) blob variable: - $dbcon->load_blobvar_from_var($blobVarName, $varName); + instead of loading blob from a file, you can also load from + an unformatted (raw) blob variable: + $dbcon->load_blobvar_from_var($blobVarName, $varName); - d) drop blob variable on db server to free up resources: - $dbconn->drop_blobvar($blobVarName); + d) drop blob variable on db server to free up resources: + $dbconn->drop_blobvar($blobVarName); Sybase_SQLAnywhere data driver. Requires ODBC. @@ -50,17 +50,17 @@ if (!defined('ADODB_SYBASE_SQLANYWHERE')){ define('ADODB_SYBASE_SQLANYWHERE',1); class ADODB_sqlanywhere extends ADODB_odbc { - var $databaseType = "sqlanywhere"; - var $hasInsertID = true; + var $databaseType = "sqlanywhere"; + var $hasInsertID = true; - function ADODB_sqlanywhere() - { - $this->ADODB_odbc(); - } + function ADODB_sqlanywhere() + { + $this->ADODB_odbc(); + } - function _insertid() { - return $this->GetOne('select @@identity'); - } + function _insertid() { + return $this->GetOne('select @@identity'); + } function create_blobvar($blobVarName) { $this->Execute("create variable $blobVarName long binary"); @@ -80,22 +80,22 @@ if (!defined('ADODB_SYBASE_SQLANYWHERE')){ $integer_chunks = (integer)filesize($filename) / $chunk_size; $modulus = filesize($filename) % $chunk_size; if ($modulus != 0){ - $integer_chunks += 1; + $integer_chunks += 1; } for($loop=1;$loop<=$integer_chunks;$loop++){ - $contents = fread ($fd, $chunk_size); - $contents = bin2hex($contents); + $contents = fread ($fd, $chunk_size); + $contents = bin2hex($contents); - $hexstring = ''; + $hexstring = ''; - for($loop2=0;$loop2qstr($hexstring); + $hexstring = $this->qstr($hexstring); - $this->Execute("set $blobVarName = $blobVarName || " . $hexstring); + $this->Execute("set $blobVarName = $blobVarName || " . $hexstring); } fclose ($fd); @@ -108,22 +108,22 @@ if (!defined('ADODB_SYBASE_SQLANYWHERE')){ $integer_chunks = (integer)strlen($varName) / $chunk_size; $modulus = strlen($varName) % $chunk_size; if ($modulus != 0){ - $integer_chunks += 1; + $integer_chunks += 1; } for($loop=1;$loop<=$integer_chunks;$loop++){ - $contents = substr ($varName, (($loop - 1) * $chunk_size), $chunk_size); - $contents = bin2hex($contents); + $contents = substr ($varName, (($loop - 1) * $chunk_size), $chunk_size); + $contents = bin2hex($contents); - $hexstring = ''; + $hexstring = ''; - for($loop2=0;$loop2qstr($hexstring); + $hexstring = $this->qstr($hexstring); - $this->Execute("set $blobVarName = $blobVarName || " . $hexstring); + $this->Execute("set $blobVarName = $blobVarName || " . $hexstring); } return; diff --git a/lib/WikiDB/adodb/drivers/adodb-sqlite.inc.php b/lib/WikiDB/adodb/drivers/adodb-sqlite.inc.php index 3b98c87f5..6193fdf31 100644 --- a/lib/WikiDB/adodb/drivers/adodb-sqlite.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-sqlite.inc.php @@ -16,304 +16,304 @@ V4.22 15 Apr 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights rese */ class ADODB_sqlite extends ADOConnection { - var $databaseType = "sqlite"; - var $replaceQuote = "''"; // string to use to replace quotes - var $concat_operator='||'; - var $_errorNo = 0; - var $hasLimit = true; - var $hasInsertID = true; /// supports autoincrement ID? - var $hasAffectedRows = true; /// supports affected rows for update/delete? - var $metaTablesSQL = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name"; - var $sysDate = "adodb_date('Y-m-d')"; - var $sysTimeStamp = "adodb_date('Y-m-d H:i:s')"; - var $fmtTimeStamp = "'Y-m-d H:i:s'"; - - function ADODB_sqlite() - { - } + var $databaseType = "sqlite"; + var $replaceQuote = "''"; // string to use to replace quotes + var $concat_operator='||'; + var $_errorNo = 0; + var $hasLimit = true; + var $hasInsertID = true; /// supports autoincrement ID? + var $hasAffectedRows = true; /// supports affected rows for update/delete? + var $metaTablesSQL = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name"; + var $sysDate = "adodb_date('Y-m-d')"; + var $sysTimeStamp = "adodb_date('Y-m-d H:i:s')"; + var $fmtTimeStamp = "'Y-m-d H:i:s'"; + + function ADODB_sqlite() + { + } /* function __get($name) { - switch($name) { - case 'sysDate': return "'".date($this->fmtDate)."'"; - case 'sysTimeStamp' : return "'".date($this->sysTimeStamp)."'"; - } + switch($name) { + case 'sysDate': return "'".date($this->fmtDate)."'"; + case 'sysTimeStamp' : return "'".date($this->sysTimeStamp)."'"; + } }*/ - function ServerInfo() - { - $arr['version'] = sqlite_libversion(); - $arr['description'] = 'SQLite '; - $arr['encoding'] = sqlite_libencoding(); - return $arr; - } - - function BeginTrans() - { - if ($this->transOff) return true; - $ret = $this->Execute("BEGIN TRANSACTION"); - $this->transCnt += 1; - return true; - } - - function CommitTrans($ok=true) - { - if ($this->transOff) return true; - if (!$ok) return $this->RollbackTrans(); - $ret = $this->Execute("COMMIT"); - if ($this->transCnt>0)$this->transCnt -= 1; - return !empty($ret); - } - - function RollbackTrans() - { - if ($this->transOff) return true; - $ret = $this->Execute("ROLLBACK"); - if ($this->transCnt>0)$this->transCnt -= 1; - return !empty($ret); - } - - function _insertid() - { - return sqlite_last_insert_rowid($this->_connectionID); - } - - function _affectedrows() - { + function ServerInfo() + { + $arr['version'] = sqlite_libversion(); + $arr['description'] = 'SQLite '; + $arr['encoding'] = sqlite_libencoding(); + return $arr; + } + + function BeginTrans() + { + if ($this->transOff) return true; + $ret = $this->Execute("BEGIN TRANSACTION"); + $this->transCnt += 1; + return true; + } + + function CommitTrans($ok=true) + { + if ($this->transOff) return true; + if (!$ok) return $this->RollbackTrans(); + $ret = $this->Execute("COMMIT"); + if ($this->transCnt>0)$this->transCnt -= 1; + return !empty($ret); + } + + function RollbackTrans() + { + if ($this->transOff) return true; + $ret = $this->Execute("ROLLBACK"); + if ($this->transCnt>0)$this->transCnt -= 1; + return !empty($ret); + } + + function _insertid() + { + return sqlite_last_insert_rowid($this->_connectionID); + } + + function _affectedrows() + { return sqlite_changes($this->_connectionID); } - function ErrorMsg() - { - if ($this->_logsql) return $this->_errorMsg; - return ($this->_errorNo) ? sqlite_error_string($this->_errorNo) : ''; - } - - function ErrorNo() - { - return $this->_errorNo; - } - - function SQLDate($fmt, $col=false) - { - $fmt = $this->qstr($fmt); - return ($col) ? "adodb_date2($fmt,$col)" : "adodb_date($fmt)"; - } - - function &MetaColumns($tab) - { - global $ADODB_FETCH_MODE; - - $rs = $this->Execute("select * from $tab limit 1"); - if (!$rs) return false; - $arr = array(); - for ($i=0,$max=$rs->_numOfFields; $i < $max; $i++) { - $fld =& $rs->FetchField($i); - if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] =& $fld; - else $arr[strtoupper($fld->name)] =& $fld; - } - $rs->Close(); - return $arr; - } - - function _createFunctions() - { - @sqlite_create_function($this->_connectionID, 'adodb_date', 'adodb_date', 1); - @sqlite_create_function($this->_connectionID, 'adodb_date2', 'adodb_date2', 2); - } - - - // returns true or false - function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) - { - if (!function_exists('sqlite_open')) return false; - - $this->_connectionID = sqlite_open($argDatabasename); - if ($this->_connectionID === false) return false; - $this->_createFunctions(); - return true; - } - - // returns true or false - function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) - { - if (!function_exists('sqlite_popen')) return false; - - $this->_connectionID = sqlite_popen($argDatabasename); - if ($this->_connectionID === false) return false; - $this->_createFunctions(); - return true; - } - - // returns query ID if successful, otherwise false - function _query($sql,$inputarr=false) - { - $rez = sqlite_query($sql,$this->_connectionID); - if (!$rez) { - $this->_errorNo = sqlite_last_error($this->_connectionID); - } - - return $rez; - } - - function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0) - { - $offsetStr = ($offset >= 0) ? " OFFSET $offset" : ''; - $limitStr = ($nrows >= 0) ? " LIMIT $nrows" : ($offset >= 0 ? ' LIMIT 999999999' : ''); - if ($secs2cache) - $rs =& $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr); - else - $rs =& $this->Execute($sql."$limitStr$offsetStr",$inputarr); - - return $rs; - } - - /* - This algorithm is not very efficient, but works even if table locking - is not available. - - Will return false if unable to generate an ID after $MAXLOOPS attempts. - */ - var $_genSeqSQL = "create table %s (id integer)"; - - function GenID($seq='adodbseq',$start=1) - { - // if you have to modify the parameter below, your database is overloaded, - // or you need to implement generation of id's yourself! - $MAXLOOPS = 100; - //$this->debug=1; - while (--$MAXLOOPS>=0) { - $num = $this->GetOne("select id from $seq"); - if ($num === false) { - $this->Execute(sprintf($this->_genSeqSQL ,$seq)); - $start -= 1; - $num = '0'; - $ok = $this->Execute("insert into $seq values($start)"); - if (!$ok) return false; - } - $this->Execute("update $seq set id=id+1 where id=$num"); - - if ($this->affected_rows() > 0) { - $num += 1; - $this->genID = $num; - return $num; - } - } - if ($fn = $this->raiseErrorFn) { - $fn($this->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts",$seq,$num); - } - return false; - } - - function CreateSequence($seqname='adodbseq',$start=1) - { - if (empty($this->_genSeqSQL)) return false; - $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname)); - if (!$ok) return false; - $start -= 1; - return $this->Execute("insert into $seqname values($start)"); - } - - var $_dropSeqSQL = 'drop table %s'; - function DropSequence($seqname) - { - if (empty($this->_dropSeqSQL)) return false; - return $this->Execute(sprintf($this->_dropSeqSQL,$seqname)); - } - - // returns true or false - function _close() - { - return @sqlite_close($this->_connectionID); - } + function ErrorMsg() + { + if ($this->_logsql) return $this->_errorMsg; + return ($this->_errorNo) ? sqlite_error_string($this->_errorNo) : ''; + } + + function ErrorNo() + { + return $this->_errorNo; + } + + function SQLDate($fmt, $col=false) + { + $fmt = $this->qstr($fmt); + return ($col) ? "adodb_date2($fmt,$col)" : "adodb_date($fmt)"; + } + + function &MetaColumns($tab) + { + global $ADODB_FETCH_MODE; + + $rs = $this->Execute("select * from $tab limit 1"); + if (!$rs) return false; + $arr = array(); + for ($i=0,$max=$rs->_numOfFields; $i < $max; $i++) { + $fld =& $rs->FetchField($i); + if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] =& $fld; + else $arr[strtoupper($fld->name)] =& $fld; + } + $rs->Close(); + return $arr; + } + + function _createFunctions() + { + @sqlite_create_function($this->_connectionID, 'adodb_date', 'adodb_date', 1); + @sqlite_create_function($this->_connectionID, 'adodb_date2', 'adodb_date2', 2); + } + + + // returns true or false + function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) + { + if (!function_exists('sqlite_open')) return false; + + $this->_connectionID = sqlite_open($argDatabasename); + if ($this->_connectionID === false) return false; + $this->_createFunctions(); + return true; + } + + // returns true or false + function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) + { + if (!function_exists('sqlite_popen')) return false; + + $this->_connectionID = sqlite_popen($argDatabasename); + if ($this->_connectionID === false) return false; + $this->_createFunctions(); + return true; + } + + // returns query ID if successful, otherwise false + function _query($sql,$inputarr=false) + { + $rez = sqlite_query($sql,$this->_connectionID); + if (!$rez) { + $this->_errorNo = sqlite_last_error($this->_connectionID); + } + + return $rez; + } + + function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0) + { + $offsetStr = ($offset >= 0) ? " OFFSET $offset" : ''; + $limitStr = ($nrows >= 0) ? " LIMIT $nrows" : ($offset >= 0 ? ' LIMIT 999999999' : ''); + if ($secs2cache) + $rs =& $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr); + else + $rs =& $this->Execute($sql."$limitStr$offsetStr",$inputarr); + + return $rs; + } + + /* + This algorithm is not very efficient, but works even if table locking + is not available. + + Will return false if unable to generate an ID after $MAXLOOPS attempts. + */ + var $_genSeqSQL = "create table %s (id integer)"; + + function GenID($seq='adodbseq',$start=1) + { + // if you have to modify the parameter below, your database is overloaded, + // or you need to implement generation of id's yourself! + $MAXLOOPS = 100; + //$this->debug=1; + while (--$MAXLOOPS>=0) { + $num = $this->GetOne("select id from $seq"); + if ($num === false) { + $this->Execute(sprintf($this->_genSeqSQL ,$seq)); + $start -= 1; + $num = '0'; + $ok = $this->Execute("insert into $seq values($start)"); + if (!$ok) return false; + } + $this->Execute("update $seq set id=id+1 where id=$num"); + + if ($this->affected_rows() > 0) { + $num += 1; + $this->genID = $num; + return $num; + } + } + if ($fn = $this->raiseErrorFn) { + $fn($this->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts",$seq,$num); + } + return false; + } + + function CreateSequence($seqname='adodbseq',$start=1) + { + if (empty($this->_genSeqSQL)) return false; + $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname)); + if (!$ok) return false; + $start -= 1; + return $this->Execute("insert into $seqname values($start)"); + } + + var $_dropSeqSQL = 'drop table %s'; + function DropSequence($seqname) + { + if (empty($this->_dropSeqSQL)) return false; + return $this->Execute(sprintf($this->_dropSeqSQL,$seqname)); + } + + // returns true or false + function _close() + { + return @sqlite_close($this->_connectionID); + } } /*-------------------------------------------------------------------------------------- - Class Name: Recordset + Class Name: Recordset --------------------------------------------------------------------------------------*/ class ADORecordset_sqlite extends ADORecordSet { - var $databaseType = "sqlite"; - var $bind = false; - - function ADORecordset_sqlite($queryID,$mode=false) - { - - if ($mode === false) { - global $ADODB_FETCH_MODE; - $mode = $ADODB_FETCH_MODE; - } - switch($mode) { - case ADODB_FETCH_NUM: $this->fetchMode = SQLITE_NUM; break; - case ADODB_FETCH_ASSOC: $this->fetchMode = SQLITE_ASSOC; break; - default: $this->fetchMode = SQLITE_BOTH; break; - } - - $this->_queryID = $queryID; - - $this->_inited = true; - $this->fields = array(); - if ($queryID) { - $this->_currentRow = 0; - $this->EOF = !$this->_fetch(); - @$this->_initrs(); - } else { - $this->_numOfRows = 0; - $this->_numOfFields = 0; - $this->EOF = true; - } - - return $this->_queryID; - } - - - function &FetchField($fieldOffset = -1) - { - $fld = new ADOFieldObject; - $fld->name = sqlite_field_name($this->_queryID, $fieldOffset); - $fld->type = 'VARCHAR'; - $fld->max_length = -1; - return $fld; - } + var $databaseType = "sqlite"; + var $bind = false; + + function ADORecordset_sqlite($queryID,$mode=false) + { + + if ($mode === false) { + global $ADODB_FETCH_MODE; + $mode = $ADODB_FETCH_MODE; + } + switch($mode) { + case ADODB_FETCH_NUM: $this->fetchMode = SQLITE_NUM; break; + case ADODB_FETCH_ASSOC: $this->fetchMode = SQLITE_ASSOC; break; + default: $this->fetchMode = SQLITE_BOTH; break; + } + + $this->_queryID = $queryID; + + $this->_inited = true; + $this->fields = array(); + if ($queryID) { + $this->_currentRow = 0; + $this->EOF = !$this->_fetch(); + @$this->_initrs(); + } else { + $this->_numOfRows = 0; + $this->_numOfFields = 0; + $this->EOF = true; + } + + return $this->_queryID; + } + + + function &FetchField($fieldOffset = -1) + { + $fld = new ADOFieldObject; + $fld->name = sqlite_field_name($this->_queryID, $fieldOffset); + $fld->type = 'VARCHAR'; + $fld->max_length = -1; + return $fld; + } function _initrs() { - $this->_numOfRows = @sqlite_num_rows($this->_queryID); - $this->_numOfFields = @sqlite_num_fields($this->_queryID); + $this->_numOfRows = @sqlite_num_rows($this->_queryID); + $this->_numOfFields = @sqlite_num_fields($this->_queryID); } - function Fields($colname) - { - if ($this->fetchMode != SQLITE_NUM) return $this->fields[$colname]; - if (!$this->bind) { - $this->bind = array(); - for ($i=0; $i < $this->_numOfFields; $i++) { - $o = $this->FetchField($i); - $this->bind[strtoupper($o->name)] = $i; - } - } - - return $this->fields[$this->bind[strtoupper($colname)]]; - } + function Fields($colname) + { + if ($this->fetchMode != SQLITE_NUM) return $this->fields[$colname]; + if (!$this->bind) { + $this->bind = array(); + for ($i=0; $i < $this->_numOfFields; $i++) { + $o = $this->FetchField($i); + $this->bind[strtoupper($o->name)] = $i; + } + } + + return $this->fields[$this->bind[strtoupper($colname)]]; + } function _seek($row) { - return sqlite_seek($this->_queryID, $row); + return sqlite_seek($this->_queryID, $row); } - function _fetch($ignore_fields=false) - { - $this->fields = @sqlite_fetch_array($this->_queryID,$this->fetchMode); - return !empty($this->fields); - } + function _fetch($ignore_fields=false) + { + $this->fields = @sqlite_fetch_array($this->_queryID,$this->fetchMode); + return !empty($this->fields); + } - function _close() - { - } + function _close() + { + } } ?> \ No newline at end of file diff --git a/lib/WikiDB/adodb/drivers/adodb-sybase.inc.php b/lib/WikiDB/adodb/drivers/adodb-sybase.inc.php index 5c80a67d6..8a29fe777 100644 --- a/lib/WikiDB/adodb/drivers/adodb-sybase.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-sybase.inc.php @@ -16,167 +16,167 @@ V4.22 15 Apr 2004 (c) 2000-2004 John Lim. All rights reserved. */ class ADODB_sybase extends ADOConnection { - var $databaseType = "sybase"; - //var $dataProvider = 'sybase'; - var $replaceQuote = "''"; // string to use to replace quotes - var $fmtDate = "'Y-m-d'"; - var $fmtTimeStamp = "'Y-m-d H:i:s'"; - var $hasInsertID = true; - var $hasAffectedRows = true; - var $metaTablesSQL="select name from sysobjects where type='U' or type='V'"; - // see http://sybooks.sybase.com/onlinebooks/group-aw/awg0800e/dbrfen8/@ebt-link;pt=5981;uf=0?target=0;window=new;showtoc=true;book=dbrfen8 - var $metaColumnsSQL = "SELECT c.column_name, c.column_type, c.width FROM syscolumn c, systable t WHERE t.table_name='%s' AND c.table_id=t.table_id AND t.table_type='BASE'"; - /* - "select c.name,t.name,c.length from - syscolumns c join systypes t on t.xusertype=c.xusertype join sysobjects o on o.id=c.id - where o.name='%s'"; - */ - var $concat_operator = '+'; - var $arrayClass = 'ADORecordSet_array_sybase'; - var $sysDate = 'GetDate()'; - var $leftOuter = '*='; - var $rightOuter = '=*'; - - function ADODB_sybase() - { - } - - // might require begintrans -- committrans - function _insertid() - { - return $this->GetOne('select @@identity'); - } - // might require begintrans -- committrans - function _affectedrows() - { - return $this->GetOne('select @@rowcount'); - } - - - function BeginTrans() - { - - if ($this->transOff) return true; - $this->transCnt += 1; - - $this->Execute('BEGIN TRAN'); - return true; - } - - function CommitTrans($ok=true) - { - if ($this->transOff) return true; - - if (!$ok) return $this->RollbackTrans(); - - $this->transCnt -= 1; - $this->Execute('COMMIT TRAN'); - return true; - } - - function RollbackTrans() - { - if ($this->transOff) return true; - $this->transCnt -= 1; - $this->Execute('ROLLBACK TRAN'); - return true; - } - - // http://www.isug.com/Sybase_FAQ/ASE/section6.1.html#6.1.4 - function RowLock($tables,$where) - { - if (!$this->_hastrans) $this->BeginTrans(); - $tables = str_replace(',',' HOLDLOCK,',$tables); - return $this->GetOne("select top 1 null as ignore from $tables HOLDLOCK where $where"); - - } - - function SelectDB($dbName) { - $this->databaseName = $dbName; - if ($this->_connectionID) { - return @sybase_select_db($dbName); - } - else return false; - } - - /* Returns: the last error message from previous database operation - Note: This function is NOT available for Microsoft SQL Server. */ - - function ErrorMsg() - { - if ($this->_logsql) return $this->_errorMsg; - $this->_errorMsg = sybase_get_last_message(); - return $this->_errorMsg; - } - - // returns true or false - function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) - { - if (!function_exists('sybase_connect')) return false; - - $this->_connectionID = sybase_connect($argHostname,$argUsername,$argPassword); - if ($this->_connectionID === false) return false; - if ($argDatabasename) return $this->SelectDB($argDatabasename); - return true; - } - // returns true or false - function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) - { - if (!function_exists('sybase_connect')) return false; - - $this->_connectionID = sybase_pconnect($argHostname,$argUsername,$argPassword); - if ($this->_connectionID === false) return false; - if ($argDatabasename) return $this->SelectDB($argDatabasename); - return true; - } - - // returns query ID if successful, otherwise false - function _query($sql,$inputarr) - { - global $ADODB_COUNTRECS; - - if ($ADODB_COUNTRECS == false && ADODB_PHPVER >= 0x4300) - return sybase_unbuffered_query($sql,$this->_connectionID); - else - return sybase_query($sql,$this->_connectionID); - } - - // See http://www.isug.com/Sybase_FAQ/ASE/section6.2.html#6.2.12 - function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0) - { - if ($secs2cache > 0) {// we do not cache rowcount, so we have to load entire recordset - $rs =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); - return $rs; - } - $cnt = ($nrows > 0) ? $nrows : 0; - if ($offset > 0 && $cnt) $cnt += $offset; - - $this->Execute("set rowcount $cnt"); - $rs =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); - $this->Execute("set rowcount 0"); - - return $rs; - } - - // returns true or false - function _close() - { - return @sybase_close($this->_connectionID); - } - - function UnixDate($v) - { - return ADORecordSet_array_sybase::UnixDate($v); - } - - function UnixTimeStamp($v) - { - return ADORecordSet_array_sybase::UnixTimeStamp($v); - } - - - - # Added 2003-10-05 by Chris Phillipson + var $databaseType = "sybase"; + //var $dataProvider = 'sybase'; + var $replaceQuote = "''"; // string to use to replace quotes + var $fmtDate = "'Y-m-d'"; + var $fmtTimeStamp = "'Y-m-d H:i:s'"; + var $hasInsertID = true; + var $hasAffectedRows = true; + var $metaTablesSQL="select name from sysobjects where type='U' or type='V'"; + // see http://sybooks.sybase.com/onlinebooks/group-aw/awg0800e/dbrfen8/@ebt-link;pt=5981;uf=0?target=0;window=new;showtoc=true;book=dbrfen8 + var $metaColumnsSQL = "SELECT c.column_name, c.column_type, c.width FROM syscolumn c, systable t WHERE t.table_name='%s' AND c.table_id=t.table_id AND t.table_type='BASE'"; + /* + "select c.name,t.name,c.length from + syscolumns c join systypes t on t.xusertype=c.xusertype join sysobjects o on o.id=c.id + where o.name='%s'"; + */ + var $concat_operator = '+'; + var $arrayClass = 'ADORecordSet_array_sybase'; + var $sysDate = 'GetDate()'; + var $leftOuter = '*='; + var $rightOuter = '=*'; + + function ADODB_sybase() + { + } + + // might require begintrans -- committrans + function _insertid() + { + return $this->GetOne('select @@identity'); + } + // might require begintrans -- committrans + function _affectedrows() + { + return $this->GetOne('select @@rowcount'); + } + + + function BeginTrans() + { + + if ($this->transOff) return true; + $this->transCnt += 1; + + $this->Execute('BEGIN TRAN'); + return true; + } + + function CommitTrans($ok=true) + { + if ($this->transOff) return true; + + if (!$ok) return $this->RollbackTrans(); + + $this->transCnt -= 1; + $this->Execute('COMMIT TRAN'); + return true; + } + + function RollbackTrans() + { + if ($this->transOff) return true; + $this->transCnt -= 1; + $this->Execute('ROLLBACK TRAN'); + return true; + } + + // http://www.isug.com/Sybase_FAQ/ASE/section6.1.html#6.1.4 + function RowLock($tables,$where) + { + if (!$this->_hastrans) $this->BeginTrans(); + $tables = str_replace(',',' HOLDLOCK,',$tables); + return $this->GetOne("select top 1 null as ignore from $tables HOLDLOCK where $where"); + + } + + function SelectDB($dbName) { + $this->databaseName = $dbName; + if ($this->_connectionID) { + return @sybase_select_db($dbName); + } + else return false; + } + + /* Returns: the last error message from previous database operation + Note: This function is NOT available for Microsoft SQL Server. */ + + function ErrorMsg() + { + if ($this->_logsql) return $this->_errorMsg; + $this->_errorMsg = sybase_get_last_message(); + return $this->_errorMsg; + } + + // returns true or false + function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) + { + if (!function_exists('sybase_connect')) return false; + + $this->_connectionID = sybase_connect($argHostname,$argUsername,$argPassword); + if ($this->_connectionID === false) return false; + if ($argDatabasename) return $this->SelectDB($argDatabasename); + return true; + } + // returns true or false + function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) + { + if (!function_exists('sybase_connect')) return false; + + $this->_connectionID = sybase_pconnect($argHostname,$argUsername,$argPassword); + if ($this->_connectionID === false) return false; + if ($argDatabasename) return $this->SelectDB($argDatabasename); + return true; + } + + // returns query ID if successful, otherwise false + function _query($sql,$inputarr) + { + global $ADODB_COUNTRECS; + + if ($ADODB_COUNTRECS == false && ADODB_PHPVER >= 0x4300) + return sybase_unbuffered_query($sql,$this->_connectionID); + else + return sybase_query($sql,$this->_connectionID); + } + + // See http://www.isug.com/Sybase_FAQ/ASE/section6.2.html#6.2.12 + function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0) + { + if ($secs2cache > 0) {// we do not cache rowcount, so we have to load entire recordset + $rs =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); + return $rs; + } + $cnt = ($nrows > 0) ? $nrows : 0; + if ($offset > 0 && $cnt) $cnt += $offset; + + $this->Execute("set rowcount $cnt"); + $rs =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); + $this->Execute("set rowcount 0"); + + return $rs; + } + + // returns true or false + function _close() + { + return @sybase_close($this->_connectionID); + } + + function UnixDate($v) + { + return ADORecordSet_array_sybase::UnixDate($v); + } + + function UnixTimeStamp($v) + { + return ADORecordSet_array_sybase::UnixTimeStamp($v); + } + + + + # Added 2003-10-05 by Chris Phillipson # Used ASA SQL Reference Manual -- http://sybooks.sybase.com/onlinebooks/group-aw/awg0800e/dbrfen8/@ebt-link;pt=16756?target=%25N%15_12018_START_RESTART_N%25 # to convert similar Microsoft SQL*Server (mssql) API into Sybase compatible version // Format date column in sql string given an input format that understands Y M D @@ -239,7 +239,7 @@ class ADODB_sybase extends ADOConnection { return $s; } - # Added 2003-10-07 by Chris Phillipson + # Added 2003-10-07 by Chris Phillipson # Used ASA SQL Reference Manual -- http://sybooks.sybase.com/onlinebooks/group-aw/awg0800e/dbrfen8/@ebt-link;pt=5981;uf=0?target=0;window=new;showtoc=true;book=dbrfen8 # to convert similar Microsoft SQL*Server (mssql) API into Sybase compatible version function MetaPrimaryKeys($table) @@ -258,148 +258,148 @@ class ADODB_sybase extends ADOConnection { } /*-------------------------------------------------------------------------------------- - Class Name: Recordset + Class Name: Recordset --------------------------------------------------------------------------------------*/ global $ADODB_sybase_mths; $ADODB_sybase_mths = array( - 'JAN'=>1,'FEB'=>2,'MAR'=>3,'APR'=>4,'MAY'=>5,'JUN'=>6, - 'JUL'=>7,'AUG'=>8,'SEP'=>9,'OCT'=>10,'NOV'=>11,'DEC'=>12); + 'JAN'=>1,'FEB'=>2,'MAR'=>3,'APR'=>4,'MAY'=>5,'JUN'=>6, + 'JUL'=>7,'AUG'=>8,'SEP'=>9,'OCT'=>10,'NOV'=>11,'DEC'=>12); class ADORecordset_sybase extends ADORecordSet { - var $databaseType = "sybase"; - var $canSeek = true; - // _mths works only in non-localised system - var $_mths = array('JAN'=>1,'FEB'=>2,'MAR'=>3,'APR'=>4,'MAY'=>5,'JUN'=>6,'JUL'=>7,'AUG'=>8,'SEP'=>9,'OCT'=>10,'NOV'=>11,'DEC'=>12); - - function ADORecordset_sybase($id,$mode=false) - { - if ($mode === false) { - global $ADODB_FETCH_MODE; - $mode = $ADODB_FETCH_MODE; - } - if (!$mode) $this->fetchMode = ADODB_FETCH_ASSOC; - else $this->fetchMode = $mode; - return $this->ADORecordSet($id,$mode); - } - - /* Returns: an object containing field information. - Get column information in the Recordset object. fetchField() can be used in order to obtain information about - fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by - fetchField() is retrieved. */ - function &FetchField($fieldOffset = -1) - { - if ($fieldOffset != -1) { - $o = @sybase_fetch_field($this->_queryID, $fieldOffset); - } - else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */ - $o = @sybase_fetch_field($this->_queryID); - } - // older versions of PHP did not support type, only numeric - if ($o && !isset($o->type)) $o->type = ($o->numeric) ? 'float' : 'varchar'; - return $o; - } - - function _initrs() - { - global $ADODB_COUNTRECS; - $this->_numOfRows = ($ADODB_COUNTRECS)? @sybase_num_rows($this->_queryID):-1; - $this->_numOfFields = @sybase_num_fields($this->_queryID); - } - - function _seek($row) - { - return @sybase_data_seek($this->_queryID, $row); - } - - function _fetch($ignore_fields=false) - { - if ($this->fetchMode == ADODB_FETCH_NUM) { - $this->fields = @sybase_fetch_row($this->_queryID); - } else if ($this->fetchMode == ADODB_FETCH_ASSOC) { - $this->fields = @sybase_fetch_row($this->_queryID); - if (is_array($this->fields)) { - $this->fields = $this->GetRowAssoc(ADODB_ASSOC_CASE); - return true; - } - return false; - } else { - $this->fields = @sybase_fetch_array($this->_queryID); - } - if ( is_array($this->fields)) { - return true; - } - - return false; - } - - /* close() only needs to be called if you are worried about using too much memory while your script - is running. All associated result memory for the specified result identifier will automatically be freed. */ - function _close() { - return @sybase_free_result($this->_queryID); - } - - // sybase/mssql uses a default date like Dec 30 2000 12:00AM - function UnixDate($v) - { - return ADORecordSet_array_sybase::UnixDate($v); - } - - function UnixTimeStamp($v) - { - return ADORecordSet_array_sybase::UnixTimeStamp($v); - } + var $databaseType = "sybase"; + var $canSeek = true; + // _mths works only in non-localised system + var $_mths = array('JAN'=>1,'FEB'=>2,'MAR'=>3,'APR'=>4,'MAY'=>5,'JUN'=>6,'JUL'=>7,'AUG'=>8,'SEP'=>9,'OCT'=>10,'NOV'=>11,'DEC'=>12); + + function ADORecordset_sybase($id,$mode=false) + { + if ($mode === false) { + global $ADODB_FETCH_MODE; + $mode = $ADODB_FETCH_MODE; + } + if (!$mode) $this->fetchMode = ADODB_FETCH_ASSOC; + else $this->fetchMode = $mode; + return $this->ADORecordSet($id,$mode); + } + + /* Returns: an object containing field information. + Get column information in the Recordset object. fetchField() can be used in order to obtain information about + fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by + fetchField() is retrieved. */ + function &FetchField($fieldOffset = -1) + { + if ($fieldOffset != -1) { + $o = @sybase_fetch_field($this->_queryID, $fieldOffset); + } + else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */ + $o = @sybase_fetch_field($this->_queryID); + } + // older versions of PHP did not support type, only numeric + if ($o && !isset($o->type)) $o->type = ($o->numeric) ? 'float' : 'varchar'; + return $o; + } + + function _initrs() + { + global $ADODB_COUNTRECS; + $this->_numOfRows = ($ADODB_COUNTRECS)? @sybase_num_rows($this->_queryID):-1; + $this->_numOfFields = @sybase_num_fields($this->_queryID); + } + + function _seek($row) + { + return @sybase_data_seek($this->_queryID, $row); + } + + function _fetch($ignore_fields=false) + { + if ($this->fetchMode == ADODB_FETCH_NUM) { + $this->fields = @sybase_fetch_row($this->_queryID); + } else if ($this->fetchMode == ADODB_FETCH_ASSOC) { + $this->fields = @sybase_fetch_row($this->_queryID); + if (is_array($this->fields)) { + $this->fields = $this->GetRowAssoc(ADODB_ASSOC_CASE); + return true; + } + return false; + } else { + $this->fields = @sybase_fetch_array($this->_queryID); + } + if ( is_array($this->fields)) { + return true; + } + + return false; + } + + /* close() only needs to be called if you are worried about using too much memory while your script + is running. All associated result memory for the specified result identifier will automatically be freed. */ + function _close() { + return @sybase_free_result($this->_queryID); + } + + // sybase/mssql uses a default date like Dec 30 2000 12:00AM + function UnixDate($v) + { + return ADORecordSet_array_sybase::UnixDate($v); + } + + function UnixTimeStamp($v) + { + return ADORecordSet_array_sybase::UnixTimeStamp($v); + } } class ADORecordSet_array_sybase extends ADORecordSet_array { - function ADORecordSet_array_sybase($id=-1) - { - $this->ADORecordSet_array($id); - } - - // sybase/mssql uses a default date like Dec 30 2000 12:00AM - function UnixDate($v) - { - global $ADODB_sybase_mths; - - //Dec 30 2000 12:00AM - if (!ereg( "([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4})" - ,$v, $rr)) return parent::UnixDate($v); - - if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; - - $themth = substr(strtoupper($rr[1]),0,3); - $themth = $ADODB_sybase_mths[$themth]; - if ($themth <= 0) return false; - // h-m-s-MM-DD-YY - return mktime(0,0,0,$themth,$rr[2],$rr[3]); - } - - function UnixTimeStamp($v) - { - global $ADODB_sybase_mths; - //11.02.2001 Toni Tunkkari toni.tunkkari@finebyte.com - //Changed [0-9] to [0-9 ] in day conversion - if (!ereg( "([A-Za-z]{3})[-/\. ]([0-9 ]{1,2})[-/\. ]([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})" - ,$v, $rr)) return parent::UnixTimeStamp($v); - if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; - - $themth = substr(strtoupper($rr[1]),0,3); - $themth = $ADODB_sybase_mths[$themth]; - if ($themth <= 0) return false; - - switch (strtoupper($rr[6])) { - case 'P': - if ($rr[4]<12) $rr[4] += 12; - break; - case 'A': - if ($rr[4]==12) $rr[4] = 0; - break; - default: - break; - } - // h-m-s-MM-DD-YY - return mktime($rr[4],$rr[5],0,$themth,$rr[2],$rr[3]); - } + function ADORecordSet_array_sybase($id=-1) + { + $this->ADORecordSet_array($id); + } + + // sybase/mssql uses a default date like Dec 30 2000 12:00AM + function UnixDate($v) + { + global $ADODB_sybase_mths; + + //Dec 30 2000 12:00AM + if (!ereg( "([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4})" + ,$v, $rr)) return parent::UnixDate($v); + + if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; + + $themth = substr(strtoupper($rr[1]),0,3); + $themth = $ADODB_sybase_mths[$themth]; + if ($themth <= 0) return false; + // h-m-s-MM-DD-YY + return mktime(0,0,0,$themth,$rr[2],$rr[3]); + } + + function UnixTimeStamp($v) + { + global $ADODB_sybase_mths; + //11.02.2001 Toni Tunkkari toni.tunkkari@finebyte.com + //Changed [0-9] to [0-9 ] in day conversion + if (!ereg( "([A-Za-z]{3})[-/\. ]([0-9 ]{1,2})[-/\. ]([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})" + ,$v, $rr)) return parent::UnixTimeStamp($v); + if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; + + $themth = substr(strtoupper($rr[1]),0,3); + $themth = $ADODB_sybase_mths[$themth]; + if ($themth <= 0) return false; + + switch (strtoupper($rr[6])) { + case 'P': + if ($rr[4]<12) $rr[4] += 12; + break; + case 'A': + if ($rr[4]==12) $rr[4] = 0; + break; + default: + break; + } + // h-m-s-MM-DD-YY + return mktime($rr[4],$rr[5],0,$themth,$rr[2],$rr[3]); + } } ?> diff --git a/lib/WikiDB/adodb/drivers/adodb-vfp.inc.php b/lib/WikiDB/adodb/drivers/adodb-vfp.inc.php index 0f761775d..85367ad2e 100644 --- a/lib/WikiDB/adodb/drivers/adodb-vfp.inc.php +++ b/lib/WikiDB/adodb/drivers/adodb-vfp.inc.php @@ -12,53 +12,53 @@ Set tabs to 4 for best viewing. */ if (!defined('_ADODB_ODBC_LAYER')) { - include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); + include(ADODB_DIR."/drivers/adodb-odbc.inc.php"); } if (!defined('ADODB_VFP')){ define('ADODB_VFP',1); class ADODB_vfp extends ADODB_odbc { - var $databaseType = "vfp"; - var $fmtDate = "{^Y-m-d}"; - var $fmtTimeStamp = "{^Y-m-d, h:i:sA}"; - var $replaceQuote = "'+chr(39)+'" ; - var $true = '.T.'; - var $false = '.F.'; - var $hasTop = 'top'; // support mssql SELECT TOP 10 * FROM TABLE - var $upperCase = 'upper'; - var $_bindInputArray = false; // strangely enough, setting to true does not work reliably - var $sysTimeStamp = 'datetime()'; - var $sysDate = 'date()'; - var $ansiOuter = true; - var $hasTransactions = false; - var $curmode = SQL_CUR_USE_ODBC ; // See sqlext.h, SQL_CUR_DEFAULT == SQL_CUR_USE_DRIVER == 2L - - function ADODB_vfp() - { - $this->ADODB_odbc(); - } - - function Time() - { - return time(); - } - - - function BeginTrans() { return false;} - - // quote string to be sent back to database - function qstr($s,$nofixquotes=false) - { - if (!$nofixquotes) return "'".str_replace("\r\n","'+chr(13)+'",str_replace("'",$this->replaceQuote,$s))."'"; - return "'".$s."'"; - } - - - // TOP requires ORDER BY for VFP - function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) - { - $this->hasTop = preg_match('/ORDER[ \t\r\n]+BY/is',$sql) ? 'top' : false; - return ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); - } + var $databaseType = "vfp"; + var $fmtDate = "{^Y-m-d}"; + var $fmtTimeStamp = "{^Y-m-d, h:i:sA}"; + var $replaceQuote = "'+chr(39)+'" ; + var $true = '.T.'; + var $false = '.F.'; + var $hasTop = 'top'; // support mssql SELECT TOP 10 * FROM TABLE + var $upperCase = 'upper'; + var $_bindInputArray = false; // strangely enough, setting to true does not work reliably + var $sysTimeStamp = 'datetime()'; + var $sysDate = 'date()'; + var $ansiOuter = true; + var $hasTransactions = false; + var $curmode = SQL_CUR_USE_ODBC ; // See sqlext.h, SQL_CUR_DEFAULT == SQL_CUR_USE_DRIVER == 2L + + function ADODB_vfp() + { + $this->ADODB_odbc(); + } + + function Time() + { + return time(); + } + + + function BeginTrans() { return false;} + + // quote string to be sent back to database + function qstr($s,$nofixquotes=false) + { + if (!$nofixquotes) return "'".str_replace("\r\n","'+chr(13)+'",str_replace("'",$this->replaceQuote,$s))."'"; + return "'".$s."'"; + } + + + // TOP requires ORDER BY for VFP + function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) + { + $this->hasTop = preg_match('/ORDER[ \t\r\n]+BY/is',$sql) ? 'top' : false; + return ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); + } @@ -67,38 +67,38 @@ class ADODB_vfp extends ADODB_odbc { class ADORecordSet_vfp extends ADORecordSet_odbc { - var $databaseType = "vfp"; + var $databaseType = "vfp"; - function ADORecordSet_vfp($id,$mode=false) - { - return $this->ADORecordSet_odbc($id,$mode); - } + function ADORecordSet_vfp($id,$mode=false) + { + return $this->ADORecordSet_odbc($id,$mode); + } - function MetaType($t,$len=-1) - { - if (is_object($t)) { - $fieldobj = $t; - $t = $fieldobj->type; - $len = $fieldobj->max_length; - } - switch (strtoupper($t)) { - case 'C': - if ($len <= $this->blobSize) return 'C'; - case 'M': - return 'X'; + function MetaType($t,$len=-1) + { + if (is_object($t)) { + $fieldobj = $t; + $t = $fieldobj->type; + $len = $fieldobj->max_length; + } + switch (strtoupper($t)) { + case 'C': + if ($len <= $this->blobSize) return 'C'; + case 'M': + return 'X'; - case 'D': return 'D'; + case 'D': return 'D'; - case 'T': return 'T'; + case 'T': return 'T'; - case 'L': return 'L'; + case 'L': return 'L'; - case 'I': return 'I'; + case 'I': return 'I'; - default: return 'N'; - } - } + default: return 'N'; + } + } } } //define diff --git a/lib/WikiDB/backend.php b/lib/WikiDB/backend.php index 1802f9e58..f2af23862 100644 --- a/lib/WikiDB/backend.php +++ b/lib/WikiDB/backend.php @@ -347,7 +347,7 @@ class WikiDB_backend * @see WikiDB::titleSearch */ function text_search($search, $fulltext=false, $sortby='', - $limit='', $exclude='') + $limit='', $exclude='') { // This method implements a simple linear search // through all the pages in the database. @@ -499,23 +499,23 @@ class WikiDB_backend * @return boolean True iff successful. */ function rebuild($args=false) { - global $request; - $dbh = $request->getDbh(); - $iter = $dbh->getAllPages(false); + global $request; + $dbh = $request->getDbh(); + $iter = $dbh->getAllPages(false); while ($page = $iter->next()) { - $current = $page->getCurrentRevision(true); - $pagename = $page->getName(); - $meta = $current->_data; - $version = $current->getVersion(); - $content =& $meta['%content']; - $formatted = new TransformedText($page, $content, $current->getMetaData()); - $type = $formatted->getType(); - $meta['pagetype'] = $type->getName(); - $links = $formatted->getWikiPageLinks(); // linkto => relation - $this->lock(array('version','page','recent','link','nonempty')); - $this->set_versiondata($pagename, $version, $meta); - $this->set_links($pagename, $links); - $this->unlock(array('version','page','recent','link','nonempty')); + $current = $page->getCurrentRevision(true); + $pagename = $page->getName(); + $meta = $current->_data; + $version = $current->getVersion(); + $content =& $meta['%content']; + $formatted = new TransformedText($page, $content, $current->getMetaData()); + $type = $formatted->getType(); + $meta['pagetype'] = $type->getName(); + $links = $formatted->getWikiPageLinks(); // linkto => relation + $this->lock(array('version','page','recent','link','nonempty')); + $this->set_versiondata($pagename, $version, $meta); + $this->set_links($pagename, $links); + $this->unlock(array('version','page','recent','link','nonempty')); } } @@ -694,22 +694,22 @@ class WikiDB_backend_iterator } function count() { - if (!empty($this->_pages)) - return count($this->_pages); - else - return 0; + if (!empty($this->_pages)) + return count($this->_pages); + else + return 0; } function asArray() { - if (!empty($this->_pages)) { + if (!empty($this->_pages)) { reset($this->_pages); return $this->_pages; - } else { - $result = array(); - while ($page = $this->next()) - $result[] = $page; + } else { + $result = array(); + while ($page = $this->next()) + $result[] = $page; return $result; - } + } } /** @@ -718,7 +718,7 @@ class WikiDB_backend_iterator * Some SQL based leave it to WikiDB/PageList - deferred filtering in the iterator. */ function limit() { - return empty($this->_options['limit']) ? 0 : $this->_options['limit']; + return empty($this->_options['limit']) ? 0 : $this->_options['limit']; } /** @@ -758,9 +758,9 @@ class WikiDB_backend_search * Keep a list of Stoplisted words to inform the poor user. */ function isStoplisted ($node) { - // check only on WORD or EXACT fulltext search - if ($node->op != 'WORD' and $node->op != 'EXACT') - return false; + // check only on WORD or EXACT fulltext search + if ($node->op != 'WORD' and $node->op != 'EXACT') + return false; if (preg_match("/^".$this->_stoplist."$/i", $node->word)) { array_push($this->stoplisted, $node->word); return true; diff --git a/lib/WikiDB/backend/ADODB.php b/lib/WikiDB/backend/ADODB.php index e825bd1f3..d04b1876d 100644 --- a/lib/WikiDB/backend/ADODB.php +++ b/lib/WikiDB/backend/ADODB.php @@ -86,14 +86,14 @@ extends WikiDB_backend // persistent is defined as DSN option, or with a config value. // phptype://username:password@hostspec/database?persistent=false - //FIXME: how to catch connection errors for dbamin_user? + //FIXME: how to catch connection errors for dbamin_user? if (!empty($parsed['persistent']) or DATABASE_PERSISTENT) $conn = $this->_dbh->PConnect($parsed['hostspec'],$parsed['username'], $parsed['password'], $parsed['database']); else $conn = $this->_dbh->Connect($parsed['hostspec'],$parsed['username'], $parsed['password'], $parsed['database']); - if (!$conn) return; + if (!$conn) return; // Since 1.3.10 we use the faster ADODB_FETCH_NUM, // with some ASSOC based recordsets. @@ -287,7 +287,7 @@ extends WikiDB_backend return $cache[$pagename]; } } - // attributes play this game. + // attributes play this game. if ($pagename === '') return 0; $dbh = &$this->_dbh; @@ -300,25 +300,25 @@ extends WikiDB_backend } $row = $dbh->GetRow($query); if (! $row ) { - //TODO: Does the DBM has subselects? Then we can do it with select max(id)+1 - // $this->lock(array('page')); - $dbh->BeginTrans( ); - $dbh->CommitLock($page_tbl); + //TODO: Does the DBM has subselects? Then we can do it with select max(id)+1 + // $this->lock(array('page')); + $dbh->BeginTrans( ); + $dbh->CommitLock($page_tbl); if (0 and $dbh->hasGenID) { - // requires create permissions + // requires create permissions $id = $dbh->GenID($page_tbl."_id"); } else { // Better generic version than with adodb::genID $row = $dbh->GetRow("SELECT MAX(id) FROM $page_tbl"); $id = $row[0] + 1; } - $rs = $dbh->Execute(sprintf("INSERT INTO $page_tbl" - . " (id,pagename,hits)" - . " VALUES (%d,%s,0)", - $id, $dbh->qstr($pagename))); - if ($rs) $dbh->CommitTrans( ); - else $dbh->RollbackTrans( ); - // $this->unlock(array('page')); + $rs = $dbh->Execute(sprintf("INSERT INTO $page_tbl" + . " (id,pagename,hits)" + . " VALUES (%d,%s,0)", + $id, $dbh->qstr($pagename))); + if ($rs) $dbh->CommitTrans( ); + else $dbh->RollbackTrans( ); + // $this->unlock(array('page')); } else { $id = $row[0]; } @@ -453,13 +453,13 @@ extends WikiDB_backend $dbh->CommitLock($version_tbl); $id = $this->_get_pageid($pagename, true); $backend_type = $this->backendType(); - $dbh->Execute(sprintf("DELETE FROM $version_tbl" - . " WHERE id=%d AND version=%d", - $id, $version)); - $rs = $dbh->Execute("INSERT INTO $version_tbl" - . " (id,version,mtime,minor_edit,content,versiondata)" - . " VALUES(?,?,?,?,?,?)", - array($id, $version, $mtime, $minor_edit, + $dbh->Execute(sprintf("DELETE FROM $version_tbl" + . " WHERE id=%d AND version=%d", + $id, $version)); + $rs = $dbh->Execute("INSERT INTO $version_tbl" + . " (id,version,mtime,minor_edit,content,versiondata)" + . " VALUES(?,?,?,?,?,?)", + array($id, $version, $mtime, $minor_edit, $content, $this->_serialize($data))); $this->_update_recent_table($id); $this->_update_nonempty_table($id); @@ -641,7 +641,7 @@ extends WikiDB_backend { trigger_error("delete empty and non-referenced link $name ($id)", E_USER_NOTICE); $dbh->Execute("DELETE FROM $recent_tbl WHERE id=$id"); // may fail - $dbh->Execute("DELETE FROM $link_tbl WHERE linkto=$id"); + $dbh->Execute("DELETE FROM $link_tbl WHERE linkto=$id"); $dbh->Execute("DELETE FROM $page_tbl WHERE id=$id"); // this purges the link } } @@ -1190,7 +1190,7 @@ id pagename linkrelation * @access protected */ function lock($tables, $write_lock = true) { - $this->_dbh->StartTrans(); + $this->_dbh->StartTrans(); if ($this->_lock_count++ == 0) { $this->_current_lock = $tables; $this->_lock_tables($tables, $write_lock); @@ -1275,7 +1275,7 @@ id pagename linkrelation $old_db = $this->database(); if ($database != $old_db) { $conn = $this->_dbh->Connect($this->_parsedDSN['hostspec'], - DBADMIN_USER ? DBADMIN_USER : $this->_parsedDSN['username'], + DBADMIN_USER ? DBADMIN_USER : $this->_parsedDSN['username'], DBADMIN_PASSWD ? DBADMIN_PASSWD : $this->_parsedDSN['password'], $database); } @@ -1285,7 +1285,7 @@ id pagename linkrelation if ($database != $old_db) { $this->_dbh->close(); $conn = $this->_dbh->Connect($this->_parsedDSN['hostspec'], - $this->_parsedDSN['username'], + $this->_parsedDSN['username'], $this->_parsedDSN['password'], $old_db); } @@ -1350,9 +1350,9 @@ extends WikiDB_backend_iterator } } function asArray () { - $result = array(); - while ($page = $this->next()) - $result[] = $page; + $result = array(); + while ($page = $this->next()) + $result[] = $page; return $result; } diff --git a/lib/WikiDB/backend/ADODB_mssqlnative.php b/lib/WikiDB/backend/ADODB_mssqlnative.php index 0d34bdc66..9df4cf2a9 100644 --- a/lib/WikiDB/backend/ADODB_mssqlnative.php +++ b/lib/WikiDB/backend/ADODB_mssqlnative.php @@ -9,7 +9,7 @@ require_once('lib/WikiDB/backend/ADODB.php'); class WikiDB_backend_ADODB_mssqlnative extends WikiDB_backend_ADODB { - /** + /** * Constructor. */ function WikiDB_backend_ADODB_mssqlnative($dbparams) { diff --git a/lib/WikiDB/backend/ADODB_mysql.php b/lib/WikiDB/backend/ADODB_mysql.php index 2703e9c1a..595cc3971 100644 --- a/lib/WikiDB/backend/ADODB_mysql.php +++ b/lib/WikiDB/backend/ADODB_mysql.php @@ -67,18 +67,18 @@ extends WikiDB_backend_ADODB * Kill timed out processes. ( so far only called on about every 50-th save. ) */ function _timeout() { - if (empty($this->_dbparams['timeout'])) return; - $result = mysql_query("SHOW processlist"); - while ($row = mysql_fetch_array($result)) { - if ($row["db"] == $this->_dsn['database'] - and $row["User"] == $this->_dsn['username'] - and $row["Time"] > $this->_dbparams['timeout'] - and $row["Command"] == "Sleep") + if (empty($this->_dbparams['timeout'])) return; + $result = mysql_query("SHOW processlist"); + while ($row = mysql_fetch_array($result)) { + if ($row["db"] == $this->_dsn['database'] + and $row["User"] == $this->_dsn['username'] + and $row["Time"] > $this->_dbparams['timeout'] + and $row["Command"] == "Sleep") { $process_id = $row["Id"]; mysql_query("KILL $process_id"); - } - } + } + } } /** @@ -102,8 +102,8 @@ extends WikiDB_backend_ADODB * support nested locks via app locks */ function _lock_tables($tables, $write_lock = true) { - if (!$tables) return; - if (DO_APP_LOCK) { + if (!$tables) return; + if (DO_APP_LOCK) { $lock = join('-',$tables); $result = $this->_dbh->GetRow("SELECT GET_LOCK('$lock',10)"); if (!$result or $result[0] == 0) { @@ -111,7 +111,7 @@ extends WikiDB_backend_ADODB E_USER_WARNING); return; } - } + } if (DO_FULL_LOCK) { // if this is not enough: $lock_type = $write_lock ? "WRITE" : "READ"; @@ -127,10 +127,10 @@ extends WikiDB_backend_ADODB * Support nested locks */ function _unlock_tables($tables) { - if (!$tables) { - $this->_dbh->Execute("UNLOCK TABLES"); - return; - } + if (!$tables) { + $this->_dbh->Execute("UNLOCK TABLES"); + return; + } if (DO_APP_LOCK) { $lock = join('-',$tables); $result = $this->_dbh->Execute("SELECT RELEASE_LOCK('$lock')"); @@ -167,7 +167,7 @@ extends WikiDB_backend_ADODB } } - // attributes play this game. + // attributes play this game. if ($pagename === '') return 0; $dbh = &$this->_dbh; @@ -180,12 +180,12 @@ extends WikiDB_backend_ADODB } $row = $dbh->GetRow($query); if (! $row ) { - // have auto-incrementing, atomic version - $rs = $dbh->Execute(sprintf("INSERT INTO $page_tbl" - . " (id,pagename)" - . " VALUES(NULL,%s)", - $dbh->qstr($pagename))); - $id = $dbh->_insertid(); + // have auto-incrementing, atomic version + $rs = $dbh->Execute(sprintf("INSERT INTO $page_tbl" + . " (id,pagename)" + . " VALUES(NULL,%s)", + $dbh->qstr($pagename))); + $id = $dbh->_insertid(); } else { $id = $row[0]; } @@ -217,12 +217,12 @@ extends WikiDB_backend_ADODB $id = $this->_get_pageid($pagename, true); $backend_type = $this->backendType(); // optimize: mysql can do this with one REPLACE INTO. - $rs = $dbh->Execute(sprintf("REPLACE INTO $version_tbl" - . " (id,version,mtime,minor_edit,content,versiondata)" - . " VALUES(%d,%d,%d,%d,%s,%s)", - $id, $version, $mtime, $minor_edit, - $dbh->qstr($content), - $dbh->qstr($this->_serialize($data)))); + $rs = $dbh->Execute(sprintf("REPLACE INTO $version_tbl" + . " (id,version,mtime,minor_edit,content,versiondata)" + . " VALUES(%d,%d,%d,%d,%s,%s)", + $id, $version, $mtime, $minor_edit, + $dbh->qstr($content), + $dbh->qstr($this->_serialize($data)))); $this->_update_recent_table($id); $this->_update_nonempty_table($id); if ($rs) $dbh->CommitTrans( ); diff --git a/lib/WikiDB/backend/ADODB_postgres7.php b/lib/WikiDB/backend/ADODB_postgres7.php index 72a96d427..b118c2ca0 100644 --- a/lib/WikiDB/backend/ADODB_postgres7.php +++ b/lib/WikiDB/backend/ADODB_postgres7.php @@ -29,8 +29,8 @@ extends WikiDB_backend_ADODB if (!empty($this->_serverinfo['version'])) { $arr = explode('.',$this->_serverinfo['version']); $this->_serverinfo['version'] = (string)(($arr[0] * 100) + $arr[1]); - if (!empty($arr[2])) - $this->_serverinfo['version'] .= ("." . (integer)$arr[2]); + if (!empty($arr[2])) + $this->_serverinfo['version'] .= ("." . (integer)$arr[2]); } } @@ -49,26 +49,26 @@ extends WikiDB_backend_ADODB // just for blobs. the rest is escaped with qstr() function _quote($s) { - if (USE_BYTEA) - return $this->_dbh->BlobEncode($s); + if (USE_BYTEA) + return $this->_dbh->BlobEncode($s); return base64_encode($s); } // just for blobs, which might be base64_encoded function _unquote($s) { - if (USE_BYTEA) { - //if function_exists('pg_unescape_bytea') - //return pg_unescape_bytea($s); - // TODO: already unescaped by ADORecordSet_postgres64::_decode? - return $s; - } + if (USE_BYTEA) { + //if function_exists('pg_unescape_bytea') + //return pg_unescape_bytea($s); + // TODO: already unescaped by ADORecordSet_postgres64::_decode? + return $s; + } return base64_decode($s); } function get_cached_html($pagename) { $dbh = &$this->_dbh; $page_tbl = $this->_table_names['page_tbl']; - $data = $dbh->GetOne(sprintf("SELECT cached_html FROM $page_tbl WHERE pagename=%s", + $data = $dbh->GetOne(sprintf("SELECT cached_html FROM $page_tbl WHERE pagename=%s", $dbh->qstr($pagename))); if ($data) return $this->_unquote($data); else return ''; @@ -77,20 +77,20 @@ extends WikiDB_backend_ADODB function set_cached_html($pagename, $data) { $dbh = &$this->_dbh; $page_tbl = $this->_table_names['page_tbl']; - if (USE_BYTEA) { - $dbh->UpdateBlob($page_tbl,'cached_html',$data,"pagename=".$dbh->qstr($pagename)); - /* - $dbh->Execute(sprintf("UPDATE $page_tbl" - . " SET cached_html='%s'" - . " WHERE pagename=%s", - $this->_quote($data), - $dbh->qstr($pagename))); - */ - } else { - $dbh->Execute("UPDATE $page_tbl" - . " SET cached_html=?" - . " WHERE pagename=?", - array($this->_quote($data), $pagename)); + if (USE_BYTEA) { + $dbh->UpdateBlob($page_tbl,'cached_html',$data,"pagename=".$dbh->qstr($pagename)); + /* + $dbh->Execute(sprintf("UPDATE $page_tbl" + . " SET cached_html='%s'" + . " WHERE pagename=%s", + $this->_quote($data), + $dbh->qstr($pagename))); + */ + } else { + $dbh->Execute("UPDATE $page_tbl" + . " SET cached_html=?" + . " WHERE pagename=?", + array($this->_quote($data), $pagename)); } } diff --git a/lib/WikiDB/backend/ADODB_sqlite.php b/lib/WikiDB/backend/ADODB_sqlite.php index 6daddd8d5..538926256 100644 --- a/lib/WikiDB/backend/ADODB_sqlite.php +++ b/lib/WikiDB/backend/ADODB_sqlite.php @@ -36,7 +36,7 @@ extends WikiDB_backend_ADODB $row = $dbh->GetRow($query); return $row ? $row[0] : false; } - // attributes play this game. + // attributes play this game. if ($pagename === '') return 0; $row = $dbh->GetRow($query); @@ -46,7 +46,7 @@ extends WikiDB_backend_ADODB // http://www.sqlite.org/faq.html#q1 $rs = $dbh->Execute(sprintf("INSERT INTO $page_tbl" . " (id,pagename)" - . " VALUES((SELECT max(id) FROM $page_tbl)+1, %s)", + . " VALUES((SELECT max(id) FROM $page_tbl)+1, %s)", $dbh->qstr($pagename))); $id = $dbh->_insertid(); } else { diff --git a/lib/WikiDB/backend/PDO.php b/lib/WikiDB/backend/PDO.php index 0d2445996..863607318 100644 --- a/lib/WikiDB/backend/PDO.php +++ b/lib/WikiDB/backend/PDO.php @@ -352,7 +352,7 @@ extends WikiDB_backend } } - // attributes play this game. + // attributes play this game. if ($pagename === '') return 0; $dbh = &$this->_dbh; @@ -699,7 +699,7 @@ extends WikiDB_backend " WHERE linkfrom=$pageid"); $sth->execute(); foreach ($sth->fetchAll(PDO_FETCH_NUM) as $id) { - // ...check if the page is empty and has no version + // ...check if the page is empty and has no version $sth1 = $dbh->prepare("SELECT $page_tbl.id FROM $page_tbl" . " LEFT JOIN $nonempty_tbl USING (id) " . " LEFT JOIN $version_tbl USING (id)" @@ -1027,7 +1027,7 @@ extends WikiDB_backend . " LEFT JOIN $page_tbl pp ON linked.linkto = pp.id" . " LEFT JOIN $nonempty_tbl ne ON linked.linkto = ne.id" . " WHERE ne.id is NULL" - . " AND p.id = linked.linkfrom" + . " AND p.id = linked.linkfrom" . $exclude_from . $exclude . $orderby; diff --git a/lib/WikiDB/backend/PDO_mysql.php b/lib/WikiDB/backend/PDO_mysql.php index 995457806..5f3c6d8c5 100644 --- a/lib/WikiDB/backend/PDO_mysql.php +++ b/lib/WikiDB/backend/PDO_mysql.php @@ -65,19 +65,19 @@ extends WikiDB_backend_PDO * Kill timed out processes. ( so far only called on about every 50-th save. ) */ function _timeout() { - if (empty($this->_dbparams['timeout'])) return; - $sth = $this->_dbh->prepare("SHOW processlist"); + if (empty($this->_dbparams['timeout'])) return; + $sth = $this->_dbh->prepare("SHOW processlist"); if ($sth->execute()) - while ($row = $sth->fetch(PDO_FETCH_ASSOC)) { - if ($row["db"] == $this->_dsn['database'] - and $row["User"] == $this->_dsn['username'] - and $row["Time"] > $this->_dbparams['timeout'] - and $row["Command"] == "Sleep") + while ($row = $sth->fetch(PDO_FETCH_ASSOC)) { + if ($row["db"] == $this->_dsn['database'] + and $row["User"] == $this->_dsn['username'] + and $row["Time"] > $this->_dbparams['timeout'] + and $row["Command"] == "Sleep") { $process_id = $row["Id"]; $this->query("KILL $process_id"); - } - } + } + } } /** diff --git a/lib/WikiDB/backend/PearDB.php b/lib/WikiDB/backend/PearDB.php index 62d2f1f03..a6d1294b6 100644 --- a/lib/WikiDB/backend/PearDB.php +++ b/lib/WikiDB/backend/PearDB.php @@ -43,7 +43,7 @@ extends WikiDB_backend // Open connection to database $this->_dsn = $dbparams['dsn']; - $this->_dbparams = $dbparams; + $this->_dbparams = $dbparams; $this->_lock_count = 0; // persistent is usually a DSN option: we override it with a config value. @@ -249,7 +249,7 @@ extends WikiDB_backend } } - // attributes play this game. + // attributes play this game. if ($pagename === '') return 0; $dbh = &$this->_dbh; @@ -513,8 +513,8 @@ extends WikiDB_backend $pageid = $this->_get_pageid($pagename, true); $dbh->query("DELETE FROM $link_tbl WHERE linkfrom=$pageid"); - if ($links) { - $linkseen = array(); + if ($links) { + $linkseen = array(); foreach ($links as $link) { $linkto = $link['linkto']; if ($linkto === "") { // ignore attributes @@ -530,17 +530,17 @@ extends WikiDB_backend if (!$relation) $linkseen[$linkto] = true; $linkid = $this->_get_pageid($linkto, true); - if (!$linkid) { - echo("No link for $linkto on page $pagename"); - //printSimpleTrace(debug_backtrace()); - trigger_error("No link for $linkto on page $pagename"); + if (!$linkid) { + echo("No link for $linkto on page $pagename"); + //printSimpleTrace(debug_backtrace()); + trigger_error("No link for $linkto on page $pagename"); } assert($linkid); $dbh->query("INSERT INTO $link_tbl (linkfrom, linkto, relation)" . " VALUES ($pageid, $linkid, $relation)"); } - unset($linkseen); - } + unset($linkseen); + } $this->unlock(); } @@ -818,11 +818,11 @@ extends WikiDB_backend $join_clause = "$page_tbl.id=$version_tbl.id"; if ($exclude_major_revisions) { - // Include only minor revisions + // Include only minor revisions $pick[] = "minor_edit <> 0"; } elseif (!$include_minor_revisions) { - // Include only major revisions + // Include only major revisions $pick[] = "minor_edit = 0"; } } @@ -1150,9 +1150,9 @@ extends WikiDB_backend $fields = array(); assert(!empty($database)); assert(!empty($table)); - $result = mysql_list_fields($database, $table, $this->_dbh->connection) or - trigger_error(__FILE__.':'.__LINE__.' '.mysql_error(), E_USER_WARNING); - if (!$result) return array(); + $result = mysql_list_fields($database, $table, $this->_dbh->connection) or + trigger_error(__FILE__.':'.__LINE__.' '.mysql_error(), E_USER_WARNING); + if (!$result) return array(); $columns = mysql_num_fields($result); for ($i = 0; $i < $columns; $i++) { $fields[] = mysql_field_name($result, $i); @@ -1226,9 +1226,9 @@ extends WikiDB_backend_iterator } function asArray () { - $result = array(); - while ($page = $this->next()) - $result[] = $page; + $result = array(); + while ($page = $this->next()) + $result[] = $page; return $result; } } diff --git a/lib/WikiDB/backend/PearDB_ffpgsql.php b/lib/WikiDB/backend/PearDB_ffpgsql.php index 17cb45ce0..71c7bf83c 100644 --- a/lib/WikiDB/backend/PearDB_ffpgsql.php +++ b/lib/WikiDB/backend/PearDB_ffpgsql.php @@ -97,7 +97,7 @@ extends WikiDB_backend_PearDB_pgsql // Note that this will fail silently if the page does not // have a record in the page table. Since it's just the // hit count, who cares? - $pagename = PAGE_PREFIX.$pagename; + $pagename = PAGE_PREFIX.$pagename; $dbh->query(sprintf("UPDATE $page_tbl SET hits=%d WHERE pagename='%s'", $newdata['hits'], $dbh->escapeSimple($pagename))); return; @@ -204,7 +204,7 @@ extends WikiDB_backend_PearDB_pgsql } } - // attributes play this game. + // attributes play this game. if ($pagename === '') return 0; $dbh = &$this->_dbh; @@ -330,7 +330,7 @@ extends WikiDB_backend_PearDB_pgsql . " FROM $page_tbl, $recent_tbl, $version_tbl" . " WHERE $page_tbl.id=$recent_tbl.id" . " AND $page_tbl.id=$version_tbl.id AND latestversion=version" - . " AND substring($page_tbl.pagename from 0 for $p) = '$pat'" + . " AND substring($page_tbl.pagename from 0 for $p) = '$pat'" . $exclude . $orderby; } @@ -341,7 +341,7 @@ extends WikiDB_backend_PearDB_pgsql . " WHERE $nonempty_tbl.id=$page_tbl.id" . " AND $page_tbl.id=$recent_tbl.id" . " AND $page_tbl.id=$version_tbl.id AND latestversion=version" - . " AND substring($page_tbl.pagename from 0 for $p) = '$pat'" + . " AND substring($page_tbl.pagename from 0 for $p) = '$pat'" . $exclude . $orderby; } @@ -352,7 +352,7 @@ extends WikiDB_backend_PearDB_pgsql . " FROM $page_tbl" . ($exclude ? " WHERE $exclude" : '') . ($exclude ? " AND " : " WHERE ") - . " substring($page_tbl.pagename from 0 for $p) = '$pat'" + . " substring($page_tbl.pagename from 0 for $p) = '$pat'" . $orderby; } else { @@ -360,7 +360,7 @@ extends WikiDB_backend_PearDB_pgsql . $this->page_tbl_fields . " FROM $nonempty_tbl, $page_tbl" . " WHERE $nonempty_tbl.id=$page_tbl.id" - . " AND substring($page_tbl.pagename from 0 for $p) = '$pat'" + . " AND substring($page_tbl.pagename from 0 for $p) = '$pat'" . $exclude . $orderby; } @@ -437,11 +437,11 @@ extends WikiDB_backend_PearDB_pgsql $join_clause = "$page_tbl.id=$version_tbl.id"; if ($exclude_major_revisions) { - // Include only minor revisions + // Include only minor revisions $pick[] = "minor_edit <> 0"; } elseif (!$include_minor_revisions) { - // Include only major revisions + // Include only major revisions $pick[] = "minor_edit = 0"; } } @@ -482,7 +482,7 @@ extends WikiDB_backend_PearDB_pgsql . $this->page_tbl_fields . ", " . $this->version_tbl_fields . " FROM $table" . " WHERE $where_clause" - . " AND substring($page_tbl.pagename from 0 for $p) = '$pat'" + . " AND substring($page_tbl.pagename from 0 for $p) = '$pat'" . " ORDER BY mtime $order"; if ($limit) { list($from, $count) = $this->limit($limit); @@ -604,7 +604,7 @@ extends WikiDB_backend_PearDB_pgsql $join_clause .= " AND $page_tbl.id=$version_tbl.id AND latestversion=version"; $fields .= ", $page_tbl.pagedata as pagedata, " . $this->version_tbl_fields; - // TODO: title still ignored, need better rank and subselect + // TODO: title still ignored, need better rank and subselect $callback = new WikiMethodCb($searchobj, "_fulltext_match_clause"); $search_string = $search->makeTsearch2SqlClauseObj($callback); $search_string = str_replace('%', '', $search_string); diff --git a/lib/WikiDB/backend/PearDB_mysql.php b/lib/WikiDB/backend/PearDB_mysql.php index 230b01997..e9a3ebed8 100644 --- a/lib/WikiDB/backend/PearDB_mysql.php +++ b/lib/WikiDB/backend/PearDB_mysql.php @@ -47,18 +47,18 @@ extends WikiDB_backend_PearDB * Kill timed out processes. ( so far only called on about every 50-th save. ) */ function _timeout() { - if (empty($this->_dbparams['timeout'])) return; - $result = mysql_query("SHOW processlist"); - while ($row = mysql_fetch_array($result)) { - if ($row["db"] == $this->_dbh->dsn['database'] - and $row["User"] == $this->_dbh->dsn['username'] - and $row["Time"] > $this->_dbparams['timeout'] - and $row["Command"] == "Sleep") + if (empty($this->_dbparams['timeout'])) return; + $result = mysql_query("SHOW processlist"); + while ($row = mysql_fetch_array($result)) { + if ($row["db"] == $this->_dbh->dsn['database'] + and $row["User"] == $this->_dbh->dsn['username'] + and $row["Time"] > $this->_dbparams['timeout'] + and $row["Command"] == "Sleep") { - $process_id = $row["Id"]; - mysql_query("KILL $process_id"); - } - } + $process_id = $row["Id"]; + mysql_query("KILL $process_id"); + } + } } /** @@ -169,7 +169,7 @@ extends WikiDB_backend_PearDB */ function optimize() { $dbh = &$this->_dbh; - $this->_timeout(); + $this->_timeout(); foreach ($this->_table_names as $table) { $dbh->query("OPTIMIZE TABLE $table"); } diff --git a/lib/WikiDB/backend/PearDB_pgsql.php b/lib/WikiDB/backend/PearDB_pgsql.php index 601006b15..585a0edc9 100644 --- a/lib/WikiDB/backend/PearDB_pgsql.php +++ b/lib/WikiDB/backend/PearDB_pgsql.php @@ -59,19 +59,19 @@ extends WikiDB_backend_PearDB function _quote($s) { if (USE_BYTEA) return pg_escape_bytea($s); - if (function_exists('pg_escape_string')) - return pg_escape_string($s); - else - return base64_encode($s); + if (function_exists('pg_escape_string')) + return pg_escape_string($s); + else + return base64_encode($s); } function _unquote($s) { if (USE_BYTEA) return pg_unescape_bytea($s); - if (function_exists('pg_escape_string')) - return $s; - else - return base64_decode($s); + if (function_exists('pg_escape_string')) + return $s; + else + return base64_decode($s); } // Until the binary escape problems on pear pgsql are solved */ @@ -229,7 +229,7 @@ extends WikiDB_backend_PearDB $join_clause .= " AND $page_tbl.id=$version_tbl.id AND latestversion=version"; $fields .= ", $page_tbl.pagedata as pagedata, " . $this->version_tbl_fields; - // TODO: title still ignored, need better rank and subselect + // TODO: title still ignored, need better rank and subselect $callback = new WikiMethodCb($searchobj, "_fulltext_match_clause"); $search_string = $search->makeTsearch2SqlClauseObj($callback); $search_string = str_replace(array("%"," "), array("","&"), $search_string); diff --git a/lib/WikiDB/backend/cvs.php b/lib/WikiDB/backend/cvs.php index 114d547ca..4362aa1ff 100644 --- a/lib/WikiDB/backend/cvs.php +++ b/lib/WikiDB/backend/cvs.php @@ -343,15 +343,15 @@ extends WikiDB_backend function rename_page($pagename, $to) { $this->_cvsDebug( "rename_page [$pagename,$to]") ; - $data = get_pagedata($pagename); - if (isset($data['pagename'])) - $data['pagename'] = $to; - //$version = $this->get_latest_version($pagename); - //$vdata = get_versiondata($pagename, $version, 1); + $data = get_pagedata($pagename); + if (isset($data['pagename'])) + $data['pagename'] = $to; + //$version = $this->get_latest_version($pagename); + //$vdata = get_versiondata($pagename, $version, 1); //$data[CMD_CONTENT] = $vdata[CMD_CONTENT]; - $this->delete_page($pagename); - $this->update_pagedata($to, $data); - return true; + $this->delete_page($pagename); + $this->update_pagedata($to, $data); + return true; } function delete_versiondata($pagename, $version) @@ -936,7 +936,7 @@ extends WikiDB_backend_iterator } function count() { - return count($this->_array); + return count($this->_array); } function free() diff --git a/lib/WikiDB/backend/dba.php b/lib/WikiDB/backend/dba.php index 132ec3156..e4857ac6f 100644 --- a/lib/WikiDB/backend/dba.php +++ b/lib/WikiDB/backend/dba.php @@ -19,12 +19,12 @@ extends WikiDB_backend_dbaBase $db = new DbaDatabase($dbfile, false, $dba_handler); $db->set_timeout($timeout); - // Workaround for BDB 4.1 bugs - if (file_exists($dbfile)) { + // Workaround for BDB 4.1 bugs + if (file_exists($dbfile)) { $mode = 'w'; - } else { + } else { $mode = 'c'; - } + } if (!$db->open($mode)) { trigger_error(sprintf(_("%s: Can't open dba database"), $dbfile), E_USER_ERROR); global $request; diff --git a/lib/WikiDB/backend/dbaBase.php b/lib/WikiDB/backend/dbaBase.php index 43b5e45170a226a68dc8c1c74b4b151cd5632cd7..6fc9e4aa77237df44b7a522b589fc157d8acb9eb 100644 GIT binary patch delta 1955 zcmZ`)U1(cn7$!B1`7?iOPSUh#zHKLM(lm>mYpY$7CT&x7{oR$CrZ#DN+8&oC-N{LZ zjDif*3w4e>ie5~d8;VY0gCo*`o7Ewx$Tk_f7^oNi76cK*i#b8hPnwerJU8cgzxVy# z-{mdE%ilU>-=?zh_d086-Onl6^>Jl8rWN6FgizIbDxr3PB|L!k=upH9usc3V;FN7aMn&K zo)i8U*ya{RINRn`z?tSpk?^(R4dO6|y1NLykmGY=VK`9m;A%uCBs{G4u03D0b>kf` z1+$M;G;6*M83+;bh*r*I*<{7@bY3p-O6$G2;BJD=zvGUKgoM9Su_jz2bmksxg|~#4 zI$vm@w=1XFP)KbuyGQ~wOQM8cDKiX6`@1j*4_G15wa=9qkrXNv{wT-t%#y=G-R`o5c5WErhP)UPpI zi6Jqvn9G+Kao&+AWvXH+F04_X(!@x#RRLpBuN+0;I##0OE`#@@o_d2XqrO@r>H_jy zS&S#g_&55z;^O4kB)$#n@yA%3vS1w#%L`%ttK3uWsacp;M`TZgV6u4du=qbl zIdC-5E*4>~gteNTI6vjV<%AOvvl(CQGveoj4L6o;_$SedGbX!PrsnjFI1!q|r|DKa zHs?et8N;Q06kbm5mW(U&T3k%_iB4@GoDP~nBI6f_LwMEEjG4g}oc1>3*q~eFiU-BR zMu{(0BUrl?n}Z?D%!Xhb8d2+SN$mnZWS659Q#39NxnSurWj0y}YWc$XO1iR4HVZVlfD+ngC!(?+od3M4g9_3lSD>uU%ap~*Rsjp?zO zGUMW^8OJFdZlrwmF74upEF3E2R+tVVo=Vcufm2?W7{IlC3Z%kx!rI89Olf>~;9!-G zqg@Kfj0P3(+^AmxAB^r+z_roprTFXUhsw(TGB7z#iAP3{%y`{3P{+i;HhbvR+!7;C zQJP_ulIrEPj?8QTj){2p_J&A=hz|-`D(ARdfoGTn!WYRLLrQF6shrPoHMXHV;a4Yi za$-<=1hjOq%wuP&RT`hFbxj6TAvrlD4YNgxl+P2Xn+rrvQT6@iK^?)=Wk9^9Gh*{3^#b9l(dkM}({X$syS&w0;# z-p}W}Ioa55xc6tnM`hAL*cn0rFB5w+shBBY*U3w;KVtSY6G2v0wi&Rn3+B%nh`!La zWrCye_SXT|EKdD?`wuN3-su`M5yE;c^SG>8Mp_7kufl$x>SWg}|ANW&?hz9a*lTwlW3R0zG=tD;T!}xp`KcknUI6s3N3KUKaijP!EY^` z03WXp%2M)$m0}Rex+*$GV8v6fl0TK#yfi!x#~{_z^0UiIDJy$HUls9$sYCmb+_#37 zTe!RbV%(Wi-D=uL;HWICMH#LzCn-f4Ip2EB z2Hm%Yoq&O`18_dv+XO>J*un(P7$}`Qx{%AuN)~**lBTKoCrg^_g$QW*eb{L=Z0Z>_ zwS);O%(`$M!n{2WWV3q<{ebpl2(SsBhuod>m zs*6o7^{}JUT@)0#RaKUjPXgDfTr4RXm5NkQjnW9aG)+TbggK3IId&X>9xC(=_XL0^ z6)FSQct?=W90~J$=}3sL>yZh*ZpN(ax5!>Yo)eqF7Oay|I>#l9gTq%?DN9O8#sP$1 zA&Pj(yK=z>@}hNh*~!g*jt1;ihM$oNTBbfHyf$`lCXUo@%=WVnXF5>ao*iPBM!I=X zj+jyCg@}i($9lQ$lbFcYj%c7-usG|kO1atou3a-*=KvB!jo`yj4re@H%t)##J?G;j z`u&`#V{=B5b90_rl0JhA&O<>u1vDTJUN8RE;A4)%RxqhHU*`c8_~E2(EWN9f_%(PU z*w;r=fbK*PFrDxNKA-RazL#(V-b`2ke@T1{`2X2`JlO;Kr;`rsq&~qecx=|Br)2(g z;3QN>8Sbc7fHP%BpXn5z_=u;G_q$m_EvXp0q0GJ8~*~eTkRr}Lc^oga1IF0Ah!`*cgflq?AYEXVV9o@5g ze%PZ+BKoc^dG}Tuz}WZ!m-@!iWizml%HRWiK63!@O6DEF%n6H)+pDrxQVW!GV*Fje ldvKa`vE!MC^iNMLHbHc~Q&u|QiF&a-1FyRN<(VH%{{ep$z5@UN diff --git a/lib/WikiDB/backend/dumb/AllRevisionsIter.php b/lib/WikiDB/backend/dumb/AllRevisionsIter.php index 98cc4673c..86b265722 100644 --- a/lib/WikiDB/backend/dumb/AllRevisionsIter.php +++ b/lib/WikiDB/backend/dumb/AllRevisionsIter.php @@ -46,15 +46,15 @@ extends WikiDB_backend_iterator if ($version == 0) return false; - if (is_string($vdata) and !empty($vdata)) { - $vdata1 = @unserialize($vdata); - if (empty($vdata1)) { - if (DEBUG) // string but unseriazible - trigger_error ("Broken page $pagename ignored. Run Check WikiDB", E_USER_WARNING); - return false; - } - $vdata = $vdata1; - } + if (is_string($vdata) and !empty($vdata)) { + $vdata1 = @unserialize($vdata); + if (empty($vdata1)) { + if (DEBUG) // string but unseriazible + trigger_error ("Broken page $pagename ignored. Run Check WikiDB", E_USER_WARNING); + return false; + } + $vdata = $vdata1; + } $rev = array('versiondata' => $vdata, 'pagename' => $pagename, 'version' => $version); diff --git a/lib/WikiDB/backend/dumb/LinkSearchIter.php b/lib/WikiDB/backend/dumb/LinkSearchIter.php index a25863b13..550aa8e13 100644 --- a/lib/WikiDB/backend/dumb/LinkSearchIter.php +++ b/lib/WikiDB/backend/dumb/LinkSearchIter.php @@ -40,122 +40,122 @@ class WikiDB_backend_dumb_LinkSearchIter extends WikiDB_backend_iterator { function WikiDB_backend_dumb_LinkSearchIter(&$backend, &$pageiter, $search, $linktype, - $relation=false, $options=array()) + $relation=false, $options=array()) { $this->_backend = &$backend; $this->_pages = $pageiter; $this->search = $search; // search the linkvalue. it should be the value or pagename $this->relation = $relation; // limit the search to this linkname $this->linktype = $linktype; - $this->_reverse = false; - $this->_want_relations = true; - $this->sortby = isset($options['sortby']) ? $options['sortby'] : ''; - $this->limit = isset($options['limit']) ? $options['limit'] : ''; - $this->exclude = isset($options['exclude']) ? $options['exclude'] : ''; - $this->_field = 'pagename'; // the name of the linkvalue field to apply the search - $this->_dbi =& $GLOBALS['request']->_dbi; - if ($linktype == 'relation') { - $this->_want_relations = true; - $this->_field = 'linkrelation'; - } - if ($linktype == 'attribute') { - $this->_want_relations = true; - $this->_field = 'attribute'; - } - if ($linktype == 'linkfrom') { - $this->_reverse = true; - } - $this->_page = false; + $this->_reverse = false; + $this->_want_relations = true; + $this->sortby = isset($options['sortby']) ? $options['sortby'] : ''; + $this->limit = isset($options['limit']) ? $options['limit'] : ''; + $this->exclude = isset($options['exclude']) ? $options['exclude'] : ''; + $this->_field = 'pagename'; // the name of the linkvalue field to apply the search + $this->_dbi =& $GLOBALS['request']->_dbi; + if ($linktype == 'relation') { + $this->_want_relations = true; + $this->_field = 'linkrelation'; + } + if ($linktype == 'attribute') { + $this->_want_relations = true; + $this->_field = 'attribute'; + } + if ($linktype == 'linkfrom') { + $this->_reverse = true; + } + $this->_page = false; } // iterate a nested page-links loop. there will be multiple results per page. // we must keep the page iter internally. function next() { - while (1) { - if (!isset($this->_links) or count($this->_links) == 0) { - $page = $this->_next_page(); // initialize all links of this page - if (!$page) return false; - } else { - $page = $this->_page; - } - // iterate the links. the links are pushed into the handy triple by _get_links - while ($link = array_shift($this->_links)) { - // unmatching relations are already filtered out - if ($this->search->match($link['linkvalue'])) { //pagename or attr-value - if ($link['linkname']) - return array('pagename' => $page, - 'linkname' => $link['linkname'], - 'linkvalue'=> $link['linkvalue']); - else - return array('pagename' => $page, - 'linkvalue'=> $link['linkvalue']); - } - } - // no links on this page anymore. - } + while (1) { + if (!isset($this->_links) or count($this->_links) == 0) { + $page = $this->_next_page(); // initialize all links of this page + if (!$page) return false; + } else { + $page = $this->_page; + } + // iterate the links. the links are pushed into the handy triple by _get_links + while ($link = array_shift($this->_links)) { + // unmatching relations are already filtered out + if ($this->search->match($link['linkvalue'])) { //pagename or attr-value + if ($link['linkname']) + return array('pagename' => $page, + 'linkname' => $link['linkname'], + 'linkvalue'=> $link['linkvalue']); + else + return array('pagename' => $page, + 'linkvalue'=> $link['linkvalue']); + } + } + // no links on this page anymore. + } } // initialize the links also function _next_page() { - unset($this->_links); - if (!($next = $this->_pages->next())) - return false; - $this->_page = $next['pagename']; - while(!($this->_links = $this->_get_links($this->_page))) { - if (!($next = $this->_pages->next())) - return false; - $this->_page = $next['pagename']; - } - return $this->_page; + unset($this->_links); + if (!($next = $this->_pages->next())) + return false; + $this->_page = $next['pagename']; + while(!($this->_links = $this->_get_links($this->_page))) { + if (!($next = $this->_pages->next())) + return false; + $this->_page = $next['pagename']; + } + return $this->_page; } // get the links of each page in advance function _get_links($pagename) { - $links = array(); - if ($this->linktype == 'attribute') { - $page = $this->_dbi->getPage($pagename); - $attribs = $page->get('attributes'); - if ($attribs) { - foreach ($attribs as $attribute => $value) { - if ($this->relation and !$this->relation->match($attribute)) continue; - // The logical operator and unit unification (not yet) is encoded into - // a seperate search object. - if (!$this->search->match($value)) continue; - $links[] = array('pagename' => $pagename, - 'linkname' => $attribute, - 'linkvalue' => $value); - } - } - unset($attribs); - } else { - $link_iter = $this->_backend->get_links($pagename, $this->_reverse, true, - $this->sortby, $this->limit, - $this->exclude, $this->_want_relations); - // we already stepped through all links. make use of that. - if ($this->_want_relations - and isset($link_iter->_options['found_relations']) - and $link_iter->_options['found_relations'] == 0) - { - $link_iter->free(); - return $links; - } - while ($link = $link_iter->next()) { - if (empty($link[$this->_field])) continue; - if ($this->_want_relations and $this->relation - and !$this->relation->match($link['linkrelation'])) continue; - // check hash values, with/out want_relations - $links[] = array('pagename' => $pagename, - 'linkname' => $this->_want_relations ? $link['linkrelation'] : '', - 'linkvalue' => $link['pagename']); - } - $link_iter->free(); - } - return $links; + $links = array(); + if ($this->linktype == 'attribute') { + $page = $this->_dbi->getPage($pagename); + $attribs = $page->get('attributes'); + if ($attribs) { + foreach ($attribs as $attribute => $value) { + if ($this->relation and !$this->relation->match($attribute)) continue; + // The logical operator and unit unification (not yet) is encoded into + // a seperate search object. + if (!$this->search->match($value)) continue; + $links[] = array('pagename' => $pagename, + 'linkname' => $attribute, + 'linkvalue' => $value); + } + } + unset($attribs); + } else { + $link_iter = $this->_backend->get_links($pagename, $this->_reverse, true, + $this->sortby, $this->limit, + $this->exclude, $this->_want_relations); + // we already stepped through all links. make use of that. + if ($this->_want_relations + and isset($link_iter->_options['found_relations']) + and $link_iter->_options['found_relations'] == 0) + { + $link_iter->free(); + return $links; + } + while ($link = $link_iter->next()) { + if (empty($link[$this->_field])) continue; + if ($this->_want_relations and $this->relation + and !$this->relation->match($link['linkrelation'])) continue; + // check hash values, with/out want_relations + $links[] = array('pagename' => $pagename, + 'linkname' => $this->_want_relations ? $link['linkrelation'] : '', + 'linkvalue' => $link['pagename']); + } + $link_iter->free(); + } + return $links; } function free() { - $this->_page = false; - unset($this->_links); + $this->_page = false; + unset($this->_links); $this->_pages->free(); } } diff --git a/lib/WikiDB/backend/dumb/MostRecentIter.php b/lib/WikiDB/backend/dumb/MostRecentIter.php index 09f13eb51..4a0686e41 100644 --- a/lib/WikiDB/backend/dumb/MostRecentIter.php +++ b/lib/WikiDB/backend/dumb/MostRecentIter.php @@ -28,8 +28,8 @@ extends WikiDB_backend_iterator if (!$vdata) continue; assert(is_array($vdata)); if (empty($vdata['mtime'])) { - $vdata['mtime'] = 0; - } + $vdata['mtime'] = 0; + } if (!empty($vdata['is_minor_edit'])) { if (!$include_minor_revisions) continue; diff --git a/lib/WikiDB/backend/dumb/TextSearchIter.php b/lib/WikiDB/backend/dumb/TextSearchIter.php index 347e471ee..8c62d8647 100644 --- a/lib/WikiDB/backend/dumb/TextSearchIter.php +++ b/lib/WikiDB/backend/dumb/TextSearchIter.php @@ -15,11 +15,11 @@ extends WikiDB_backend_iterator $this->_stoplist =& $search->_stoplist; $this->stoplisted = array(); - $this->_from = 0; + $this->_from = 0; if (isset($options['limit'])) // extract from,count from limit - list($this->_from, $this->_count) = WikiDB_backend::limit($options['limit']); + list($this->_from, $this->_count) = WikiDB_backend::limit($options['limit']); else - $this->_count = 0; + $this->_count = 0; if (isset($options['exclude'])) $this->_exclude = $options['exclude']; else $this->_exclude = false; } @@ -39,7 +39,7 @@ extends WikiDB_backend_iterator $text = $page['pagename']; if ($result = $this->_search->match($text)) { // first match the pagename only return $this->_search->score($text) * 2.0; - } + } if ($this->_fulltext) { // eliminate stoplist words from fulltext search @@ -50,29 +50,29 @@ extends WikiDB_backend_iterator $text .= "\n" . $this->_get_content($page); // Todo: Bonus for meta keywords (* 1.5) and headers if ($this->_search->match($text)) - return $this->_search->score($text); + return $this->_search->score($text); } else { return $result; - } + } } function next() { $pages = &$this->_pages; while ($page = $pages->next()) { if ($score = $this->_match($page)) { - $this->_index++; - if (($this->_from > 0) and ($this->_index <= $this->_from)) + $this->_index++; + if (($this->_from > 0) and ($this->_index <= $this->_from)) // not yet reached the offset - continue; + continue; /*if ($this->_count and ($this->_index > $this->_count)) { // reached the limit, but need getTotal $this->_count++; return false; }*/ if (is_array($page)) - $page['score'] = $score; - else - $page->score = $score; + $page['score'] = $score; + else + $page->score = $score; return $page; } } diff --git a/lib/WikiDB/backend/dumb/WantedPagesIter.php b/lib/WikiDB/backend/dumb/WantedPagesIter.php index 12d14783a..a29fe82be 100644 --- a/lib/WikiDB/backend/dumb/WantedPagesIter.php +++ b/lib/WikiDB/backend/dumb/WantedPagesIter.php @@ -34,14 +34,14 @@ extends WikiDB_backend_iterator function next() { while ($page = $this->_allpages->next()) { while ($this->pagelinks) { // deferred return - return array_pop($this->pagelinks); + return array_pop($this->pagelinks); } - $this->pagelinks = array(); + $this->pagelinks = array(); if ($this->limit and $this->pos > $this->limit) break; $pagename = $page['pagename']; $links = $this->_backend->get_links($pagename, false); while ($link = $links->next()) { - if ($this->limit and $this->pos > $this->limit) break; + if ($this->limit and $this->pos > $this->limit) break; if ($this->exclude and in_array($link['pagename'], $this->exclude)) continue; // better membership for a pageiterator? if (! in_array($link['pagename'], $this->_allpages_array)) { diff --git a/lib/WikiDB/backend/file.php b/lib/WikiDB/backend/file.php index df4684ccc..76e167a29 100644 --- a/lib/WikiDB/backend/file.php +++ b/lib/WikiDB/backend/file.php @@ -58,7 +58,7 @@ extends WikiDB_backend { $this->data_dir = $dbparam['directory']; if (file_exists($this->data_dir) and is_file($this->data_dir)) - unlink($this->data_dir); + unlink($this->data_dir); if (is_dir($this->data_dir) == false) { mkdir($this->data_dir, 0755); } @@ -70,8 +70,8 @@ extends WikiDB_backend 'links' => $this->data_dir.'/'.'links' ); foreach ($this->_dir_names as $key => $val) { - if (file_exists($val) and is_file($val)) - unlink($val); + if (file_exists($val) and is_file($val)) + unlink($val); if (is_dir($val) == false) mkdir($val, 0755); } @@ -107,13 +107,13 @@ extends WikiDB_backend $pd['pagename'] = $pagename; if ($version != 0) $pd['version'] = $version; - if (!is_array($pd)) - ExitWiki(sprintf(gettext("'%s': corrupt file"), - htmlspecialchars($filename))); + if (!is_array($pd)) + ExitWiki(sprintf(gettext("'%s': corrupt file"), + htmlspecialchars($filename))); else return $pd; - } - fclose($fd); + } + fclose($fd); } return NULL; } @@ -345,10 +345,10 @@ extends WikiDB_backend */ function get_previous_version($pagename, $version) { $prev = ($version > 0 ? $version - 1 : 0); - while ($prev and !file_exists($this->_pagename2filename('ver_data', $pagename, $prev))) { + while ($prev and !file_exists($this->_pagename2filename('ver_data', $pagename, $prev))) { $prev--; - } - return $prev; + } + return $prev; } /** @@ -377,7 +377,7 @@ extends WikiDB_backend * @see WikiDB_PageRevision::get */ function get_versiondata($pagename, $version, $want_content = false) { - $vd = $this->_loadVersionData($pagename, $version); + $vd = $this->_loadVersionData($pagename, $version); if ($vd == NULL) return false; return $vd; @@ -532,7 +532,7 @@ extends WikiDB_backend foreach ($pagenames as $key => $val) { $links = $this->_loadPageLinks($key); - foreach ($links as $key2 => $val2) { + foreach ($links as $key2 => $val2) { if ($val2['linkto'] == $pagename) array_push($out, $key); } @@ -573,7 +573,7 @@ extends WikiDB_backend * @return object A WikiDB_backend_iterator. */ function get_all_pages($include_empty=false, $sortby='', $limit='', $exclude='') { - require_once("lib/PageList.php"); + require_once("lib/PageList.php"); $this->_loadLatestVersions(); $a = array_keys($this->_latest_versions); if (empty($a)) @@ -738,7 +738,7 @@ class WikiDB_backend_file_iter extends WikiDB_backend_iterator return $this->_result; } function count() { - return count($this->_result); + return count($this->_result); } function free () { $this->_result = array(); diff --git a/lib/WikiDB/backend/flatfile.php b/lib/WikiDB/backend/flatfile.php index 642ba34d1..90f768311 100644 --- a/lib/WikiDB/backend/flatfile.php +++ b/lib/WikiDB/backend/flatfile.php @@ -42,11 +42,11 @@ extends WikiDB_backend_file // common file load / save functions: // FilenameForPage is from loadsave.php function _pagename2filename($type, $pagename, $version) { - $fpagename = FilenameForPage($pagename); - if (strstr($fpagename, "/")) { + $fpagename = FilenameForPage($pagename); + if (strstr($fpagename, "/")) { $fpagename = preg_replace("/\//", "%2F", $fpagename); } - return $this->_dir_names[$type].'/'.$fpagename; + return $this->_dir_names[$type].'/'.$fpagename; /* if ($version == 0) return $this->_dir_names[$type].'/'.FilenameForPage($pagename); else @@ -67,23 +67,23 @@ extends WikiDB_backend_file if (!file_exists($filename)) return NULL; if (!filesize($filename)) return array(); if ($fd = @fopen($filename, "rb")) { - $locked = flock($fd, 1); // Read lock - if (!$locked) { - ExitWiki("Timeout while obtaining lock. Please try again"); - } - if ($data = fread($fd, filesize($filename))) { - // This is the only difference from file: - if ($parts = ParseMimeifiedPages($data)) { - $pd = $parts[0]; - } - //if ($set_pagename == true) - $pd['pagename'] = $pagename; - //if ($version != 0) $pd['version'] = $version; - if (!is_array($pd)) - ExitWiki(sprintf(gettext("'%s': corrupt file"), - htmlspecialchars($filename))); - } - fclose($fd); + $locked = flock($fd, 1); // Read lock + if (!$locked) { + ExitWiki("Timeout while obtaining lock. Please try again"); + } + if ($data = fread($fd, filesize($filename))) { + // This is the only difference from file: + if ($parts = ParseMimeifiedPages($data)) { + $pd = $parts[0]; + } + //if ($set_pagename == true) + $pd['pagename'] = $pagename; + //if ($version != 0) $pd['version'] = $version; + if (!is_array($pd)) + ExitWiki(sprintf(gettext("'%s': corrupt file"), + htmlspecialchars($filename))); + } + fclose($fd); } if ($pd != NULL) @@ -178,18 +178,18 @@ extends WikiDB_backend_file $pagedata .= MimeifyPageRevision($page, $current); if ($fd = fopen($filename, 'a+b')) { - $locked = flock($fd, 2); // Exclusive blocking lock - if (!$locked) { - ExitWiki("Timeout while obtaining lock. Please try again"); - } - rewind($fd); - ftruncate($fd, 0); + $locked = flock($fd, 2); // Exclusive blocking lock + if (!$locked) { + ExitWiki("Timeout while obtaining lock. Please try again"); + } + rewind($fd); + ftruncate($fd, 0); $len = strlen($pagedata); - $num = fwrite($fd, $pagedata, $len); - assert($num == $len); - fclose($fd); + $num = fwrite($fd, $pagedata, $len); + assert($num == $len); + fclose($fd); } else { - ExitWiki("Error while writing page '$pagename'"); + ExitWiki("Error while writing page '$pagename'"); } } }; diff --git a/lib/WysiwygEdit/FCKeditor.php b/lib/WysiwygEdit/FCKeditor.php index 8e317ea2b..2c3bb6ab8 100644 --- a/lib/WysiwygEdit/FCKeditor.php +++ b/lib/WysiwygEdit/FCKeditor.php @@ -20,10 +20,10 @@ class WysiwygEdit_FCKeditor extends WysiwygEdit { function WysiwygEdit_FCKeditor() { global $LANG; $this->_transformer_tags = false; - $this->BasePath = DATA_PATH.'/themes/default/FCKeditor/'; - $this->_htmltextid = "edit-content"; // FCKEditor1; + $this->BasePath = DATA_PATH.'/themes/default/FCKeditor/'; + $this->_htmltextid = "edit-content"; // FCKEditor1; $this->_wikitextid = "editareawiki"; - $this->_jsdefault = " + $this->_jsdefault = " oFCKeditor.BasePath = '$this->BasePath'; oFCKeditor.Height = 300; // oFCKeditor.ToolbarSet = 'Basic' ; @@ -31,8 +31,8 @@ oFCKeditor.Config.DefaultLanguage = '$LANG'; oFCKeditor.Config.LinkBrowserURL = oFCKeditor.BasePath + 'editor/filemanager/browser/default/browser.html?Connector=connectors/php/connector.php'; oFCKeditor.Config.ImageBrowserURL = oFCKeditor.BasePath + 'editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/php/connector.php'; "; - if (!empty($_REQUEST['start_debug'])) - $this->_jsdefault = "\noFCKeditor.Config.Debug = true;"; + if (!empty($_REQUEST['start_debug'])) + $this->_jsdefault = "\noFCKeditor.Config.Debug = true;"; } function Head($name='edit[content]') { @@ -40,7 +40,7 @@ oFCKeditor.Config.ImageBrowserURL = oFCKeditor.BasePath + 'editor/filemanager/br $WikiTheme->addMoreHeaders (Javascript('', array('src' => $this->BasePath . 'fckeditor.js', 'language' => 'JavaScript'))); - return JavaScript(" + return JavaScript(" window.onload = function() { var oFCKeditor = new FCKeditor( '$this->_htmltextid' ) ;" @@ -52,23 +52,23 @@ oFCKeditor.ReplaceTextarea(); } function Textarea ($textarea, $wikitext, $name='edit[content]') { - return $this->Textarea_Replace($textarea, $wikitext, $name); + return $this->Textarea_Replace($textarea, $wikitext, $name); } /* either iframe or textarea */ function Textarea_Create ($textarea, $wikitext, $name='edit[content]') { $htmltextid = $name; $out = HTML( - JavaScript(" + JavaScript(" var oFCKeditor = new FCKeditor( '$htmltextid' ) ; oFCKeditor.Value = '" . $textarea->_content[0]->asXML() . "';" . $this->_jsdefault . " oFCKeditor.Create();"), - HTML::div(array("id" => $this->_wikitextid, - 'style' => 'display:none'), - $wikitext), - "\n"); - return $out; + HTML::div(array("id" => $this->_wikitextid, + 'style' => 'display:none'), + $wikitext), + "\n"); + return $out; } /* textarea only */ @@ -76,32 +76,32 @@ oFCKeditor.Create();"), $htmltextid = $this->_htmltextid; $textarea->SetAttr('id', $htmltextid); $out = HTML($textarea, - HTML::div(array("id" => $this->_wikitextid, - 'style' => 'display:none'), - $wikitext), - "\n"); - return $out; + HTML::div(array("id" => $this->_wikitextid, + 'style' => 'display:none'), + $wikitext), + "\n"); + return $out; } /* via the PHP object */ function Textarea_PHP ($textarea, $wikitext, $name='edit[content]') { global $LANG; - $this->FilePath = realpath(PHPWIKI_DIR.'/themes/default/FCKeditor') . "/"; + $this->FilePath = realpath(PHPWIKI_DIR.'/themes/default/FCKeditor') . "/"; $htmltextid = "edit-content"; - include_once($this->FilePath . 'fckeditor.php'); - $this->oFCKeditor = new FCKeditor($htmltextid) ; - $this->oFCKeditor->BasePath = $this->BasePath; - $this->oFCKeditor->Value = $textarea->_content[0]->asXML(); + include_once($this->FilePath . 'fckeditor.php'); + $this->oFCKeditor = new FCKeditor($htmltextid) ; + $this->oFCKeditor->BasePath = $this->BasePath; + $this->oFCKeditor->Value = $textarea->_content[0]->asXML(); - $this->oFCKeditor->Config['AutoDetectLanguage'] = true ; - $this->oFCKeditor->Config['DefaultLanguage'] = $LANG; - $this->oFCKeditor->Create(); + $this->oFCKeditor->Config['AutoDetectLanguage'] = true ; + $this->oFCKeditor->Config['DefaultLanguage'] = $LANG; + $this->oFCKeditor->Create(); - return HTML::div(array("id" => $this->_wikitextid, - 'style' => 'display:none'), - $wikitext); + return HTML::div(array("id" => $this->_wikitextid, + 'style' => 'display:none'), + $wikitext); } } diff --git a/lib/WysiwygEdit/Wikiwyg.php b/lib/WysiwygEdit/Wikiwyg.php index 24b6f232e..666043138 100644 --- a/lib/WysiwygEdit/Wikiwyg.php +++ b/lib/WysiwygEdit/Wikiwyg.php @@ -20,13 +20,13 @@ class WysiwygEdit_Wikiwyg extends WysiwygEdit { function WysiwygEdit_Wikiwyg() { global $request, $LANG; $this->_transformer_tags = false; - $this->BasePath = DATA_PATH.'/themes/default/Wikiwyg'; - $this->_htmltextid = "edit-content"; + $this->BasePath = DATA_PATH.'/themes/default/Wikiwyg'; + $this->_htmltextid = "edit-content"; $this->_wikitextid = "editareawiki"; - $script_url = deduce_script_name(); - if ((DEBUG & _DEBUG_REMOTE) and isset($_GET['start_debug'])) - $script_url .= ("?start_debug=".$_GET['start_debug']); - $this->_jsdefault = ""; + $script_url = deduce_script_name(); + if ((DEBUG & _DEBUG_REMOTE) and isset($_GET['start_debug'])) + $script_url .= ("?start_debug=".$_GET['start_debug']); + $this->_jsdefault = ""; } function Head($name='edit[content]') { @@ -40,7 +40,7 @@ class WysiwygEdit_Wikiwyg extends WysiwygEdit { } $doubleClickToEdit = ($GLOBALS['request']->getPref('doubleClickEdit') or ENABLE_DOUBLECLICKEDIT) ? 'true' : 'false'; - if ($GLOBALS['request']->getArg('mode') && $GLOBALS['request']->getArg('mode') == 'wysiwyg'){ + if ($GLOBALS['request']->getArg('mode') && $GLOBALS['request']->getArg('mode') == 'wysiwyg'){ return JavaScript($this->_jsdefault . " window.onload = function() { var wikiwyg = new Wikiwyg.Phpwiki(); @@ -48,50 +48,50 @@ class WysiwygEdit_Wikiwyg extends WysiwygEdit { doubleClickToEdit: $doubleClickToEdit, javascriptLocation: data_path+'/themes/default/Wikiwyg/', toolbar: { - imagesLocation: data_path+'/themes/default/Wikiwyg/images/', - controlLayout: [ - 'save','preview','save_button','|', - 'p','|', - 'h2', 'h3', 'h4','|', - 'bold', 'italic', '|', + imagesLocation: data_path+'/themes/default/Wikiwyg/images/', + controlLayout: [ + 'save','preview','save_button','|', + 'p','|', + 'h2', 'h3', 'h4','|', + 'bold', 'italic', '|', 'sup', 'sub', '|', 'toc', 'wikitext','|', - 'pre','|', - 'ordered', 'unordered','hr','|', - 'link','|', + 'pre','|', + 'ordered', 'unordered','hr','|', + 'link','|', 'table' - ], - styleSelector: [ - 'label', 'p', 'h2', 'h3', 'h4', 'pre' - ], - controlLabels: { - save: '"._("Apply changes")."', - cancel: '"._("Exit toolbar")."', - h2: '"._("Title 1")."', - h3: '"._("Title 2")."', - h4: '"._("Title 3")."', - verbatim: '"._("Verbatim")."', + ], + styleSelector: [ + 'label', 'p', 'h2', 'h3', 'h4', 'pre' + ], + controlLabels: { + save: '"._("Apply changes")."', + cancel: '"._("Exit toolbar")."', + h2: '"._("Title 1")."', + h3: '"._("Title 2")."', + h4: '"._("Title 3")."', + verbatim: '"._("Verbatim")."', toc: '"._("Table of Contents")."', wikitext: '"._("Insert Wikitext section")."', sup: '"._("Sup")."', sub: '"._("Sub")."', preview: '"._("Preview")."', save_button:'"._("Save")."' - } + } }, wysiwyg: { iframeId: 'iframe0' }, - wikitext: { - supportCamelCaseLinks: true - } + wikitext: { + supportCamelCaseLinks: true + } }; var div = document.getElementById(\"" . $this->_htmltextid . "\"); wikiwyg.createWikiwygArea(div, config); wikiwyg_divs.push(wikiwyg); wikiwyg.editMode();}" - ); + ); } } @@ -102,15 +102,15 @@ class WysiwygEdit_Wikiwyg extends WysiwygEdit { $textarea->SetAttr('id', $htmltextid); $iframe0 = new RawXml(''); if ($request->getArg('mode') and $request->getArg('mode') == 'wysiwyg'){ - $out = HTML(HTML::div(array('class' => 'hint'), + $out = HTML(HTML::div(array('class' => 'hint'), _("Warning: This Wikiwyg editor has only Beta quality!")), $textarea, $iframe0, - "\n"); - } else { - $out = HTML($textarea, $iframe0, "\n"); - } - return $out; + "\n"); + } else { + $out = HTML($textarea, $iframe0, "\n"); + } + return $out; } /** @@ -134,44 +134,44 @@ class WysiwygEdit_Wikiwyg extends WysiwygEdit { class WikiToHtml { function WikiToHtml ($wikitext, &$request) { $this->_wikitext = $wikitext; - $this->_request =& $request; - $this->_html = ""; - $this->html_content = ""; + $this->_request =& $request; + $this->_html = ""; + $this->html_content = ""; } function send() { $this->convert(); - echo $this->html_content; + echo $this->html_content; } function convert() { require_once("lib/BlockParser.php"); - $xmlcontent = TransformText($this->_wikitext, 2.0, $this->_request->getArg('pagename')); - $this->_html = $xmlcontent->AsXML(); + $xmlcontent = TransformText($this->_wikitext, 2.0, $this->_request->getArg('pagename')); + $this->_html = $xmlcontent->AsXML(); - $this->replace_inside_html(); + $this->replace_inside_html(); } function replace_inside_html() { - global $charset; + global $charset; - $this->clean_links(); + $this->clean_links(); $this->clean_plugin_name(); $this->replace_known_plugins(); $this->replace_unknown_plugins(); - // $this->replace_tags(); - $this->clean_plugin(); + // $this->replace_tags(); + $this->clean_plugin(); - if ($charset != 'utf-8') { - if ($charset == 'iso-8959-1') { - $this->_html = utf8_decode($this->_html); - } else { + if ($charset != 'utf-8') { + if ($charset == 'iso-8959-1') { + $this->_html = utf8_decode($this->_html); + } else { // check for iconv support loadPhpExtension("iconv"); - $this->_html = iconv("UTF-8", $charset, $this->_html); - } + $this->_html = iconv("UTF-8", $charset, $this->_html); + } } - $this->html_content = $this->_html; + $this->html_content = $this->_html; } // Draft function to replace RichTable @@ -182,20 +182,20 @@ class WikiToHtml { $pattern = '/\<\;\?plugin\s+RichTable(.*)\?\>\;/Umsi'; $replace_string = "replace_rich_table"; $this->_html = preg_replace_callback($pattern, - $replace_string, - $this->_html); + $replace_string, + $this->_html); } // Replace unknown plugins by keyword Wikitext { tag } function replace_unknown_plugins() { $pattern = '/(\<\;\?plugin[^?]*\?\>\;)/Usi'; - $replace_string = - '

Wikitext { + $replace_string = + '

Wikitext {
\1
}

'; - $this->_html = preg_replace($pattern, - $replace_string, - $this->_html); + $this->_html = preg_replace($pattern, + $replace_string, + $this->_html); } // Clean links to keep only name @@ -242,21 +242,21 @@ class WikiToHtml { // tag to keep formatting function clean_plugin() { $pattern = '/(\<\;\?plugin.*\?\>\;)/Umsei'; - $replace_string = 'preg_replace("/\n/Ums","
","\1")'; + $replace_string = 'preg_replace("/\n/Ums","
","\1")'; - $this->_html = preg_replace($pattern, - $replace_string, - $this->_html) ; + $this->_html = preg_replace($pattern, + $replace_string, + $this->_html) ; } function clean_plugin_name() { - // Remove plugin name converted in a link - $pattern = '/(\<\;\?plugin\s)\\\(\w+)\<\/a\><\/span\><\/span>([^?]*\?\>\;)/Umsi'; - $replace_string = '\1 \2 \3'; - $this->_html = preg_replace($pattern, - $replace_string, - $this->_html) ; + // Remove plugin name converted in a link + $pattern = '/(\<\;\?plugin\s)\\\(\w+)\<\/a\><\/span\><\/span>([^?]*\?\>\;)/Umsi'; + $replace_string = '\1 \2 \3'; + $this->_html = preg_replace($pattern, + $replace_string, + $this->_html) ; } } diff --git a/lib/WysiwygEdit/htmlarea2.php b/lib/WysiwygEdit/htmlarea2.php index ba35b64e9..6c5c058a5 100644 --- a/lib/WysiwygEdit/htmlarea2.php +++ b/lib/WysiwygEdit/htmlarea2.php @@ -29,8 +29,8 @@ if (win_ie_ver >= 5.5) { document.write('function editor_generate() { return false; }'); } ", - array('version' => 'JavaScript1.2', - 'type' => 'text/javascript')); + array('version' => 'JavaScript1.2', + 'type' => 'text/javascript')); } // to be called after diff --git a/lib/WysiwygEdit/tinymce.php b/lib/WysiwygEdit/tinymce.php index 238d4a660..13d9a1fd4 100644 --- a/lib/WysiwygEdit/tinymce.php +++ b/lib/WysiwygEdit/tinymce.php @@ -20,8 +20,8 @@ class WysiwygEdit_tinymce extends WysiwygEdit { function WysiwygEdit_tinymce() { $this->_transformer_tags = false; - $this->BasePath = DATA_PATH.'/themes/default/tiny_mce/'; - $this->_htmltextid = "edit-content"; + $this->BasePath = DATA_PATH.'/themes/default/tiny_mce/'; + $this->_htmltextid = "edit-content"; $this->_wikitextid = "editareawiki"; } @@ -32,21 +32,21 @@ class WysiwygEdit_tinymce extends WysiwygEdit { 'language' => 'JavaScript'))); return Javascript(" tinyMCE.init({ - mode : 'exact', - elements: '$name', + mode : 'exact', + elements: '$name', theme : 'advanced', language: \"$LANG\", ask : false, - theme_advanced_toolbar_location : \"top\", - theme_advanced_toolbar_align : \"left\", - theme_advanced_path_location : \"bottom\", - theme_advanced_buttons1 : \"bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,link,unlink\", - theme_advanced_buttons2 : \"\", - theme_advanced_buttons3 : \"\", + theme_advanced_toolbar_location : \"top\", + theme_advanced_toolbar_align : \"left\", + theme_advanced_path_location : \"bottom\", + theme_advanced_buttons1 : \"bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,link,unlink\", + theme_advanced_buttons2 : \"\", + theme_advanced_buttons3 : \"\", });"); /* plugins : \"table,contextmenu,paste,searchreplace,iespell,insertdatetime\", - extended_valid_elements : \"a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]\" + extended_valid_elements : \"a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]\" }); */ } diff --git a/lib/XMLRPC/utils.php b/lib/XMLRPC/utils.php index fc394251c..c30275d23 100644 --- a/lib/XMLRPC/utils.php +++ b/lib/XMLRPC/utils.php @@ -68,10 +68,10 @@ function xu_query_http_post($request, $host, $uri, $port, $debug, $fsockopen = $secure ? "fsockopen_ssl" : "fsockopen"; dbg1("opening socket to host: $host, port: $port, uri: $uri", $debug); - if ($secure) - $query_fd = fsockopen_ssl($host, $port, $errno, $errstr, 10); - else - $query_fd = fsockopen($host, $port, $errno, $errstr, 10); + if ($secure) + $query_fd = fsockopen_ssl($host, $port, $errno, $errstr, 10); + else + $query_fd = fsockopen($host, $port, $errno, $errstr, 10); if ($query_fd) { @@ -221,19 +221,19 @@ function xu_rpc_http_concise($params) { /* call an xmlrpc method on a remote http server. legacy support. */ function xu_rpc_http($method, $args, $host, $uri="/", $port=80, $debug=false, $timeout=0, $user=false, $pass=false, $secure=false) { - return xu_rpc_http_concise( - array( - 'method' => $method, - 'args' => $args, - 'host' => $host, - 'uri' => $uri, - 'port' => $port, - 'debug' => $debug, - 'timeout' => $timeout, - 'user' => $user, - 'pass' => $pass, - 'secure' => $secure - )); + return xu_rpc_http_concise( + array( + 'method' => $method, + 'args' => $args, + 'host' => $host, + 'uri' => $uri, + 'port' => $port, + 'debug' => $debug, + 'timeout' => $timeout, + 'user' => $user, + 'pass' => $pass, + 'secure' => $secure + )); } diff --git a/lib/fpdf/chinese.php b/lib/fpdf/chinese.php index e6ed86d21..609583e6c 100644 --- a/lib/fpdf/chinese.php +++ b/lib/fpdf/chinese.php @@ -6,451 +6,451 @@ require('lib/pdf.php'); $Big5_widths=array(' '=>250,'!'=>250,'"'=>408,'#'=>668,'$'=>490,'%'=>875,'&'=>698,'\''=>250, - '('=>240,')'=>240,'*'=>417,'+'=>667,','=>250,'-'=>313,'.'=>250,'/'=>520,'0'=>500,'1'=>500, - '2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>250,';'=>250, - '<'=>667,'='=>667,'>'=>667,'?'=>396,'@'=>921,'A'=>677,'B'=>615,'C'=>719,'D'=>760,'E'=>625, - 'F'=>552,'G'=>771,'H'=>802,'I'=>354,'J'=>354,'K'=>781,'L'=>604,'M'=>927,'N'=>750,'O'=>823, - 'P'=>563,'Q'=>823,'R'=>729,'S'=>542,'T'=>698,'U'=>771,'V'=>729,'W'=>948,'X'=>771,'Y'=>677, - 'Z'=>635,'['=>344,'\\'=>520,']'=>344,'^'=>469,'_'=>500,'`'=>250,'a'=>469,'b'=>521,'c'=>427, - 'd'=>521,'e'=>438,'f'=>271,'g'=>469,'h'=>531,'i'=>250,'j'=>250,'k'=>458,'l'=>240,'m'=>802, - 'n'=>531,'o'=>500,'p'=>521,'q'=>521,'r'=>365,'s'=>333,'t'=>292,'u'=>521,'v'=>458,'w'=>677, - 'x'=>479,'y'=>458,'z'=>427,'{'=>480,'|'=>496,'}'=>480,'~'=>667); + '('=>240,')'=>240,'*'=>417,'+'=>667,','=>250,'-'=>313,'.'=>250,'/'=>520,'0'=>500,'1'=>500, + '2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>250,';'=>250, + '<'=>667,'='=>667,'>'=>667,'?'=>396,'@'=>921,'A'=>677,'B'=>615,'C'=>719,'D'=>760,'E'=>625, + 'F'=>552,'G'=>771,'H'=>802,'I'=>354,'J'=>354,'K'=>781,'L'=>604,'M'=>927,'N'=>750,'O'=>823, + 'P'=>563,'Q'=>823,'R'=>729,'S'=>542,'T'=>698,'U'=>771,'V'=>729,'W'=>948,'X'=>771,'Y'=>677, + 'Z'=>635,'['=>344,'\\'=>520,']'=>344,'^'=>469,'_'=>500,'`'=>250,'a'=>469,'b'=>521,'c'=>427, + 'd'=>521,'e'=>438,'f'=>271,'g'=>469,'h'=>531,'i'=>250,'j'=>250,'k'=>458,'l'=>240,'m'=>802, + 'n'=>531,'o'=>500,'p'=>521,'q'=>521,'r'=>365,'s'=>333,'t'=>292,'u'=>521,'v'=>458,'w'=>677, + 'x'=>479,'y'=>458,'z'=>427,'{'=>480,'|'=>496,'}'=>480,'~'=>667); $GB_widths=array(' '=>207,'!'=>270,'"'=>342,'#'=>467,'$'=>462,'%'=>797,'&'=>710,'\''=>239, - '('=>374,')'=>374,'*'=>423,'+'=>605,','=>238,'-'=>375,'.'=>238,'/'=>334,'0'=>462,'1'=>462, - '2'=>462,'3'=>462,'4'=>462,'5'=>462,'6'=>462,'7'=>462,'8'=>462,'9'=>462,':'=>238,';'=>238, - '<'=>605,'='=>605,'>'=>605,'?'=>344,'@'=>748,'A'=>684,'B'=>560,'C'=>695,'D'=>739,'E'=>563, - 'F'=>511,'G'=>729,'H'=>793,'I'=>318,'J'=>312,'K'=>666,'L'=>526,'M'=>896,'N'=>758,'O'=>772, - 'P'=>544,'Q'=>772,'R'=>628,'S'=>465,'T'=>607,'U'=>753,'V'=>711,'W'=>972,'X'=>647,'Y'=>620, - 'Z'=>607,'['=>374,'\\'=>333,']'=>374,'^'=>606,'_'=>500,'`'=>239,'a'=>417,'b'=>503,'c'=>427, - 'd'=>529,'e'=>415,'f'=>264,'g'=>444,'h'=>518,'i'=>241,'j'=>230,'k'=>495,'l'=>228,'m'=>793, - 'n'=>527,'o'=>524,'p'=>524,'q'=>504,'r'=>338,'s'=>336,'t'=>277,'u'=>517,'v'=>450,'w'=>652, - 'x'=>466,'y'=>452,'z'=>407,'{'=>370,'|'=>258,'}'=>370,'~'=>605); + '('=>374,')'=>374,'*'=>423,'+'=>605,','=>238,'-'=>375,'.'=>238,'/'=>334,'0'=>462,'1'=>462, + '2'=>462,'3'=>462,'4'=>462,'5'=>462,'6'=>462,'7'=>462,'8'=>462,'9'=>462,':'=>238,';'=>238, + '<'=>605,'='=>605,'>'=>605,'?'=>344,'@'=>748,'A'=>684,'B'=>560,'C'=>695,'D'=>739,'E'=>563, + 'F'=>511,'G'=>729,'H'=>793,'I'=>318,'J'=>312,'K'=>666,'L'=>526,'M'=>896,'N'=>758,'O'=>772, + 'P'=>544,'Q'=>772,'R'=>628,'S'=>465,'T'=>607,'U'=>753,'V'=>711,'W'=>972,'X'=>647,'Y'=>620, + 'Z'=>607,'['=>374,'\\'=>333,']'=>374,'^'=>606,'_'=>500,'`'=>239,'a'=>417,'b'=>503,'c'=>427, + 'd'=>529,'e'=>415,'f'=>264,'g'=>444,'h'=>518,'i'=>241,'j'=>230,'k'=>495,'l'=>228,'m'=>793, + 'n'=>527,'o'=>524,'p'=>524,'q'=>504,'r'=>338,'s'=>336,'t'=>277,'u'=>517,'v'=>450,'w'=>652, + 'x'=>466,'y'=>452,'z'=>407,'{'=>370,'|'=>258,'}'=>370,'~'=>605); class PDF_Chinese extends PDF { function AddCIDFont($family,$style,$name,$cw,$CMap,$registry) { - $fontkey=strtolower($family).strtoupper($style); - if(isset($this->fonts[$fontkey])) - $this->Error("Font already added: $family $style"); - $i=count($this->fonts)+1; - $name=str_replace(' ','',$name); - $this->fonts[$fontkey]=array('i'=>$i,'type'=>'Type0','name'=>$name,'up'=>-130,'ut'=>40,'cw'=>$cw,'CMap'=>$CMap,'registry'=>$registry); + $fontkey=strtolower($family).strtoupper($style); + if(isset($this->fonts[$fontkey])) + $this->Error("Font already added: $family $style"); + $i=count($this->fonts)+1; + $name=str_replace(' ','',$name); + $this->fonts[$fontkey]=array('i'=>$i,'type'=>'Type0','name'=>$name,'up'=>-130,'ut'=>40,'cw'=>$cw,'CMap'=>$CMap,'registry'=>$registry); } function AddCIDFonts($family,$name,$cw,$CMap,$registry) { - $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry); - $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry); - $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry); - $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry); + $this->AddCIDFont($family,'',$name,$cw,$CMap,$registry); + $this->AddCIDFont($family,'B',$name.',Bold',$cw,$CMap,$registry); + $this->AddCIDFont($family,'I',$name.',Italic',$cw,$CMap,$registry); + $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry); } function AddBig5Font($family='Big5',$name='MSungStd-Light-Acro') { - //Add Big5 font with proportional Latin - $cw=$GLOBALS['Big5_widths']; - $CMap='ETenms-B5-H'; - $registry=array('ordering'=>'CNS1','supplement'=>0); - $this->AddCIDFonts($family,$name,$cw,$CMap,$registry); + //Add Big5 font with proportional Latin + $cw=$GLOBALS['Big5_widths']; + $CMap='ETenms-B5-H'; + $registry=array('ordering'=>'CNS1','supplement'=>0); + $this->AddCIDFonts($family,$name,$cw,$CMap,$registry); } function AddBig5hwFont($family='Big5-hw',$name='MSungStd-Light-Acro') { - //Add Big5 font with half-witdh Latin - for($i=32;$i<=126;$i++) - $cw[chr($i)]=500; - $CMap='ETen-B5-H'; - $registry=array('ordering'=>'CNS1','supplement'=>0); - $this->AddCIDFonts($family,$name,$cw,$CMap,$registry); + //Add Big5 font with half-witdh Latin + for($i=32;$i<=126;$i++) + $cw[chr($i)]=500; + $CMap='ETen-B5-H'; + $registry=array('ordering'=>'CNS1','supplement'=>0); + $this->AddCIDFonts($family,$name,$cw,$CMap,$registry); } function AddGBFont($family='GB',$name='STSongStd-Light-Acro') { - //Add GB font with proportional Latin - $cw=$GLOBALS['GB_widths']; - $CMap='GBKp-EUC-H'; - $registry=array('ordering'=>'GB1','supplement'=>2); - $this->AddCIDFonts($family,$name,$cw,$CMap,$registry); + //Add GB font with proportional Latin + $cw=$GLOBALS['GB_widths']; + $CMap='GBKp-EUC-H'; + $registry=array('ordering'=>'GB1','supplement'=>2); + $this->AddCIDFonts($family,$name,$cw,$CMap,$registry); } function AddGBhwFont($family='GB-hw',$name='STSongStd-Light-Acro') { - //Add GB font with half-width Latin - for($i=32;$i<=126;$i++) - $cw[chr($i)]=500; - $CMap='GBK-EUC-H'; - $registry=array('ordering'=>'GB1','supplement'=>2); - $this->AddCIDFonts($family,$name,$cw,$CMap,$registry); + //Add GB font with half-width Latin + for($i=32;$i<=126;$i++) + $cw[chr($i)]=500; + $CMap='GBK-EUC-H'; + $registry=array('ordering'=>'GB1','supplement'=>2); + $this->AddCIDFonts($family,$name,$cw,$CMap,$registry); } function GetStringWidth($s) { - if ($this->CurrentFont['type']=='Type0') - return $this->GetMBStringWidth($s); - else - return parent::GetStringWidth($s); + if ($this->CurrentFont['type']=='Type0') + return $this->GetMBStringWidth($s); + else + return parent::GetStringWidth($s); } function GetMBStringWidth($s) { - //Multi-byte version of GetStringWidth() - $l=0; - $cw=&$this->CurrentFont['cw']; - $nb=strlen($s); - $i=0; - while($i<$nb) - { - $c=$s[$i]; - if(ord($c)<128) - { - $l+=$cw[$c]; - $i++; - } - else - { - $l+=1000; - $i+=2; - } - } - return $l*$this->FontSize/1000; + //Multi-byte version of GetStringWidth() + $l=0; + $cw=&$this->CurrentFont['cw']; + $nb=strlen($s); + $i=0; + while($i<$nb) + { + $c=$s[$i]; + if(ord($c)<128) + { + $l+=$cw[$c]; + $i++; + } + else + { + $l+=1000; + $i+=2; + } + } + return $l*$this->FontSize/1000; } function MultiCell($w,$h,$txt,$border=0,$align='L',$fill=0) { - if($this->CurrentFont['type']=='Type0') - $this->MBMultiCell($w,$h,$txt,$border,$align,$fill); - else - parent::MultiCell($w,$h,$txt,$border,$align,$fill); + if($this->CurrentFont['type']=='Type0') + $this->MBMultiCell($w,$h,$txt,$border,$align,$fill); + else + parent::MultiCell($w,$h,$txt,$border,$align,$fill); } function MBMultiCell($w,$h,$txt,$border=0,$align='L',$fill=0) { - //Multi-byte version of MultiCell() - $cw=&$this->CurrentFont['cw']; - if($w==0) - $w=$this->w-$this->rMargin-$this->x; - $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; - $s=str_replace("\r",'',$txt); - $nb=strlen($s); - if($nb>0 and $s[$nb-1]=="\n") - $nb--; - $b=0; - if($border) - { - if($border==1) - { - $border='LTRB'; - $b='LRT'; - $b2='LR'; - } - else - { - $b2=''; - if(is_int(strpos($border,'L'))) - $b2.='L'; - if(is_int(strpos($border,'R'))) - $b2.='R'; - $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2; - } - } - $sep=-1; - $i=0; - $j=0; - $l=0; - $nl=1; - while($i<$nb) - { - //Get next character - $c=$s[$i]; - //Check if ASCII or MB - $ascii=(ord($c)<128); - if($c=="\n") - { - //Explicit line break - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); - $i++; - $sep=-1; - $j=$i; - $l=0; - $nl++; - if($border and $nl==2) - $b=$b2; - continue; - } - if(!$ascii) - { - $sep=$i; - $ls=$l; - } - elseif($c==' ') - { - $sep=$i; - $ls=$l; - } - $l+=$ascii ? $cw[$c] : 1000; - if($l>$wmax) - { - //Automatic line break - if($sep==-1 or $i==$j) - { - if($i==$j) - $i+=$ascii ? 1 : 2; - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); - } - else - { - $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); - $i=($s[$sep]==' ') ? $sep+1 : $sep; - } - $sep=-1; - $j=$i; - $l=0; - $nl++; - if($border and $nl==2) - $b=$b2; - } - else - $i+=$ascii ? 1 : 2; - } - //Last chunk - if($border and is_int(strpos($border,'B'))) - $b.='B'; - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); - $this->x=$this->lMargin; + //Multi-byte version of MultiCell() + $cw=&$this->CurrentFont['cw']; + if($w==0) + $w=$this->w-$this->rMargin-$this->x; + $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; + $s=str_replace("\r",'',$txt); + $nb=strlen($s); + if($nb>0 and $s[$nb-1]=="\n") + $nb--; + $b=0; + if($border) + { + if($border==1) + { + $border='LTRB'; + $b='LRT'; + $b2='LR'; + } + else + { + $b2=''; + if(is_int(strpos($border,'L'))) + $b2.='L'; + if(is_int(strpos($border,'R'))) + $b2.='R'; + $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2; + } + } + $sep=-1; + $i=0; + $j=0; + $l=0; + $nl=1; + while($i<$nb) + { + //Get next character + $c=$s[$i]; + //Check if ASCII or MB + $ascii=(ord($c)<128); + if($c=="\n") + { + //Explicit line break + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); + $i++; + $sep=-1; + $j=$i; + $l=0; + $nl++; + if($border and $nl==2) + $b=$b2; + continue; + } + if(!$ascii) + { + $sep=$i; + $ls=$l; + } + elseif($c==' ') + { + $sep=$i; + $ls=$l; + } + $l+=$ascii ? $cw[$c] : 1000; + if($l>$wmax) + { + //Automatic line break + if($sep==-1 or $i==$j) + { + if($i==$j) + $i+=$ascii ? 1 : 2; + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); + } + else + { + $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); + $i=($s[$sep]==' ') ? $sep+1 : $sep; + } + $sep=-1; + $j=$i; + $l=0; + $nl++; + if($border and $nl==2) + $b=$b2; + } + else + $i+=$ascii ? 1 : 2; + } + //Last chunk + if($border and is_int(strpos($border,'B'))) + $b.='B'; + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); + $this->x=$this->lMargin; } function Write($h,$txt,$link='') { - if($this->CurrentFont['type']=='Type0') - $this->MBWrite($h,$txt,$link); - else - parent::Write($h,$txt,$link); + if($this->CurrentFont['type']=='Type0') + $this->MBWrite($h,$txt,$link); + else + parent::Write($h,$txt,$link); } function MBWrite($h,$txt,$link) { - //Multi-byte version of Write() - $cw=&$this->CurrentFont['cw']; - $w=$this->w-$this->rMargin-$this->x; - $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; - $s=str_replace("\r",'',$txt); - $nb=strlen($s); - $sep=-1; - $i=0; - $j=0; - $l=0; - $nl=1; - while($i<$nb) - { - //Get next character - $c=$s[$i]; - //Check if ASCII or MB - $ascii=(ord($c)<128); - if($c=="\n") - { - //Explicit line break - $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); - $i++; - $sep=-1; - $j=$i; - $l=0; - if($nl==1) - { - $this->x=$this->lMargin; - $w=$this->w-$this->rMargin-$this->x; - $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; - } - $nl++; - continue; - } - if(!$ascii or $c==' ') - $sep=$i; - $l+=$ascii ? $cw[$c] : 1000; - if($l>$wmax) - { - //Automatic line break - if($sep==-1 or $i==$j) - { - if($this->x>$this->lMargin) - { - //Move to next line - $this->x=$this->lMargin; - $this->y+=$h; - $w=$this->w-$this->rMargin-$this->x; - $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; - $i++; - $nl++; - continue; - } - if($i==$j) - $i+=$ascii ? 1 : 2; - $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); - } - else - { - $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',0,$link); - $i=($s[$sep]==' ') ? $sep+1 : $sep; - } - $sep=-1; - $j=$i; - $l=0; - if($nl==1) - { - $this->x=$this->lMargin; - $w=$this->w-$this->rMargin-$this->x; - $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; - } - $nl++; - } - else - $i+=$ascii ? 1 : 2; - } - //Last chunk - if($i!=$j) - $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j,$i-$j),0,0,'',0,$link); + //Multi-byte version of Write() + $cw=&$this->CurrentFont['cw']; + $w=$this->w-$this->rMargin-$this->x; + $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; + $s=str_replace("\r",'',$txt); + $nb=strlen($s); + $sep=-1; + $i=0; + $j=0; + $l=0; + $nl=1; + while($i<$nb) + { + //Get next character + $c=$s[$i]; + //Check if ASCII or MB + $ascii=(ord($c)<128); + if($c=="\n") + { + //Explicit line break + $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); + $i++; + $sep=-1; + $j=$i; + $l=0; + if($nl==1) + { + $this->x=$this->lMargin; + $w=$this->w-$this->rMargin-$this->x; + $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; + } + $nl++; + continue; + } + if(!$ascii or $c==' ') + $sep=$i; + $l+=$ascii ? $cw[$c] : 1000; + if($l>$wmax) + { + //Automatic line break + if($sep==-1 or $i==$j) + { + if($this->x>$this->lMargin) + { + //Move to next line + $this->x=$this->lMargin; + $this->y+=$h; + $w=$this->w-$this->rMargin-$this->x; + $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; + $i++; + $nl++; + continue; + } + if($i==$j) + $i+=$ascii ? 1 : 2; + $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); + } + else + { + $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',0,$link); + $i=($s[$sep]==' ') ? $sep+1 : $sep; + } + $sep=-1; + $j=$i; + $l=0; + if($nl==1) + { + $this->x=$this->lMargin; + $w=$this->w-$this->rMargin-$this->x; + $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; + } + $nl++; + } + else + $i+=$ascii ? 1 : 2; + } + //Last chunk + if($i!=$j) + $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j,$i-$j),0,0,'',0,$link); } function _putfonts() { - $nf=$this->n; - foreach($this->diffs as $diff) - { - //Encodings - $this->_newobj(); - $this->_out('<>'); - $this->_out('endobj'); - } + $nf=$this->n; + foreach($this->diffs as $diff) + { + //Encodings + $this->_newobj(); + $this->_out('<>'); + $this->_out('endobj'); + } - if (!check_php_version(5,3)) { - $mqr=get_magic_quotes_runtime(); - set_magic_quotes_runtime(0); - } - foreach($this->FontFiles as $file=>$info) - { - //Font file embedding - $this->_newobj(); - $this->FontFiles[$file]['n']=$this->n; - if(defined('FPDF_FONTPATH')) - $file=FPDF_FONTPATH.$file; - $size=filesize($file); - if(!$size) - $this->Error('Font file not found'); - $this->_out('<_out('/Filter /FlateDecode'); - $this->_out('/Length1 '.$info['length1']); - if(isset($info['length2'])) - $this->_out('/Length2 '.$info['length2'].' /Length3 0'); - $this->_out('>>'); - $f=fopen($file,'rb'); - $this->_putstream(fread($f,$size)); - fclose($f); - $this->_out('endobj'); - } - if (!check_php_version(5,3)) { - set_magic_quotes_runtime($mqr); - } - foreach($this->fonts as $k=>$font) - { - //Font objects - $this->_newobj(); - $this->fonts[$k]['n']=$this->n; - $this->_out('<_putType0($font); - else - { - $name=$font['name']; - $this->_out('/BaseFont /'.$name); - if($font['type']=='core') - { - //Standard font - $this->_out('/Subtype /Type1'); - if($name!='Symbol' and $name!='ZapfDingbats') - $this->_out('/Encoding /WinAnsiEncoding'); - } - else - { - //Additional font - $this->_out('/Subtype /'.$font['type']); - $this->_out('/FirstChar 32'); - $this->_out('/LastChar 255'); - $this->_out('/Widths '.($this->n+1).' 0 R'); - $this->_out('/FontDescriptor '.($this->n+2).' 0 R'); - if($font['enc']) - { - if(isset($font['diff'])) - $this->_out('/Encoding '.($nf+$font['diff']).' 0 R'); - else - $this->_out('/Encoding /WinAnsiEncoding'); - } - } - $this->_out('>>'); - $this->_out('endobj'); - if($font['type']!='core') - { - //Widths - $this->_newobj(); - $cw=&$font['cw']; - $s='['; - for($i=32;$i<=255;$i++) - $s.=$cw[chr($i)].' '; - $this->_out($s.']'); - $this->_out('endobj'); - //Descriptor - $this->_newobj(); - $s='<$v) - $s.=' /'.$k.' '.$v; - $file=$font['file']; - if($file) - $s.=' /FontFile'.($font['type']=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R'; - $this->_out($s.'>>'); - $this->_out('endobj'); - } - } - } + if (!check_php_version(5,3)) { + $mqr=get_magic_quotes_runtime(); + set_magic_quotes_runtime(0); + } + foreach($this->FontFiles as $file=>$info) + { + //Font file embedding + $this->_newobj(); + $this->FontFiles[$file]['n']=$this->n; + if(defined('FPDF_FONTPATH')) + $file=FPDF_FONTPATH.$file; + $size=filesize($file); + if(!$size) + $this->Error('Font file not found'); + $this->_out('<_out('/Filter /FlateDecode'); + $this->_out('/Length1 '.$info['length1']); + if(isset($info['length2'])) + $this->_out('/Length2 '.$info['length2'].' /Length3 0'); + $this->_out('>>'); + $f=fopen($file,'rb'); + $this->_putstream(fread($f,$size)); + fclose($f); + $this->_out('endobj'); + } + if (!check_php_version(5,3)) { + set_magic_quotes_runtime($mqr); + } + foreach($this->fonts as $k=>$font) + { + //Font objects + $this->_newobj(); + $this->fonts[$k]['n']=$this->n; + $this->_out('<_putType0($font); + else + { + $name=$font['name']; + $this->_out('/BaseFont /'.$name); + if($font['type']=='core') + { + //Standard font + $this->_out('/Subtype /Type1'); + if($name!='Symbol' and $name!='ZapfDingbats') + $this->_out('/Encoding /WinAnsiEncoding'); + } + else + { + //Additional font + $this->_out('/Subtype /'.$font['type']); + $this->_out('/FirstChar 32'); + $this->_out('/LastChar 255'); + $this->_out('/Widths '.($this->n+1).' 0 R'); + $this->_out('/FontDescriptor '.($this->n+2).' 0 R'); + if($font['enc']) + { + if(isset($font['diff'])) + $this->_out('/Encoding '.($nf+$font['diff']).' 0 R'); + else + $this->_out('/Encoding /WinAnsiEncoding'); + } + } + $this->_out('>>'); + $this->_out('endobj'); + if($font['type']!='core') + { + //Widths + $this->_newobj(); + $cw=&$font['cw']; + $s='['; + for($i=32;$i<=255;$i++) + $s.=$cw[chr($i)].' '; + $this->_out($s.']'); + $this->_out('endobj'); + //Descriptor + $this->_newobj(); + $s='<$v) + $s.=' /'.$k.' '.$v; + $file=$font['file']; + if($file) + $s.=' /FontFile'.($font['type']=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R'; + $this->_out($s.'>>'); + $this->_out('endobj'); + } + } + } } function _putType0($font) { - //Type0 - $this->_out('/Subtype /Type0'); - $this->_out('/BaseFont /'.$font['name'].'-'.$font['CMap']); - $this->_out('/Encoding /'.$font['CMap']); - $this->_out('/DescendantFonts ['.($this->n+1).' 0 R]'); - $this->_out('>>'); - $this->_out('endobj'); - //CIDFont - $this->_newobj(); - $this->_out('<_out('/Subtype /CIDFontType0'); - $this->_out('/BaseFont /'.$font['name']); - $this->_out('/CIDSystemInfo <_textstring('Adobe').' /Ordering '.$this->_textstring($font['registry']['ordering']).' /Supplement '.$font['registry']['supplement'].'>>'); - $this->_out('/FontDescriptor '.($this->n+1).' 0 R'); - if($font['CMap']=='ETen-B5-H') - $W='13648 13742 500'; - elseif($font['CMap']=='GBK-EUC-H') - $W='814 907 500 7716 [500]'; - else - $W='1 ['.implode(' ',$font['cw']).']'; - $this->_out('/W ['.$W.']>>'); - $this->_out('endobj'); - //Font descriptor - $this->_newobj(); - $this->_out('<_out('/FontName /'.$font['name']); - $this->_out('/Flags 6'); - $this->_out('/FontBBox [0 -200 1000 900]'); - $this->_out('/ItalicAngle 0'); - $this->_out('/Ascent 800'); - $this->_out('/Descent -200'); - $this->_out('/CapHeight 800'); - $this->_out('/StemV 50'); - $this->_out('>>'); - $this->_out('endobj'); + //Type0 + $this->_out('/Subtype /Type0'); + $this->_out('/BaseFont /'.$font['name'].'-'.$font['CMap']); + $this->_out('/Encoding /'.$font['CMap']); + $this->_out('/DescendantFonts ['.($this->n+1).' 0 R]'); + $this->_out('>>'); + $this->_out('endobj'); + //CIDFont + $this->_newobj(); + $this->_out('<_out('/Subtype /CIDFontType0'); + $this->_out('/BaseFont /'.$font['name']); + $this->_out('/CIDSystemInfo <_textstring('Adobe').' /Ordering '.$this->_textstring($font['registry']['ordering']).' /Supplement '.$font['registry']['supplement'].'>>'); + $this->_out('/FontDescriptor '.($this->n+1).' 0 R'); + if($font['CMap']=='ETen-B5-H') + $W='13648 13742 500'; + elseif($font['CMap']=='GBK-EUC-H') + $W='814 907 500 7716 [500]'; + else + $W='1 ['.implode(' ',$font['cw']).']'; + $this->_out('/W ['.$W.']>>'); + $this->_out('endobj'); + //Font descriptor + $this->_newobj(); + $this->_out('<_out('/FontName /'.$font['name']); + $this->_out('/Flags 6'); + $this->_out('/FontBBox [0 -200 1000 900]'); + $this->_out('/ItalicAngle 0'); + $this->_out('/Ascent 800'); + $this->_out('/Descent -200'); + $this->_out('/CapHeight 800'); + $this->_out('/StemV 50'); + $this->_out('>>'); + $this->_out('endobj'); } } diff --git a/lib/fpdf/courier.php b/lib/fpdf/courier.php index 4c009f39b..450b81d7e 100644 --- a/lib/fpdf/courier.php +++ b/lib/fpdf/courier.php @@ -1,6 +1,6 @@ 278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278, - chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>278,'"'=>355,'#'=>556,'$'=>556,'%'=>889,'&'=>667,'\''=>191,'('=>333,')'=>333,'*'=>389,'+'=>584, - ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>278,';'=>278,'<'=>584,'='=>584,'>'=>584,'?'=>556,'@'=>1015,'A'=>667, - 'B'=>667,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>500,'K'=>667,'L'=>556,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944, - 'X'=>667,'Y'=>667,'Z'=>611,'['=>278,'\\'=>278,']'=>278,'^'=>469,'_'=>556,'`'=>333,'a'=>556,'b'=>556,'c'=>500,'d'=>556,'e'=>556,'f'=>278,'g'=>556,'h'=>556,'i'=>222,'j'=>222,'k'=>500,'l'=>222,'m'=>833, - 'n'=>556,'o'=>556,'p'=>556,'q'=>556,'r'=>333,'s'=>500,'t'=>278,'u'=>556,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>500,'{'=>334,'|'=>260,'}'=>334,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>222,chr(131)=>556, - chr(132)=>333,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>222,chr(146)=>222,chr(147)=>333,chr(148)=>333,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, - chr(154)=>500,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>260,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333, - chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>556,chr(182)=>537,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>667,chr(193)=>667,chr(194)=>667,chr(195)=>667,chr(196)=>667,chr(197)=>667, - chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, - chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>500,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>556,chr(241)=>556, - chr(242)=>556,chr(243)=>556,chr(244)=>556,chr(245)=>556,chr(246)=>556,chr(247)=>584,chr(248)=>611,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>500,chr(254)=>556,chr(255)=>500); + chr(0)=>278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278, + chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>278,'"'=>355,'#'=>556,'$'=>556,'%'=>889,'&'=>667,'\''=>191,'('=>333,')'=>333,'*'=>389,'+'=>584, + ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>278,';'=>278,'<'=>584,'='=>584,'>'=>584,'?'=>556,'@'=>1015,'A'=>667, + 'B'=>667,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>500,'K'=>667,'L'=>556,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944, + 'X'=>667,'Y'=>667,'Z'=>611,'['=>278,'\\'=>278,']'=>278,'^'=>469,'_'=>556,'`'=>333,'a'=>556,'b'=>556,'c'=>500,'d'=>556,'e'=>556,'f'=>278,'g'=>556,'h'=>556,'i'=>222,'j'=>222,'k'=>500,'l'=>222,'m'=>833, + 'n'=>556,'o'=>556,'p'=>556,'q'=>556,'r'=>333,'s'=>500,'t'=>278,'u'=>556,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>500,'{'=>334,'|'=>260,'}'=>334,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>222,chr(131)=>556, + chr(132)=>333,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>222,chr(146)=>222,chr(147)=>333,chr(148)=>333,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, + chr(154)=>500,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>260,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333, + chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>556,chr(182)=>537,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>667,chr(193)=>667,chr(194)=>667,chr(195)=>667,chr(196)=>667,chr(197)=>667, + chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>500,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>556,chr(241)=>556, + chr(242)=>556,chr(243)=>556,chr(244)=>556,chr(245)=>556,chr(246)=>556,chr(247)=>584,chr(248)=>611,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>500,chr(254)=>556,chr(255)=>500); ?> diff --git a/lib/fpdf/helveticab.php b/lib/fpdf/helveticab.php index a8473c94d..e4900ca6d 100644 --- a/lib/fpdf/helveticab.php +++ b/lib/fpdf/helveticab.php @@ -1,15 +1,15 @@ 278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278, - chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>333,'"'=>474,'#'=>556,'$'=>556,'%'=>889,'&'=>722,'\''=>238,'('=>333,')'=>333,'*'=>389,'+'=>584, - ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>333,';'=>333,'<'=>584,'='=>584,'>'=>584,'?'=>611,'@'=>975,'A'=>722, - 'B'=>722,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>556,'K'=>722,'L'=>611,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944, - 'X'=>667,'Y'=>667,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>584,'_'=>556,'`'=>333,'a'=>556,'b'=>611,'c'=>556,'d'=>611,'e'=>556,'f'=>333,'g'=>611,'h'=>611,'i'=>278,'j'=>278,'k'=>556,'l'=>278,'m'=>889, - 'n'=>611,'o'=>611,'p'=>611,'q'=>611,'r'=>389,'s'=>556,'t'=>333,'u'=>611,'v'=>556,'w'=>778,'x'=>556,'y'=>556,'z'=>500,'{'=>389,'|'=>280,'}'=>389,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>278,chr(131)=>556, - chr(132)=>500,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>278,chr(146)=>278,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, - chr(154)=>556,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>280,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333, - chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>611,chr(182)=>556,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722, - chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, - chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>556,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>611,chr(241)=>611, - chr(242)=>611,chr(243)=>611,chr(244)=>611,chr(245)=>611,chr(246)=>611,chr(247)=>584,chr(248)=>611,chr(249)=>611,chr(250)=>611,chr(251)=>611,chr(252)=>611,chr(253)=>556,chr(254)=>611,chr(255)=>556); + chr(0)=>278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278, + chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>333,'"'=>474,'#'=>556,'$'=>556,'%'=>889,'&'=>722,'\''=>238,'('=>333,')'=>333,'*'=>389,'+'=>584, + ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>333,';'=>333,'<'=>584,'='=>584,'>'=>584,'?'=>611,'@'=>975,'A'=>722, + 'B'=>722,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>556,'K'=>722,'L'=>611,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944, + 'X'=>667,'Y'=>667,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>584,'_'=>556,'`'=>333,'a'=>556,'b'=>611,'c'=>556,'d'=>611,'e'=>556,'f'=>333,'g'=>611,'h'=>611,'i'=>278,'j'=>278,'k'=>556,'l'=>278,'m'=>889, + 'n'=>611,'o'=>611,'p'=>611,'q'=>611,'r'=>389,'s'=>556,'t'=>333,'u'=>611,'v'=>556,'w'=>778,'x'=>556,'y'=>556,'z'=>500,'{'=>389,'|'=>280,'}'=>389,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>278,chr(131)=>556, + chr(132)=>500,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>278,chr(146)=>278,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, + chr(154)=>556,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>280,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333, + chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>611,chr(182)=>556,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722, + chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>556,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>611,chr(241)=>611, + chr(242)=>611,chr(243)=>611,chr(244)=>611,chr(245)=>611,chr(246)=>611,chr(247)=>584,chr(248)=>611,chr(249)=>611,chr(250)=>611,chr(251)=>611,chr(252)=>611,chr(253)=>556,chr(254)=>611,chr(255)=>556); ?> diff --git a/lib/fpdf/helveticabi.php b/lib/fpdf/helveticabi.php index 41379537d..d1a09a70d 100644 --- a/lib/fpdf/helveticabi.php +++ b/lib/fpdf/helveticabi.php @@ -1,15 +1,15 @@ 278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278, - chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>333,'"'=>474,'#'=>556,'$'=>556,'%'=>889,'&'=>722,'\''=>238,'('=>333,')'=>333,'*'=>389,'+'=>584, - ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>333,';'=>333,'<'=>584,'='=>584,'>'=>584,'?'=>611,'@'=>975,'A'=>722, - 'B'=>722,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>556,'K'=>722,'L'=>611,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944, - 'X'=>667,'Y'=>667,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>584,'_'=>556,'`'=>333,'a'=>556,'b'=>611,'c'=>556,'d'=>611,'e'=>556,'f'=>333,'g'=>611,'h'=>611,'i'=>278,'j'=>278,'k'=>556,'l'=>278,'m'=>889, - 'n'=>611,'o'=>611,'p'=>611,'q'=>611,'r'=>389,'s'=>556,'t'=>333,'u'=>611,'v'=>556,'w'=>778,'x'=>556,'y'=>556,'z'=>500,'{'=>389,'|'=>280,'}'=>389,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>278,chr(131)=>556, - chr(132)=>500,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>278,chr(146)=>278,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, - chr(154)=>556,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>280,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333, - chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>611,chr(182)=>556,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722, - chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, - chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>556,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>611,chr(241)=>611, - chr(242)=>611,chr(243)=>611,chr(244)=>611,chr(245)=>611,chr(246)=>611,chr(247)=>584,chr(248)=>611,chr(249)=>611,chr(250)=>611,chr(251)=>611,chr(252)=>611,chr(253)=>556,chr(254)=>611,chr(255)=>556); + chr(0)=>278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278, + chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>333,'"'=>474,'#'=>556,'$'=>556,'%'=>889,'&'=>722,'\''=>238,'('=>333,')'=>333,'*'=>389,'+'=>584, + ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>333,';'=>333,'<'=>584,'='=>584,'>'=>584,'?'=>611,'@'=>975,'A'=>722, + 'B'=>722,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>556,'K'=>722,'L'=>611,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944, + 'X'=>667,'Y'=>667,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>584,'_'=>556,'`'=>333,'a'=>556,'b'=>611,'c'=>556,'d'=>611,'e'=>556,'f'=>333,'g'=>611,'h'=>611,'i'=>278,'j'=>278,'k'=>556,'l'=>278,'m'=>889, + 'n'=>611,'o'=>611,'p'=>611,'q'=>611,'r'=>389,'s'=>556,'t'=>333,'u'=>611,'v'=>556,'w'=>778,'x'=>556,'y'=>556,'z'=>500,'{'=>389,'|'=>280,'}'=>389,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>278,chr(131)=>556, + chr(132)=>500,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>278,chr(146)=>278,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, + chr(154)=>556,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>280,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333, + chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>611,chr(182)=>556,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722, + chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>556,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>611,chr(241)=>611, + chr(242)=>611,chr(243)=>611,chr(244)=>611,chr(245)=>611,chr(246)=>611,chr(247)=>584,chr(248)=>611,chr(249)=>611,chr(250)=>611,chr(251)=>611,chr(252)=>611,chr(253)=>556,chr(254)=>611,chr(255)=>556); ?> diff --git a/lib/fpdf/helveticai.php b/lib/fpdf/helveticai.php index d5bb6e094..47438d6bd 100644 --- a/lib/fpdf/helveticai.php +++ b/lib/fpdf/helveticai.php @@ -1,15 +1,15 @@ 278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278, - chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>278,'"'=>355,'#'=>556,'$'=>556,'%'=>889,'&'=>667,'\''=>191,'('=>333,')'=>333,'*'=>389,'+'=>584, - ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>278,';'=>278,'<'=>584,'='=>584,'>'=>584,'?'=>556,'@'=>1015,'A'=>667, - 'B'=>667,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>500,'K'=>667,'L'=>556,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944, - 'X'=>667,'Y'=>667,'Z'=>611,'['=>278,'\\'=>278,']'=>278,'^'=>469,'_'=>556,'`'=>333,'a'=>556,'b'=>556,'c'=>500,'d'=>556,'e'=>556,'f'=>278,'g'=>556,'h'=>556,'i'=>222,'j'=>222,'k'=>500,'l'=>222,'m'=>833, - 'n'=>556,'o'=>556,'p'=>556,'q'=>556,'r'=>333,'s'=>500,'t'=>278,'u'=>556,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>500,'{'=>334,'|'=>260,'}'=>334,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>222,chr(131)=>556, - chr(132)=>333,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>222,chr(146)=>222,chr(147)=>333,chr(148)=>333,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, - chr(154)=>500,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>260,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333, - chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>556,chr(182)=>537,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>667,chr(193)=>667,chr(194)=>667,chr(195)=>667,chr(196)=>667,chr(197)=>667, - chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, - chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>500,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>556,chr(241)=>556, - chr(242)=>556,chr(243)=>556,chr(244)=>556,chr(245)=>556,chr(246)=>556,chr(247)=>584,chr(248)=>611,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>500,chr(254)=>556,chr(255)=>500); + chr(0)=>278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278, + chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>278,'"'=>355,'#'=>556,'$'=>556,'%'=>889,'&'=>667,'\''=>191,'('=>333,')'=>333,'*'=>389,'+'=>584, + ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>278,';'=>278,'<'=>584,'='=>584,'>'=>584,'?'=>556,'@'=>1015,'A'=>667, + 'B'=>667,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>500,'K'=>667,'L'=>556,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944, + 'X'=>667,'Y'=>667,'Z'=>611,'['=>278,'\\'=>278,']'=>278,'^'=>469,'_'=>556,'`'=>333,'a'=>556,'b'=>556,'c'=>500,'d'=>556,'e'=>556,'f'=>278,'g'=>556,'h'=>556,'i'=>222,'j'=>222,'k'=>500,'l'=>222,'m'=>833, + 'n'=>556,'o'=>556,'p'=>556,'q'=>556,'r'=>333,'s'=>500,'t'=>278,'u'=>556,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>500,'{'=>334,'|'=>260,'}'=>334,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>222,chr(131)=>556, + chr(132)=>333,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>222,chr(146)=>222,chr(147)=>333,chr(148)=>333,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, + chr(154)=>500,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>260,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333, + chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>556,chr(182)=>537,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>667,chr(193)=>667,chr(194)=>667,chr(195)=>667,chr(196)=>667,chr(197)=>667, + chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>500,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>556,chr(241)=>556, + chr(242)=>556,chr(243)=>556,chr(244)=>556,chr(245)=>556,chr(246)=>556,chr(247)=>584,chr(248)=>611,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>500,chr(254)=>556,chr(255)=>500); ?> diff --git a/lib/fpdf/japanese.php b/lib/fpdf/japanese.php index f98d2070c..64779587f 100644 --- a/lib/fpdf/japanese.php +++ b/lib/fpdf/japanese.php @@ -188,35 +188,35 @@ class PDF_Japanese extends PDF { $sep=$i; } } - //Last chunk - if($border and is_int(strpos($border,'B'))) + //Last chunk + if($border and is_int(strpos($border,'B'))) $b.='B'; - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); - $this->x=$this->lMargin; + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); + $this->x=$this->lMargin; } function Write($h,$txt,$link='') { - if($this->CurrentFont['type']=='Type0') + if($this->CurrentFont['type']=='Type0') $this->SJISWrite($h,$txt,$link); - else + else parent::Write($h,$txt,$link); } function SJISWrite($h,$txt,$link) { - //SJIS version of Write() - $cw=&$this->CurrentFont['cw']; - $w=$this->w-$this->rMargin-$this->x; - $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; - $s=str_replace("\r",'',$txt); - $nb=strlen($s); - $sep=-1; - $i=0; - $j=0; - $l=0; - $nl=1; - while($i<$nb) { + //SJIS version of Write() + $cw=&$this->CurrentFont['cw']; + $w=$this->w-$this->rMargin-$this->x; + $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; + $s=str_replace("\r",'',$txt); + $nb=strlen($s); + $sep=-1; + $i=0; + $j=0; + $l=0; + $nl=1; + while($i<$nb) { //Get next character $c=$s{$i}; $o=ord($c); @@ -288,25 +288,25 @@ class PDF_Japanese extends PDF { $sep=$i; } } - //Last chunk - if($i!=$j) + //Last chunk + if($i!=$j) $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j,$i-$j),0,0,'',0,$link); } function _putfonts() { - $nf=$this->n; - foreach($this->diffs as $diff) { + $nf=$this->n; + foreach($this->diffs as $diff) { //Encodings $this->_newobj(); $this->_out('<>'); $this->_out('endobj'); } - if (!check_php_version(5,3)) { - $mqr=get_magic_quotes_runtime(); - set_magic_quotes_runtime(0); - } - foreach($this->FontFiles as $file=>$info) { + if (!check_php_version(5,3)) { + $mqr=get_magic_quotes_runtime(); + set_magic_quotes_runtime(0); + } + foreach($this->FontFiles as $file=>$info) { //Font file embedding $this->_newobj(); $this->FontFiles[$file]['n']=$this->n; @@ -327,10 +327,10 @@ class PDF_Japanese extends PDF { fclose($f); $this->_out('endobj'); } - if (!check_php_version(5,3)) { - set_magic_quotes_runtime($mqr); - } - foreach($this->fonts as $k=>$font) { + if (!check_php_version(5,3)) { + set_magic_quotes_runtime($mqr); + } + foreach($this->fonts as $k=>$font) { //Font objects $this->_newobj(); $this->fonts[$k]['n']=$this->n; @@ -387,39 +387,39 @@ class PDF_Japanese extends PDF { function _putType0($font) { - //Type0 - $this->_out('/Subtype /Type0'); - $this->_out('/BaseFont /'.$font['name'].'-'.$font['CMap']); - $this->_out('/Encoding /'.$font['CMap']); - $this->_out('/DescendantFonts ['.($this->n+1).' 0 R]'); - $this->_out('>>'); - $this->_out('endobj'); - //CIDFont - $this->_newobj(); - $this->_out('<_out('/Subtype /CIDFontType0'); - $this->_out('/BaseFont /'.$font['name']); - $this->_out('/CIDSystemInfo <>'); - $this->_out('/FontDescriptor '.($this->n+1).' 0 R'); - $W='/W [1 ['; - foreach($font['cw'] as $w) + //Type0 + $this->_out('/Subtype /Type0'); + $this->_out('/BaseFont /'.$font['name'].'-'.$font['CMap']); + $this->_out('/Encoding /'.$font['CMap']); + $this->_out('/DescendantFonts ['.($this->n+1).' 0 R]'); + $this->_out('>>'); + $this->_out('endobj'); + //CIDFont + $this->_newobj(); + $this->_out('<_out('/Subtype /CIDFontType0'); + $this->_out('/BaseFont /'.$font['name']); + $this->_out('/CIDSystemInfo <>'); + $this->_out('/FontDescriptor '.($this->n+1).' 0 R'); + $W='/W [1 ['; + foreach($font['cw'] as $w) $W.=$w.' '; - $this->_out($W.'] 231 325 500 631 [500] 326 389 500]'); - $this->_out('>>'); - $this->_out('endobj'); - //Font descriptor - $this->_newobj(); - $this->_out('<_out('/FontName /'.$font['name']); - $this->_out('/Flags 6'); - $this->_out('/FontBBox [0 -200 1000 900]'); - $this->_out('/ItalicAngle 0'); - $this->_out('/Ascent 800'); - $this->_out('/Descent -200'); - $this->_out('/CapHeight 800'); - $this->_out('/StemV 60'); - $this->_out('>>'); - $this->_out('endobj'); + $this->_out($W.'] 231 325 500 631 [500] 326 389 500]'); + $this->_out('>>'); + $this->_out('endobj'); + //Font descriptor + $this->_newobj(); + $this->_out('<_out('/FontName /'.$font['name']); + $this->_out('/Flags 6'); + $this->_out('/FontBBox [0 -200 1000 900]'); + $this->_out('/ItalicAngle 0'); + $this->_out('/Ascent 800'); + $this->_out('/Descent -200'); + $this->_out('/CapHeight 800'); + $this->_out('/StemV 60'); + $this->_out('>>'); + $this->_out('endobj'); } } diff --git a/lib/fpdf/symbol.php b/lib/fpdf/symbol.php index b556ed84c..f2efa7b47 100644 --- a/lib/fpdf/symbol.php +++ b/lib/fpdf/symbol.php @@ -1,15 +1,15 @@ 250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, - chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>713,'#'=>500,'$'=>549,'%'=>833,'&'=>778,'\''=>439,'('=>333,')'=>333,'*'=>500,'+'=>549, - ','=>250,'-'=>549,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>278,';'=>278,'<'=>549,'='=>549,'>'=>549,'?'=>444,'@'=>549,'A'=>722, - 'B'=>667,'C'=>722,'D'=>612,'E'=>611,'F'=>763,'G'=>603,'H'=>722,'I'=>333,'J'=>631,'K'=>722,'L'=>686,'M'=>889,'N'=>722,'O'=>722,'P'=>768,'Q'=>741,'R'=>556,'S'=>592,'T'=>611,'U'=>690,'V'=>439,'W'=>768, - 'X'=>645,'Y'=>795,'Z'=>611,'['=>333,'\\'=>863,']'=>333,'^'=>658,'_'=>500,'`'=>500,'a'=>631,'b'=>549,'c'=>549,'d'=>494,'e'=>439,'f'=>521,'g'=>411,'h'=>603,'i'=>329,'j'=>603,'k'=>549,'l'=>549,'m'=>576, - 'n'=>521,'o'=>549,'p'=>549,'q'=>521,'r'=>549,'s'=>603,'t'=>439,'u'=>576,'v'=>713,'w'=>686,'x'=>493,'y'=>686,'z'=>494,'{'=>480,'|'=>200,'}'=>480,'~'=>549,chr(127)=>0,chr(128)=>0,chr(129)=>0,chr(130)=>0,chr(131)=>0, - chr(132)=>0,chr(133)=>0,chr(134)=>0,chr(135)=>0,chr(136)=>0,chr(137)=>0,chr(138)=>0,chr(139)=>0,chr(140)=>0,chr(141)=>0,chr(142)=>0,chr(143)=>0,chr(144)=>0,chr(145)=>0,chr(146)=>0,chr(147)=>0,chr(148)=>0,chr(149)=>0,chr(150)=>0,chr(151)=>0,chr(152)=>0,chr(153)=>0, - chr(154)=>0,chr(155)=>0,chr(156)=>0,chr(157)=>0,chr(158)=>0,chr(159)=>0,chr(160)=>750,chr(161)=>620,chr(162)=>247,chr(163)=>549,chr(164)=>167,chr(165)=>713,chr(166)=>500,chr(167)=>753,chr(168)=>753,chr(169)=>753,chr(170)=>753,chr(171)=>1042,chr(172)=>987,chr(173)=>603,chr(174)=>987,chr(175)=>603, - chr(176)=>400,chr(177)=>549,chr(178)=>411,chr(179)=>549,chr(180)=>549,chr(181)=>713,chr(182)=>494,chr(183)=>460,chr(184)=>549,chr(185)=>549,chr(186)=>549,chr(187)=>549,chr(188)=>1000,chr(189)=>603,chr(190)=>1000,chr(191)=>658,chr(192)=>823,chr(193)=>686,chr(194)=>795,chr(195)=>987,chr(196)=>768,chr(197)=>768, - chr(198)=>823,chr(199)=>768,chr(200)=>768,chr(201)=>713,chr(202)=>713,chr(203)=>713,chr(204)=>713,chr(205)=>713,chr(206)=>713,chr(207)=>713,chr(208)=>768,chr(209)=>713,chr(210)=>790,chr(211)=>790,chr(212)=>890,chr(213)=>823,chr(214)=>549,chr(215)=>250,chr(216)=>713,chr(217)=>603,chr(218)=>603,chr(219)=>1042, - chr(220)=>987,chr(221)=>603,chr(222)=>987,chr(223)=>603,chr(224)=>494,chr(225)=>329,chr(226)=>790,chr(227)=>790,chr(228)=>786,chr(229)=>713,chr(230)=>384,chr(231)=>384,chr(232)=>384,chr(233)=>384,chr(234)=>384,chr(235)=>384,chr(236)=>494,chr(237)=>494,chr(238)=>494,chr(239)=>494,chr(240)=>0,chr(241)=>329, - chr(242)=>274,chr(243)=>686,chr(244)=>686,chr(245)=>686,chr(246)=>384,chr(247)=>384,chr(248)=>384,chr(249)=>384,chr(250)=>384,chr(251)=>384,chr(252)=>494,chr(253)=>494,chr(254)=>494,chr(255)=>0); + chr(0)=>250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, + chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>713,'#'=>500,'$'=>549,'%'=>833,'&'=>778,'\''=>439,'('=>333,')'=>333,'*'=>500,'+'=>549, + ','=>250,'-'=>549,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>278,';'=>278,'<'=>549,'='=>549,'>'=>549,'?'=>444,'@'=>549,'A'=>722, + 'B'=>667,'C'=>722,'D'=>612,'E'=>611,'F'=>763,'G'=>603,'H'=>722,'I'=>333,'J'=>631,'K'=>722,'L'=>686,'M'=>889,'N'=>722,'O'=>722,'P'=>768,'Q'=>741,'R'=>556,'S'=>592,'T'=>611,'U'=>690,'V'=>439,'W'=>768, + 'X'=>645,'Y'=>795,'Z'=>611,'['=>333,'\\'=>863,']'=>333,'^'=>658,'_'=>500,'`'=>500,'a'=>631,'b'=>549,'c'=>549,'d'=>494,'e'=>439,'f'=>521,'g'=>411,'h'=>603,'i'=>329,'j'=>603,'k'=>549,'l'=>549,'m'=>576, + 'n'=>521,'o'=>549,'p'=>549,'q'=>521,'r'=>549,'s'=>603,'t'=>439,'u'=>576,'v'=>713,'w'=>686,'x'=>493,'y'=>686,'z'=>494,'{'=>480,'|'=>200,'}'=>480,'~'=>549,chr(127)=>0,chr(128)=>0,chr(129)=>0,chr(130)=>0,chr(131)=>0, + chr(132)=>0,chr(133)=>0,chr(134)=>0,chr(135)=>0,chr(136)=>0,chr(137)=>0,chr(138)=>0,chr(139)=>0,chr(140)=>0,chr(141)=>0,chr(142)=>0,chr(143)=>0,chr(144)=>0,chr(145)=>0,chr(146)=>0,chr(147)=>0,chr(148)=>0,chr(149)=>0,chr(150)=>0,chr(151)=>0,chr(152)=>0,chr(153)=>0, + chr(154)=>0,chr(155)=>0,chr(156)=>0,chr(157)=>0,chr(158)=>0,chr(159)=>0,chr(160)=>750,chr(161)=>620,chr(162)=>247,chr(163)=>549,chr(164)=>167,chr(165)=>713,chr(166)=>500,chr(167)=>753,chr(168)=>753,chr(169)=>753,chr(170)=>753,chr(171)=>1042,chr(172)=>987,chr(173)=>603,chr(174)=>987,chr(175)=>603, + chr(176)=>400,chr(177)=>549,chr(178)=>411,chr(179)=>549,chr(180)=>549,chr(181)=>713,chr(182)=>494,chr(183)=>460,chr(184)=>549,chr(185)=>549,chr(186)=>549,chr(187)=>549,chr(188)=>1000,chr(189)=>603,chr(190)=>1000,chr(191)=>658,chr(192)=>823,chr(193)=>686,chr(194)=>795,chr(195)=>987,chr(196)=>768,chr(197)=>768, + chr(198)=>823,chr(199)=>768,chr(200)=>768,chr(201)=>713,chr(202)=>713,chr(203)=>713,chr(204)=>713,chr(205)=>713,chr(206)=>713,chr(207)=>713,chr(208)=>768,chr(209)=>713,chr(210)=>790,chr(211)=>790,chr(212)=>890,chr(213)=>823,chr(214)=>549,chr(215)=>250,chr(216)=>713,chr(217)=>603,chr(218)=>603,chr(219)=>1042, + chr(220)=>987,chr(221)=>603,chr(222)=>987,chr(223)=>603,chr(224)=>494,chr(225)=>329,chr(226)=>790,chr(227)=>790,chr(228)=>786,chr(229)=>713,chr(230)=>384,chr(231)=>384,chr(232)=>384,chr(233)=>384,chr(234)=>384,chr(235)=>384,chr(236)=>494,chr(237)=>494,chr(238)=>494,chr(239)=>494,chr(240)=>0,chr(241)=>329, + chr(242)=>274,chr(243)=>686,chr(244)=>686,chr(245)=>686,chr(246)=>384,chr(247)=>384,chr(248)=>384,chr(249)=>384,chr(250)=>384,chr(251)=>384,chr(252)=>494,chr(253)=>494,chr(254)=>494,chr(255)=>0); ?> diff --git a/lib/fpdf/times.php b/lib/fpdf/times.php index b9be1b21d..60e2179af 100644 --- a/lib/fpdf/times.php +++ b/lib/fpdf/times.php @@ -1,15 +1,15 @@ 250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, - chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>408,'#'=>500,'$'=>500,'%'=>833,'&'=>778,'\''=>180,'('=>333,')'=>333,'*'=>500,'+'=>564, - ','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>278,';'=>278,'<'=>564,'='=>564,'>'=>564,'?'=>444,'@'=>921,'A'=>722, - 'B'=>667,'C'=>667,'D'=>722,'E'=>611,'F'=>556,'G'=>722,'H'=>722,'I'=>333,'J'=>389,'K'=>722,'L'=>611,'M'=>889,'N'=>722,'O'=>722,'P'=>556,'Q'=>722,'R'=>667,'S'=>556,'T'=>611,'U'=>722,'V'=>722,'W'=>944, - 'X'=>722,'Y'=>722,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>469,'_'=>500,'`'=>333,'a'=>444,'b'=>500,'c'=>444,'d'=>500,'e'=>444,'f'=>333,'g'=>500,'h'=>500,'i'=>278,'j'=>278,'k'=>500,'l'=>278,'m'=>778, - 'n'=>500,'o'=>500,'p'=>500,'q'=>500,'r'=>333,'s'=>389,'t'=>278,'u'=>500,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>444,'{'=>480,'|'=>200,'}'=>480,'~'=>541,chr(127)=>350,chr(128)=>500,chr(129)=>350,chr(130)=>333,chr(131)=>500, - chr(132)=>444,chr(133)=>1000,chr(134)=>500,chr(135)=>500,chr(136)=>333,chr(137)=>1000,chr(138)=>556,chr(139)=>333,chr(140)=>889,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>333,chr(146)=>333,chr(147)=>444,chr(148)=>444,chr(149)=>350,chr(150)=>500,chr(151)=>1000,chr(152)=>333,chr(153)=>980, - chr(154)=>389,chr(155)=>333,chr(156)=>722,chr(157)=>350,chr(158)=>444,chr(159)=>722,chr(160)=>250,chr(161)=>333,chr(162)=>500,chr(163)=>500,chr(164)=>500,chr(165)=>500,chr(166)=>200,chr(167)=>500,chr(168)=>333,chr(169)=>760,chr(170)=>276,chr(171)=>500,chr(172)=>564,chr(173)=>333,chr(174)=>760,chr(175)=>333, - chr(176)=>400,chr(177)=>564,chr(178)=>300,chr(179)=>300,chr(180)=>333,chr(181)=>500,chr(182)=>453,chr(183)=>250,chr(184)=>333,chr(185)=>300,chr(186)=>310,chr(187)=>500,chr(188)=>750,chr(189)=>750,chr(190)=>750,chr(191)=>444,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722, - chr(198)=>889,chr(199)=>667,chr(200)=>611,chr(201)=>611,chr(202)=>611,chr(203)=>611,chr(204)=>333,chr(205)=>333,chr(206)=>333,chr(207)=>333,chr(208)=>722,chr(209)=>722,chr(210)=>722,chr(211)=>722,chr(212)=>722,chr(213)=>722,chr(214)=>722,chr(215)=>564,chr(216)=>722,chr(217)=>722,chr(218)=>722,chr(219)=>722, - chr(220)=>722,chr(221)=>722,chr(222)=>556,chr(223)=>500,chr(224)=>444,chr(225)=>444,chr(226)=>444,chr(227)=>444,chr(228)=>444,chr(229)=>444,chr(230)=>667,chr(231)=>444,chr(232)=>444,chr(233)=>444,chr(234)=>444,chr(235)=>444,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>500,chr(241)=>500, - chr(242)=>500,chr(243)=>500,chr(244)=>500,chr(245)=>500,chr(246)=>500,chr(247)=>564,chr(248)=>500,chr(249)=>500,chr(250)=>500,chr(251)=>500,chr(252)=>500,chr(253)=>500,chr(254)=>500,chr(255)=>500); + chr(0)=>250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, + chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>408,'#'=>500,'$'=>500,'%'=>833,'&'=>778,'\''=>180,'('=>333,')'=>333,'*'=>500,'+'=>564, + ','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>278,';'=>278,'<'=>564,'='=>564,'>'=>564,'?'=>444,'@'=>921,'A'=>722, + 'B'=>667,'C'=>667,'D'=>722,'E'=>611,'F'=>556,'G'=>722,'H'=>722,'I'=>333,'J'=>389,'K'=>722,'L'=>611,'M'=>889,'N'=>722,'O'=>722,'P'=>556,'Q'=>722,'R'=>667,'S'=>556,'T'=>611,'U'=>722,'V'=>722,'W'=>944, + 'X'=>722,'Y'=>722,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>469,'_'=>500,'`'=>333,'a'=>444,'b'=>500,'c'=>444,'d'=>500,'e'=>444,'f'=>333,'g'=>500,'h'=>500,'i'=>278,'j'=>278,'k'=>500,'l'=>278,'m'=>778, + 'n'=>500,'o'=>500,'p'=>500,'q'=>500,'r'=>333,'s'=>389,'t'=>278,'u'=>500,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>444,'{'=>480,'|'=>200,'}'=>480,'~'=>541,chr(127)=>350,chr(128)=>500,chr(129)=>350,chr(130)=>333,chr(131)=>500, + chr(132)=>444,chr(133)=>1000,chr(134)=>500,chr(135)=>500,chr(136)=>333,chr(137)=>1000,chr(138)=>556,chr(139)=>333,chr(140)=>889,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>333,chr(146)=>333,chr(147)=>444,chr(148)=>444,chr(149)=>350,chr(150)=>500,chr(151)=>1000,chr(152)=>333,chr(153)=>980, + chr(154)=>389,chr(155)=>333,chr(156)=>722,chr(157)=>350,chr(158)=>444,chr(159)=>722,chr(160)=>250,chr(161)=>333,chr(162)=>500,chr(163)=>500,chr(164)=>500,chr(165)=>500,chr(166)=>200,chr(167)=>500,chr(168)=>333,chr(169)=>760,chr(170)=>276,chr(171)=>500,chr(172)=>564,chr(173)=>333,chr(174)=>760,chr(175)=>333, + chr(176)=>400,chr(177)=>564,chr(178)=>300,chr(179)=>300,chr(180)=>333,chr(181)=>500,chr(182)=>453,chr(183)=>250,chr(184)=>333,chr(185)=>300,chr(186)=>310,chr(187)=>500,chr(188)=>750,chr(189)=>750,chr(190)=>750,chr(191)=>444,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722, + chr(198)=>889,chr(199)=>667,chr(200)=>611,chr(201)=>611,chr(202)=>611,chr(203)=>611,chr(204)=>333,chr(205)=>333,chr(206)=>333,chr(207)=>333,chr(208)=>722,chr(209)=>722,chr(210)=>722,chr(211)=>722,chr(212)=>722,chr(213)=>722,chr(214)=>722,chr(215)=>564,chr(216)=>722,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>722,chr(222)=>556,chr(223)=>500,chr(224)=>444,chr(225)=>444,chr(226)=>444,chr(227)=>444,chr(228)=>444,chr(229)=>444,chr(230)=>667,chr(231)=>444,chr(232)=>444,chr(233)=>444,chr(234)=>444,chr(235)=>444,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>500,chr(241)=>500, + chr(242)=>500,chr(243)=>500,chr(244)=>500,chr(245)=>500,chr(246)=>500,chr(247)=>564,chr(248)=>500,chr(249)=>500,chr(250)=>500,chr(251)=>500,chr(252)=>500,chr(253)=>500,chr(254)=>500,chr(255)=>500); ?> diff --git a/lib/fpdf/timesb.php b/lib/fpdf/timesb.php index c3eb9fa75..018605104 100644 --- a/lib/fpdf/timesb.php +++ b/lib/fpdf/timesb.php @@ -1,15 +1,15 @@ 250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, - chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>555,'#'=>500,'$'=>500,'%'=>1000,'&'=>833,'\''=>278,'('=>333,')'=>333,'*'=>500,'+'=>570, - ','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>333,';'=>333,'<'=>570,'='=>570,'>'=>570,'?'=>500,'@'=>930,'A'=>722, - 'B'=>667,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>778,'I'=>389,'J'=>500,'K'=>778,'L'=>667,'M'=>944,'N'=>722,'O'=>778,'P'=>611,'Q'=>778,'R'=>722,'S'=>556,'T'=>667,'U'=>722,'V'=>722,'W'=>1000, - 'X'=>722,'Y'=>722,'Z'=>667,'['=>333,'\\'=>278,']'=>333,'^'=>581,'_'=>500,'`'=>333,'a'=>500,'b'=>556,'c'=>444,'d'=>556,'e'=>444,'f'=>333,'g'=>500,'h'=>556,'i'=>278,'j'=>333,'k'=>556,'l'=>278,'m'=>833, - 'n'=>556,'o'=>500,'p'=>556,'q'=>556,'r'=>444,'s'=>389,'t'=>333,'u'=>556,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>444,'{'=>394,'|'=>220,'}'=>394,'~'=>520,chr(127)=>350,chr(128)=>500,chr(129)=>350,chr(130)=>333,chr(131)=>500, - chr(132)=>500,chr(133)=>1000,chr(134)=>500,chr(135)=>500,chr(136)=>333,chr(137)=>1000,chr(138)=>556,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>667,chr(143)=>350,chr(144)=>350,chr(145)=>333,chr(146)=>333,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>500,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, - chr(154)=>389,chr(155)=>333,chr(156)=>722,chr(157)=>350,chr(158)=>444,chr(159)=>722,chr(160)=>250,chr(161)=>333,chr(162)=>500,chr(163)=>500,chr(164)=>500,chr(165)=>500,chr(166)=>220,chr(167)=>500,chr(168)=>333,chr(169)=>747,chr(170)=>300,chr(171)=>500,chr(172)=>570,chr(173)=>333,chr(174)=>747,chr(175)=>333, - chr(176)=>400,chr(177)=>570,chr(178)=>300,chr(179)=>300,chr(180)=>333,chr(181)=>556,chr(182)=>540,chr(183)=>250,chr(184)=>333,chr(185)=>300,chr(186)=>330,chr(187)=>500,chr(188)=>750,chr(189)=>750,chr(190)=>750,chr(191)=>500,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722, - chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>389,chr(205)=>389,chr(206)=>389,chr(207)=>389,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>570,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, - chr(220)=>722,chr(221)=>722,chr(222)=>611,chr(223)=>556,chr(224)=>500,chr(225)=>500,chr(226)=>500,chr(227)=>500,chr(228)=>500,chr(229)=>500,chr(230)=>722,chr(231)=>444,chr(232)=>444,chr(233)=>444,chr(234)=>444,chr(235)=>444,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>500,chr(241)=>556, - chr(242)=>500,chr(243)=>500,chr(244)=>500,chr(245)=>500,chr(246)=>500,chr(247)=>570,chr(248)=>500,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>500,chr(254)=>556,chr(255)=>500); + chr(0)=>250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, + chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>555,'#'=>500,'$'=>500,'%'=>1000,'&'=>833,'\''=>278,'('=>333,')'=>333,'*'=>500,'+'=>570, + ','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>333,';'=>333,'<'=>570,'='=>570,'>'=>570,'?'=>500,'@'=>930,'A'=>722, + 'B'=>667,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>778,'I'=>389,'J'=>500,'K'=>778,'L'=>667,'M'=>944,'N'=>722,'O'=>778,'P'=>611,'Q'=>778,'R'=>722,'S'=>556,'T'=>667,'U'=>722,'V'=>722,'W'=>1000, + 'X'=>722,'Y'=>722,'Z'=>667,'['=>333,'\\'=>278,']'=>333,'^'=>581,'_'=>500,'`'=>333,'a'=>500,'b'=>556,'c'=>444,'d'=>556,'e'=>444,'f'=>333,'g'=>500,'h'=>556,'i'=>278,'j'=>333,'k'=>556,'l'=>278,'m'=>833, + 'n'=>556,'o'=>500,'p'=>556,'q'=>556,'r'=>444,'s'=>389,'t'=>333,'u'=>556,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>444,'{'=>394,'|'=>220,'}'=>394,'~'=>520,chr(127)=>350,chr(128)=>500,chr(129)=>350,chr(130)=>333,chr(131)=>500, + chr(132)=>500,chr(133)=>1000,chr(134)=>500,chr(135)=>500,chr(136)=>333,chr(137)=>1000,chr(138)=>556,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>667,chr(143)=>350,chr(144)=>350,chr(145)=>333,chr(146)=>333,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>500,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, + chr(154)=>389,chr(155)=>333,chr(156)=>722,chr(157)=>350,chr(158)=>444,chr(159)=>722,chr(160)=>250,chr(161)=>333,chr(162)=>500,chr(163)=>500,chr(164)=>500,chr(165)=>500,chr(166)=>220,chr(167)=>500,chr(168)=>333,chr(169)=>747,chr(170)=>300,chr(171)=>500,chr(172)=>570,chr(173)=>333,chr(174)=>747,chr(175)=>333, + chr(176)=>400,chr(177)=>570,chr(178)=>300,chr(179)=>300,chr(180)=>333,chr(181)=>556,chr(182)=>540,chr(183)=>250,chr(184)=>333,chr(185)=>300,chr(186)=>330,chr(187)=>500,chr(188)=>750,chr(189)=>750,chr(190)=>750,chr(191)=>500,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722, + chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>389,chr(205)=>389,chr(206)=>389,chr(207)=>389,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>570,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>722,chr(222)=>611,chr(223)=>556,chr(224)=>500,chr(225)=>500,chr(226)=>500,chr(227)=>500,chr(228)=>500,chr(229)=>500,chr(230)=>722,chr(231)=>444,chr(232)=>444,chr(233)=>444,chr(234)=>444,chr(235)=>444,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>500,chr(241)=>556, + chr(242)=>500,chr(243)=>500,chr(244)=>500,chr(245)=>500,chr(246)=>500,chr(247)=>570,chr(248)=>500,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>500,chr(254)=>556,chr(255)=>500); ?> diff --git a/lib/fpdf/timesbi.php b/lib/fpdf/timesbi.php index 161f6302c..ce001aaec 100644 --- a/lib/fpdf/timesbi.php +++ b/lib/fpdf/timesbi.php @@ -1,15 +1,15 @@ 250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, - chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>389,'"'=>555,'#'=>500,'$'=>500,'%'=>833,'&'=>778,'\''=>278,'('=>333,')'=>333,'*'=>500,'+'=>570, - ','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>333,';'=>333,'<'=>570,'='=>570,'>'=>570,'?'=>500,'@'=>832,'A'=>667, - 'B'=>667,'C'=>667,'D'=>722,'E'=>667,'F'=>667,'G'=>722,'H'=>778,'I'=>389,'J'=>500,'K'=>667,'L'=>611,'M'=>889,'N'=>722,'O'=>722,'P'=>611,'Q'=>722,'R'=>667,'S'=>556,'T'=>611,'U'=>722,'V'=>667,'W'=>889, - 'X'=>667,'Y'=>611,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>570,'_'=>500,'`'=>333,'a'=>500,'b'=>500,'c'=>444,'d'=>500,'e'=>444,'f'=>333,'g'=>500,'h'=>556,'i'=>278,'j'=>278,'k'=>500,'l'=>278,'m'=>778, - 'n'=>556,'o'=>500,'p'=>500,'q'=>500,'r'=>389,'s'=>389,'t'=>278,'u'=>556,'v'=>444,'w'=>667,'x'=>500,'y'=>444,'z'=>389,'{'=>348,'|'=>220,'}'=>348,'~'=>570,chr(127)=>350,chr(128)=>500,chr(129)=>350,chr(130)=>333,chr(131)=>500, - chr(132)=>500,chr(133)=>1000,chr(134)=>500,chr(135)=>500,chr(136)=>333,chr(137)=>1000,chr(138)=>556,chr(139)=>333,chr(140)=>944,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>333,chr(146)=>333,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>500,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, - chr(154)=>389,chr(155)=>333,chr(156)=>722,chr(157)=>350,chr(158)=>389,chr(159)=>611,chr(160)=>250,chr(161)=>389,chr(162)=>500,chr(163)=>500,chr(164)=>500,chr(165)=>500,chr(166)=>220,chr(167)=>500,chr(168)=>333,chr(169)=>747,chr(170)=>266,chr(171)=>500,chr(172)=>606,chr(173)=>333,chr(174)=>747,chr(175)=>333, - chr(176)=>400,chr(177)=>570,chr(178)=>300,chr(179)=>300,chr(180)=>333,chr(181)=>576,chr(182)=>500,chr(183)=>250,chr(184)=>333,chr(185)=>300,chr(186)=>300,chr(187)=>500,chr(188)=>750,chr(189)=>750,chr(190)=>750,chr(191)=>500,chr(192)=>667,chr(193)=>667,chr(194)=>667,chr(195)=>667,chr(196)=>667,chr(197)=>667, - chr(198)=>944,chr(199)=>667,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>389,chr(205)=>389,chr(206)=>389,chr(207)=>389,chr(208)=>722,chr(209)=>722,chr(210)=>722,chr(211)=>722,chr(212)=>722,chr(213)=>722,chr(214)=>722,chr(215)=>570,chr(216)=>722,chr(217)=>722,chr(218)=>722,chr(219)=>722, - chr(220)=>722,chr(221)=>611,chr(222)=>611,chr(223)=>500,chr(224)=>500,chr(225)=>500,chr(226)=>500,chr(227)=>500,chr(228)=>500,chr(229)=>500,chr(230)=>722,chr(231)=>444,chr(232)=>444,chr(233)=>444,chr(234)=>444,chr(235)=>444,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>500,chr(241)=>556, - chr(242)=>500,chr(243)=>500,chr(244)=>500,chr(245)=>500,chr(246)=>500,chr(247)=>570,chr(248)=>500,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>444,chr(254)=>500,chr(255)=>444); + chr(0)=>250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, + chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>389,'"'=>555,'#'=>500,'$'=>500,'%'=>833,'&'=>778,'\''=>278,'('=>333,')'=>333,'*'=>500,'+'=>570, + ','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>333,';'=>333,'<'=>570,'='=>570,'>'=>570,'?'=>500,'@'=>832,'A'=>667, + 'B'=>667,'C'=>667,'D'=>722,'E'=>667,'F'=>667,'G'=>722,'H'=>778,'I'=>389,'J'=>500,'K'=>667,'L'=>611,'M'=>889,'N'=>722,'O'=>722,'P'=>611,'Q'=>722,'R'=>667,'S'=>556,'T'=>611,'U'=>722,'V'=>667,'W'=>889, + 'X'=>667,'Y'=>611,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>570,'_'=>500,'`'=>333,'a'=>500,'b'=>500,'c'=>444,'d'=>500,'e'=>444,'f'=>333,'g'=>500,'h'=>556,'i'=>278,'j'=>278,'k'=>500,'l'=>278,'m'=>778, + 'n'=>556,'o'=>500,'p'=>500,'q'=>500,'r'=>389,'s'=>389,'t'=>278,'u'=>556,'v'=>444,'w'=>667,'x'=>500,'y'=>444,'z'=>389,'{'=>348,'|'=>220,'}'=>348,'~'=>570,chr(127)=>350,chr(128)=>500,chr(129)=>350,chr(130)=>333,chr(131)=>500, + chr(132)=>500,chr(133)=>1000,chr(134)=>500,chr(135)=>500,chr(136)=>333,chr(137)=>1000,chr(138)=>556,chr(139)=>333,chr(140)=>944,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>333,chr(146)=>333,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>500,chr(151)=>1000,chr(152)=>333,chr(153)=>1000, + chr(154)=>389,chr(155)=>333,chr(156)=>722,chr(157)=>350,chr(158)=>389,chr(159)=>611,chr(160)=>250,chr(161)=>389,chr(162)=>500,chr(163)=>500,chr(164)=>500,chr(165)=>500,chr(166)=>220,chr(167)=>500,chr(168)=>333,chr(169)=>747,chr(170)=>266,chr(171)=>500,chr(172)=>606,chr(173)=>333,chr(174)=>747,chr(175)=>333, + chr(176)=>400,chr(177)=>570,chr(178)=>300,chr(179)=>300,chr(180)=>333,chr(181)=>576,chr(182)=>500,chr(183)=>250,chr(184)=>333,chr(185)=>300,chr(186)=>300,chr(187)=>500,chr(188)=>750,chr(189)=>750,chr(190)=>750,chr(191)=>500,chr(192)=>667,chr(193)=>667,chr(194)=>667,chr(195)=>667,chr(196)=>667,chr(197)=>667, + chr(198)=>944,chr(199)=>667,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>389,chr(205)=>389,chr(206)=>389,chr(207)=>389,chr(208)=>722,chr(209)=>722,chr(210)=>722,chr(211)=>722,chr(212)=>722,chr(213)=>722,chr(214)=>722,chr(215)=>570,chr(216)=>722,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>611,chr(222)=>611,chr(223)=>500,chr(224)=>500,chr(225)=>500,chr(226)=>500,chr(227)=>500,chr(228)=>500,chr(229)=>500,chr(230)=>722,chr(231)=>444,chr(232)=>444,chr(233)=>444,chr(234)=>444,chr(235)=>444,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>500,chr(241)=>556, + chr(242)=>500,chr(243)=>500,chr(244)=>500,chr(245)=>500,chr(246)=>500,chr(247)=>570,chr(248)=>500,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>444,chr(254)=>500,chr(255)=>444); ?> diff --git a/lib/fpdf/timesi.php b/lib/fpdf/timesi.php index de171fd19..d2d71a30b 100644 --- a/lib/fpdf/timesi.php +++ b/lib/fpdf/timesi.php @@ -1,15 +1,15 @@ 250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, - chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>420,'#'=>500,'$'=>500,'%'=>833,'&'=>778,'\''=>214,'('=>333,')'=>333,'*'=>500,'+'=>675, - ','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>333,';'=>333,'<'=>675,'='=>675,'>'=>675,'?'=>500,'@'=>920,'A'=>611, - 'B'=>611,'C'=>667,'D'=>722,'E'=>611,'F'=>611,'G'=>722,'H'=>722,'I'=>333,'J'=>444,'K'=>667,'L'=>556,'M'=>833,'N'=>667,'O'=>722,'P'=>611,'Q'=>722,'R'=>611,'S'=>500,'T'=>556,'U'=>722,'V'=>611,'W'=>833, - 'X'=>611,'Y'=>556,'Z'=>556,'['=>389,'\\'=>278,']'=>389,'^'=>422,'_'=>500,'`'=>333,'a'=>500,'b'=>500,'c'=>444,'d'=>500,'e'=>444,'f'=>278,'g'=>500,'h'=>500,'i'=>278,'j'=>278,'k'=>444,'l'=>278,'m'=>722, - 'n'=>500,'o'=>500,'p'=>500,'q'=>500,'r'=>389,'s'=>389,'t'=>278,'u'=>500,'v'=>444,'w'=>667,'x'=>444,'y'=>444,'z'=>389,'{'=>400,'|'=>275,'}'=>400,'~'=>541,chr(127)=>350,chr(128)=>500,chr(129)=>350,chr(130)=>333,chr(131)=>500, - chr(132)=>556,chr(133)=>889,chr(134)=>500,chr(135)=>500,chr(136)=>333,chr(137)=>1000,chr(138)=>500,chr(139)=>333,chr(140)=>944,chr(141)=>350,chr(142)=>556,chr(143)=>350,chr(144)=>350,chr(145)=>333,chr(146)=>333,chr(147)=>556,chr(148)=>556,chr(149)=>350,chr(150)=>500,chr(151)=>889,chr(152)=>333,chr(153)=>980, - chr(154)=>389,chr(155)=>333,chr(156)=>667,chr(157)=>350,chr(158)=>389,chr(159)=>556,chr(160)=>250,chr(161)=>389,chr(162)=>500,chr(163)=>500,chr(164)=>500,chr(165)=>500,chr(166)=>275,chr(167)=>500,chr(168)=>333,chr(169)=>760,chr(170)=>276,chr(171)=>500,chr(172)=>675,chr(173)=>333,chr(174)=>760,chr(175)=>333, - chr(176)=>400,chr(177)=>675,chr(178)=>300,chr(179)=>300,chr(180)=>333,chr(181)=>500,chr(182)=>523,chr(183)=>250,chr(184)=>333,chr(185)=>300,chr(186)=>310,chr(187)=>500,chr(188)=>750,chr(189)=>750,chr(190)=>750,chr(191)=>500,chr(192)=>611,chr(193)=>611,chr(194)=>611,chr(195)=>611,chr(196)=>611,chr(197)=>611, - chr(198)=>889,chr(199)=>667,chr(200)=>611,chr(201)=>611,chr(202)=>611,chr(203)=>611,chr(204)=>333,chr(205)=>333,chr(206)=>333,chr(207)=>333,chr(208)=>722,chr(209)=>667,chr(210)=>722,chr(211)=>722,chr(212)=>722,chr(213)=>722,chr(214)=>722,chr(215)=>675,chr(216)=>722,chr(217)=>722,chr(218)=>722,chr(219)=>722, - chr(220)=>722,chr(221)=>556,chr(222)=>611,chr(223)=>500,chr(224)=>500,chr(225)=>500,chr(226)=>500,chr(227)=>500,chr(228)=>500,chr(229)=>500,chr(230)=>667,chr(231)=>444,chr(232)=>444,chr(233)=>444,chr(234)=>444,chr(235)=>444,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>500,chr(241)=>500, - chr(242)=>500,chr(243)=>500,chr(244)=>500,chr(245)=>500,chr(246)=>500,chr(247)=>675,chr(248)=>500,chr(249)=>500,chr(250)=>500,chr(251)=>500,chr(252)=>500,chr(253)=>444,chr(254)=>500,chr(255)=>444); + chr(0)=>250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250, + chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>420,'#'=>500,'$'=>500,'%'=>833,'&'=>778,'\''=>214,'('=>333,')'=>333,'*'=>500,'+'=>675, + ','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>333,';'=>333,'<'=>675,'='=>675,'>'=>675,'?'=>500,'@'=>920,'A'=>611, + 'B'=>611,'C'=>667,'D'=>722,'E'=>611,'F'=>611,'G'=>722,'H'=>722,'I'=>333,'J'=>444,'K'=>667,'L'=>556,'M'=>833,'N'=>667,'O'=>722,'P'=>611,'Q'=>722,'R'=>611,'S'=>500,'T'=>556,'U'=>722,'V'=>611,'W'=>833, + 'X'=>611,'Y'=>556,'Z'=>556,'['=>389,'\\'=>278,']'=>389,'^'=>422,'_'=>500,'`'=>333,'a'=>500,'b'=>500,'c'=>444,'d'=>500,'e'=>444,'f'=>278,'g'=>500,'h'=>500,'i'=>278,'j'=>278,'k'=>444,'l'=>278,'m'=>722, + 'n'=>500,'o'=>500,'p'=>500,'q'=>500,'r'=>389,'s'=>389,'t'=>278,'u'=>500,'v'=>444,'w'=>667,'x'=>444,'y'=>444,'z'=>389,'{'=>400,'|'=>275,'}'=>400,'~'=>541,chr(127)=>350,chr(128)=>500,chr(129)=>350,chr(130)=>333,chr(131)=>500, + chr(132)=>556,chr(133)=>889,chr(134)=>500,chr(135)=>500,chr(136)=>333,chr(137)=>1000,chr(138)=>500,chr(139)=>333,chr(140)=>944,chr(141)=>350,chr(142)=>556,chr(143)=>350,chr(144)=>350,chr(145)=>333,chr(146)=>333,chr(147)=>556,chr(148)=>556,chr(149)=>350,chr(150)=>500,chr(151)=>889,chr(152)=>333,chr(153)=>980, + chr(154)=>389,chr(155)=>333,chr(156)=>667,chr(157)=>350,chr(158)=>389,chr(159)=>556,chr(160)=>250,chr(161)=>389,chr(162)=>500,chr(163)=>500,chr(164)=>500,chr(165)=>500,chr(166)=>275,chr(167)=>500,chr(168)=>333,chr(169)=>760,chr(170)=>276,chr(171)=>500,chr(172)=>675,chr(173)=>333,chr(174)=>760,chr(175)=>333, + chr(176)=>400,chr(177)=>675,chr(178)=>300,chr(179)=>300,chr(180)=>333,chr(181)=>500,chr(182)=>523,chr(183)=>250,chr(184)=>333,chr(185)=>300,chr(186)=>310,chr(187)=>500,chr(188)=>750,chr(189)=>750,chr(190)=>750,chr(191)=>500,chr(192)=>611,chr(193)=>611,chr(194)=>611,chr(195)=>611,chr(196)=>611,chr(197)=>611, + chr(198)=>889,chr(199)=>667,chr(200)=>611,chr(201)=>611,chr(202)=>611,chr(203)=>611,chr(204)=>333,chr(205)=>333,chr(206)=>333,chr(207)=>333,chr(208)=>722,chr(209)=>667,chr(210)=>722,chr(211)=>722,chr(212)=>722,chr(213)=>722,chr(214)=>722,chr(215)=>675,chr(216)=>722,chr(217)=>722,chr(218)=>722,chr(219)=>722, + chr(220)=>722,chr(221)=>556,chr(222)=>611,chr(223)=>500,chr(224)=>500,chr(225)=>500,chr(226)=>500,chr(227)=>500,chr(228)=>500,chr(229)=>500,chr(230)=>667,chr(231)=>444,chr(232)=>444,chr(233)=>444,chr(234)=>444,chr(235)=>444,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>500,chr(241)=>500, + chr(242)=>500,chr(243)=>500,chr(244)=>500,chr(245)=>500,chr(246)=>500,chr(247)=>675,chr(248)=>500,chr(249)=>500,chr(250)=>500,chr(251)=>500,chr(252)=>500,chr(253)=>444,chr(254)=>500,chr(255)=>444); ?> diff --git a/lib/fpdf/zapfdingbats.php b/lib/fpdf/zapfdingbats.php index f2bdfd5c9..ef565a026 100644 --- a/lib/fpdf/zapfdingbats.php +++ b/lib/fpdf/zapfdingbats.php @@ -1,15 +1,15 @@ 0,chr(1)=>0,chr(2)=>0,chr(3)=>0,chr(4)=>0,chr(5)=>0,chr(6)=>0,chr(7)=>0,chr(8)=>0,chr(9)=>0,chr(10)=>0,chr(11)=>0,chr(12)=>0,chr(13)=>0,chr(14)=>0,chr(15)=>0,chr(16)=>0,chr(17)=>0,chr(18)=>0,chr(19)=>0,chr(20)=>0,chr(21)=>0, - chr(22)=>0,chr(23)=>0,chr(24)=>0,chr(25)=>0,chr(26)=>0,chr(27)=>0,chr(28)=>0,chr(29)=>0,chr(30)=>0,chr(31)=>0,' '=>278,'!'=>974,'"'=>961,'#'=>974,'$'=>980,'%'=>719,'&'=>789,'\''=>790,'('=>791,')'=>690,'*'=>960,'+'=>939, - ','=>549,'-'=>855,'.'=>911,'/'=>933,'0'=>911,'1'=>945,'2'=>974,'3'=>755,'4'=>846,'5'=>762,'6'=>761,'7'=>571,'8'=>677,'9'=>763,':'=>760,';'=>759,'<'=>754,'='=>494,'>'=>552,'?'=>537,'@'=>577,'A'=>692, - 'B'=>786,'C'=>788,'D'=>788,'E'=>790,'F'=>793,'G'=>794,'H'=>816,'I'=>823,'J'=>789,'K'=>841,'L'=>823,'M'=>833,'N'=>816,'O'=>831,'P'=>923,'Q'=>744,'R'=>723,'S'=>749,'T'=>790,'U'=>792,'V'=>695,'W'=>776, - 'X'=>768,'Y'=>792,'Z'=>759,'['=>707,'\\'=>708,']'=>682,'^'=>701,'_'=>826,'`'=>815,'a'=>789,'b'=>789,'c'=>707,'d'=>687,'e'=>696,'f'=>689,'g'=>786,'h'=>787,'i'=>713,'j'=>791,'k'=>785,'l'=>791,'m'=>873, - 'n'=>761,'o'=>762,'p'=>762,'q'=>759,'r'=>759,'s'=>892,'t'=>892,'u'=>788,'v'=>784,'w'=>438,'x'=>138,'y'=>277,'z'=>415,'{'=>392,'|'=>392,'}'=>668,'~'=>668,chr(127)=>0,chr(128)=>390,chr(129)=>390,chr(130)=>317,chr(131)=>317, - chr(132)=>276,chr(133)=>276,chr(134)=>509,chr(135)=>509,chr(136)=>410,chr(137)=>410,chr(138)=>234,chr(139)=>234,chr(140)=>334,chr(141)=>334,chr(142)=>0,chr(143)=>0,chr(144)=>0,chr(145)=>0,chr(146)=>0,chr(147)=>0,chr(148)=>0,chr(149)=>0,chr(150)=>0,chr(151)=>0,chr(152)=>0,chr(153)=>0, - chr(154)=>0,chr(155)=>0,chr(156)=>0,chr(157)=>0,chr(158)=>0,chr(159)=>0,chr(160)=>0,chr(161)=>732,chr(162)=>544,chr(163)=>544,chr(164)=>910,chr(165)=>667,chr(166)=>760,chr(167)=>760,chr(168)=>776,chr(169)=>595,chr(170)=>694,chr(171)=>626,chr(172)=>788,chr(173)=>788,chr(174)=>788,chr(175)=>788, - chr(176)=>788,chr(177)=>788,chr(178)=>788,chr(179)=>788,chr(180)=>788,chr(181)=>788,chr(182)=>788,chr(183)=>788,chr(184)=>788,chr(185)=>788,chr(186)=>788,chr(187)=>788,chr(188)=>788,chr(189)=>788,chr(190)=>788,chr(191)=>788,chr(192)=>788,chr(193)=>788,chr(194)=>788,chr(195)=>788,chr(196)=>788,chr(197)=>788, - chr(198)=>788,chr(199)=>788,chr(200)=>788,chr(201)=>788,chr(202)=>788,chr(203)=>788,chr(204)=>788,chr(205)=>788,chr(206)=>788,chr(207)=>788,chr(208)=>788,chr(209)=>788,chr(210)=>788,chr(211)=>788,chr(212)=>894,chr(213)=>838,chr(214)=>1016,chr(215)=>458,chr(216)=>748,chr(217)=>924,chr(218)=>748,chr(219)=>918, - chr(220)=>927,chr(221)=>928,chr(222)=>928,chr(223)=>834,chr(224)=>873,chr(225)=>828,chr(226)=>924,chr(227)=>924,chr(228)=>917,chr(229)=>930,chr(230)=>931,chr(231)=>463,chr(232)=>883,chr(233)=>836,chr(234)=>836,chr(235)=>867,chr(236)=>867,chr(237)=>696,chr(238)=>696,chr(239)=>874,chr(240)=>0,chr(241)=>874, - chr(242)=>760,chr(243)=>946,chr(244)=>771,chr(245)=>865,chr(246)=>771,chr(247)=>888,chr(248)=>967,chr(249)=>888,chr(250)=>831,chr(251)=>873,chr(252)=>927,chr(253)=>970,chr(254)=>918,chr(255)=>0); + chr(0)=>0,chr(1)=>0,chr(2)=>0,chr(3)=>0,chr(4)=>0,chr(5)=>0,chr(6)=>0,chr(7)=>0,chr(8)=>0,chr(9)=>0,chr(10)=>0,chr(11)=>0,chr(12)=>0,chr(13)=>0,chr(14)=>0,chr(15)=>0,chr(16)=>0,chr(17)=>0,chr(18)=>0,chr(19)=>0,chr(20)=>0,chr(21)=>0, + chr(22)=>0,chr(23)=>0,chr(24)=>0,chr(25)=>0,chr(26)=>0,chr(27)=>0,chr(28)=>0,chr(29)=>0,chr(30)=>0,chr(31)=>0,' '=>278,'!'=>974,'"'=>961,'#'=>974,'$'=>980,'%'=>719,'&'=>789,'\''=>790,'('=>791,')'=>690,'*'=>960,'+'=>939, + ','=>549,'-'=>855,'.'=>911,'/'=>933,'0'=>911,'1'=>945,'2'=>974,'3'=>755,'4'=>846,'5'=>762,'6'=>761,'7'=>571,'8'=>677,'9'=>763,':'=>760,';'=>759,'<'=>754,'='=>494,'>'=>552,'?'=>537,'@'=>577,'A'=>692, + 'B'=>786,'C'=>788,'D'=>788,'E'=>790,'F'=>793,'G'=>794,'H'=>816,'I'=>823,'J'=>789,'K'=>841,'L'=>823,'M'=>833,'N'=>816,'O'=>831,'P'=>923,'Q'=>744,'R'=>723,'S'=>749,'T'=>790,'U'=>792,'V'=>695,'W'=>776, + 'X'=>768,'Y'=>792,'Z'=>759,'['=>707,'\\'=>708,']'=>682,'^'=>701,'_'=>826,'`'=>815,'a'=>789,'b'=>789,'c'=>707,'d'=>687,'e'=>696,'f'=>689,'g'=>786,'h'=>787,'i'=>713,'j'=>791,'k'=>785,'l'=>791,'m'=>873, + 'n'=>761,'o'=>762,'p'=>762,'q'=>759,'r'=>759,'s'=>892,'t'=>892,'u'=>788,'v'=>784,'w'=>438,'x'=>138,'y'=>277,'z'=>415,'{'=>392,'|'=>392,'}'=>668,'~'=>668,chr(127)=>0,chr(128)=>390,chr(129)=>390,chr(130)=>317,chr(131)=>317, + chr(132)=>276,chr(133)=>276,chr(134)=>509,chr(135)=>509,chr(136)=>410,chr(137)=>410,chr(138)=>234,chr(139)=>234,chr(140)=>334,chr(141)=>334,chr(142)=>0,chr(143)=>0,chr(144)=>0,chr(145)=>0,chr(146)=>0,chr(147)=>0,chr(148)=>0,chr(149)=>0,chr(150)=>0,chr(151)=>0,chr(152)=>0,chr(153)=>0, + chr(154)=>0,chr(155)=>0,chr(156)=>0,chr(157)=>0,chr(158)=>0,chr(159)=>0,chr(160)=>0,chr(161)=>732,chr(162)=>544,chr(163)=>544,chr(164)=>910,chr(165)=>667,chr(166)=>760,chr(167)=>760,chr(168)=>776,chr(169)=>595,chr(170)=>694,chr(171)=>626,chr(172)=>788,chr(173)=>788,chr(174)=>788,chr(175)=>788, + chr(176)=>788,chr(177)=>788,chr(178)=>788,chr(179)=>788,chr(180)=>788,chr(181)=>788,chr(182)=>788,chr(183)=>788,chr(184)=>788,chr(185)=>788,chr(186)=>788,chr(187)=>788,chr(188)=>788,chr(189)=>788,chr(190)=>788,chr(191)=>788,chr(192)=>788,chr(193)=>788,chr(194)=>788,chr(195)=>788,chr(196)=>788,chr(197)=>788, + chr(198)=>788,chr(199)=>788,chr(200)=>788,chr(201)=>788,chr(202)=>788,chr(203)=>788,chr(204)=>788,chr(205)=>788,chr(206)=>788,chr(207)=>788,chr(208)=>788,chr(209)=>788,chr(210)=>788,chr(211)=>788,chr(212)=>894,chr(213)=>838,chr(214)=>1016,chr(215)=>458,chr(216)=>748,chr(217)=>924,chr(218)=>748,chr(219)=>918, + chr(220)=>927,chr(221)=>928,chr(222)=>928,chr(223)=>834,chr(224)=>873,chr(225)=>828,chr(226)=>924,chr(227)=>924,chr(228)=>917,chr(229)=>930,chr(230)=>931,chr(231)=>463,chr(232)=>883,chr(233)=>836,chr(234)=>836,chr(235)=>867,chr(236)=>867,chr(237)=>696,chr(238)=>696,chr(239)=>874,chr(240)=>0,chr(241)=>874, + chr(242)=>760,chr(243)=>946,chr(244)=>771,chr(245)=>865,chr(246)=>771,chr(247)=>888,chr(248)=>967,chr(249)=>888,chr(250)=>831,chr(251)=>873,chr(252)=>927,chr(253)=>970,chr(254)=>918,chr(255)=>0); ?> diff --git a/lib/nusoap/nusoap.php b/lib/nusoap/nusoap.php index 6f2fe15ab..68d096a3b 100644 --- a/lib/nusoap/nusoap.php +++ b/lib/nusoap/nusoap.php @@ -177,7 +177,7 @@ class nusoap_base { */ function serialize_val($val,$name=false,$type=false,$name_ns=false, $type_ns=false,$attributes=false,$use='encoded') { - if(is_object($val) && strtolower(get_class($val)) == 'soapval'){ + if(is_object($val) && strtolower(get_class($val)) == 'soapval'){ return $val->serialize($use); } $this->debug( "in serialize_val: $val, $name, $type, $name_ns, $type_ns, $attributes, $use"); @@ -357,21 +357,21 @@ class nusoap_base { * @access public */ function serializeEnvelope($body,$headers=false,$namespaces=array(),$style='rpc'){ - // serialize namespaces + // serialize namespaces $ns_string = ''; - foreach(array_merge($this->namespaces,$namespaces) as $k => $v){ - $ns_string .= " xmlns:$k=\"$v\""; - } - if($style == 'rpc') { + foreach(array_merge($this->namespaces,$namespaces) as $k => $v){ + $ns_string .= " xmlns:$k=\"$v\""; + } + if($style == 'rpc') { $ns_string = ' SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"' . $ns_string; - } + } - // serialize headers - if($headers){ + // serialize headers + if($headers){ $headers = "".$headers.""; - } - // serialize envelope - return + } + // serialize envelope + return 'soap_defencoding .'"?'.">". '". $headers. @@ -468,14 +468,14 @@ function timestamp_to_iso8601($timestamp,$utc=true){ */ function iso8601_to_timestamp($datestr){ $eregStr = - '([0-9]{4})-'. // centuries & years CCYY- - '([0-9]{2})-'. // months MM- - '([0-9]{2})'. // days DD - 'T'. // separator T - '([0-9]{2}):'. // hours hh: - '([0-9]{2}):'. // minutes mm: - '([0-9]{2})(\.[0-9]+)?'. // seconds ss.ss... - '(Z|[+\-][0-9]{2}:?[0-9]{2})?'; // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's + '([0-9]{4})-'. // centuries & years CCYY- + '([0-9]{2})-'. // months MM- + '([0-9]{2})'. // days DD + 'T'. // separator T + '([0-9]{2}):'. // hours hh: + '([0-9]{2}):'. // minutes mm: + '([0-9]{2})(\.[0-9]+)?'. // seconds ss.ss... + '(Z|[+\-][0-9]{2}:?[0-9]{2})?'; // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's if(ereg($eregStr,$datestr,$regs)){ // not utc if($regs[8] != 'Z'){ @@ -543,11 +543,11 @@ class soap_fault extends nusoap_base { '\n". ''. ''. - ''.$this->faultcode.''. - ''.$this->faultactor.''. - ''.$this->faultstring.''. - ''.$this->serialize_val($this->faultdetail).''. - ''. + ''.$this->faultcode.''. + ''.$this->faultactor.''. + ''.$this->faultstring.''. + ''.$this->serialize_val($this->faultdetail).''. + ''. ''. ''; return $return_msg; @@ -569,46 +569,46 @@ class soap_fault extends nusoap_base { */ class XMLSchema extends nusoap_base { - // files - var $schema = ''; - var $xml = ''; - // define internal arrays of bindings, ports, operations, messages, etc. - var $complexTypes = array(); - // target namespace - var $schemaTargetNamespace = ''; - // parser vars - var $parser; - var $position; - var $depth = 0; - var $depth_array = array(); - - /** - * constructor - * - * @param string $schema schema document URI - * @param string $xml xml document URI - * @access public - */ - function XMLSchema($schema='',$xml=''){ - - $this->debug('xmlschema class instantiated, inside constructor'); - // files - $this->schema = $schema; - $this->xml = $xml; - - // parse schema file - if($schema != ''){ - $this->debug('initial schema file: '.$schema); - $this->parseFile($schema); - } - - // parse xml file - if($xml != ''){ - $this->debug('initial xml file: '.$xml); - $this->parseFile($xml); - } - - } + // files + var $schema = ''; + var $xml = ''; + // define internal arrays of bindings, ports, operations, messages, etc. + var $complexTypes = array(); + // target namespace + var $schemaTargetNamespace = ''; + // parser vars + var $parser; + var $position; + var $depth = 0; + var $depth_array = array(); + + /** + * constructor + * + * @param string $schema schema document URI + * @param string $xml xml document URI + * @access public + */ + function XMLSchema($schema='',$xml=''){ + + $this->debug('xmlschema class instantiated, inside constructor'); + // files + $this->schema = $schema; + $this->xml = $xml; + + // parse schema file + if($schema != ''){ + $this->debug('initial schema file: '.$schema); + $this->parseFile($schema); + } + + // parse xml file + if($xml != ''){ + $this->debug('initial xml file: '.$xml); + $this->parseFile($xml); + } + + } /** * parse an XML file @@ -618,77 +618,77 @@ class XMLSchema extends nusoap_base { * @return boolean * @access public */ - function parseFile($xml,$type){ - // parse xml file - if($xml != ""){ - $this->debug('parsing $xml'); - $xmlStr = @join("",@file($xml)); - if($xmlStr == ""){ - $this->setError('No file at the specified URL: '.$xml); - return false; - } else { - $this->parseString($xmlStr,$type); - return true; - } - } - return false; - } - - /** + function parseFile($xml,$type){ + // parse xml file + if($xml != ""){ + $this->debug('parsing $xml'); + $xmlStr = @join("",@file($xml)); + if($xmlStr == ""){ + $this->setError('No file at the specified URL: '.$xml); + return false; + } else { + $this->parseString($xmlStr,$type); + return true; + } + } + return false; + } + + /** * parse an XML string * * @param string $xml path or URL * @param string $type, (schema|xml) * @access private */ - function parseString($xml,$type){ - // parse xml string - if($xml != ""){ - - // Create an XML parser. - $this->parser = xml_parser_create(); - // Set the options for parsing the XML data. - xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); - - // Set the object for the parser. - xml_set_object($this->parser, $this); - - // Set the element handlers for the parser. - if($type == "schema"){ - xml_set_element_handler($this->parser, 'schemaStartElement','schemaEndElement'); - xml_set_character_data_handler($this->parser,'schemaCharacterData'); - } elseif($type == "xml"){ - xml_set_element_handler($this->parser, 'xmlStartElement','xmlEndElement'); - xml_set_character_data_handler($this->parser,'xmlCharacterData'); - } - - // Parse the XML file. - if(!xml_parse($this->parser,$xml,true)){ - // Display an error message. - $errstr = sprintf('XML error on line %d: %s', - xml_get_current_line_number($this->parser), - xml_error_string(xml_get_error_code($this->parser)) - ); - $this->debug('XML parse error: '.$errstr); - $this->setError('Parser error: '.$errstr); - } - - xml_parser_free($this->parser); - } else{ - $this->debug('no xml passed to parseString()!!'); - $this->setError('no xml passed to parseString()!!'); - } - } - - /** - * start-element handler - * - * @param string $parser XML parser object - * @param string $name element name - * @param string $attrs associative array of attributes - * @access private - */ - function schemaStartElement($parser, $name, $attrs) { + function parseString($xml,$type){ + // parse xml string + if($xml != ""){ + + // Create an XML parser. + $this->parser = xml_parser_create(); + // Set the options for parsing the XML data. + xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); + + // Set the object for the parser. + xml_set_object($this->parser, $this); + + // Set the element handlers for the parser. + if($type == "schema"){ + xml_set_element_handler($this->parser, 'schemaStartElement','schemaEndElement'); + xml_set_character_data_handler($this->parser,'schemaCharacterData'); + } elseif($type == "xml"){ + xml_set_element_handler($this->parser, 'xmlStartElement','xmlEndElement'); + xml_set_character_data_handler($this->parser,'xmlCharacterData'); + } + + // Parse the XML file. + if(!xml_parse($this->parser,$xml,true)){ + // Display an error message. + $errstr = sprintf('XML error on line %d: %s', + xml_get_current_line_number($this->parser), + xml_error_string(xml_get_error_code($this->parser)) + ); + $this->debug('XML parse error: '.$errstr); + $this->setError('Parser error: '.$errstr); + } + + xml_parser_free($this->parser); + } else{ + $this->debug('no xml passed to parseString()!!'); + $this->setError('no xml passed to parseString()!!'); + } + } + + /** + * start-element handler + * + * @param string $parser XML parser object + * @param string $name element name + * @param string $attrs associative array of attributes + * @access private + */ + function schemaStartElement($parser, $name, $attrs) { // position in the total number of elements, starting from 0 $pos = $this->position++; @@ -701,7 +701,7 @@ class XMLSchema extends nusoap_base { // get unqualified name $name = $this->getLocalPart($name); } else { - $prefix = ''; + $prefix = ''; } // loop thru attributes, expanding, and registering namespace declarations @@ -709,9 +709,9 @@ class XMLSchema extends nusoap_base { foreach($attrs as $k => $v){ // if ns declarations, add to class level array of valid namespaces if(ereg("^xmlns",$k)){ - //$this->xdebug("$k: $v"); - //$this->xdebug('ns_prefix: '.$this->getPrefix($k)); - if($ns_prefix = substr(strrchr($k,':'),1)){ + //$this->xdebug("$k: $v"); + //$this->xdebug('ns_prefix: '.$this->getPrefix($k)); + if($ns_prefix = substr(strrchr($k,':'),1)){ $this->namespaces[$ns_prefix] = $v; } else { $this->namespaces['ns'.(count($this->namespaces)+1)] = $v; @@ -721,16 +721,16 @@ class XMLSchema extends nusoap_base { $this->namespaces['xsi'] = $v.'-instance'; } } - } - foreach($attrs as $k => $v) { + } + foreach($attrs as $k => $v) { // expand each attribute $k = strpos($k,':') ? $this->expandQname($k) : $k; $v = strpos($v,':') ? $this->expandQname($v) : $v; $eAttrs[$k] = $v; - } - $attrs = $eAttrs; + } + $attrs = $eAttrs; } else { - $attrs = array(); + $attrs = array(); } // find status, register data switch($name) { @@ -742,10 +742,10 @@ class XMLSchema extends nusoap_base { } break; case 'attribute': - //$this->xdebug("parsing attribute $attrs[name] $attrs[ref] of value: ".$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']); + //$this->xdebug("parsing attribute $attrs[name] $attrs[ref] of value: ".$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']); if(isset($attrs['name'])){ - $this->attributes[$attrs['name']] = $attrs; - $aname = $attrs['name']; + $this->attributes[$attrs['name']] = $attrs; + $aname = $attrs['name']; } elseif(isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType'){ $aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; } elseif(isset($attrs['ref'])){ @@ -832,19 +832,19 @@ class XMLSchema extends nusoap_base { $this->elements[ $attrs['name'] ]['typeClass'] = 'element'; break; } - } + } - /** + /** * end-element handler * * @param string $parser XML parser object * @param string $name element name * @access private */ - function schemaEndElement($parser, $name) { + function schemaEndElement($parser, $name) { // position of current element is equal to the last value left in depth_array for my depth if(isset($this->depth_array[$this->depth])){ - $pos = $this->depth_array[$this->depth]; + $pos = $this->depth_array[$this->depth]; } // bring depth down a notch $this->depth--; @@ -856,26 +856,26 @@ class XMLSchema extends nusoap_base { if($name == 'element'){ $this->currentElement = false; } - } + } - /** + /** * element content handler * * @param string $parser XML parser object * @param string $data element content * @access private */ - function schemaCharacterData($parser, $data){ + function schemaCharacterData($parser, $data){ $pos = $this->depth_array[$this->depth]; $this->message[$pos]['cdata'] .= $data; - } + } - /** + /** * serialize the schema * * @access public */ - function serializeSchema(){ + function serializeSchema(){ $schemaPrefix = $this->getPrefixFromNamespace($this->XMLSchemaVersion); $xml = ''; @@ -941,16 +941,16 @@ class XMLSchema extends nusoap_base { // finish 'er up $xml = "<$schemaPrefix:schema xmlns=\"$this->XMLSchemaVersion\" targetNamespace=\"$this->schemaTargetNamespace\">".$xml.""; return $xml; - } - - /** - * expands a qualified name - * - * @param string $string qname - * @return string expanded qname - * @access private - */ - function expandQname($qname){ + } + + /** + * expands a qualified name + * + * @param string $string qname + * @return string expanded qname + * @access private + */ + function expandQname($qname){ // get element prefix if(strpos($qname,':') && !ereg('^http://',$qname)){ // get unqualified name @@ -965,17 +965,17 @@ class XMLSchema extends nusoap_base { } else { return $qname; } - } + } - /** + /** * adds debug data to the clas level debug string * * @param string $string debug data * @access private */ - function xdebug($string){ + function xdebug($string){ $this->debug(' xmlschema: '.$string); - } + } /** * get the PHP type of a user defined type in the schema @@ -988,7 +988,7 @@ class XMLSchema extends nusoap_base { * @return mixed * @access public */ - function getPHPType($type,$ns){ + function getPHPType($type,$ns){ global $typemap; if(isset($typemap[$ns][$type])){ //print "found type '$type' and ns $ns in typemap
"; @@ -998,7 +998,7 @@ class XMLSchema extends nusoap_base { return $this->complexTypes[$type]['phpType']; } return false; - } + } /** * returns the local part of a prefixed string @@ -1008,16 +1008,16 @@ class XMLSchema extends nusoap_base { * @return string * @access public */ - function getLocalPart($str){ + function getLocalPart($str){ if($sstr = strrchr($str,':')){ // get unqualified name return substr( $sstr, 1 ); } else { return $str; } - } + } - /** + /** * returns the prefix part of a prefixed string * returns false, if not prefixed * @@ -1025,15 +1025,15 @@ class XMLSchema extends nusoap_base { * @return mixed * @access public */ - function getPrefix($str){ + function getPrefix($str){ if($pos = strrpos($str,':')){ // get prefix return substr($str,0,$pos); } return false; - } + } - /** + /** * pass it a prefix, it returns a namespace * returns false if no namespace registered with the given prefix * @@ -1041,15 +1041,15 @@ class XMLSchema extends nusoap_base { * @return mixed * @access public */ - function getNamespaceFromPrefix($prefix){ + function getNamespaceFromPrefix($prefix){ if(isset($this->namespaces[$prefix])){ return $this->namespaces[$prefix]; } //$this->setError("No namespace registered for prefix '$prefix'"); return false; - } + } - /** + /** * returns the prefix for a given namespace (or prefix) * or false if no prefixes registered for the given namespace * @@ -1057,7 +1057,7 @@ class XMLSchema extends nusoap_base { * @return mixed * @access public */ - function getPrefixFromNamespace($ns){ + function getPrefixFromNamespace($ns){ foreach($this->namespaces as $p => $n){ if($ns == $n || $ns == $p){ $this->usedNamespaces[$p] = $n; @@ -1065,9 +1065,9 @@ class XMLSchema extends nusoap_base { } } return false; - } + } - /** + /** * returns an array of information about a given type * returns false if no type exists by the given name * @@ -1083,7 +1083,7 @@ class XMLSchema extends nusoap_base { * @return mixed * @access public */ - function getTypeDef($type){ + function getTypeDef($type){ if(isset($this->complexTypes[$type])){ return $this->complexTypes[$type]; } elseif(isset($this->elements[$type])){ @@ -1092,9 +1092,9 @@ class XMLSchema extends nusoap_base { return $this->attributes[$type]; } return false; - } + } - /** + /** * returns a sample serialization of a given type, or false if no type by the given name * * @param string $type, name of type @@ -1104,7 +1104,7 @@ class XMLSchema extends nusoap_base { function serializeTypeDef($type){ //print "in sTD() for type $type
"; if($typeDef = $this->getTypeDef($type)){ - $str .= '<'.$type; + $str .= '<'.$type; if(is_array($typeDef['attrs'])){ foreach($attrs as $attName => $data){ $str .= " $attName=\"{type = ".$data['type']."}\""; @@ -1136,7 +1136,7 @@ class XMLSchema extends nusoap_base { * @return string * @access public */ - function typeToForm($name,$type){ + function typeToForm($name,$type){ // get typedef if($typeDef = $this->getTypeDef($type)){ // if struct @@ -1163,49 +1163,49 @@ class XMLSchema extends nusoap_base { $buffer .= ""; } return $buffer; - } - - /** - * adds an XML Schema complex type to the WSDL types - * - * example: array - * - * addType( - * 'ArrayOfstring', - * 'complexType', - * 'array', - * '', - * 'SOAP-ENC:Array', - * array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]'), - * 'xsd:string' - * ); - * - * example: PHP associative array ( SOAP Struct ) - * - * addType( - * 'SOAPStruct', - * 'complexType', - * 'struct', - * 'all', - * array('myVar'=> array('name'=>'myVar','type'=>'string') - * ); - * - * @param name - * @param typeClass (complexType|simpleType|attribute) - * @param phpType: currently supported are array and struct (php assoc array) - * @param compositor (all|sequence|choice) - * @param restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) - * @param elements = array ( name = array(name=>'',type=>'') ) - * @param attrs = array( - * array( - * 'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType", - * "http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]" - * ) - * ) - * @param arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string) - * - */ - function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType=''){ + } + + /** + * adds an XML Schema complex type to the WSDL types + * + * example: array + * + * addType( + * 'ArrayOfstring', + * 'complexType', + * 'array', + * '', + * 'SOAP-ENC:Array', + * array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]'), + * 'xsd:string' + * ); + * + * example: PHP associative array ( SOAP Struct ) + * + * addType( + * 'SOAPStruct', + * 'complexType', + * 'struct', + * 'all', + * array('myVar'=> array('name'=>'myVar','type'=>'string') + * ); + * + * @param name + * @param typeClass (complexType|simpleType|attribute) + * @param phpType: currently supported are array and struct (php assoc array) + * @param compositor (all|sequence|choice) + * @param restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) + * @param elements = array ( name = array(name=>'',type=>'') ) + * @param attrs = array( + * array( + * 'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType", + * "http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]" + * ) + * ) + * @param arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string) + * + */ + function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType=''){ $this->complexTypes[$name] = array( 'name' => $name, 'typeClass' => $typeClass, @@ -1216,7 +1216,7 @@ class XMLSchema extends nusoap_base { 'attrs' => $attrs, 'arrayType' => $arrayType ); - } + } } ?>encoding != '' && function_exists('gzdeflate')){ $this->outgoing_payload .= "Accept-Encoding: $this->encoding\r\n". "Connection: close\r\n"; - if (!check_php_version(5,3)) { + if (!check_php_version(5,3)) { set_magic_quotes_runtime(0); - } + } } // set soapaction if($this->useSOAPAction){ @@ -1558,9 +1558,9 @@ class soap_transport_http extends nusoap_base { if(function_exists('gzdeflate')){ $encoding_headers = "Accept-Encoding: $this->encoding\r\n". "Connection: close\r\n"; - if (!check_php_version(5,3)) { + if (!check_php_version(5,3)) { set_magic_quotes_runtime(0); - } + } } } @@ -1864,7 +1864,7 @@ class soap_server extends nusoap_base { $payload = $response; // add debug data if in debug mode if(isset($this->debug_flag) && $this->debug_flag == 1){ - $payload .= ""; + $payload .= ""; } // print headers if($this->fault){ @@ -2139,94 +2139,94 @@ class soap_server extends nusoap_base { * @access private */ function webDescription(){ - $b = ' - NuSOAP: '.$this->wsdl->serviceName.' - - - - -
-

-
'.$this->wsdl->serviceName.'
-
'; return $b; } @@ -2429,7 +2429,7 @@ class wsdl extends XMLSchema { $base64auth = base64_encode($wsdl_props['user'] . ":" . $wsdl_props['pass']); $sHeader .= "Authorization: Basic $base64auth\r\n"; } - $sHeader .= "Host: " . $wsdl_props['host'] . ( isset($wsdl_props['port']) ? ":".$wsdl_props['port'] : "" ) . "\r\n\r\n"; + $sHeader .= "Host: " . $wsdl_props['host'] . ( isset($wsdl_props['port']) ? ":".$wsdl_props['port'] : "" ) . "\r\n\r\n"; fputs($fp, $sHeader); while (fgets($fp, 1024) != "\r\n") { @@ -2496,20 +2496,20 @@ class wsdl extends XMLSchema { foreach($bindingData['operations'] as $operation => $data) { $this->debug('post-parse data gathering for ' . $operation); $this->bindings[$binding]['operations'][$operation]['input'] = - isset($this->bindings[$binding]['operations'][$operation]['input']) ? - array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[ $bindingData['portType'] ][$operation]['input']) : - $this->portTypes[ $bindingData['portType'] ][$operation]['input']; + isset($this->bindings[$binding]['operations'][$operation]['input']) ? + array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[ $bindingData['portType'] ][$operation]['input']) : + $this->portTypes[ $bindingData['portType'] ][$operation]['input']; $this->bindings[$binding]['operations'][$operation]['output'] = - isset($this->bindings[$binding]['operations'][$operation]['output']) ? - array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[ $bindingData['portType'] ][$operation]['output']) : - $this->portTypes[ $bindingData['portType'] ][$operation]['output']; + isset($this->bindings[$binding]['operations'][$operation]['output']) ? + array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[ $bindingData['portType'] ][$operation]['output']) : + $this->portTypes[ $bindingData['portType'] ][$operation]['output']; if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ])){ - $this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ]; - } - if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ])){ - $this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ]; + $this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ]; + } + if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ])){ + $this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ]; } - if (isset($bindingData['style'])) { + if (isset($bindingData['style'])) { $this->bindings[$binding]['operations'][$operation]['style'] = $bindingData['style']; } $this->bindings[$binding]['operations'][$operation]['transport'] = isset($bindingData['transport']) ? $bindingData['transport'] : ''; @@ -2581,139 +2581,139 @@ class wsdl extends XMLSchema { switch ($this->status) { case 'message': if ($name == 'part') { - if (isset($attrs['type'])) { - $this->debug("msg " . $this->currentMessage . ": found part $attrs[name]: " . implode(',', $attrs)); - $this->messages[$this->currentMessage][$attrs['name']] = $attrs['type']; - } - if (isset($attrs['element'])) { - $this->messages[$this->currentMessage][$attrs['name']] = $attrs['element']; - } - } - break; - case 'portType': - switch ($name) { - case 'operation': - $this->currentPortOperation = $attrs['name']; - $this->debug("portType $this->currentPortType operation: $this->currentPortOperation"); - if (isset($attrs['parameterOrder'])) { - $this->portTypes[$this->currentPortType][$attrs['name']]['parameterOrder'] = $attrs['parameterOrder']; - } - break; - case 'documentation': - $this->documentation = true; - break; - // merge input/output data - default: - $m = isset($attrs['message']) ? $this->getLocalPart($attrs['message']) : ''; - $this->portTypes[$this->currentPortType][$this->currentPortOperation][$name]['message'] = $m; - break; - } - break; - case 'binding': - switch ($name) { - case 'binding': - // get ns prefix - if (isset($attrs['style'])) { - $this->bindings[$this->currentBinding]['prefix'] = $prefix; - } - $this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding], $attrs); - break; - case 'header': - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus]['headers'][] = $attrs; - break; - case 'operation': - if (isset($attrs['soapAction'])) { - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction']; - } - if (isset($attrs['style'])) { - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['style'] = $attrs['style']; - } - if (isset($attrs['name'])) { - $this->currentOperation = $attrs['name']; - $this->debug("current binding operation: $this->currentOperation"); - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['name'] = $attrs['name']; - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['binding'] = $this->currentBinding; - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['endpoint'] = isset($this->bindings[$this->currentBinding]['endpoint']) ? $this->bindings[$this->currentBinding]['endpoint'] : ''; - } - break; - case 'input': - $this->opStatus = 'input'; - break; - case 'output': - $this->opStatus = 'output'; - break; - case 'body': - if (isset($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus])) { - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = array_merge($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus], $attrs); - } else { - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs; - } - break; - } - break; - case 'service': - switch ($name) { - case 'port': - $this->currentPort = $attrs['name']; - $this->debug('current port: ' . $this->currentPort); - $this->ports[$this->currentPort]['binding'] = $this->getLocalPart($attrs['binding']); - - break; - case 'address': - $this->ports[$this->currentPort]['location'] = $attrs['location']; - $this->ports[$this->currentPort]['bindingType'] = $namespace; - $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['bindingType'] = $namespace; - $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['endpoint'] = $attrs['location']; - break; - } - break; - } - // set status - switch ($name) { - case "import": - if (isset($attrs['location'])) { - $this->import[$attrs['namespace']] = $attrs['location']; - } - break; - case 'types': - $this->status = 'schema'; - break; - case 'message': - $this->status = 'message'; - $this->messages[$attrs['name']] = array(); - $this->currentMessage = $attrs['name']; - break; - case 'portType': - $this->status = 'portType'; - $this->portTypes[$attrs['name']] = array(); - $this->currentPortType = $attrs['name']; - break; - case "binding": - if (isset($attrs['name'])) { - // get binding name - if (strpos($attrs['name'], ':')) { - $this->currentBinding = $this->getLocalPart($attrs['name']); - } else { - $this->currentBinding = $attrs['name']; - } - $this->status = 'binding'; - $this->bindings[$this->currentBinding]['portType'] = $this->getLocalPart($attrs['type']); - $this->debug("current binding: $this->currentBinding of portType: " . $attrs['type']); - } - break; - case 'service': - $this->serviceName = $attrs['name']; - $this->status = 'service'; - $this->debug('current service: ' . $this->serviceName); - break; - case 'definitions': - foreach ($attrs as $name => $value) { - $this->wsdl_info[$name] = $value; - } - break; - } - } - } + if (isset($attrs['type'])) { + $this->debug("msg " . $this->currentMessage . ": found part $attrs[name]: " . implode(',', $attrs)); + $this->messages[$this->currentMessage][$attrs['name']] = $attrs['type']; + } + if (isset($attrs['element'])) { + $this->messages[$this->currentMessage][$attrs['name']] = $attrs['element']; + } + } + break; + case 'portType': + switch ($name) { + case 'operation': + $this->currentPortOperation = $attrs['name']; + $this->debug("portType $this->currentPortType operation: $this->currentPortOperation"); + if (isset($attrs['parameterOrder'])) { + $this->portTypes[$this->currentPortType][$attrs['name']]['parameterOrder'] = $attrs['parameterOrder']; + } + break; + case 'documentation': + $this->documentation = true; + break; + // merge input/output data + default: + $m = isset($attrs['message']) ? $this->getLocalPart($attrs['message']) : ''; + $this->portTypes[$this->currentPortType][$this->currentPortOperation][$name]['message'] = $m; + break; + } + break; + case 'binding': + switch ($name) { + case 'binding': + // get ns prefix + if (isset($attrs['style'])) { + $this->bindings[$this->currentBinding]['prefix'] = $prefix; + } + $this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding], $attrs); + break; + case 'header': + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus]['headers'][] = $attrs; + break; + case 'operation': + if (isset($attrs['soapAction'])) { + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction']; + } + if (isset($attrs['style'])) { + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['style'] = $attrs['style']; + } + if (isset($attrs['name'])) { + $this->currentOperation = $attrs['name']; + $this->debug("current binding operation: $this->currentOperation"); + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['name'] = $attrs['name']; + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['binding'] = $this->currentBinding; + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['endpoint'] = isset($this->bindings[$this->currentBinding]['endpoint']) ? $this->bindings[$this->currentBinding]['endpoint'] : ''; + } + break; + case 'input': + $this->opStatus = 'input'; + break; + case 'output': + $this->opStatus = 'output'; + break; + case 'body': + if (isset($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus])) { + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = array_merge($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus], $attrs); + } else { + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs; + } + break; + } + break; + case 'service': + switch ($name) { + case 'port': + $this->currentPort = $attrs['name']; + $this->debug('current port: ' . $this->currentPort); + $this->ports[$this->currentPort]['binding'] = $this->getLocalPart($attrs['binding']); + + break; + case 'address': + $this->ports[$this->currentPort]['location'] = $attrs['location']; + $this->ports[$this->currentPort]['bindingType'] = $namespace; + $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['bindingType'] = $namespace; + $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['endpoint'] = $attrs['location']; + break; + } + break; + } + // set status + switch ($name) { + case "import": + if (isset($attrs['location'])) { + $this->import[$attrs['namespace']] = $attrs['location']; + } + break; + case 'types': + $this->status = 'schema'; + break; + case 'message': + $this->status = 'message'; + $this->messages[$attrs['name']] = array(); + $this->currentMessage = $attrs['name']; + break; + case 'portType': + $this->status = 'portType'; + $this->portTypes[$attrs['name']] = array(); + $this->currentPortType = $attrs['name']; + break; + case "binding": + if (isset($attrs['name'])) { + // get binding name + if (strpos($attrs['name'], ':')) { + $this->currentBinding = $this->getLocalPart($attrs['name']); + } else { + $this->currentBinding = $attrs['name']; + } + $this->status = 'binding'; + $this->bindings[$this->currentBinding]['portType'] = $this->getLocalPart($attrs['type']); + $this->debug("current binding: $this->currentBinding of portType: " . $attrs['type']); + } + break; + case 'service': + $this->serviceName = $attrs['name']; + $this->status = 'service'; + $this->debug('current service: ' . $this->serviceName); + break; + case 'definitions': + foreach ($attrs as $name => $value) { + $this->wsdl_info[$name] = $value; + } + break; + } + } + } /** * end-element handler @@ -3124,14 +3124,14 @@ class wsdl extends XMLSchema { */ function addOperation($name, $in = false, $out = false, $namespace = false, $soapaction = false, $style = 'rpc', $use = 'encoded', $documentation = '') { - if ($style == 'rpc' && $use == 'encoded') { + if ($style == 'rpc' && $use == 'encoded') { $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/'; - } else { + } else { $encodingStyle = ''; - } - // get binding - $this->bindings[ $this->serviceName . 'Binding' ]['operations'][$name] = - array( + } + // get binding + $this->bindings[ $this->serviceName . 'Binding' ]['operations'][$name] = + array( 'name' => $name, 'binding' => $this->serviceName . 'Binding', 'endpoint' => $this->endpoint, @@ -3152,8 +3152,8 @@ class wsdl extends XMLSchema { 'namespace' => $namespace, 'transport' => 'http://schemas.xmlsoap.org/soap/http', 'documentation' => $documentation); - // add portTypes - // add messages + // add portTypes + // add messages if($in) { foreach($in as $pName => $pType) @@ -3175,7 +3175,7 @@ class wsdl extends XMLSchema { $this->messages[$name.'Response'][$pName] = $pType; } } - return true; + return true; } } @@ -3229,382 +3229,382 @@ class soap_parser extends nusoap_base { * @access public */ function soap_parser($xml,$encoding='UTF-8',$method=''){ - $this->xml = $xml; - $this->xml_encoding = $encoding; - $this->method = $method; - - // Check whether content has been read. - if(!empty($xml)){ - $this->debug('Entering soap_parser()'); - // Create an XML parser. - $this->parser = xml_parser_create($this->xml_encoding); - // Set the options for parsing the XML data. - //xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); - xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); - // Set the object for the parser. - xml_set_object($this->parser, $this); - // Set the element handlers for the parser. - xml_set_element_handler($this->parser, 'start_element','end_element'); - xml_set_character_data_handler($this->parser,'character_data'); - - // Parse the XML file. - if(!xml_parse($this->parser,$xml,true)){ - // Display an error message. - $err = sprintf('XML error on line %d: %s', - xml_get_current_line_number($this->parser), - xml_error_string(xml_get_error_code($this->parser))); - $this->debug('parse error: '.$err); - $this->errstr = $err; - } else { - $this->debug('parsed successfully, found root struct: '.$this->root_struct.' of name '.$this->root_struct_name); - // get final value - $this->soapresponse = $this->message[$this->root_struct]['result']; - // get header value - if($this->root_header != '' && isset($this->message[$this->root_header]['result'])){ - $this->responseHeaders = $this->message[$this->root_header]['result']; - } - // resolve hrefs/ids - if(sizeof($this->multirefs) > 0){ - foreach($this->multirefs as $id => $hrefs){ - $this->debug('resolving multirefs for id: '.$id); - $idVal = $this->buildVal($this->ids[$id]); - foreach($hrefs as $refPos => $ref){ - $this->debug('resolving href at pos '.$refPos); - $this->multirefs[$id][$refPos] = $idVal; - } - } - } - } - xml_parser_free($this->parser); - } else { - $this->debug('xml was empty, didn\'t parse!'); - $this->errstr = 'xml was empty, didn\'t parse!'; - } - } - - /** - * start-element handler - * - * @param string $parser XML parser object - * @param string $name element name - * @param string $attrs associative array of attributes - * @access private - */ - function start_element($parser, $name, $attrs) { - // position in a total number of elements, starting from 0 - // update class level pos - $pos = $this->position++; - // and set mine - $this->message[$pos] = array('pos' => $pos,'children'=>'','cdata'=>''); - // depth = how many levels removed from root? - // set mine as current global depth and increment global depth value - $this->message[$pos]['depth'] = $this->depth++; - - // else add self as child to whoever the current parent is - if($pos != 0){ - $this->message[$this->parent]['children'] .= '|'.$pos; - } - // set my parent - $this->message[$pos]['parent'] = $this->parent; - // set self as current parent - $this->parent = $pos; - // set self as current value for this depth - $this->depth_array[$this->depth] = $pos; - // get element prefix - if(strpos($name,':')){ - // get ns prefix - $prefix = substr($name,0,strpos($name,':')); - // get unqualified name - $name = substr(strstr($name,':'),1); - } - // set status - if($name == 'Envelope'){ - $this->status = 'envelope'; - } elseif($name == 'Header'){ - $this->root_header = $pos; - $this->status = 'header'; - } elseif($name == 'Body'){ - $this->status = 'body'; - $this->body_position = $pos; - // set method - } elseif($this->status == 'body' && $pos == ($this->body_position+1)){ - $this->status = 'method'; - $this->root_struct_name = $name; - $this->root_struct = $pos; - $this->message[$pos]['type'] = 'struct'; - $this->debug("found root struct $this->root_struct_name, pos $this->root_struct"); - } - // set my status - $this->message[$pos]['status'] = $this->status; - // set name - $this->message[$pos]['name'] = htmlspecialchars($name); - // set attrs - $this->message[$pos]['attrs'] = $attrs; - - // loop through atts, logging ns and type declarations + $this->xml = $xml; + $this->xml_encoding = $encoding; + $this->method = $method; + + // Check whether content has been read. + if(!empty($xml)){ + $this->debug('Entering soap_parser()'); + // Create an XML parser. + $this->parser = xml_parser_create($this->xml_encoding); + // Set the options for parsing the XML data. + //xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); + xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); + // Set the object for the parser. + xml_set_object($this->parser, $this); + // Set the element handlers for the parser. + xml_set_element_handler($this->parser, 'start_element','end_element'); + xml_set_character_data_handler($this->parser,'character_data'); + + // Parse the XML file. + if(!xml_parse($this->parser,$xml,true)){ + // Display an error message. + $err = sprintf('XML error on line %d: %s', + xml_get_current_line_number($this->parser), + xml_error_string(xml_get_error_code($this->parser))); + $this->debug('parse error: '.$err); + $this->errstr = $err; + } else { + $this->debug('parsed successfully, found root struct: '.$this->root_struct.' of name '.$this->root_struct_name); + // get final value + $this->soapresponse = $this->message[$this->root_struct]['result']; + // get header value + if($this->root_header != '' && isset($this->message[$this->root_header]['result'])){ + $this->responseHeaders = $this->message[$this->root_header]['result']; + } + // resolve hrefs/ids + if(sizeof($this->multirefs) > 0){ + foreach($this->multirefs as $id => $hrefs){ + $this->debug('resolving multirefs for id: '.$id); + $idVal = $this->buildVal($this->ids[$id]); + foreach($hrefs as $refPos => $ref){ + $this->debug('resolving href at pos '.$refPos); + $this->multirefs[$id][$refPos] = $idVal; + } + } + } + } + xml_parser_free($this->parser); + } else { + $this->debug('xml was empty, didn\'t parse!'); + $this->errstr = 'xml was empty, didn\'t parse!'; + } + } + + /** + * start-element handler + * + * @param string $parser XML parser object + * @param string $name element name + * @param string $attrs associative array of attributes + * @access private + */ + function start_element($parser, $name, $attrs) { + // position in a total number of elements, starting from 0 + // update class level pos + $pos = $this->position++; + // and set mine + $this->message[$pos] = array('pos' => $pos,'children'=>'','cdata'=>''); + // depth = how many levels removed from root? + // set mine as current global depth and increment global depth value + $this->message[$pos]['depth'] = $this->depth++; + + // else add self as child to whoever the current parent is + if($pos != 0){ + $this->message[$this->parent]['children'] .= '|'.$pos; + } + // set my parent + $this->message[$pos]['parent'] = $this->parent; + // set self as current parent + $this->parent = $pos; + // set self as current value for this depth + $this->depth_array[$this->depth] = $pos; + // get element prefix + if(strpos($name,':')){ + // get ns prefix + $prefix = substr($name,0,strpos($name,':')); + // get unqualified name + $name = substr(strstr($name,':'),1); + } + // set status + if($name == 'Envelope'){ + $this->status = 'envelope'; + } elseif($name == 'Header'){ + $this->root_header = $pos; + $this->status = 'header'; + } elseif($name == 'Body'){ + $this->status = 'body'; + $this->body_position = $pos; + // set method + } elseif($this->status == 'body' && $pos == ($this->body_position+1)){ + $this->status = 'method'; + $this->root_struct_name = $name; + $this->root_struct = $pos; + $this->message[$pos]['type'] = 'struct'; + $this->debug("found root struct $this->root_struct_name, pos $this->root_struct"); + } + // set my status + $this->message[$pos]['status'] = $this->status; + // set name + $this->message[$pos]['name'] = htmlspecialchars($name); + // set attrs + $this->message[$pos]['attrs'] = $attrs; + + // loop through atts, logging ns and type declarations $attstr = ''; - foreach($attrs as $key => $value){ - $key_prefix = $this->getPrefix($key); - $key_localpart = $this->getLocalPart($key); - // if ns declarations, add to class level array of valid namespaces + foreach($attrs as $key => $value){ + $key_prefix = $this->getPrefix($key); + $key_localpart = $this->getLocalPart($key); + // if ns declarations, add to class level array of valid namespaces if($key_prefix == 'xmlns'){ - if(ereg('^http://www.w3.org/[0-9]{4}/XMLSchema$',$value)){ - $this->XMLSchemaVersion = $value; - $this->namespaces['xsd'] = $this->XMLSchemaVersion; - $this->namespaces['xsi'] = $this->XMLSchemaVersion.'-instance'; - } + if(ereg('^http://www.w3.org/[0-9]{4}/XMLSchema$',$value)){ + $this->XMLSchemaVersion = $value; + $this->namespaces['xsd'] = $this->XMLSchemaVersion; + $this->namespaces['xsi'] = $this->XMLSchemaVersion.'-instance'; + } $this->namespaces[$key_localpart] = $value; - // set method namespace - if($name == $this->root_struct_name){ - $this->methodNamespace = $value; - } - // if it's a type declaration, set type + // set method namespace + if($name == $this->root_struct_name){ + $this->methodNamespace = $value; + } + // if it's a type declaration, set type } elseif($key_localpart == 'type'){ - $value_prefix = $this->getPrefix($value); + $value_prefix = $this->getPrefix($value); $value_localpart = $this->getLocalPart($value); - $this->message[$pos]['type'] = $value_localpart; - $this->message[$pos]['typePrefix'] = $value_prefix; + $this->message[$pos]['type'] = $value_localpart; + $this->message[$pos]['typePrefix'] = $value_prefix; if(isset($this->namespaces[$value_prefix])){ - $this->message[$pos]['type_namespace'] = $this->namespaces[$value_prefix]; + $this->message[$pos]['type_namespace'] = $this->namespaces[$value_prefix]; } else if(isset($attrs['xmlns:'.$value_prefix])) { - $this->message[$pos]['type_namespace'] = $attrs['xmlns:'.$value_prefix]; - } - // should do something here with the namespace of specified type? - } elseif($key_localpart == 'arrayType'){ - $this->message[$pos]['type'] = 'array'; - /* do arrayType ereg here - [1] arrayTypeValue ::= atype asize - [2] atype ::= QName rank* - [3] rank ::= '[' (',')* ']' - [4] asize ::= '[' length~ ']' - [5] length ::= nextDimension* Digit+ - [6] nextDimension ::= Digit+ ',' - */ - $expr = '([A-Za-z0-9_]+):([A-Za-z]+[A-Za-z0-9_]+)\[([0-9]+),?([0-9]*)\]'; - if(ereg($expr,$value,$regs)){ - $this->message[$pos]['typePrefix'] = $regs[1]; - $this->message[$pos]['arraySize'] = $regs[3]; - $this->message[$pos]['arrayCols'] = $regs[4]; - } - } - // log id - if($key == 'id'){ - $this->ids[$value] = $pos; - } - // root - if($key_localpart == 'root' && $value == 1){ - $this->status = 'method'; - $this->root_struct_name = $name; - $this->root_struct = $pos; - $this->debug("found root struct $this->root_struct_name, pos $pos"); - } + $this->message[$pos]['type_namespace'] = $attrs['xmlns:'.$value_prefix]; + } + // should do something here with the namespace of specified type? + } elseif($key_localpart == 'arrayType'){ + $this->message[$pos]['type'] = 'array'; + /* do arrayType ereg here + [1] arrayTypeValue ::= atype asize + [2] atype ::= QName rank* + [3] rank ::= '[' (',')* ']' + [4] asize ::= '[' length~ ']' + [5] length ::= nextDimension* Digit+ + [6] nextDimension ::= Digit+ ',' + */ + $expr = '([A-Za-z0-9_]+):([A-Za-z]+[A-Za-z0-9_]+)\[([0-9]+),?([0-9]*)\]'; + if(ereg($expr,$value,$regs)){ + $this->message[$pos]['typePrefix'] = $regs[1]; + $this->message[$pos]['arraySize'] = $regs[3]; + $this->message[$pos]['arrayCols'] = $regs[4]; + } + } + // log id + if($key == 'id'){ + $this->ids[$value] = $pos; + } + // root + if($key_localpart == 'root' && $value == 1){ + $this->status = 'method'; + $this->root_struct_name = $name; + $this->root_struct = $pos; + $this->debug("found root struct $this->root_struct_name, pos $pos"); + } // for doclit $attstr .= " $key=\"$value\""; - } + } // get namespace - must be done after namespace atts are processed - if(isset($prefix)){ - $this->message[$pos]['namespace'] = $this->namespaces[$prefix]; - $this->default_namespace = $this->namespaces[$prefix]; - } else { - $this->message[$pos]['namespace'] = $this->default_namespace; - } + if(isset($prefix)){ + $this->message[$pos]['namespace'] = $this->namespaces[$prefix]; + $this->default_namespace = $this->namespaces[$prefix]; + } else { + $this->message[$pos]['namespace'] = $this->default_namespace; + } if($this->status == 'header'){ - $this->responseHeaders .= "<$name$attstr>"; + $this->responseHeaders .= "<$name$attstr>"; } elseif($this->root_struct_name != ''){ - $this->document .= "<$name$attstr>"; + $this->document .= "<$name$attstr>"; } - } + } - /** - * end-element handler - * - * @param string $parser XML parser object - * @param string $name element name - * @access private - */ - function end_element($parser, $name) { - // position of current element is equal to the last value left in depth_array for my depth - $pos = $this->depth_array[$this->depth--]; + /** + * end-element handler + * + * @param string $parser XML parser object + * @param string $name element name + * @access private + */ + function end_element($parser, $name) { + // position of current element is equal to the last value left in depth_array for my depth + $pos = $this->depth_array[$this->depth--]; // get element prefix - if(strpos($name,':')){ - // get ns prefix - $prefix = substr($name,0,strpos($name,':')); - // get unqualified name - $name = substr(strstr($name,':'),1); - } - - // build to native type - if(isset($this->body_position) && $pos > $this->body_position){ - // deal w/ multirefs - if(isset($this->message[$pos]['attrs']['href'])){ - // get id - $id = substr($this->message[$pos]['attrs']['href'],1); - // add placeholder to href array - $this->multirefs[$id][$pos] = "placeholder"; - // add set a reference to it as the result value - $this->message[$pos]['result'] =& $this->multirefs[$id][$pos]; + if(strpos($name,':')){ + // get ns prefix + $prefix = substr($name,0,strpos($name,':')); + // get unqualified name + $name = substr(strstr($name,':'),1); + } + + // build to native type + if(isset($this->body_position) && $pos > $this->body_position){ + // deal w/ multirefs + if(isset($this->message[$pos]['attrs']['href'])){ + // get id + $id = substr($this->message[$pos]['attrs']['href'],1); + // add placeholder to href array + $this->multirefs[$id][$pos] = "placeholder"; + // add set a reference to it as the result value + $this->message[$pos]['result'] =& $this->multirefs[$id][$pos]; // build complex values - } elseif($this->message[$pos]['children'] != ""){ - $this->message[$pos]['result'] = $this->buildVal($pos); - } else { - $this->debug('adding data for scalar value '.$this->message[$pos]['name'].' of value '.$this->message[$pos]['cdata']); - if(is_numeric($this->message[$pos]['cdata']) ){ - if( strpos($this->message[$pos]['cdata'],'.') ){ - $this->message[$pos]['result'] = doubleval($this->message[$pos]['cdata']); + } elseif($this->message[$pos]['children'] != ""){ + $this->message[$pos]['result'] = $this->buildVal($pos); + } else { + $this->debug('adding data for scalar value '.$this->message[$pos]['name'].' of value '.$this->message[$pos]['cdata']); + if(is_numeric($this->message[$pos]['cdata']) ){ + if( strpos($this->message[$pos]['cdata'],'.') ){ + $this->message[$pos]['result'] = doubleval($this->message[$pos]['cdata']); } else { - $this->message[$pos]['result'] = intval($this->message[$pos]['cdata']); + $this->message[$pos]['result'] = intval($this->message[$pos]['cdata']); } } else { - $this->message[$pos]['result'] = $this->message[$pos]['cdata']; - } - } - } - - // switch status - if($pos == $this->root_struct){ - $this->status = 'body'; - } elseif($name == 'Body'){ - $this->status = 'header'; - } elseif($name == 'Header'){ - $this->status = 'envelope'; - } elseif($name == 'Envelope'){ - // - } - // set parent back to my parent - $this->parent = $this->message[$pos]['parent']; + $this->message[$pos]['result'] = $this->message[$pos]['cdata']; + } + } + } + + // switch status + if($pos == $this->root_struct){ + $this->status = 'body'; + } elseif($name == 'Body'){ + $this->status = 'header'; + } elseif($name == 'Header'){ + $this->status = 'envelope'; + } elseif($name == 'Envelope'){ + // + } + // set parent back to my parent + $this->parent = $this->message[$pos]['parent']; // for doclit if($this->status == 'header'){ - $this->responseHeaders .= ""; + $this->responseHeaders .= ""; } elseif($pos >= $this->root_struct){ - $this->document .= ""; - } - } - - /** - * element content handler - * - * @param string $parser XML parser object - * @param string $data element content - * @access private - */ - function character_data($parser, $data){ - $pos = $this->depth_array[$this->depth]; - if ($this->xml_encoding=='UTF-8'){ - $data = utf8_decode($data); - } + $this->document .= ""; + } + } + + /** + * element content handler + * + * @param string $parser XML parser object + * @param string $data element content + * @access private + */ + function character_data($parser, $data){ + $pos = $this->depth_array[$this->depth]; + if ($this->xml_encoding=='UTF-8'){ + $data = utf8_decode($data); + } $this->message[$pos]['cdata'] .= $data; // for doclit if($this->status == 'header'){ - $this->responseHeaders .= $data; + $this->responseHeaders .= $data; } else { - $this->document .= $data; - } - } - - /** - * get the parsed message - * - * @return mixed - * @access public - */ - function get_response(){ - return $this->soapresponse; - } - - /** - * get the parsed headers - * - * @return string XML or empty if no headers - * @access public - */ - function getHeaders(){ - return $this->responseHeaders; - } - - /** - * decodes entities - * - * @param string $text string to translate - * @access private - */ - function decode_entities($text){ - foreach($this->entities as $entity => $encoded){ - $text = str_replace($encoded,$entity,$text); - } - return $text; - } - - /** - * builds response structures for compound values (arrays/structs) - * - * @param string $pos position in node tree - * @access private - */ - function buildVal($pos){ - if(!isset($this->message[$pos]['type'])){ - $this->message[$pos]['type'] = ''; - } - $this->debug('inside buildVal() for '.$this->message[$pos]['name']."(pos $pos) of type ".$this->message[$pos]['type']); - // if there are children... - if($this->message[$pos]['children'] != ''){ - $children = explode('|',$this->message[$pos]['children']); - array_shift($children); // knock off empty - // md array - if(isset($this->message[$pos]['arrayCols']) && $this->message[$pos]['arrayCols'] != ''){ - $r=0; // rowcount - $c=0; // colcount - foreach($children as $child_pos){ - $this->debug("got an MD array element: $r, $c"); - $params[$r][] = $this->message[$child_pos]['result']; - $c++; - if($c == $this->message[$pos]['arrayCols']){ - $c = 0; - $r++; - } + $this->document .= $data; + } + } + + /** + * get the parsed message + * + * @return mixed + * @access public + */ + function get_response(){ + return $this->soapresponse; + } + + /** + * get the parsed headers + * + * @return string XML or empty if no headers + * @access public + */ + function getHeaders(){ + return $this->responseHeaders; + } + + /** + * decodes entities + * + * @param string $text string to translate + * @access private + */ + function decode_entities($text){ + foreach($this->entities as $entity => $encoded){ + $text = str_replace($encoded,$entity,$text); + } + return $text; + } + + /** + * builds response structures for compound values (arrays/structs) + * + * @param string $pos position in node tree + * @access private + */ + function buildVal($pos){ + if(!isset($this->message[$pos]['type'])){ + $this->message[$pos]['type'] = ''; + } + $this->debug('inside buildVal() for '.$this->message[$pos]['name']."(pos $pos) of type ".$this->message[$pos]['type']); + // if there are children... + if($this->message[$pos]['children'] != ''){ + $children = explode('|',$this->message[$pos]['children']); + array_shift($children); // knock off empty + // md array + if(isset($this->message[$pos]['arrayCols']) && $this->message[$pos]['arrayCols'] != ''){ + $r=0; // rowcount + $c=0; // colcount + foreach($children as $child_pos){ + $this->debug("got an MD array element: $r, $c"); + $params[$r][] = $this->message[$child_pos]['result']; + $c++; + if($c == $this->message[$pos]['arrayCols']){ + $c = 0; + $r++; + } } // array - } elseif($this->message[$pos]['type'] == 'array' || $this->message[$pos]['type'] == 'Array'){ + } elseif($this->message[$pos]['type'] == 'array' || $this->message[$pos]['type'] == 'Array'){ $this->debug('adding array '.$this->message[$pos]['name']); foreach($children as $child_pos){ - $params[] = &$this->message[$child_pos]['result']; + $params[] = &$this->message[$child_pos]['result']; } // apache Map type: java hashtable } elseif($this->message[$pos]['type'] == 'Map' && $this->message[$pos]['type_namespace'] == 'http://xml.apache.org/xml-soap'){ foreach($children as $child_pos){ - $kv = explode("|",$this->message[$child_pos]['children']); - $params[$this->message[$kv[1]]['result']] = &$this->message[$kv[2]]['result']; + $kv = explode("|",$this->message[$child_pos]['children']); + $params[$this->message[$kv[1]]['result']] = &$this->message[$kv[2]]['result']; } // generic compound type //} elseif($this->message[$pos]['type'] == 'SOAPStruct' || $this->message[$pos]['type'] == 'struct') { } else { - // is array or struct? better way to do this probably - foreach($children as $child_pos){ - if(isset($keys) && isset($keys[$this->message[$child_pos]['name']])){ - $struct = 1; - break; - } - $keys[$this->message[$child_pos]['name']] = 1; - } - // - foreach($children as $child_pos){ - if(isset($struct)){ - $params[] = &$this->message[$child_pos]['result']; - } else { - $params[$this->message[$child_pos]['name']] = &$this->message[$child_pos]['result']; - } - } - } - return is_array($params) ? $params : array(); - } else { - $this->debug('no children'); + // is array or struct? better way to do this probably + foreach($children as $child_pos){ + if(isset($keys) && isset($keys[$this->message[$child_pos]['name']])){ + $struct = 1; + break; + } + $keys[$this->message[$child_pos]['name']] = 1; + } + // + foreach($children as $child_pos){ + if(isset($struct)){ + $params[] = &$this->message[$child_pos]['result']; + } else { + $params[$this->message[$child_pos]['name']] = &$this->message[$child_pos]['result']; + } + } + } + return is_array($params) ? $params : array(); + } else { + $this->debug('no children'); if(strpos($this->message[$pos]['cdata'],'&')){ - return strtr($this->message[$pos]['cdata'],array_flip($this->entities)); + return strtr($this->message[$pos]['cdata'],array_flip($this->entities)); } else { - return $this->message[$pos]['cdata']; + return $this->message[$pos]['cdata']; } - } - } + } + } } @@ -3771,7 +3771,7 @@ class pwsoapclient extends nusoap_base { $style = 'rpc'; } if($namespace == ''){ - $namespace = 'http://testuri.org'; + $namespace = 'http://testuri.org'; $this->wsdl->namespaces['ns1'] = $namespace; } // serialize envelope @@ -3820,19 +3820,19 @@ class pwsoapclient extends nusoap_base { } } - /** - * get available data pertaining to an operation - * - * @param string $operation operation name - * @return array array of data pertaining to the operation - * @access public - */ - function getOperationData($operation){ - if(isset($this->operations[$operation])){ - return $this->operations[$operation]; - } - $this->debug("No data for operation: $operation"); - } + /** + * get available data pertaining to an operation + * + * @param string $operation operation name + * @return array array of data pertaining to the operation + * @access public + */ + function getOperationData($operation){ + if(isset($this->operations[$operation])){ + return $this->operations[$operation]; + } + $this->debug("No data for operation: $operation"); + } /** * send the SOAP message @@ -3841,85 +3841,85 @@ class pwsoapclient extends nusoap_base { * the return value of this method will be an array * of those values. * - * @param string $msg a SOAPx4 soapmsg object - * @param string $soapaction SOAPAction value - * @param integer $timeout set timeout in seconds - * @return mixed native PHP types. - * @access private - */ - function send($msg, $soapaction = '', $timeout=0) { - // detect transport - switch(true){ - // http(s) - case ereg('^http',$this->endpoint): - $this->debug('transporting via HTTP'); - if($this->persistentConnection && is_object($this->persistentConnection)){ - $http =& $this->persistentConnection; - } else { - $http = new soap_transport_http($this->endpoint); - // pass encoding into transport layer, so appropriate http headers are sent - $http->soap_defencoding = $this->soap_defencoding; - } - $http->setSOAPAction($soapaction); - if($this->proxyhost && $this->proxyport){ - $http->setProxy($this->proxyhost,$this->proxyport); - } + * @param string $msg a SOAPx4 soapmsg object + * @param string $soapaction SOAPAction value + * @param integer $timeout set timeout in seconds + * @return mixed native PHP types. + * @access private + */ + function send($msg, $soapaction = '', $timeout=0) { + // detect transport + switch(true){ + // http(s) + case ereg('^http',$this->endpoint): + $this->debug('transporting via HTTP'); + if($this->persistentConnection && is_object($this->persistentConnection)){ + $http =& $this->persistentConnection; + } else { + $http = new soap_transport_http($this->endpoint); + // pass encoding into transport layer, so appropriate http headers are sent + $http->soap_defencoding = $this->soap_defencoding; + } + $http->setSOAPAction($soapaction); + if($this->proxyhost && $this->proxyport){ + $http->setProxy($this->proxyhost,$this->proxyport); + } if($this->username != '' && $this->password != '') { - $http->setCredentials($this->username,$this->password); - } - if($this->http_encoding != ''){ - $http->setEncoding($this->http_encoding); - } - $this->debug('sending message, length: '.strlen($msg)); - if(ereg('^http:',$this->endpoint)){ - //if(strpos($this->endpoint,'http:')){ - $response = $http->send($msg,$timeout); - } elseif(ereg('^https',$this->endpoint)){ - //} elseif(strpos($this->endpoint,'https:')){ - //if(phpversion() == '4.3.0-dev'){ - //$response = $http->send($msg,$timeout); - //$this->request = $http->outgoing_payload; - //$this->response = $http->incoming_payload; - //} else - if (extension_loaded('curl')) { - $response = $http->sendHTTPS($msg,$timeout); - } else { - $this->setError('CURL Extension, or OpenSSL extension w/ PHP version >= 4.3 is required for HTTPS'); - } - } else { - $this->setError('no http/s in endpoint url'); - } - $this->request = $http->outgoing_payload; - $this->response = $http->incoming_payload; - $this->debug("transport debug data...\n".$http->debug_str); - // save transport object if using persistent connections - if($this->persistentConnection && !is_object($this->persistentConnection)){ - $this->persistentConnection = $http; - } - if($err = $http->getError()){ - $this->setError('HTTP Error: '.$err); - return false; - } elseif($this->getError()){ - return false; - } else { - $this->debug('got response, length: '.strlen($response)); - return $this->parseResponse($response); - } - break; - default: - $this->setError('no transport found, or selected transport is not yet supported!'); - return false; - break; - } - } - - /** - * processes SOAP message returned from server - * - * @param string unprocessed response data from server - * @return mixed value of the message, decoded into a PHP type - * @access private - */ + $http->setCredentials($this->username,$this->password); + } + if($this->http_encoding != ''){ + $http->setEncoding($this->http_encoding); + } + $this->debug('sending message, length: '.strlen($msg)); + if(ereg('^http:',$this->endpoint)){ + //if(strpos($this->endpoint,'http:')){ + $response = $http->send($msg,$timeout); + } elseif(ereg('^https',$this->endpoint)){ + //} elseif(strpos($this->endpoint,'https:')){ + //if(phpversion() == '4.3.0-dev'){ + //$response = $http->send($msg,$timeout); + //$this->request = $http->outgoing_payload; + //$this->response = $http->incoming_payload; + //} else + if (extension_loaded('curl')) { + $response = $http->sendHTTPS($msg,$timeout); + } else { + $this->setError('CURL Extension, or OpenSSL extension w/ PHP version >= 4.3 is required for HTTPS'); + } + } else { + $this->setError('no http/s in endpoint url'); + } + $this->request = $http->outgoing_payload; + $this->response = $http->incoming_payload; + $this->debug("transport debug data...\n".$http->debug_str); + // save transport object if using persistent connections + if($this->persistentConnection && !is_object($this->persistentConnection)){ + $this->persistentConnection = $http; + } + if($err = $http->getError()){ + $this->setError('HTTP Error: '.$err); + return false; + } elseif($this->getError()){ + return false; + } else { + $this->debug('got response, length: '.strlen($response)); + return $this->parseResponse($response); + } + break; + default: + $this->setError('no transport found, or selected transport is not yet supported!'); + return false; + break; + } + } + + /** + * processes SOAP message returned from server + * + * @param string unprocessed response data from server + * @return mixed value of the message, decoded into a PHP type + * @access private + */ function parseResponse($data) { $this->debug('Entering parseResponse(), about to create soap_parser instance'); $parser = new soap_parser($data,$this->xml_encoding,$this->operation); @@ -3967,61 +3967,61 @@ class pwsoapclient extends nusoap_base { } } - /** + /** * set proxy info here * * @param string $proxyhost * @param string $proxyport * @access public */ - function setHTTPProxy($proxyhost, $proxyport) { + function setHTTPProxy($proxyhost, $proxyport) { $this->proxyhost = $proxyhost; $this->proxyport = $proxyport; - } + } - /** + /** * if authenticating, set user credentials here * * @param string $username * @param string $password * @access public */ - function setCredentials($username, $password) { + function setCredentials($username, $password) { $this->username = $username; $this->password = $password; - } + } - /** + /** * use HTTP encoding * * @param string $enc * @access public */ - function setHTTPEncoding($enc='gzip, deflate'){ + function setHTTPEncoding($enc='gzip, deflate'){ $this->http_encoding = $enc; - } + } - /** + /** * use HTTP persistent connections if possible * * @access public */ - function useHTTPPersistentConnection(){ + function useHTTPPersistentConnection(){ $this->persistentConnection = true; - } + } - /** + /** * gets the default RPC parameter setting. * If true, default is that call params are like RPC even for document style. * Each call() can override this value. * * @access public */ - function getDefaultRpcParams() { + function getDefaultRpcParams() { return $this->defaultRpcParams; - } + } - /** + /** * sets the default RPC parameter setting. * If true, default is that call params are like RPC even for document style * Each call() can override this value. @@ -4029,17 +4029,17 @@ class pwsoapclient extends nusoap_base { * @param boolean $rpcParams * @access public */ - function setDefaultRpcParams($rpcParams) { + function setDefaultRpcParams($rpcParams) { $this->defaultRpcParams = $rpcParams; - } + } - /** + /** * dynamically creates proxy class, allowing user to directly call methods from wsdl * * @return object soap_proxy object * @access public */ - function getProxy(){ + function getProxy(){ $evalStr = ''; foreach($this->operations as $operation => $opData){ if($operation != ''){ @@ -4053,17 +4053,17 @@ class pwsoapclient extends nusoap_base { } $opData['namespace'] = !isset($opData['namespace']) ? 'http://testuri.com' : $opData['namespace']; $evalStr .= "function $operation ($paramStr){ - // load params into array - \$params = array($paramStr); - return \$this->call('$operation',\$params,'".$opData['namespace']."','".$opData['soapAction']."'); - }"; + // load params into array + \$params = array($paramStr); + return \$this->call('$operation',\$params,'".$opData['namespace']."','".$opData['soapAction']."'); + }"; unset($paramStr); } } $r = rand(); $evalStr = 'class soap_proxy_'.$r.' extends soapclient { - '.$evalStr.' - }'; + '.$evalStr.' + }'; //print "proxy class:
$evalStr
"; // eval the class eval($evalStr); @@ -4076,7 +4076,7 @@ class pwsoapclient extends nusoap_base { $proxy->operations = $this->operations; $proxy->defaultRpcParams = $this->defaultRpcParams; return $proxy; - } + } } // Local Variables: diff --git a/lib/pear/Cache/Container/file.php b/lib/pear/Cache/Container/file.php index c6698b54a..49f33ba5a 100644 --- a/lib/pear/Cache/Container/file.php +++ b/lib/pear/Cache/Container/file.php @@ -195,7 +195,7 @@ class Cache_Container_file extends Cache_Container { fclose($fh); // I'm not sure if we need this - // i don't think we need this (chregu) + // i don't think we need this (chregu) // touch($file); return true; diff --git a/lib/pear/Cache/Container/imgfile.php b/lib/pear/Cache/Container/imgfile.php index 472d335ab..cade0ddeb 100644 --- a/lib/pear/Cache/Container/imgfile.php +++ b/lib/pear/Cache/Container/imgfile.php @@ -165,7 +165,7 @@ class Cache_Container_file extends Cache_Container { fclose($fh); // I'm not sure if we need this - // i don't think we need this (chregu) + // i don't think we need this (chregu) // touch($file); //JOHANNES START diff --git a/lib/pear/File_Passwd.php b/lib/pear/File_Passwd.php index f71dbbda4..a414f67d3 100644 --- a/lib/pear/File_Passwd.php +++ b/lib/pear/File_Passwd.php @@ -92,13 +92,13 @@ class File_Passwd { //check if already locked, on some error or race condition or other user. //FIXME: implement timeout as with dba if (!empty($this->lockfile) and file_exists($this->lockfile)) { - if (isset($GLOBALS['HTTP_GET_VARS']['force_unlock'])) { - $this->fplock = fopen($this->lockfile, 'w'); - flock($this->fplock, LOCK_UN); - fclose($this->fplock); - } else { + if (isset($GLOBALS['HTTP_GET_VARS']['force_unlock'])) { + $this->fplock = fopen($this->lockfile, 'w'); + flock($this->fplock, LOCK_UN); + fclose($this->fplock); + } else { trigger_error('File_Passwd lock conflict: Try &force_unlock=1',E_USER_NOTICE); - } + } } $this->fplock = fopen($this->lockfile, 'w'); flock($this->fplock, LOCK_EX); diff --git a/tests/unit/lib/InlineParserTest.php b/tests/unit/lib/InlineParserTest.php index d2a32cac5..8a0199ee0 100644 --- a/tests/unit/lib/InlineParserTest.php +++ b/tests/unit/lib/InlineParserTest.php @@ -13,44 +13,44 @@ class InlineParserTest extends phpwiki_TestCase { function _tests() { $uplink = getUploadDataPath().'/image.jpg'; // last update: 1.3.13 - return array( - "[label|link]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:4:"link";s:6:"_label";s:5:"label";s:9:"_basepage";b:0;}i:2;s:0:"";}}', - "[ label | link.jpg ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:8:"link.jpg";s:6:"_label";s:5:"label";s:9:"_basepage";b:0;}i:2;s:0:"";}}', - "[ image.jpg | link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"HtmlElement":4:{s:4:"_tag";s:6:"object";s:5:"_attr";a:5:{s:3:"src";s:0:"";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:12:"inlineobject";s:4:"type";b:0;}s:8:"_content";a:1:{i:0;O:11:"HtmlElement":4:{s:4:"_tag";s:5:"embed";s:5:"_attr";a:5:{s:3:"src";s:0:"";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:12:"inlineobject";s:4:"type";b:0;}s:8:"_content";a:0:{}s:11:"_properties";i:4;}}s:11:"_properties";i:6;}s:9:"_basepage";b:0;}i:2;s:0:"";}}', - "[ Upload:image.jpg | link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"HtmlElement":4:{s:4:"_tag";s:3:"img";s:5:"_attr";a:4:{s:3:"src";s:'.strlen($uplink).':"'.$uplink.'";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:11:"inlineimage";}s:8:"_content";a:0:{}s:11:"_properties";i:7;}s:9:"_basepage";b:0;}i:2;s:0:"";}}', - "[ http://server/image.jpg | link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"HtmlElement":4:{s:4:"_tag";s:3:"img";s:5:"_attr";a:4:{s:3:"src";s:23:"http://server/image.jpg";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:11:"inlineimage";}s:8:"_content";a:0:{}s:11:"_properties";i:7;}s:9:"_basepage";b:0;}i:2;s:0:"";}}', - "[ label | http://server/link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":2:{s:4:"_url";s:18:"http://server/link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', - "[ label | Upload:link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:20:"Cached_InterwikiLink":2:{s:5:"_link";s:11:"Upload:link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', - "[ label | phpwiki:action=link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:17:"Cached_PhpwikiURL":2:{s:4:"_url";s:19:"phpwiki:action=link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', - "Upload:image.jpg" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:20:"Cached_InterwikiLink":1:{s:5:"_link";s:16:"Upload:image.jpg";}i:2;s:0:"";}}', - "http://server/image.jpg" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":1:{s:4:"_url";s:23:"http://server/image.jpg";}i:2;s:0:"";}}', - "http://server/link" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":1:{s:4:"_url";s:18:"http://server/link";}i:2;s:0:"";}}', - "[http:/server/~name/]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":1:{s:4:"_url";s:18:"http:/server/name/";}i:2;s:0:"";}}', - "http:/server/~name/" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":1:{s:4:"_url";s:18:"http:/server/name/";}i:2;s:0:"";}}', - "[label|:link]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":4:{s:5:"_page";s:4:"link";s:7:"_nolink";b:1;s:6:"_label";s:5:"label";s:9:"_basepage";b:0;}i:2;s:0:"";}}', - "[:link]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:4:"link";s:7:"_nolink";b:1;s:9:"_basepage";b:0;}i:2;s:0:"";}}', - "relation::link" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":3:{s:4:"_url";s:14:"relation::link";s:9:"_relation";s:8:"relation";s:5:"_page";s:4:"link";}i:2;s:0:"";}}', - "[label|relation::link]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":4:{s:4:"_url";s:14:"relation::link";s:6:"_label";s:5:"label";s:9:"_relation";s:8:"relation";s:5:"_page";s:4:"link";}i:2;s:0:"";}}', - "attribute:=1000" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":5:{s:4:"_url";s:15:"attribute:=1000";s:9:"_relation";s:9:"attribute";s:10:"_attribute";s:4:"1000";s:15:"_attribute_base";s:4:"1000";s:5:"_unit";s:0:"";}i:2;s:0:"";}}', - "attribute:=1,000km" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":5:{s:4:"_url";s:18:"attribute:=1,000km";s:9:"_relation";s:9:"attribute";s:10:"_attribute";s:7:"1,000km";s:15:"_attribute_base";s:9:"1000000 m";s:5:"_unit";s:1:"m";}i:2;s:0:"";}}', - "attribute:=1,000 km" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":5:{s:4:"_url";s:16:"attribute:=1,000";s:9:"_relation";s:9:"attribute";s:10:"_attribute";s:5:"1,000";s:15:"_attribute_base";s:4:"1000";s:5:"_unit";s:0:"";}i:2;s:3:" km";}}', - "[attribute:=1,000 km]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":5:{s:4:"_url";s:19:"attribute:=1,000 km";s:9:"_relation";s:9:"attribute";s:10:"_attribute";s:8:"1,000 km";s:15:"_attribute_base";s:9:"1000000 m";s:5:"_unit";s:1:"m";}i:2;s:0:"";}}', - "[label|attribute:=1,000 km]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":6:{s:4:"_url";s:19:"attribute:=1,000 km";s:6:"_label";s:5:"label";s:9:"_relation";s:9:"attribute";s:10:"_attribute";s:8:"1,000 km";s:15:"_attribute_base";s:9:"1000000 m";s:5:"_unit";s:1:"m";}i:2;s:0:"";}}', - "This is a :PageLink" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:11:"This is a :";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:8:"PageLink";s:9:"_basepage";b:0;}i:2;s:0:"";}}', - "This is a ::PageLink" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:12:"This is a ::";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:8:"PageLink";s:9:"_basepage";b:0;}i:2;s:0:"";}}', - "This is a :=PageAttr" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:12:"This is a :=";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:8:"PageAttr";s:9:"_basepage";b:0;}i:2;s:0:"";}}', - "This is :~NoLink" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:9:"This is :";i:1;s:6:"NoLink";i:2;s:0:"";}}', - "This is ::~NoLink" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:10:"This is ::";i:1;s:6:"NoLink";i:2;s:0:"";}}', - "This is :=~NoLink" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:10:"This is :=";i:1;s:6:"NoLink";i:2;s:0:"";}}'); + return array( + "[label|link]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:4:"link";s:6:"_label";s:5:"label";s:9:"_basepage";b:0;}i:2;s:0:"";}}', + "[ label | link.jpg ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:8:"link.jpg";s:6:"_label";s:5:"label";s:9:"_basepage";b:0;}i:2;s:0:"";}}', + "[ image.jpg | link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"HtmlElement":4:{s:4:"_tag";s:6:"object";s:5:"_attr";a:5:{s:3:"src";s:0:"";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:12:"inlineobject";s:4:"type";b:0;}s:8:"_content";a:1:{i:0;O:11:"HtmlElement":4:{s:4:"_tag";s:5:"embed";s:5:"_attr";a:5:{s:3:"src";s:0:"";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:12:"inlineobject";s:4:"type";b:0;}s:8:"_content";a:0:{}s:11:"_properties";i:4;}}s:11:"_properties";i:6;}s:9:"_basepage";b:0;}i:2;s:0:"";}}', + "[ Upload:image.jpg | link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"HtmlElement":4:{s:4:"_tag";s:3:"img";s:5:"_attr";a:4:{s:3:"src";s:'.strlen($uplink).':"'.$uplink.'";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:11:"inlineimage";}s:8:"_content";a:0:{}s:11:"_properties";i:7;}s:9:"_basepage";b:0;}i:2;s:0:"";}}', + "[ http://server/image.jpg | link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"HtmlElement":4:{s:4:"_tag";s:3:"img";s:5:"_attr";a:4:{s:3:"src";s:23:"http://server/image.jpg";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:11:"inlineimage";}s:8:"_content";a:0:{}s:11:"_properties";i:7;}s:9:"_basepage";b:0;}i:2;s:0:"";}}', + "[ label | http://server/link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":2:{s:4:"_url";s:18:"http://server/link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', + "[ label | Upload:link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:20:"Cached_InterwikiLink":2:{s:5:"_link";s:11:"Upload:link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', + "[ label | phpwiki:action=link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:17:"Cached_PhpwikiURL":2:{s:4:"_url";s:19:"phpwiki:action=link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', + "Upload:image.jpg" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:20:"Cached_InterwikiLink":1:{s:5:"_link";s:16:"Upload:image.jpg";}i:2;s:0:"";}}', + "http://server/image.jpg" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":1:{s:4:"_url";s:23:"http://server/image.jpg";}i:2;s:0:"";}}', + "http://server/link" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":1:{s:4:"_url";s:18:"http://server/link";}i:2;s:0:"";}}', + "[http:/server/~name/]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":1:{s:4:"_url";s:18:"http:/server/name/";}i:2;s:0:"";}}', + "http:/server/~name/" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":1:{s:4:"_url";s:18:"http:/server/name/";}i:2;s:0:"";}}', + "[label|:link]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":4:{s:5:"_page";s:4:"link";s:7:"_nolink";b:1;s:6:"_label";s:5:"label";s:9:"_basepage";b:0;}i:2;s:0:"";}}', + "[:link]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:4:"link";s:7:"_nolink";b:1;s:9:"_basepage";b:0;}i:2;s:0:"";}}', + "relation::link" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":3:{s:4:"_url";s:14:"relation::link";s:9:"_relation";s:8:"relation";s:5:"_page";s:4:"link";}i:2;s:0:"";}}', + "[label|relation::link]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":4:{s:4:"_url";s:14:"relation::link";s:6:"_label";s:5:"label";s:9:"_relation";s:8:"relation";s:5:"_page";s:4:"link";}i:2;s:0:"";}}', + "attribute:=1000" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":5:{s:4:"_url";s:15:"attribute:=1000";s:9:"_relation";s:9:"attribute";s:10:"_attribute";s:4:"1000";s:15:"_attribute_base";s:4:"1000";s:5:"_unit";s:0:"";}i:2;s:0:"";}}', + "attribute:=1,000km" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":5:{s:4:"_url";s:18:"attribute:=1,000km";s:9:"_relation";s:9:"attribute";s:10:"_attribute";s:7:"1,000km";s:15:"_attribute_base";s:9:"1000000 m";s:5:"_unit";s:1:"m";}i:2;s:0:"";}}', + "attribute:=1,000 km" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":5:{s:4:"_url";s:16:"attribute:=1,000";s:9:"_relation";s:9:"attribute";s:10:"_attribute";s:5:"1,000";s:15:"_attribute_base";s:4:"1000";s:5:"_unit";s:0:"";}i:2;s:3:" km";}}', + "[attribute:=1,000 km]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":5:{s:4:"_url";s:19:"attribute:=1,000 km";s:9:"_relation";s:9:"attribute";s:10:"_attribute";s:8:"1,000 km";s:15:"_attribute_base";s:9:"1000000 m";s:5:"_unit";s:1:"m";}i:2;s:0:"";}}', + "[label|attribute:=1,000 km]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":6:{s:4:"_url";s:19:"attribute:=1,000 km";s:6:"_label";s:5:"label";s:9:"_relation";s:9:"attribute";s:10:"_attribute";s:8:"1,000 km";s:15:"_attribute_base";s:9:"1000000 m";s:5:"_unit";s:1:"m";}i:2;s:0:"";}}', + "This is a :PageLink" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:11:"This is a :";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:8:"PageLink";s:9:"_basepage";b:0;}i:2;s:0:"";}}', + "This is a ::PageLink" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:12:"This is a ::";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:8:"PageLink";s:9:"_basepage";b:0;}i:2;s:0:"";}}', + "This is a :=PageAttr" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:12:"This is a :=";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:8:"PageAttr";s:9:"_basepage";b:0;}i:2;s:0:"";}}', + "This is :~NoLink" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:9:"This is :";i:1;s:6:"NoLink";i:2;s:0:"";}}', + "This is ::~NoLink" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:10:"This is ::";i:1;s:6:"NoLink";i:2;s:0:"";}}', + "This is :=~NoLink" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:10:"This is :=";i:1;s:6:"NoLink";i:2;s:0:"";}}'); } function runTest() { - if (substr($this->_name,0,5) == "_test") { - $name = rawurldecode(substr($this->_name,5)); - $this->_testLink($name); - } else { - call_user_func(array(&$this, $this->_name)); - } + if (substr($this->_name,0,5) == "_test") { + $name = rawurldecode(substr($this->_name,5)); + $this->_testLink($name); + } else { + call_user_func(array(&$this, $this->_name)); + } } function testNoWikiWords() { @@ -85,7 +85,7 @@ class InlineParserTest extends phpwiki_TestCase { $this->assertTrue(isa($xml, 'XmlContent')); $expectobj = unserialize($expected); /* if (DEBUG & _DEBUG_VERBOSE) - echo "\t\"",$wiki,'" => \'',serialize($xml),"',\n"; flush(); */ + echo "\t\"",$wiki,'" => \'',serialize($xml),"',\n"; flush(); */ $this->assertEquals($expectobj, $xml); } } diff --git a/tests/unit/lib/SetupWiki.php b/tests/unit/lib/SetupWiki.php index 0146960a3..1a96c5e22 100644 --- a/tests/unit/lib/SetupWiki.php +++ b/tests/unit/lib/SetupWiki.php @@ -25,12 +25,12 @@ class SetupWiki extends phpwiki_TestCase { /* // Broken since r.7418 function testOldMarkupTestPage() { - $this->_loadPage('Help/OldMarkupTestPage'); + $this->_loadPage('Help/OldMarkupTestPage'); }*/ /* ADODB set_links _id_cache error: IncludePagePlugin => HomePage */ function testIncludePagePlugin() { - $this->_loadPage('Help/IncludePagePlugin'); + $this->_loadPage('Help/IncludePagePlugin'); } function testSetupWiki() { diff --git a/tests/unit/lib/TextSearchTest.php b/tests/unit/lib/TextSearchTest.php index 22d4aba8f..b435b46b9 100644 --- a/tests/unit/lib/TextSearchTest.php +++ b/tests/unit/lib/TextSearchTest.php @@ -7,69 +7,69 @@ class TextSearchTest extends phpwiki_TestCase { function testTitleSearch() { global $request; - // find subpages - $pagename = "PgsrcTranslation"; + // find subpages + $pagename = "PgsrcTranslation"; $query = new TextSearchQuery($pagename . SUBPAGE_SEPARATOR . '*', true, 'glob'); - $sortby = false; $limit = 20; $exclude = ""; + $sortby = false; $limit = 20; $exclude = ""; $dbi = $request->getDbh(); $subpages = $dbi->titleSearch($query, $sortby, $limit, $exclude); - $result = array(); - while ($page = $subpages->next()) - $result[] = $page->getName(); + $result = array(); + while ($page = $subpages->next()) + $result[] = $page->getName(); $this->assertTrue(count($result) > 0, "glob count > 0"); - // apply limit - $sortby = false; $limit = 5; $exclude = ""; + // apply limit + $sortby = false; $limit = 5; $exclude = ""; $subpages = $dbi->titleSearch($query, $sortby, $limit, $exclude); - // don't trust count() with limit - $this->assertTrue($subpages->count() > 0 and $subpages->count() <= 7, - "0 < count() <= 7"); - $result = array(); - // but the iterator should limit - while ($page = $subpages->next()) - $result[] = $page->getName(); - $this->assertEquals(5, count($result), "limit 5"); + // don't trust count() with limit + $this->assertTrue($subpages->count() > 0 and $subpages->count() <= 7, + "0 < count() <= 7"); + $result = array(); + // but the iterator should limit + while ($page = $subpages->next()) + $result[] = $page->getName(); + $this->assertEquals(5, count($result), "limit 5"); } function testFulltextSearch() { global $request; $dbi = $request->getDbh(); - $sortby = false; $limit = 2; $exclude = ""; + $sortby = false; $limit = 2; $exclude = ""; $query = new TextSearchQuery('WikiPlugin to let users attach comments', true); // auto $pages = $dbi->fullSearch($query, $sortby, $limit, $exclude); $result = array(); - while ($page = $pages->next()) - $result[] = $page->getName(); + while ($page = $pages->next()) + $result[] = $page->getName(); $this->assertTrue(in_array("AddCommentPlugin", $result), "found all, no regex"); $query = new TextSearchQuery('WikiPlugin* to let users attach comments*', false); // auto - /* => (LOWER(pagename) LIKE 'wikiplugin%' OR content LIKE 'wikiplugin%') AND (LOWER(pagename) LIKE '%to%') AND (LOWER(pagename) LIKE '%let%' OR content LIKE '%let%') AND (LOWER(pagename) LIKE '%users%' OR content LIKE '%users%') AND (LOWER(pagename) LIKE '%attach%' OR content LIKE '%attach%') AND (LOWER(pagename) LIKE 'comments%' OR content LIKE 'comments%') - SELECT page.id AS id, page.pagename AS pagename, page.hits AS hits,page.pagedata as pagedata,version.version AS version, version.mtime AS mtime, version.minor_edit AS minor_edit, version.content AS content, version.versiondata AS versiondata FROM nonempty, page, recent, version WHERE nonempty.id=page.id AND page.id=recent.id AND page.id=version.id AND latestversion=version AND ((LOWER(pagename) LIKE 'wikiplugin%' OR content LIKE 'wikiplugin%') AND (LOWER(pagename) LIKE '%to%') AND (LOWER(pagename) LIKE '%let%' OR content LIKE '%let%') AND (LOWER(pagename) LIKE '%users%' OR content LIKE '%users%') AND (LOWER(pagename) LIKE '%attach%' OR content LIKE '%attach%') AND (LOWER(pagename) LIKE 'comments%' OR content LIKE 'comments%')) - SELECT page.id AS id, page.pagename AS pagename, page.hits AS hits,page.pagedata as pagedata,version.version AS version, version.mtime AS mtime, version.minor_edit AS minor_edit, version.content AS content, version.versiondata AS versiondata FROM nonempty, page, recent, version WHERE nonempty.id=page.id AND page.id=recent.id AND page.id=version.id AND latestversion=version AND ((LOWER(pagename) LIKE 'wikiplugin%' OR content LIKE 'wikiplugin%') AND (1=1) AND (LOWER(pagename) LIKE '%let%' OR content LIKE '%let%') AND (LOWER(pagename) LIKE '%users%' OR content LIKE '%users%') AND (LOWER(pagename) LIKE '%attach%' OR content LIKE '%attach%') AND (LOWER(pagename) LIKE 'comments%' OR content LIKE 'comments%')) - */ + /* => (LOWER(pagename) LIKE 'wikiplugin%' OR content LIKE 'wikiplugin%') AND (LOWER(pagename) LIKE '%to%') AND (LOWER(pagename) LIKE '%let%' OR content LIKE '%let%') AND (LOWER(pagename) LIKE '%users%' OR content LIKE '%users%') AND (LOWER(pagename) LIKE '%attach%' OR content LIKE '%attach%') AND (LOWER(pagename) LIKE 'comments%' OR content LIKE 'comments%') + SELECT page.id AS id, page.pagename AS pagename, page.hits AS hits,page.pagedata as pagedata,version.version AS version, version.mtime AS mtime, version.minor_edit AS minor_edit, version.content AS content, version.versiondata AS versiondata FROM nonempty, page, recent, version WHERE nonempty.id=page.id AND page.id=recent.id AND page.id=version.id AND latestversion=version AND ((LOWER(pagename) LIKE 'wikiplugin%' OR content LIKE 'wikiplugin%') AND (LOWER(pagename) LIKE '%to%') AND (LOWER(pagename) LIKE '%let%' OR content LIKE '%let%') AND (LOWER(pagename) LIKE '%users%' OR content LIKE '%users%') AND (LOWER(pagename) LIKE '%attach%' OR content LIKE '%attach%') AND (LOWER(pagename) LIKE 'comments%' OR content LIKE 'comments%')) + SELECT page.id AS id, page.pagename AS pagename, page.hits AS hits,page.pagedata as pagedata,version.version AS version, version.mtime AS mtime, version.minor_edit AS minor_edit, version.content AS content, version.versiondata AS versiondata FROM nonempty, page, recent, version WHERE nonempty.id=page.id AND page.id=recent.id AND page.id=version.id AND latestversion=version AND ((LOWER(pagename) LIKE 'wikiplugin%' OR content LIKE 'wikiplugin%') AND (1=1) AND (LOWER(pagename) LIKE '%let%' OR content LIKE '%let%') AND (LOWER(pagename) LIKE '%users%' OR content LIKE '%users%') AND (LOWER(pagename) LIKE '%attach%' OR content LIKE '%attach%') AND (LOWER(pagename) LIKE 'comments%' OR content LIKE 'comments%')) + */ $pages = $dbi->fullSearch($query, $sortby, $limit, $exclude); $result = array(); - while ($page = $pages->next()) - $result[] = $page->getName(); + while ($page = $pages->next()) + $result[] = $page->getName(); $this->assertTrue(in_array("AddCommentPlugin", $result), "found regex all"); - $sortby = false; $limit = 2; $exclude = ""; + $sortby = false; $limit = 2; $exclude = ""; $query = new TextSearchQuery('"Indent the paragraph"', false); // case-insensitive, auto $pages = $dbi->fullSearch($query, $sortby, $limit, $exclude); $result = array(); - while ($page = $pages->next()) - $result[] = $page->getName(); + while ($page = $pages->next()) + $result[] = $page->getName(); $this->assertTrue(in_array("TextFormattingRules", $result), "found phrase"); $query = new TextSearchQuery('"Indent the paragraph"', false); // case-insensitive, auto $pages = $dbi->fullSearch($query, $sortby, $limit, $exclude); $result = array(); - while ($page = $pages->next()) - $result[] = $page->getName(); + while ($page = $pages->next()) + $result[] = $page->getName(); $this->assertTrue(in_array("TextFormattingRules", $result), "found case phrase"); } diff --git a/tests/unit/lib/XmlRpcTest.php b/tests/unit/lib/XmlRpcTest.php index bff8ae2a9..9a02f2476 100644 --- a/tests/unit/lib/XmlRpcTest.php +++ b/tests/unit/lib/XmlRpcTest.php @@ -24,17 +24,17 @@ class XmlRpcTest extends phpwiki_TestCase { function testSelfAPI_v2() { $v = wiki_xmlrpc_post("wiki.getRPCVersionSupported"); $this->assertTrue($v >= 2); - // struct getAttachment( string localpath ) + // struct getAttachment( string localpath ) } */ /* function testSelfAPI_private() { - // struct getUploadedFileInfo( string localpath ) - // boolean wiki.mailPasswordToUser ( username ) - // array wiki.titleSearch(String substring [, String option = "0"]) - // array wiki.listPlugins() - // String wiki.getPluginSynopsis(String plugin) + // struct getUploadedFileInfo( string localpath ) + // boolean wiki.mailPasswordToUser ( username ) + // array wiki.titleSearch(String substring [, String option = "0"]) + // array wiki.listPlugins() + // String wiki.getPluginSynopsis(String plugin) // array wiki.listRelations([ Integer option = 1 ]) // array wiki.callPlugin(String name, String args) @@ -42,7 +42,7 @@ class XmlRpcTest extends phpwiki_TestCase { } function testSelfAPI_planned() { - // String pingback.ping(String sourceURI, String targetURI) + // String pingback.ping(String sourceURI, String targetURI) // boolean wiki.rssPleaseNotify ( notifyProcedure, port, path, protocol, urlList ) $this->assertTrue(true); } diff --git a/tests/unit/lib/plugin/IncludePageTest.php b/tests/unit/lib/plugin/IncludePageTest.php index 3ca07ea6a..e7b7d6df9 100644 --- a/tests/unit/lib/plugin/IncludePageTest.php +++ b/tests/unit/lib/plugin/IncludePageTest.php @@ -9,42 +9,42 @@ class IncludePageTest extends phpwiki_TestCase { function _ensure_loaded($pagename) { global $request; $dbi = $request->getDbh(); - if (! $dbi->isWikiPage($pagename)) { - require_once 'lib/loadsave.php'; + if (! $dbi->isWikiPage($pagename)) { + require_once 'lib/loadsave.php'; - $request->setArg('source', FindFile('pgsrc/'.urlencode($pagename))); - $request->setArg('overwrite', 1); - LoadAny($request, $request->getArg('source')); - $request->setArg('source', false); - } + $request->setArg('source', FindFile('pgsrc/'.urlencode($pagename))); + $request->setArg('overwrite', 1); + LoadAny($request, $request->getArg('source')); + $request->setArg('source', false); + } } // extract Synopsis function testOldTextFormattingRules() { global $request; - $pagename = 'Help/OldTextFormattingRules'; - $this->_ensure_loaded($pagename); + $pagename = 'Help/OldTextFormattingRules'; + $this->_ensure_loaded($pagename); $dbi = $request->getDbh(); $p = $dbi->getPage($pagename); - $r = $p->getCurrentRevision(); + $r = $p->getCurrentRevision(); $c = $r->getContent(); - $section = extractSection('Synopsis', $c, $pagename, 1); - $this->assertTrue(strstr(join("", $section), "OldTextFormattingRules%%%")); + $section = extractSection('Synopsis', $c, $pagename, 1); + $this->assertTrue(strstr(join("", $section), "OldTextFormattingRules%%%")); } // extract Synopsis function testTextFormattingRules() { global $request; - $pagename = 'Help/TextFormattingRules'; - $this->_ensure_loaded($pagename); + $pagename = 'Help/TextFormattingRules'; + $this->_ensure_loaded($pagename); $dbi = $request->getDbh(); $p = $dbi->getPage($pagename); - $r = $p->getCurrentRevision(); + $r = $p->getCurrentRevision(); $c = $r->getContent(); - $section = extractSection('Synopsis', $c, $pagename, 1); - $this->assertTrue(strstr(join("", $section), "TextFormattingRules%%%")); + $section = extractSection('Synopsis', $c, $pagename, 1); + $this->assertTrue(strstr(join("", $section), "TextFormattingRules%%%")); } /** @@ -52,15 +52,15 @@ class IncludePageTest extends phpwiki_TestCase { */ function testIncludePageSynopsis() { global $request; - $pagename = 'Help/TextFormattingRules'; + $pagename = 'Help/TextFormattingRules'; $lp = new WikiPlugin_IncludePage(); $this->assertEquals("IncludePage", $lp->getName()); $dbi = $request->getDbh(); $result = $lp->run($dbi, "page=$pagename section=Synopsis quiet=1", - $request, "IncludePage"); + $request, "IncludePage"); $this->assertType('object', $result, 'isa HtmlElement'); - //TODO: check content for found and extracted section + //TODO: check content for found and extracted section } } diff --git a/tests/unit/pcre-crash.php b/tests/unit/pcre-crash.php index d4788b071..c5e306d1f 100644 --- a/tests/unit/pcre-crash.php +++ b/tests/unit/pcre-crash.php @@ -1,5 +1,5 @@ = 5) @@ -192,7 +192,7 @@ function purge_dir($dir) { $fileSet = new fileSet($dir); assert(!empty($dir)); foreach ($fileSet->getFiles() as $f) { - unlink("$dir/$f"); + unlink("$dir/$f"); } } @@ -406,11 +406,11 @@ $alltests = array(/* valid tests without clean virgin setup */ if (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) { $argv = array(); foreach ($HTTP_GET_VARS as $key => $val) { - if (is_array($val)) - foreach ($val as $k => $v) $argv[] = $key."=".$k; - elseif (strstr($val,",") and in_array($key, array("test","db"))) - foreach (explode(",",$val) as $v) $argv[] = $key."=".$v; - else + if (is_array($val)) + foreach ($val as $k => $v) $argv[] = $key."=".$k; + elseif (strstr($val,",") and in_array($key, array("test","db"))) + foreach (explode(",",$val) as $v) $argv[] = $key."=".$v; + else $argv[] = $key."=".$val; } } elseif (!empty($argv) and preg_match("/test\.php$/", $argv[0])) { @@ -456,10 +456,10 @@ if ($debug_level & 1) { echo "debug=", $debug_level,"\n"; echo "level=", $user_level,"\n"; if (!empty($define)) { - foreach ($define as $k => $v) printConstant($k); + foreach ($define as $k => $v) printConstant($k); } if ($debug_level & 8) { - echo "pid=",getmypid(),"\n"; + echo "pid=",getmypid(),"\n"; } echo "\n"; } @@ -517,7 +517,7 @@ class MockRequest extends WikiRequest { $this->Request(); } function getGroup() { - if (is_object($this->_group)) + if (is_object($this->_group)) return $this->_group; else // FIXME: this is set to "/f:" somewhere. return new GroupNone(); @@ -569,7 +569,7 @@ if (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) { class phpwiki_TestCase extends PHPUnit_TestCase { function setUp() { global $request, $WikiTheme; - include_once("themes/" . THEME . "/themeinfo.php"); + include_once("themes/" . THEME . "/themeinfo.php"); $this->_savedargs = $request->_args; $request->_args = array(); if (DEBUG & 1) { @@ -592,23 +592,23 @@ foreach ($run_database_backends as $dbtype) { // printMemoryUsage("PHPUnitInitialized"); $DBParams['dbtype'] = $dbtype; if (string_starts_with($dbtype, 'PearDB_')) { - $DBParams['dbtype'] = 'SQL'; - $DBParams['dsn'] = preg_replace("/^([^:]+):/", substr($dbtype, 7).":", $DBParams['dsn']); + $DBParams['dbtype'] = 'SQL'; + $DBParams['dsn'] = preg_replace("/^([^:]+):/", substr($dbtype, 7).":", $DBParams['dsn']); echo "dsn: ",$DBParams['dsn'],"\n"; } if (string_starts_with($dbtype, 'ADODB_')) { - $DBParams['dbtype'] = 'ADODB'; - $DBParams['dsn'] = preg_replace("/^([^:]+):/", substr($dbtype, 6).":", $DBParams['dsn']); + $DBParams['dbtype'] = 'ADODB'; + $DBParams['dsn'] = preg_replace("/^([^:]+):/", substr($dbtype, 6).":", $DBParams['dsn']); echo "dsn: ",$DBParams['dsn'],"\n"; } if (string_starts_with($dbtype, 'PDO_')) { - $DBParams['dbtype'] = 'PDO'; - $DBParams['dsn'] = preg_replace("/^([^:]+):/", substr($dbtype, 4).":", $DBParams['dsn']); + $DBParams['dbtype'] = 'PDO'; + $DBParams['dsn'] = preg_replace("/^([^:]+):/", substr($dbtype, 4).":", $DBParams['dsn']); echo "dsn: ",$DBParams['dsn'],"\n"; } // sqlite fix: if (preg_match('/sqlite$/', $dbtype)) { - $DBParams['dsn'] = preg_replace("/127\.0\.0\.1/", '', $DBParams['dsn']); + $DBParams['dsn'] = preg_replace("/127\.0\.0\.1/", '', $DBParams['dsn']); echo "dsn: ",$DBParams['dsn'],"\n"; } $DBParams['directory'] = $cur_dir . '/.testbox'; @@ -629,7 +629,7 @@ foreach ($run_database_backends as $dbtype) { printMemoryUsage("PhpWikiInitialized"); foreach ($runtests as $test) { - if (!@ob_get_level()) ob_start(); + if (!@ob_get_level()) ob_start(); $suite = new PHPUnit_TestSuite("phpwiki"); if (file_exists(dirname(__FILE__).'/lib/'.$test.'.php')) require_once dirname(__FILE__).'/lib/'.$test.'.php'; diff --git a/tests/xmlrpc/interop-server.php b/tests/xmlrpc/interop-server.php index 60e243c96..5b82a07f2 100644 --- a/tests/xmlrpc/interop-server.php +++ b/tests/xmlrpc/interop-server.php @@ -6,8 +6,8 @@ include("xmlrpc_utils.php"); function method_echo($method, $params) { // we use array_pop instead of $params[0] because it works with either // soap (named params) or xmlrpc (ordered params) - $foo = array_pop($params); - //var_dump($foo); + $foo = array_pop($params); + //var_dump($foo); return $foo; } @@ -17,7 +17,7 @@ function method_echo_void($method, $params) { /* takes no params, returns a random int */ function method_no_in_params($method, $params) { - return (int)5; + return (int)5; } @@ -94,7 +94,7 @@ else { xmlrpc_server_register_method($xmlrpc_server, "interopEchoTests.whichToolkit", "method_toolkit"); xmlrpc_server_register_method($xmlrpc_server, "interopEchoTests.noInParams", "method_no_in_params"); - // soap methods (interop test naming conventions are slightly different for soap) + // soap methods (interop test naming conventions are slightly different for soap) xmlrpc_server_register_method($xmlrpc_server, "echoBoolean", "method_echo"); xmlrpc_server_register_method($xmlrpc_server, "echoString", "method_echo"); xmlrpc_server_register_method($xmlrpc_server, "echoInteger", "method_echo"); @@ -114,10 +114,10 @@ else { xmlrpc_server_register_introspection_callback($xmlrpc_server, "introspection_cb"); - //$val = xmlrpc_decode($request_xml, &$method); - //echo "xml: $request_xml\n"; - //echo "method: $method\nvar: "; - //print_r($val); + //$val = xmlrpc_decode($request_xml, &$method); + //echo "xml: $request_xml\n"; + //echo "method: $method\nvar: "; + //print_r($val); // parse xml and call method echo xmlrpc_server_call_method($xmlrpc_server, $request_xml, $response, array(output_type => "xml", version => "auto")); diff --git a/tests/xmlrpc/validate-form.php b/tests/xmlrpc/validate-form.php index eb08d64f3..ac40b41ca 100644 --- a/tests/xmlrpc/validate-form.php +++ b/tests/xmlrpc/validate-form.php @@ -956,20 +956,20 @@ array( curly - -23 - + -23 + larry - 96 - + 96 + moe - 17 - + 17 + @@ -1147,8 +1147,8 @@ array( validator1.simpleStructReturnTest - 55 - + 55 + ") diff --git a/tests/xmlrpc/validate.php b/tests/xmlrpc/validate.php index d0cecb5a8..8c240b362 100644 --- a/tests/xmlrpc/validate.php +++ b/tests/xmlrpc/validate.php @@ -195,7 +195,7 @@ function validator1_simpleStructReturnTest ($method_name, $params, $app_data) { xmlrpc_server_register_method($server, "validator1.nestedStructTest", "validator1_nestedStructTest"); xmlrpc_server_register_method($server, "validator1.simpleStructReturnTest", "validator1_simpleStructReturnTest"); - // name differently for soap. + // name differently for soap. xmlrpc_server_register_method($server, "arrayOfStructsTest", "validator1_arrayOfStructsTest"); xmlrpc_server_register_method($server, "countTheEntities", "validator1_countTheEntities"); xmlrpc_server_register_method($server, "easyStructTest", "validator1_easyStructTest"); diff --git a/tests/xmlrpc/xmlrpc-servers.php b/tests/xmlrpc/xmlrpc-servers.php index 3fd222ca3..506d58831 100644 --- a/tests/xmlrpc/xmlrpc-servers.php +++ b/tests/xmlrpc/xmlrpc-servers.php @@ -244,10 +244,10 @@ function print_servers_form($server_list, $action_url=false, $print_user=true) { some    much    -

XML Serialization

- XML-RPC    - SOAP    - simpleRPC    +

XML Serialization

+ XML-RPC    + SOAP    + simpleRPC   

diff --git a/wikilist.php b/wikilist.php index b52820bf1..860709de4 100644 --- a/wikilist.php +++ b/wikilist.php @@ -32,11 +32,11 @@ $sortorder = getStringFromRequest('sortorder', 'group_name'); $sortorder = util_ensure_value_in_set ($sortorder, array ('group_name','register_time','unix_group_name','is_public','is_external','members')) ; $res = db_query_params('SELECT group_name,register_time,unix_group_name,groups.group_id,is_public,is_external,status, COUNT(user_group.group_id) AS members - FROM groups LEFT JOIN user_group ON user_group.group_id=groups.group_id + FROM groups LEFT JOIN user_group ON user_group.group_id=groups.group_id WHERE status=$1 GROUP BY group_name,register_time,unix_group_name,groups.group_id,is_public,is_external,status ORDER BY '.$sortorder, - array('A')); + array('A')); $headers = array( _('Project Name'), -- 2.45.0