Ugly patch to maintain old DB handle code working quietly
We have to replace this database engine with a modern one
This commit is contained in:
parent
d75b5d2f4a
commit
daa5f87fd4
File diff suppressed because it is too large
Load Diff
|
@ -22,81 +22,88 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Common usages:
|
* Common usages:
|
||||||
* // blobs
|
* // blobs
|
||||||
* $data = DB_DataObject_Cast::blob($somefile);
|
* $data = DB_DataObject_Cast::blob($somefile);
|
||||||
* $data = DB_DataObject_Cast::string($somefile);
|
* $data = DB_DataObject_Cast::string($somefile);
|
||||||
* $dataObject->someblobfield = $data
|
* $dataObject->someblobfield = $data
|
||||||
*
|
*
|
||||||
* // dates?
|
* // dates?
|
||||||
* $d1 = new DB_DataObject_Cast::date('12/12/2000');
|
* $d1 = new DB_DataObject_Cast::date('12/12/2000');
|
||||||
* $d2 = new DB_DataObject_Cast::date(2000,12,30);
|
* $d2 = new DB_DataObject_Cast::date(2000,12,30);
|
||||||
* $d3 = new DB_DataObject_Cast::date($d1->year, $d1->month+30, $d1->day+30);
|
* $d3 = new DB_DataObject_Cast::date($d1->year, $d1->month+30, $d1->day+30);
|
||||||
*
|
*
|
||||||
* // time, datetime.. ?????????
|
* // time, datetime.. ?????????
|
||||||
*
|
*
|
||||||
* // raw sql????
|
* // raw sql????
|
||||||
* $data = DB_DataObject_Cast::sql('cast("123123",datetime)');
|
* $data = DB_DataObject_Cast::sql('cast("123123",datetime)');
|
||||||
* $data = DB_DataObject_Cast::sql('NULL');
|
* $data = DB_DataObject_Cast::sql('NULL');
|
||||||
*
|
*
|
||||||
* // int's/string etc. are proably pretty pointless..!!!!
|
* // int's/string etc. are proably pretty pointless..!!!!
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* inside DB_DataObject,
|
* inside DB_DataObject,
|
||||||
* if (is_a($v,'db_dataobject_class')) {
|
* if (is_a($v,'db_dataobject_class')) {
|
||||||
* $value .= $v->toString(DB_DATAOBJECT_INT,'mysql');
|
* $value .= $v->toString(DB_DATAOBJECT_INT,'mysql');
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
class DB_DataObject_Cast
|
class DB_DataObject_Cast
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type of data Stored in the object..
|
* Type of data Stored in the object..
|
||||||
*
|
*
|
||||||
* @var string (date|blob|.....?)
|
* @var string (date|blob|.....?)
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public $type;
|
public $type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data For date representation
|
* Data For date representation
|
||||||
*
|
*
|
||||||
* @var int day/month/year
|
* @var int day/month/year
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public $day;
|
public $day;
|
||||||
public $month;
|
public $month;
|
||||||
public $year;
|
public $year;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic Data..
|
* Generic Data..
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public $value;
|
public $value;
|
||||||
|
/**
|
||||||
|
* Data For time representation ** does not handle timezones!!
|
||||||
|
*
|
||||||
|
* @var int hour/minute/second
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
public $hour;
|
||||||
|
public $minute;
|
||||||
|
public $second;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blob consructor
|
* Blob consructor
|
||||||
*
|
*
|
||||||
* create a Cast object from some raw data.. (binary)
|
* create a Cast object from some raw data.. (binary)
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param string (with binary data!)
|
* @param string (with binary data!)
|
||||||
*
|
*
|
||||||
* @return object DB_DataObject_Cast
|
* @return object DB_DataObject_Cast
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function blob($value)
|
public function blob($value)
|
||||||
{
|
{
|
||||||
|
@ -106,18 +113,17 @@ class DB_DataObject_Cast
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String consructor (actually use if for ints and everything else!!!
|
* String consructor (actually use if for ints and everything else!!!
|
||||||
*
|
*
|
||||||
* create a Cast object from some string (not binary)
|
* create a Cast object from some string (not binary)
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param string (with binary data!)
|
* @param string (with binary data!)
|
||||||
*
|
*
|
||||||
* @return object DB_DataObject_Cast
|
* @return object DB_DataObject_Cast
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function string($value)
|
public function string($value)
|
||||||
{
|
{
|
||||||
|
@ -128,15 +134,15 @@ class DB_DataObject_Cast
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SQL constructor (for raw SQL insert)
|
* SQL constructor (for raw SQL insert)
|
||||||
*
|
*
|
||||||
* create a Cast object from some sql
|
* create a Cast object from some sql
|
||||||
*
|
*
|
||||||
* @param string (with binary data!)
|
* @param string (with binary data!)
|
||||||
*
|
*
|
||||||
* @return object DB_DataObject_Cast
|
* @return object DB_DataObject_Cast
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function sql($value)
|
public function sql($value)
|
||||||
{
|
{
|
||||||
|
@ -146,33 +152,94 @@ class DB_DataObject_Cast
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DateTime Constructor
|
||||||
|
*
|
||||||
|
* create a Cast object from a Date/Time
|
||||||
|
* Maybe should accept a Date object.!
|
||||||
|
* NO VALIDATION DONE, although some crappy re-calcing done!
|
||||||
|
*
|
||||||
|
* @param vargs... accepts
|
||||||
|
* noargs (now)
|
||||||
|
* yyyy-mm-dd HH:MM:SS (Iso)
|
||||||
|
* array(yyyy,mm,dd,HH,MM,SS)
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return bool|object
|
||||||
|
* @access public
|
||||||
|
* @author therion 5 at hotmail
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function dateTime()
|
||||||
|
{
|
||||||
|
$args = func_get_args();
|
||||||
|
switch (count($args)) {
|
||||||
|
case 0: // no args = now!
|
||||||
|
$datetime = date('Y-m-d G:i:s', mktime());
|
||||||
|
|
||||||
|
// no break
|
||||||
|
case 1:
|
||||||
|
// continue on from 0 args.
|
||||||
|
if (!isset($datetime)) {
|
||||||
|
$datetime = $args[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
$parts = explode(' ', $datetime);
|
||||||
|
$bits = explode('-', $parts[0]);
|
||||||
|
$bits = array_merge($bits, explode(':', $parts[1]));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: // 2 or more..
|
||||||
|
$bits = $args;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($bits) != 6) {
|
||||||
|
// PEAR ERROR?
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$r = DB_DataObject_Cast::date($bits[0], $bits[1], $bits[2]);
|
||||||
|
if (!$r) {
|
||||||
|
return $r; // pass thru error (False) - doesnt happen at present!
|
||||||
|
}
|
||||||
|
// change the type!
|
||||||
|
$r->type = 'datetime';
|
||||||
|
|
||||||
|
// should we mathematically sort this out..
|
||||||
|
// (or just assume that no-one's dumb enough to enter 26:90:90 as a time!
|
||||||
|
$r->hour = $bits[3];
|
||||||
|
$r->minute = $bits[4];
|
||||||
|
$r->second = $bits[5];
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Date Constructor
|
* Date Constructor
|
||||||
*
|
*
|
||||||
* create a Cast object from some string (not binary)
|
* create a Cast object from some string (not binary)
|
||||||
* NO VALIDATION DONE, although some crappy re-calcing done!
|
* NO VALIDATION DONE, although some crappy re-calcing done!
|
||||||
*
|
*
|
||||||
* @param vargs... accepts
|
* @param vargs... accepts
|
||||||
* dd/mm
|
* dd/mm
|
||||||
* dd/mm/yyyy
|
* dd/mm/yyyy
|
||||||
* yyyy-mm
|
* yyyy-mm
|
||||||
* yyyy-mm-dd
|
* yyyy-mm-dd
|
||||||
* array(yyyy,dd)
|
* array(yyyy,dd)
|
||||||
* array(yyyy,dd,mm)
|
* array(yyyy,dd,mm)
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @return object DB_DataObject_Cast
|
* @return object DB_DataObject_Cast
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function date()
|
public function date()
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
switch (count($args)) {
|
switch (count($args)) {
|
||||||
case 0: // no args = today!
|
case 0: // no args = today!
|
||||||
$bits = explode('-', date('Y-m-d'));
|
$bits = explode('-', date('Y-m-d'));
|
||||||
break;
|
break;
|
||||||
case 1: // one arg = a string
|
case 1: // one arg = a string
|
||||||
|
|
||||||
|
@ -211,100 +278,23 @@ class DB_DataObject_Cast
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data For time representation ** does not handle timezones!!
|
* time Constructor
|
||||||
*
|
*
|
||||||
* @var int hour/minute/second
|
* create a Cast object from a Date/Time
|
||||||
* @access public
|
* Maybe should accept a Date object.!
|
||||||
*/
|
* NO VALIDATION DONE, and no-recalcing done!
|
||||||
public $hour;
|
*
|
||||||
public $minute;
|
* @param vargs... accepts
|
||||||
public $second;
|
* noargs (now)
|
||||||
|
* HH:MM:SS (Iso)
|
||||||
|
* array(HH,MM,SS)
|
||||||
/**
|
*
|
||||||
* DateTime Constructor
|
*
|
||||||
*
|
* @return bool|object
|
||||||
* create a Cast object from a Date/Time
|
* @access public
|
||||||
* Maybe should accept a Date object.!
|
* @author therion 5 at hotmail
|
||||||
* NO VALIDATION DONE, although some crappy re-calcing done!
|
*/
|
||||||
*
|
|
||||||
* @param vargs... accepts
|
|
||||||
* noargs (now)
|
|
||||||
* yyyy-mm-dd HH:MM:SS (Iso)
|
|
||||||
* array(yyyy,mm,dd,HH,MM,SS)
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return object DB_DataObject_Cast
|
|
||||||
* @access public
|
|
||||||
* @author therion 5 at hotmail
|
|
||||||
*/
|
|
||||||
|
|
||||||
public function dateTime()
|
|
||||||
{
|
|
||||||
$args = func_get_args();
|
|
||||||
switch (count($args)) {
|
|
||||||
case 0: // no args = now!
|
|
||||||
$datetime = date('Y-m-d G:i:s', mktime());
|
|
||||||
|
|
||||||
// no break
|
|
||||||
case 1:
|
|
||||||
// continue on from 0 args.
|
|
||||||
if (!isset($datetime)) {
|
|
||||||
$datetime = $args[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
$parts = explode(' ', $datetime);
|
|
||||||
$bits = explode('-', $parts[0]);
|
|
||||||
$bits = array_merge($bits, explode(':', $parts[1]));
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: // 2 or more..
|
|
||||||
$bits = $args;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($bits) != 6) {
|
|
||||||
// PEAR ERROR?
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$r = DB_DataObject_Cast::date($bits[0], $bits[1], $bits[2]);
|
|
||||||
if (!$r) {
|
|
||||||
return $r; // pass thru error (False) - doesnt happen at present!
|
|
||||||
}
|
|
||||||
// change the type!
|
|
||||||
$r->type = 'datetime';
|
|
||||||
|
|
||||||
// should we mathematically sort this out..
|
|
||||||
// (or just assume that no-one's dumb enough to enter 26:90:90 as a time!
|
|
||||||
$r->hour = $bits[3];
|
|
||||||
$r->minute = $bits[4];
|
|
||||||
$r->second = $bits[5];
|
|
||||||
return $r;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* time Constructor
|
|
||||||
*
|
|
||||||
* create a Cast object from a Date/Time
|
|
||||||
* Maybe should accept a Date object.!
|
|
||||||
* NO VALIDATION DONE, and no-recalcing done!
|
|
||||||
*
|
|
||||||
* @param vargs... accepts
|
|
||||||
* noargs (now)
|
|
||||||
* HH:MM:SS (Iso)
|
|
||||||
* array(HH,MM,SS)
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return object DB_DataObject_Cast
|
|
||||||
* @access public
|
|
||||||
* @author therion 5 at hotmail
|
|
||||||
*/
|
|
||||||
public function time()
|
public function time()
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
|
@ -312,13 +302,13 @@ class DB_DataObject_Cast
|
||||||
case 0: // no args = now!
|
case 0: // no args = now!
|
||||||
$time = date('G:i:s', mktime());
|
$time = date('G:i:s', mktime());
|
||||||
|
|
||||||
// no break
|
// no break
|
||||||
case 1:
|
case 1:
|
||||||
// continue on from 0 args.
|
// continue on from 0 args.
|
||||||
if (!isset($time)) {
|
if (!isset($time)) {
|
||||||
$time = $args[0];
|
$time = $args[0];
|
||||||
}
|
}
|
||||||
$bits = explode(':', $time);
|
$bits = explode(':', $time);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: // 2 or more..
|
default: // 2 or more..
|
||||||
|
@ -340,38 +330,37 @@ class DB_DataObject_Cast
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the string to use in the SQL statement for this...
|
* get the string to use in the SQL statement for this...
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param int $to Type (DB_DATAOBJECT_*
|
* @param bool $to Type (DB_DATAOBJECT_*
|
||||||
* @param object $db DB Connection Object
|
* @param object $db DB Connection Object
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function toString($to=false, $db)
|
public function toString($to = false, $db)
|
||||||
{
|
{
|
||||||
// if $this->type is not set, we are in serious trouble!!!!
|
// if $this->type is not set, we are in serious trouble!!!!
|
||||||
// values for to:
|
// values for to:
|
||||||
$method = 'toStringFrom'.$this->type;
|
$method = 'toStringFrom' . $this->type;
|
||||||
return $this->$method($to, $db);
|
return $this->$method($to, $db);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the string to use in the SQL statement from a blob of binary data
|
* get the string to use in the SQL statement from a blob of binary data
|
||||||
* ** Suppots only blob->postgres::bytea
|
* ** Suppots only blob->postgres::bytea
|
||||||
*
|
*
|
||||||
* @param int $to Type (DB_DATAOBJECT_*
|
* @param int $to Type (DB_DATAOBJECT_*
|
||||||
* @param object $db DB Connection Object
|
* @param object $db DB Connection Object
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function toStringFromBlob($to, $db)
|
public function toStringFromBlob($to, $db)
|
||||||
{
|
{
|
||||||
// first weed out invalid casts..
|
// first weed out invalid casts..
|
||||||
|
@ -380,23 +369,23 @@ class DB_DataObject_Cast
|
||||||
// perhaps we should support TEXT fields???
|
// perhaps we should support TEXT fields???
|
||||||
|
|
||||||
if (!($to & DB_DATAOBJECT_BLOB)) {
|
if (!($to & DB_DATAOBJECT_BLOB)) {
|
||||||
return PEAR::raiseError('Invalid Cast from a DB_DataObject_Cast::blob to something other than a blob!');
|
return (new PEAR)->raiseError('Invalid Cast from a DB_DataObject_Cast::blob to something other than a blob!');
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($db->dsn["phptype"]) {
|
switch ($db->dsn["phptype"]) {
|
||||||
case 'pgsql':
|
case 'pgsql':
|
||||||
return "'".pg_escape_bytea($this->value)."'::bytea";
|
return "'" . pg_escape_bytea($this->value) . "'::bytea";
|
||||||
|
|
||||||
case 'mysql':
|
case 'mysql':
|
||||||
return "'".mysql_real_escape_string($this->value, $db->connection)."'";
|
return "'" . mysql_real_escape_string($this->value, $db->connection) . "'";
|
||||||
|
|
||||||
case 'mysqli':
|
case 'mysqli':
|
||||||
// this is funny - the parameter order is reversed ;)
|
// this is funny - the parameter order is reversed ;)
|
||||||
return "'".mysqli_real_escape_string($db->connection, $this->value)."'";
|
return "'" . mysqli_real_escape_string($db->connection, $this->value) . "'";
|
||||||
|
|
||||||
case 'sqlite':
|
case 'sqlite':
|
||||||
// this is funny - the parameter order is reversed ;)
|
// this is funny - the parameter order is reversed ;)
|
||||||
return "'".sqlite_escape_string($this->value)."'";
|
return "'" . sqlite_escape_string($this->value) . "'";
|
||||||
|
|
||||||
case 'mssql':
|
case 'mssql':
|
||||||
|
|
||||||
|
@ -407,24 +396,23 @@ class DB_DataObject_Cast
|
||||||
return '0x' . $unpacked['hex'];
|
return '0x' . $unpacked['hex'];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return PEAR::raiseError("DB_DataObject_Cast cant handle blobs for Database:{$db->dsn['phptype']} Yet");
|
return (new PEAR)->raiseError("DB_DataObject_Cast cant handle blobs for Database:{$db->dsn['phptype']} Yet");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the string to use in the SQL statement for a blob from a string!
|
* get the string to use in the SQL statement for a blob from a string!
|
||||||
* ** Suppots only string->postgres::bytea
|
* ** Suppots only string->postgres::bytea
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param int $to Type (DB_DATAOBJECT_*
|
* @param int $to Type (DB_DATAOBJECT_*
|
||||||
* @param object $db DB Connection Object
|
* @param object $db DB Connection Object
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function toStringFromString($to, $db)
|
public function toStringFromString($to, $db)
|
||||||
{
|
{
|
||||||
// first weed out invalid casts..
|
// first weed out invalid casts..
|
||||||
|
@ -440,42 +428,42 @@ class DB_DataObject_Cast
|
||||||
|
|
||||||
switch ($db->dsn['phptype']) {
|
switch ($db->dsn['phptype']) {
|
||||||
case 'pgsql':
|
case 'pgsql':
|
||||||
return "'".pg_escape_string($this->value)."'::bytea";
|
return "'" . pg_escape_string($this->value) . "'::bytea";
|
||||||
|
|
||||||
case 'mysql':
|
case 'mysql':
|
||||||
return "'".mysql_real_escape_string($this->value, $db->connection)."'";
|
return "'" . mysql_real_escape_string($this->value, $db->connection) . "'";
|
||||||
|
|
||||||
|
|
||||||
case 'mysqli':
|
case 'mysqli':
|
||||||
return "'".mysqli_real_escape_string($db->connection, $this->value)."'";
|
return "'" . mysqli_real_escape_string($db->connection, $this->value) . "'";
|
||||||
|
|
||||||
case 'mssql':
|
case 'mssql':
|
||||||
// copied from the old DB mssql code...?? not sure how safe this is.
|
// copied from the old DB mssql code...?? not sure how safe this is.
|
||||||
return "'" . str_replace(
|
return "'" . str_replace(
|
||||||
array("'", "\\\r\n", "\\\n"),
|
array("'", "\\\r\n", "\\\n"),
|
||||||
array("''", "\\\\\r\n\r\n", "\\\\\n\n"),
|
array("''", "\\\\\r\n\r\n", "\\\\\n\n"),
|
||||||
$this->value
|
$this->value
|
||||||
) . "'";
|
) . "'";
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return PEAR::raiseError("DB_DataObject_Cast cant handle blobs for Database:{$db->dsn['phptype']} Yet");
|
return (new PEAR)->raiseError("DB_DataObject_Cast cant handle blobs for Database:{$db->dsn['phptype']} Yet");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the string to use in the SQL statement for a date
|
* get the string to use in the SQL statement for a date
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param int $to Type (DB_DATAOBJECT_*
|
* @param int $to Type (DB_DATAOBJECT_*
|
||||||
* @param object $db DB Connection Object
|
* @param object $db DB Connection Object
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function toStringFromDate($to, $db)
|
public function toStringFromDate($to, $db)
|
||||||
{
|
{
|
||||||
// first weed out invalid casts..
|
// first weed out invalid casts..
|
||||||
|
@ -484,25 +472,25 @@ class DB_DataObject_Cast
|
||||||
//
|
//
|
||||||
|
|
||||||
if (($to !== false) && !($to & DB_DATAOBJECT_DATE)) {
|
if (($to !== false) && !($to & DB_DATAOBJECT_DATE)) {
|
||||||
return PEAR::raiseError('Invalid Cast from a DB_DataObject_Cast::string to something other than a date!'.
|
return (new PEAR)->raiseError('Invalid Cast from a DB_DataObject_Cast::string to something other than a date!' .
|
||||||
' (why not just use native features)');
|
' (why not just use native features)');
|
||||||
}
|
}
|
||||||
return "'{$this->year}-{$this->month}-{$this->day}'";
|
return "'{$this->year}-{$this->month}-{$this->day}'";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the string to use in the SQL statement for a datetime
|
* get the string to use in the SQL statement for a datetime
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param int $to Type (DB_DATAOBJECT_*
|
* @param int $to Type (DB_DATAOBJECT_*
|
||||||
* @param object $db DB Connection Object
|
* @param object $db DB Connection Object
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @access public
|
* @access public
|
||||||
* @author therion 5 at hotmail
|
* @author therion 5 at hotmail
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function toStringFromDateTime($to, $db)
|
public function toStringFromDateTime($to, $db)
|
||||||
{
|
{
|
||||||
|
@ -511,7 +499,7 @@ class DB_DataObject_Cast
|
||||||
// perhaps we should support TEXT fields???
|
// perhaps we should support TEXT fields???
|
||||||
if (($to !== false) &&
|
if (($to !== false) &&
|
||||||
!($to & (DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME))) {
|
!($to & (DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME))) {
|
||||||
return PEAR::raiseError('Invalid Cast from a ' .
|
return (new PEAR)->raiseError('Invalid Cast from a ' .
|
||||||
' DB_DataObject_Cast::dateTime to something other than a datetime!' .
|
' DB_DataObject_Cast::dateTime to something other than a datetime!' .
|
||||||
' (try using native features)');
|
' (try using native features)');
|
||||||
}
|
}
|
||||||
|
@ -519,18 +507,18 @@ class DB_DataObject_Cast
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the string to use in the SQL statement for a time
|
* get the string to use in the SQL statement for a time
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param int $to Type (DB_DATAOBJECT_*
|
* @param int $to Type (DB_DATAOBJECT_*
|
||||||
* @param object $db DB Connection Object
|
* @param object $db DB Connection Object
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @access public
|
* @access public
|
||||||
* @author therion 5 at hotmail
|
* @author therion 5 at hotmail
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function toStringFromTime($to, $db)
|
public function toStringFromTime($to, $db)
|
||||||
{
|
{
|
||||||
|
@ -538,23 +526,23 @@ class DB_DataObject_Cast
|
||||||
// in blobs can only be cast to blobs.!
|
// in blobs can only be cast to blobs.!
|
||||||
// perhaps we should support TEXT fields???
|
// perhaps we should support TEXT fields???
|
||||||
if (($to !== false) && !($to & DB_DATAOBJECT_TIME)) {
|
if (($to !== false) && !($to & DB_DATAOBJECT_TIME)) {
|
||||||
return PEAR::raiseError('Invalid Cast from a' .
|
return (new PEAR)->raiseError('Invalid Cast from a' .
|
||||||
' DB_DataObject_Cast::time to something other than a time!'.
|
' DB_DataObject_Cast::time to something other than a time!' .
|
||||||
' (try using native features)');
|
' (try using native features)');
|
||||||
}
|
}
|
||||||
return "'{$this->hour}:{$this->minute}:{$this->second}'";
|
return "'{$this->hour}:{$this->minute}:{$this->second}'";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the string to use in the SQL statement for a raw sql statement.
|
* get the string to use in the SQL statement for a raw sql statement.
|
||||||
*
|
*
|
||||||
* @param int $to Type (DB_DATAOBJECT_*
|
* @param int $to Type (DB_DATAOBJECT_*
|
||||||
* @param object $db DB Connection Object
|
* @param object $db DB Connection Object
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function toStringFromSql($to, $db)
|
public function toStringFromSql($to, $db)
|
||||||
{
|
{
|
||||||
return $this->value;
|
return $this->value;
|
||||||
|
|
|
@ -29,21 +29,21 @@ class DB_DataObject_Error extends PEAR_Error
|
||||||
/**
|
/**
|
||||||
* DB_DataObject_Error constructor.
|
* DB_DataObject_Error constructor.
|
||||||
*
|
*
|
||||||
* @param mixed $code DB error code, or string with error message.
|
* @param string $message
|
||||||
* @param integer $mode what "error mode" to operate in
|
* @param mixed $code DB error code, or string with error message.
|
||||||
* @param integer $level what error level to use for $mode & PEAR_ERROR_TRIGGER
|
* @param integer $mode what "error mode" to operate in
|
||||||
* @param mixed $debuginfo additional debug info, such as the last query
|
* @param integer $level what error level to use for $mode & PEAR_ERROR_TRIGGER
|
||||||
*
|
|
||||||
* @access public
|
* @access public
|
||||||
*
|
*
|
||||||
* @see PEAR_Error
|
* @see PEAR_Error
|
||||||
*/
|
*/
|
||||||
public function DB_DataObject_Error(
|
public function __construct(
|
||||||
$message = '',
|
$message = '',
|
||||||
$code = DB_ERROR,
|
$code = DB_ERROR,
|
||||||
$mode = PEAR_ERROR_RETURN,
|
$mode = PEAR_ERROR_RETURN,
|
||||||
$level = E_USER_NOTICE
|
$level = E_USER_NOTICE
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
$this->PEAR_Error('DB_DataObject Error: ' . $message, $code, $mode, $level);
|
$this->PEAR_Error('DB_DataObject Error: ' . $message, $code, $mode, $level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -39,8 +39,8 @@
|
||||||
class DB_DataObject_Links
|
class DB_DataObject_Links
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @property {DB_DataObject} do DataObject to apply this to.
|
* @property {DB_DataObject} do DataObject to apply this to.
|
||||||
*/
|
*/
|
||||||
public $do = false;
|
public $do = false;
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,105 +79,90 @@ class DB_DataObject_Links
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* -- good ole style..
|
* -- good ole style..
|
||||||
* @param {DB_DataObject} do DataObject to apply to.
|
* @param {DB_DataObject} do DataObject to apply to.
|
||||||
* @param {Array} cfg Configuration (basically properties of this object)
|
* @param array $cfg
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function DB_DataObject_Links($do, $cfg= array())
|
public function __construct($do, $cfg = array())
|
||||||
{
|
{
|
||||||
// check if do is set!!!?
|
// check if do is set!!!?
|
||||||
$this->do = $do;
|
$this->do = $do;
|
||||||
|
|
||||||
foreach ($cfg as $k=>$v) {
|
foreach ($cfg as $k => $v) {
|
||||||
$this->$k = $v;
|
$this->$k = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return name from related object
|
* a generic geter/setter provider..
|
||||||
*
|
*
|
||||||
* The relies on a <dbname>.links.ini file, unless you specify the arguments.
|
* provides a generic getter setter for the referenced object
|
||||||
|
* eg.
|
||||||
|
* $link->link('company_id') returns getLink for the object
|
||||||
|
* if nothing is linked (it will return an empty dataObject)
|
||||||
|
* $link->link('company_id', array(1)) - just sets the
|
||||||
*
|
*
|
||||||
* you can also use $this->getLink('thisColumnName','otherTable','otherTableColumnName')
|
* also array as the field speck supports
|
||||||
|
* $link->link(array('company_id', 'company:id'))
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param string $field|array either row or row.xxxxx or links spec.
|
* @param string|array $field the field to fetch or link spec.
|
||||||
* @param string|DB_DataObject $table (optional) name of table to look up value in
|
* @param array $args
|
||||||
* @param string $link (optional) name of column in other table to match
|
* @return mixed true of false on set, the object on getter.
|
||||||
* @author Tim White <tim@cyface.com>
|
* @params array $args the arguments sent to the getter setter
|
||||||
* @access public
|
|
||||||
* @return mixed object on success false on failure or '0' when not linked
|
|
||||||
*/
|
*/
|
||||||
public function getLink($field, $table= false, $link='')
|
public function link($field, $args = array())
|
||||||
{
|
{
|
||||||
static $cache = array();
|
$info = $this->linkInfo($field);
|
||||||
|
|
||||||
// GUESS THE LINKED TABLE.. (if found - recursevly call self)
|
if (!$info) {
|
||||||
|
|
||||||
if ($table == false) {
|
|
||||||
$info = $this->linkInfo($field);
|
|
||||||
|
|
||||||
if ($info) {
|
|
||||||
return $this->getLink($field, $info[0], $link === false ? $info[1] : $link);
|
|
||||||
}
|
|
||||||
|
|
||||||
// no links defined.. - use borked BC method...
|
|
||||||
// use the old _ method - this shouldnt happen if called via getLinks()
|
|
||||||
if (!($p = strpos($field, '_'))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$table = substr($field, 0, $p);
|
|
||||||
return $this->getLink($field, $table);
|
|
||||||
}
|
|
||||||
|
|
||||||
$tn = is_string($table) ? $table : $table->tableName();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!isset($this->do->$field)) {
|
|
||||||
$this->do->raiseError("getLink: row not set $field", DB_DATAOBJECT_ERROR_NODATA);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check to see if we know anything about this table..
|
|
||||||
|
|
||||||
|
|
||||||
if (empty($this->do->$field) || $this->do->$field < 0) {
|
|
||||||
return 0; // no record.
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->cached && isset($cache[$tn.':'. $link .':'. $this->do->$field])) {
|
|
||||||
return $cache[$tn.':'. $link .':'. $this->do->$field];
|
|
||||||
}
|
|
||||||
|
|
||||||
$obj = is_string($table) ? $this->do->factory($tn) : $table;
|
|
||||||
;
|
|
||||||
|
|
||||||
if (!is_a($obj, 'DB_DataObject')) {
|
|
||||||
$this->do->raiseError(
|
$this->do->raiseError(
|
||||||
"getLink:Could not find class for row $field, table $tn",
|
"getLink:Could not find link for row $field",
|
||||||
DB_DATAOBJECT_ERROR_INVALIDCONFIG
|
DB_DATAOBJECT_ERROR_INVALIDCONFIG
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// -1 or 0 -- no referenced record..
|
$field = $info[2];
|
||||||
|
|
||||||
$ret = false;
|
|
||||||
if ($link) {
|
if (empty($args)) { // either an empty array or really empty....
|
||||||
if ($obj->get($link, $this->do->$field)) {
|
|
||||||
$ret = $obj;
|
if (!isset($this->do->$field)) {
|
||||||
|
return $info[0]; // empty dataobject.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$ret = $this->getLink($field);
|
||||||
|
// nothing linked -- return new object..
|
||||||
|
return ($ret === 0) ? $info[0] : $ret;
|
||||||
|
}
|
||||||
|
$assign = is_array($args) ? $args[0] : $args;
|
||||||
|
|
||||||
// this really only happens when no link config is set (old BC stuff)
|
// otherwise it's a set call..
|
||||||
} elseif ($obj->get($this->do->$field)) {
|
if (!is_a($assign, 'DB_DataObject')) {
|
||||||
$ret= $obj;
|
if (is_numeric($assign) && is_integer($assign * 1)) {
|
||||||
|
if ($assign > 0) {
|
||||||
|
if (!$info) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// check that record exists..
|
||||||
|
if (!$info[0]->get($info[1], $assign)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->do->$field = $assign;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if ($this->cached) {
|
|
||||||
$cache[$tn.':'. $link .':'. $this->do->$field] = $ret;
|
// otherwise we are assigning it ...
|
||||||
}
|
|
||||||
return $ret;
|
$this->do->$field = $assign->{$info[1]};
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get link information for a field or field specification
|
* get link information for a field or field specification
|
||||||
*
|
*
|
||||||
|
@ -187,8 +172,7 @@ class DB_DataObject_Links
|
||||||
* array(3) : 'field', $dataobject, 'remote_col' (handy for joinAdd to do nested joins.)
|
* array(3) : 'field', $dataobject, 'remote_col' (handy for joinAdd to do nested joins.)
|
||||||
*
|
*
|
||||||
* @param string|array $field or link spec to use.
|
* @param string|array $field or link spec to use.
|
||||||
* @return (false|array) array of dataobject and linked field or false.
|
* @return array|bool (false|array) array of dataobject and linked field or false.
|
||||||
*
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -239,77 +223,90 @@ class DB_DataObject_Links
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a generic geter/setter provider..
|
* return name from related object
|
||||||
*
|
*
|
||||||
* provides a generic getter setter for the referenced object
|
* The relies on a <dbname>.links.ini file, unless you specify the arguments.
|
||||||
* eg.
|
|
||||||
* $link->link('company_id') returns getLink for the object
|
|
||||||
* if nothing is linked (it will return an empty dataObject)
|
|
||||||
* $link->link('company_id', array(1)) - just sets the
|
|
||||||
*
|
*
|
||||||
* also array as the field speck supports
|
* you can also use $this->getLink('thisColumnName','otherTable','otherTableColumnName')
|
||||||
* $link->link(array('company_id', 'company:id'))
|
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param string|array $field the field to fetch or link spec.
|
* @param string $field |array either row or row.xxxxx or links spec.
|
||||||
* @params array $args the arguments sent to the getter setter
|
* @param bool $table (optional) name of table to look up value in
|
||||||
* @return mixed true of false on set, the object on getter.
|
* @param string $link (optional) name of column in other table to match
|
||||||
*
|
* @return mixed object on success false on failure or '0' when not linked
|
||||||
|
* @author Tim White <tim@cyface.com>
|
||||||
|
* @access public
|
||||||
*/
|
*/
|
||||||
public function link($field, $args = array())
|
public function getLink($field, $table = false, $link = '')
|
||||||
{
|
{
|
||||||
$info = $this->linkInfo($field);
|
static $cache = array();
|
||||||
|
|
||||||
if (!$info) {
|
// GUESS THE LINKED TABLE.. (if found - recursevly call self)
|
||||||
|
|
||||||
|
if ($table == false) {
|
||||||
|
$info = $this->linkInfo($field);
|
||||||
|
|
||||||
|
if ($info) {
|
||||||
|
return $this->getLink($field, $info[0], $link === false ? $info[1] : $link);
|
||||||
|
}
|
||||||
|
|
||||||
|
// no links defined.. - use borked BC method...
|
||||||
|
// use the old _ method - this shouldnt happen if called via getLinks()
|
||||||
|
if (!($p = strpos($field, '_'))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$table = substr($field, 0, $p);
|
||||||
|
return $this->getLink($field, $table);
|
||||||
|
}
|
||||||
|
|
||||||
|
$tn = is_string($table) ? $table : $table->tableName();
|
||||||
|
|
||||||
|
|
||||||
|
if (!isset($this->do->$field)) {
|
||||||
|
$this->do->raiseError("getLink: row not set $field", DB_DATAOBJECT_ERROR_NODATA);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check to see if we know anything about this table..
|
||||||
|
|
||||||
|
|
||||||
|
if (empty($this->do->$field) || $this->do->$field < 0) {
|
||||||
|
return 0; // no record.
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->cached && isset($cache[$tn . ':' . $link . ':' . $this->do->$field])) {
|
||||||
|
return $cache[$tn . ':' . $link . ':' . $this->do->$field];
|
||||||
|
}
|
||||||
|
|
||||||
|
$obj = is_string($table) ? $this->do->factory($tn) : $table;;
|
||||||
|
|
||||||
|
if (!is_a($obj, 'DB_DataObject')) {
|
||||||
$this->do->raiseError(
|
$this->do->raiseError(
|
||||||
"getLink:Could not find link for row $field",
|
"getLink:Could not find class for row $field, table $tn",
|
||||||
DB_DATAOBJECT_ERROR_INVALIDCONFIG
|
DB_DATAOBJECT_ERROR_INVALIDCONFIG
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$field = $info[2];
|
// -1 or 0 -- no referenced record..
|
||||||
|
|
||||||
|
$ret = false;
|
||||||
if (empty($args)) { // either an empty array or really empty....
|
if ($link) {
|
||||||
|
if ($obj->get($link, $this->do->$field)) {
|
||||||
if (!isset($this->do->$field)) {
|
$ret = $obj;
|
||||||
return $info[0]; // empty dataobject.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = $this->getLink($field);
|
|
||||||
// nothing linked -- return new object..
|
// this really only happens when no link config is set (old BC stuff)
|
||||||
return ($ret === 0) ? $info[0] : $ret;
|
} elseif ($obj->get($this->do->$field)) {
|
||||||
|
$ret = $obj;
|
||||||
}
|
}
|
||||||
$assign = is_array($args) ? $args[0] : $args;
|
if ($this->cached) {
|
||||||
|
$cache[$tn . ':' . $link . ':' . $this->do->$field] = $ret;
|
||||||
// otherwise it's a set call..
|
|
||||||
if (!is_a($assign, 'DB_DataObject')) {
|
|
||||||
if (is_numeric($assign) && is_integer($assign * 1)) {
|
|
||||||
if ($assign > 0) {
|
|
||||||
if (!$info) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// check that record exists..
|
|
||||||
if (!$info[0]->get($info[1], $assign)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->do->$field = $assign ;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return $ret;
|
||||||
// otherwise we are assigning it ...
|
|
||||||
|
|
||||||
$this->do->$field = $assign->{$info[1]};
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* load related objects
|
* load related objects
|
||||||
*
|
*
|
||||||
|
@ -322,10 +319,10 @@ class DB_DataObject_Links
|
||||||
* object vars the links are stored in by changeing the format parameter
|
* object vars the links are stored in by changeing the format parameter
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param string format (default _%s) where %s is the table name.
|
* @param string format (default _%s) where %s is the table name.
|
||||||
|
* @return boolean , true on success
|
||||||
* @author Tim White <tim@cyface.com>
|
* @author Tim White <tim@cyface.com>
|
||||||
* @access public
|
* @access public
|
||||||
* @return boolean , true on success
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function applyLinks($format = '_%s')
|
public function applyLinks($format = '_%s')
|
||||||
|
@ -337,7 +334,7 @@ class DB_DataObject_Links
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->do->_link_loaded = false;
|
$this->do->_link_loaded = false;
|
||||||
$cols = $this->do->table();
|
$cols = $this->do->table();
|
||||||
$links = $this->do->links();
|
$links = $this->do->links();
|
||||||
|
|
||||||
$loaded = array();
|
$loaded = array();
|
||||||
|
@ -374,7 +371,7 @@ class DB_DataObject_Links
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// does the table exist.
|
// does the table exist.
|
||||||
$k =sprintf($format, $key);
|
$k = sprintf($format, $key);
|
||||||
$this->do->$k = $this->getLink($key);
|
$this->do->$k = $this->getLink($key);
|
||||||
if (is_object($this->do->$k)) {
|
if (is_object($this->do->$k)) {
|
||||||
$loaded[] = $k;
|
$loaded[] = $k;
|
||||||
|
@ -392,11 +389,11 @@ class DB_DataObject_Links
|
||||||
* You may also use this with all parameters to specify, the column and related table.
|
* You may also use this with all parameters to specify, the column and related table.
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $field- either column or column.xxxxx
|
* @param string $field - either column or column.xxxxx
|
||||||
* @param string $table (optional) name of table to look up value in
|
* @param string $table (optional) name of table to look up value in
|
||||||
* @param string $fkey (optional) fetchall key see DB_DataObject::fetchAll()
|
* @param bool $fkey (optional) fetchall key see DB_DataObject::fetchAll()
|
||||||
* @param string $fval (optional)fetchall val DB_DataObject::fetchAll()
|
* @param bool $fval (optional) fetchall method DB_DataObject::fetchAll()
|
||||||
* @param string $fval (optional) fetchall method DB_DataObject::fetchAll()
|
* @param bool $fmethod
|
||||||
* @return array - array of results (empty array on failure)
|
* @return array - array of results (empty array on failure)
|
||||||
*
|
*
|
||||||
* Example - Getting the related objects
|
* Example - Getting the related objects
|
||||||
|
@ -409,7 +406,6 @@ class DB_DataObject_Links
|
||||||
* foreach ($children as $child) {
|
* foreach ($children as $child) {
|
||||||
* echo $child->name, '<br />';
|
* echo $child->name, '<br />';
|
||||||
* }
|
* }
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public function getLinkArray($field, $table = null, $fkey = false, $fval = false, $fmethod = false)
|
public function getLinkArray($field, $table = null, $fkey = false, $fval = false, $fmethod = false)
|
||||||
{
|
{
|
||||||
|
@ -431,7 +427,7 @@ class DB_DataObject_Links
|
||||||
return $this->getLinkArray($field, substr($field, 0, $p));
|
return $this->getLinkArray($field, substr($field, 0, $p));
|
||||||
}
|
}
|
||||||
|
|
||||||
$c = $this->do->factory($table);
|
$c = $this->do->factory($table);
|
||||||
|
|
||||||
if (!is_object($c) || !is_a($c, 'DB_DataObject')) {
|
if (!is_object($c) || !is_a($c, 'DB_DataObject')) {
|
||||||
$this->do->raiseError(
|
$this->do->raiseError(
|
||||||
|
|
|
@ -25,32 +25,32 @@
|
||||||
define('DB_DATAOBJECT_NO_OVERLOAD', 1);
|
define('DB_DATAOBJECT_NO_OVERLOAD', 1);
|
||||||
|
|
||||||
//require_once 'DB/DataObject/Generator.php';
|
//require_once 'DB/DataObject/Generator.php';
|
||||||
require_once 'DB/DataObject/Generator.php';
|
require_once 'Generator.php';
|
||||||
|
|
||||||
if (php_sapi_name() != 'cli') {
|
if (php_sapi_name() != 'cli') {
|
||||||
PEAR::raiseError("\nERROR: You must turn use the cli sapi to run this", null, PEAR_ERROR_DIE);
|
(new PEAR)->raiseError("\nERROR: You must turn use the cli sapi to run this", null, PEAR_ERROR_DIE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ini_get('register_argc_argv')) {
|
if (!ini_get('register_argc_argv')) {
|
||||||
PEAR::raiseError("\nERROR: You must turn register_argc_argv On in you php.ini file for this to work\neg.\n\nregister_argc_argv = On\n\n", null, PEAR_ERROR_DIE);
|
(new PEAR)->raiseError("\nERROR: You must turn register_argc_argv On in you php.ini file for this to work\neg.\n\nregister_argc_argv = On\n\n", null, PEAR_ERROR_DIE);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!@$_SERVER['argv'][1]) {
|
if (!@$_SERVER['argv'][1]) {
|
||||||
PEAR::raiseError("\nERROR: createTable.php usage:\n\n" .$_SERVER['argv'][0] . " example.ini\n\n", null, PEAR_ERROR_DIE);
|
(new PEAR)->raiseError("\nERROR: createTable.php usage:\n\n" . $_SERVER['argv'][0] . " example.ini\n\n", null, PEAR_ERROR_DIE);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$config = parse_ini_file($_SERVER['argv'][1], true);
|
$config = parse_ini_file($_SERVER['argv'][1], true);
|
||||||
foreach ($config as $class=>$values) {
|
foreach ($config as $class => $values) {
|
||||||
$options = &PEAR::getStaticProperty($class, 'options');
|
$options = &(new PEAR)->getStaticProperty($class, 'options');
|
||||||
$options = $values;
|
$options = $values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$options = &PEAR::getStaticProperty('DB_DataObject', 'options');
|
$options = &(new PEAR)->getStaticProperty('DB_DataObject', 'options');
|
||||||
if (empty($options)) {
|
if (empty($options)) {
|
||||||
PEAR::raiseError("\nERROR: could not read ini file\n\n", null, PEAR_ERROR_DIE);
|
(new PEAR)->raiseError("\nERROR: could not read ini file\n\n", null, PEAR_ERROR_DIE);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
1143
extlib/DB/common.php
1143
extlib/DB/common.php
File diff suppressed because it is too large
Load Diff
|
@ -27,7 +27,8 @@
|
||||||
/**
|
/**
|
||||||
* Obtain the DB_common class so it can be extended from
|
* Obtain the DB_common class so it can be extended from
|
||||||
*/
|
*/
|
||||||
require_once 'DB/common.php';
|
//require_once 'DB/common.php';
|
||||||
|
require_once 'common.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The methods PEAR DB uses to interact with PHP's dbase extension
|
* The methods PEAR DB uses to interact with PHP's dbase extension
|
||||||
|
@ -74,21 +75,20 @@ class DB_dbase extends DB_common
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $features = array(
|
public $features = array(
|
||||||
'limit' => false,
|
'limit' => false,
|
||||||
'new_link' => false,
|
'new_link' => false,
|
||||||
'numrows' => true,
|
'numrows' => true,
|
||||||
'pconnect' => false,
|
'pconnect' => false,
|
||||||
'prepare' => false,
|
'prepare' => false,
|
||||||
'ssl' => false,
|
'ssl' => false,
|
||||||
'transactions' => false,
|
'transactions' => false,
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mapping of native error codes to DB error codes
|
* A mapping of native error codes to DB error codes
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $errorcode_map = array(
|
public $errorcode_map = array();
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The raw database connection created by PHP
|
* The raw database connection created by PHP
|
||||||
|
@ -189,15 +189,15 @@ class DB_dbase extends DB_common
|
||||||
* );
|
* );
|
||||||
*
|
*
|
||||||
* $db = DB::connect($dsn, $options);
|
* $db = DB::connect($dsn, $options);
|
||||||
* if (PEAR::isError($db)) {
|
* if ((new PEAR)->isError($db)) {
|
||||||
* die($db->getMessage());
|
* die($db->getMessage());
|
||||||
* }
|
* }
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @param array $dsn the data source name
|
* @param array $dsn the data source name
|
||||||
* @param bool $persistent should the connection be persistent?
|
* @param bool $persistent should the connection be persistent?
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function connect($dsn, $persistent = false)
|
public function connect($dsn, $persistent = false)
|
||||||
{
|
{
|
||||||
|
@ -226,9 +226,9 @@ class DB_dbase extends DB_common
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
'the dbase file does not exist and '
|
'the dbase file does not exist and '
|
||||||
. 'it could not be created because '
|
. 'it could not be created because '
|
||||||
. 'the "fields" element of the DSN '
|
. 'the "fields" element of the DSN '
|
||||||
. 'is not properly set'
|
. 'is not properly set'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$this->connection = @dbase_create(
|
$this->connection = @dbase_create(
|
||||||
|
@ -242,8 +242,8 @@ class DB_dbase extends DB_common
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
'the dbase file does not exist and '
|
'the dbase file does not exist and '
|
||||||
. 'the attempt to create it failed: '
|
. 'the attempt to create it failed: '
|
||||||
. $php_errormsg
|
. $php_errormsg
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -306,10 +306,10 @@ class DB_dbase extends DB_common
|
||||||
* DB_result::fetchInto() instead. It can't be declared "protected"
|
* DB_result::fetchInto() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result the query result resource
|
* @param resource $result the query result resource
|
||||||
* @param array $arr the referenced array to put the data in
|
* @param array $arr the referenced array to put the data in
|
||||||
* @param int $fetchmode how the resulting array should be indexed
|
* @param int $fetchmode how the resulting array should be indexed
|
||||||
* @param int $rownum the row number to fetch (0 = first row)
|
* @param int $rownum the row number to fetch (0 = first row)
|
||||||
*
|
*
|
||||||
* @return mixed DB_OK on success, NULL when the end of a result set is
|
* @return mixed DB_OK on success, NULL when the end of a result set is
|
||||||
* reached or on failure
|
* reached or on failure
|
||||||
|
@ -350,7 +350,7 @@ class DB_dbase extends DB_common
|
||||||
* This method is a no-op for dbase, as there aren't result resources in
|
* This method is a no-op for dbase, as there aren't result resources in
|
||||||
* the same sense as most other database backends.
|
* the same sense as most other database backends.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return bool TRUE on success, FALSE if $result is invalid
|
* @return bool TRUE on success, FALSE if $result is invalid
|
||||||
*
|
*
|
||||||
|
@ -371,8 +371,7 @@ class DB_dbase extends DB_common
|
||||||
* DB_result::numCols() instead. It can't be declared "protected"
|
* DB_result::numCols() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param $foo
|
||||||
*
|
|
||||||
* @return int the number of columns. A DB_Error object on failure.
|
* @return int the number of columns. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_result::numCols()
|
* @see DB_result::numCols()
|
||||||
|
@ -392,8 +391,7 @@ class DB_dbase extends DB_common
|
||||||
* DB_result::numRows() instead. It can't be declared "protected"
|
* DB_result::numRows() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param $foo
|
||||||
*
|
|
||||||
* @return int the number of rows. A DB_Error object on failure.
|
* @return int the number of rows. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_result::numRows()
|
* @see DB_result::numRows()
|
||||||
|
@ -426,11 +424,11 @@ class DB_dbase extends DB_common
|
||||||
/**
|
/**
|
||||||
* Returns information about the current database
|
* Returns information about the current database
|
||||||
*
|
*
|
||||||
* @param mixed $result THIS IS UNUSED IN DBASE. The current database
|
* @param mixed $result THIS IS UNUSED IN DBASE. The current database
|
||||||
* is examined regardless of what is provided here.
|
* is examined regardless of what is provided here.
|
||||||
* @param int $mode a valid tableInfo mode
|
* @param int $mode a valid tableInfo mode
|
||||||
*
|
*
|
||||||
* @return array an associative array with the information requested.
|
* @return array|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::tableInfo()
|
* @see DB_common::tableInfo()
|
||||||
|
@ -467,7 +465,7 @@ class DB_dbase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
$id = array();
|
$id = array();
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
$line = fread($db, 32);
|
$line = fread($db, 32);
|
||||||
while (!feof($db)) {
|
while (!feof($db)) {
|
||||||
|
@ -478,8 +476,8 @@ class DB_dbase extends DB_common
|
||||||
$pos = strpos(substr($line, 0, 10), chr(0));
|
$pos = strpos(substr($line, 0, 10), chr(0));
|
||||||
$pos = ($pos == 0 ? 10 : $pos);
|
$pos = ($pos == 0 ? 10 : $pos);
|
||||||
$id[$i] = array(
|
$id[$i] = array(
|
||||||
'name' => substr($line, 0, $pos),
|
'name' => substr($line, 0, $pos),
|
||||||
'type' => $this->types[substr($line, 11, 1)],
|
'type' => $this->types[substr($line, 11, 1)],
|
||||||
'length' => ord(substr($line, 16, 1)),
|
'length' => ord(substr($line, 16, 1)),
|
||||||
'precision' => ord(substr($line, 17, 1)),
|
'precision' => ord(substr($line, 17, 1)),
|
||||||
);
|
);
|
||||||
|
@ -496,7 +494,7 @@ class DB_dbase extends DB_common
|
||||||
$case_func = 'strval';
|
$case_func = 'strval';
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = array();
|
$res = array();
|
||||||
$count = count($id);
|
$count = count($id);
|
||||||
|
|
||||||
if ($mode) {
|
if ($mode) {
|
||||||
|
@ -506,9 +504,9 @@ class DB_dbase extends DB_common
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$res[$i] = array(
|
$res[$i] = array(
|
||||||
'table' => $this->dsn['database'],
|
'table' => $this->dsn['database'],
|
||||||
'name' => $case_func($id[$i]['name']),
|
'name' => $case_func($id[$i]['name']),
|
||||||
'type' => $id[$i]['type'],
|
'type' => $id[$i]['type'],
|
||||||
'len' => $id[$i]['length'],
|
'len' => $id[$i]['length'],
|
||||||
'flags' => ''
|
'flags' => ''
|
||||||
);
|
);
|
||||||
if ($mode & DB_TABLEINFO_ORDER) {
|
if ($mode & DB_TABLEINFO_ORDER) {
|
||||||
|
|
|
@ -27,7 +27,8 @@
|
||||||
/**
|
/**
|
||||||
* Obtain the DB_common class so it can be extended from
|
* Obtain the DB_common class so it can be extended from
|
||||||
*/
|
*/
|
||||||
require_once 'DB/common.php';
|
//require_once 'DB/common.php';
|
||||||
|
require_once 'common.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The methods PEAR DB uses to interact with PHP's fbsql extension
|
* The methods PEAR DB uses to interact with PHP's fbsql extension
|
||||||
|
@ -75,13 +76,13 @@ class DB_fbsql extends DB_common
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $features = array(
|
public $features = array(
|
||||||
'limit' => 'alter',
|
'limit' => 'alter',
|
||||||
'new_link' => false,
|
'new_link' => false,
|
||||||
'numrows' => true,
|
'numrows' => true,
|
||||||
'pconnect' => true,
|
'pconnect' => true,
|
||||||
'prepare' => false,
|
'prepare' => false,
|
||||||
'ssl' => false,
|
'ssl' => false,
|
||||||
'transactions' => true,
|
'transactions' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,8 +90,8 @@ class DB_fbsql extends DB_common
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $errorcode_map = array(
|
public $errorcode_map = array(
|
||||||
22 => DB_ERROR_SYNTAX,
|
22 => DB_ERROR_SYNTAX,
|
||||||
85 => DB_ERROR_ALREADY_EXISTS,
|
85 => DB_ERROR_ALREADY_EXISTS,
|
||||||
108 => DB_ERROR_SYNTAX,
|
108 => DB_ERROR_SYNTAX,
|
||||||
116 => DB_ERROR_NOSUCHTABLE,
|
116 => DB_ERROR_NOSUCHTABLE,
|
||||||
124 => DB_ERROR_VALUE_COUNT_ON_ROW,
|
124 => DB_ERROR_VALUE_COUNT_ON_ROW,
|
||||||
|
@ -141,10 +142,10 @@ class DB_fbsql extends DB_common
|
||||||
*
|
*
|
||||||
* Don't call this method directly. Use DB::connect() instead.
|
* Don't call this method directly. Use DB::connect() instead.
|
||||||
*
|
*
|
||||||
* @param array $dsn the data source name
|
* @param array $dsn the data source name
|
||||||
* @param bool $persistent should the connection be persistent?
|
* @param bool $persistent should the connection be persistent?
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function connect($dsn, $persistent = false)
|
public function connect($dsn, $persistent = false)
|
||||||
{
|
{
|
||||||
|
@ -203,6 +204,35 @@ class DB_fbsql extends DB_common
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ disconnect()
|
// {{{ disconnect()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produces a DB_Error object regarding the current problem
|
||||||
|
*
|
||||||
|
* @param int $errno if the error is being manually raised pass a
|
||||||
|
* DB_ERROR* constant here. If this isn't passed
|
||||||
|
* the error information gathered from the DBMS.
|
||||||
|
*
|
||||||
|
* @return object the DB_Error object
|
||||||
|
*
|
||||||
|
* @see DB_common::raiseError(),
|
||||||
|
* DB_fbsql::errorNative(), DB_common::errorCode()
|
||||||
|
*/
|
||||||
|
public function fbsqlRaiseError($errno = null)
|
||||||
|
{
|
||||||
|
if ($errno === null) {
|
||||||
|
$errno = $this->errorCode(fbsql_errno($this->connection));
|
||||||
|
}
|
||||||
|
return $this->raiseError(
|
||||||
|
$errno,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
@fbsql_error($this->connection)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ simpleQuery()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disconnects from the database server
|
* Disconnects from the database server
|
||||||
*
|
*
|
||||||
|
@ -216,7 +246,7 @@ class DB_fbsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ simpleQuery()
|
// {{{ nextResult()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a query to the database server
|
* Sends a query to the database server
|
||||||
|
@ -244,7 +274,7 @@ class DB_fbsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ nextResult()
|
// {{{ fetchInto()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the internal fbsql result pointer to the next available result
|
* Move the internal fbsql result pointer to the next available result
|
||||||
|
@ -261,7 +291,7 @@ class DB_fbsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ fetchInto()
|
// {{{ freeResult()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Places a row from the result set into the given array
|
* Places a row from the result set into the given array
|
||||||
|
@ -273,10 +303,10 @@ class DB_fbsql extends DB_common
|
||||||
* DB_result::fetchInto() instead. It can't be declared "protected"
|
* DB_result::fetchInto() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result the query result resource
|
* @param resource $result the query result resource
|
||||||
* @param array $arr the referenced array to put the data in
|
* @param array $arr the referenced array to put the data in
|
||||||
* @param int $fetchmode how the resulting array should be indexed
|
* @param int $fetchmode how the resulting array should be indexed
|
||||||
* @param int $rownum the row number to fetch (0 = first row)
|
* @param int $rownum the row number to fetch (0 = first row)
|
||||||
*
|
*
|
||||||
* @return mixed DB_OK on success, NULL when the end of a result set is
|
* @return mixed DB_OK on success, NULL when the end of a result set is
|
||||||
* reached or on failure
|
* reached or on failure
|
||||||
|
@ -311,7 +341,7 @@ class DB_fbsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ freeResult()
|
// {{{ autoCommit()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the result set and frees the memory occupied by the result set
|
* Deletes the result set and frees the memory occupied by the result set
|
||||||
|
@ -320,7 +350,7 @@ class DB_fbsql extends DB_common
|
||||||
* DB_result::free() instead. It can't be declared "protected"
|
* DB_result::free() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return bool TRUE on success, FALSE if $result is invalid
|
* @return bool TRUE on success, FALSE if $result is invalid
|
||||||
*
|
*
|
||||||
|
@ -332,27 +362,28 @@ class DB_fbsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ autoCommit()
|
// {{{ commit()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables or disables automatic commits
|
* Enables or disables automatic commits
|
||||||
*
|
*
|
||||||
* @param bool $onoff true turns it on, false turns it off
|
* @param bool $onoff true turns it on, false turns it off
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object if the driver
|
* @return int DB_OK on success. A DB_Error object if the driver
|
||||||
* doesn't support auto-committing transactions.
|
* doesn't support auto-committing transactions.
|
||||||
*/
|
*/
|
||||||
public function autoCommit($onoff=false)
|
public function autoCommit($onoff = false)
|
||||||
{
|
{
|
||||||
if ($onoff) {
|
if ($onoff) {
|
||||||
$this->query("SET COMMIT TRUE");
|
$this->query("SET COMMIT TRUE");
|
||||||
} else {
|
} else {
|
||||||
$this->query("SET COMMIT FALSE");
|
$this->query("SET COMMIT FALSE");
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ commit()
|
// {{{ rollback()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commits the current transaction
|
* Commits the current transaction
|
||||||
|
@ -362,10 +393,11 @@ class DB_fbsql extends DB_common
|
||||||
public function commit()
|
public function commit()
|
||||||
{
|
{
|
||||||
@fbsql_commit($this->connection);
|
@fbsql_commit($this->connection);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ rollback()
|
// {{{ numCols()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverts the current transaction
|
* Reverts the current transaction
|
||||||
|
@ -375,10 +407,11 @@ class DB_fbsql extends DB_common
|
||||||
public function rollback()
|
public function rollback()
|
||||||
{
|
{
|
||||||
@fbsql_rollback($this->connection);
|
@fbsql_rollback($this->connection);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ numCols()
|
// {{{ numRows()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of columns in a result set
|
* Gets the number of columns in a result set
|
||||||
|
@ -387,9 +420,9 @@ class DB_fbsql extends DB_common
|
||||||
* DB_result::numCols() instead. It can't be declared "protected"
|
* DB_result::numCols() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return int the number of columns. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @see DB_result::numCols()
|
* @see DB_result::numCols()
|
||||||
*/
|
*/
|
||||||
|
@ -403,7 +436,7 @@ class DB_fbsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ numRows()
|
// {{{ affectedRows()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of rows in a result set
|
* Gets the number of rows in a result set
|
||||||
|
@ -412,9 +445,9 @@ class DB_fbsql extends DB_common
|
||||||
* DB_result::numRows() instead. It can't be declared "protected"
|
* DB_result::numRows() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return int the number of rows. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @see DB_result::numRows()
|
* @see DB_result::numRows()
|
||||||
*/
|
*/
|
||||||
|
@ -428,7 +461,7 @@ class DB_fbsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ affectedRows()
|
// {{{ nextId()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the number of rows affected by a data maniuplation query
|
* Determines the number of rows affected by a data maniuplation query
|
||||||
|
@ -447,17 +480,14 @@ class DB_fbsql extends DB_common
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ nextId()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the next free id in a sequence
|
* Returns the next free id in a sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the sequence
|
* @param string $seq_name name of the sequence
|
||||||
* @param boolean $ondemand when true, the seqence is automatically
|
* @param boolean $ondemand when true, the seqence is automatically
|
||||||
* created if it does not exist
|
* created if it does not exist
|
||||||
*
|
*
|
||||||
* @return int the next id number in the sequence.
|
* @return int|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
||||||
|
@ -489,10 +519,13 @@ class DB_fbsql extends DB_common
|
||||||
return $tmp[0];
|
return $tmp[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ dropSequence()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new sequence
|
* Creates a new sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the new sequence
|
* @param string $seq_name name of the new sequence
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
|
@ -503,8 +536,8 @@ class DB_fbsql extends DB_common
|
||||||
{
|
{
|
||||||
$seqname = $this->getSequenceName($seq_name);
|
$seqname = $this->getSequenceName($seq_name);
|
||||||
$res = $this->query('CREATE TABLE ' . $seqname
|
$res = $this->query('CREATE TABLE ' . $seqname
|
||||||
. ' (id INTEGER NOT NULL,'
|
. ' (id INTEGER NOT NULL,'
|
||||||
. ' PRIMARY KEY(id))');
|
. ' PRIMARY KEY(id))');
|
||||||
if ($res) {
|
if ($res) {
|
||||||
$res = $this->query('SET UNIQUE = 0 FOR ' . $seqname);
|
$res = $this->query('SET UNIQUE = 0 FOR ' . $seqname);
|
||||||
}
|
}
|
||||||
|
@ -512,12 +545,12 @@ class DB_fbsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ dropSequence()
|
// {{{ modifyLimitQuery()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a sequence
|
* Deletes a sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the sequence to be deleted
|
* @param string $seq_name name of the sequence to be deleted
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
|
@ -527,19 +560,19 @@ class DB_fbsql extends DB_common
|
||||||
public function dropSequence($seq_name)
|
public function dropSequence($seq_name)
|
||||||
{
|
{
|
||||||
return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name)
|
return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name)
|
||||||
. ' RESTRICT');
|
. ' RESTRICT');
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ modifyLimitQuery()
|
// {{{ quoteBoolean()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds LIMIT clauses to a query string according to current DBMS standards
|
* Adds LIMIT clauses to a query string according to current DBMS standards
|
||||||
*
|
*
|
||||||
* @param string $query the query to modify
|
* @param string $query the query to modify
|
||||||
* @param int $from the row to start to fetching (0 = the first row)
|
* @param int $from the row to start to fetching (0 = the first row)
|
||||||
* @param int $count the numbers of rows to fetch
|
* @param int $count the numbers of rows to fetch
|
||||||
* @param mixed $params array, string or numeric data to be used in
|
* @param mixed $params array, string or numeric data to be used in
|
||||||
* execution of the statement. Quantity of items
|
* execution of the statement. Quantity of items
|
||||||
* passed must match quantity of placeholders in
|
* passed must match quantity of placeholders in
|
||||||
* query: meaning 1 placeholder for non-array
|
* query: meaning 1 placeholder for non-array
|
||||||
|
@ -567,7 +600,7 @@ class DB_fbsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ quoteBoolean()
|
// {{{ quoteFloat()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats a boolean value for use within a query in a locale-independent
|
* Formats a boolean value for use within a query in a locale-independent
|
||||||
|
@ -584,7 +617,7 @@ class DB_fbsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ quoteFloat()
|
// {{{ fbsqlRaiseError()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats a float value for use within a query in a locale-independent
|
* Formats a float value for use within a query in a locale-independent
|
||||||
|
@ -600,35 +633,6 @@ class DB_fbsql extends DB_common
|
||||||
return $this->escapeSimple(str_replace(',', '.', strval(floatval($float))));
|
return $this->escapeSimple(str_replace(',', '.', strval(floatval($float))));
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ fbsqlRaiseError()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Produces a DB_Error object regarding the current problem
|
|
||||||
*
|
|
||||||
* @param int $errno if the error is being manually raised pass a
|
|
||||||
* DB_ERROR* constant here. If this isn't passed
|
|
||||||
* the error information gathered from the DBMS.
|
|
||||||
*
|
|
||||||
* @return object the DB_Error object
|
|
||||||
*
|
|
||||||
* @see DB_common::raiseError(),
|
|
||||||
* DB_fbsql::errorNative(), DB_common::errorCode()
|
|
||||||
*/
|
|
||||||
public function fbsqlRaiseError($errno = null)
|
|
||||||
{
|
|
||||||
if ($errno === null) {
|
|
||||||
$errno = $this->errorCode(fbsql_errno($this->connection));
|
|
||||||
}
|
|
||||||
return $this->raiseError(
|
|
||||||
$errno,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
@fbsql_error($this->connection)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ errorNative()
|
// {{{ errorNative()
|
||||||
|
|
||||||
|
@ -648,14 +652,14 @@ class DB_fbsql extends DB_common
|
||||||
/**
|
/**
|
||||||
* Returns information about a table or a result set
|
* Returns information about a table or a result set
|
||||||
*
|
*
|
||||||
* @param object|string $result DB_result object from a query or a
|
* @param object|string $result DB_result object from a query or a
|
||||||
* string containing the name of a table.
|
* string containing the name of a table.
|
||||||
* While this also accepts a query result
|
* While this also accepts a query result
|
||||||
* resource identifier, this behavior is
|
* resource identifier, this behavior is
|
||||||
* deprecated.
|
* deprecated.
|
||||||
* @param int $mode a valid tableInfo mode
|
* @param int $mode a valid tableInfo mode
|
||||||
*
|
*
|
||||||
* @return array an associative array with the information requested.
|
* @return array|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::tableInfo()
|
* @see DB_common::tableInfo()
|
||||||
|
@ -701,7 +705,7 @@ class DB_fbsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = @fbsql_num_fields($id);
|
$count = @fbsql_num_fields($id);
|
||||||
$res = array();
|
$res = array();
|
||||||
|
|
||||||
if ($mode) {
|
if ($mode) {
|
||||||
$res['num_fields'] = $count;
|
$res['num_fields'] = $count;
|
||||||
|
@ -710,9 +714,9 @@ class DB_fbsql extends DB_common
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$res[$i] = array(
|
$res[$i] = array(
|
||||||
'table' => $case_func(@fbsql_field_table($id, $i)),
|
'table' => $case_func(@fbsql_field_table($id, $i)),
|
||||||
'name' => $case_func(@fbsql_field_name($id, $i)),
|
'name' => $case_func(@fbsql_field_name($id, $i)),
|
||||||
'type' => @fbsql_field_type($id, $i),
|
'type' => @fbsql_field_type($id, $i),
|
||||||
'len' => @fbsql_field_len($id, $i),
|
'len' => @fbsql_field_len($id, $i),
|
||||||
'flags' => @fbsql_field_flags($id, $i),
|
'flags' => @fbsql_field_flags($id, $i),
|
||||||
);
|
);
|
||||||
if ($mode & DB_TABLEINFO_ORDER) {
|
if ($mode & DB_TABLEINFO_ORDER) {
|
||||||
|
@ -736,7 +740,7 @@ class DB_fbsql extends DB_common
|
||||||
/**
|
/**
|
||||||
* Obtains the query string needed for listing a given type of objects
|
* Obtains the query string needed for listing a given type of objects
|
||||||
*
|
*
|
||||||
* @param string $type the kind of objects you want to retrieve
|
* @param string $type the kind of objects you want to retrieve
|
||||||
*
|
*
|
||||||
* @return string the SQL query string or null if the driver doesn't
|
* @return string the SQL query string or null if the driver doesn't
|
||||||
* support the object type requested
|
* support the object type requested
|
||||||
|
@ -749,32 +753,32 @@ class DB_fbsql extends DB_common
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'tables':
|
case 'tables':
|
||||||
return 'SELECT "table_name" FROM information_schema.tables'
|
return 'SELECT "table_name" FROM information_schema.tables'
|
||||||
. ' t0, information_schema.schemata t1'
|
. ' t0, information_schema.schemata t1'
|
||||||
. ' WHERE t0.schema_pk=t1.schema_pk AND'
|
. ' WHERE t0.schema_pk=t1.schema_pk AND'
|
||||||
. ' "table_type" = \'BASE TABLE\''
|
. ' "table_type" = \'BASE TABLE\''
|
||||||
. ' AND "schema_name" = current_schema';
|
. ' AND "schema_name" = current_schema';
|
||||||
case 'views':
|
case 'views':
|
||||||
return 'SELECT "table_name" FROM information_schema.tables'
|
return 'SELECT "table_name" FROM information_schema.tables'
|
||||||
. ' t0, information_schema.schemata t1'
|
. ' t0, information_schema.schemata t1'
|
||||||
. ' WHERE t0.schema_pk=t1.schema_pk AND'
|
. ' WHERE t0.schema_pk=t1.schema_pk AND'
|
||||||
. ' "table_type" = \'VIEW\''
|
. ' "table_type" = \'VIEW\''
|
||||||
. ' AND "schema_name" = current_schema';
|
. ' AND "schema_name" = current_schema';
|
||||||
case 'users':
|
case 'users':
|
||||||
return 'SELECT "user_name" from information_schema.users';
|
return 'SELECT "user_name" from information_schema.users';
|
||||||
case 'functions':
|
case 'functions':
|
||||||
return 'SELECT "routine_name" FROM'
|
return 'SELECT "routine_name" FROM'
|
||||||
. ' information_schema.psm_routines'
|
. ' information_schema.psm_routines'
|
||||||
. ' t0, information_schema.schemata t1'
|
. ' t0, information_schema.schemata t1'
|
||||||
. ' WHERE t0.schema_pk=t1.schema_pk'
|
. ' WHERE t0.schema_pk=t1.schema_pk'
|
||||||
. ' AND "routine_kind"=\'FUNCTION\''
|
. ' AND "routine_kind"=\'FUNCTION\''
|
||||||
. ' AND "schema_name" = current_schema';
|
. ' AND "schema_name" = current_schema';
|
||||||
case 'procedures':
|
case 'procedures':
|
||||||
return 'SELECT "routine_name" FROM'
|
return 'SELECT "routine_name" FROM'
|
||||||
. ' information_schema.psm_routines'
|
. ' information_schema.psm_routines'
|
||||||
. ' t0, information_schema.schemata t1'
|
. ' t0, information_schema.schemata t1'
|
||||||
. ' WHERE t0.schema_pk=t1.schema_pk'
|
. ' WHERE t0.schema_pk=t1.schema_pk'
|
||||||
. ' AND "routine_kind"=\'PROCEDURE\''
|
. ' AND "routine_kind"=\'PROCEDURE\''
|
||||||
. ' AND "schema_name" = current_schema';
|
. ' AND "schema_name" = current_schema';
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,8 @@
|
||||||
/**
|
/**
|
||||||
* Obtain the DB_common class so it can be extended from
|
* Obtain the DB_common class so it can be extended from
|
||||||
*/
|
*/
|
||||||
require_once 'DB/common.php';
|
//require_once 'DB/common.php';
|
||||||
|
require_once 'common.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The methods PEAR DB uses to interact with PHP's interbase extension
|
* The methods PEAR DB uses to interact with PHP's interbase extension
|
||||||
|
@ -85,13 +86,13 @@ class DB_ibase extends DB_common
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $features = array(
|
public $features = array(
|
||||||
'limit' => false,
|
'limit' => false,
|
||||||
'new_link' => false,
|
'new_link' => false,
|
||||||
'numrows' => 'emulate',
|
'numrows' => 'emulate',
|
||||||
'pconnect' => true,
|
'pconnect' => true,
|
||||||
'prepare' => true,
|
'prepare' => true,
|
||||||
'ssl' => false,
|
'ssl' => false,
|
||||||
'transactions' => true,
|
'transactions' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -207,10 +208,10 @@ class DB_ibase extends DB_common
|
||||||
* Functional only with InterBase 6 and up.
|
* Functional only with InterBase 6 and up.
|
||||||
* + role Functional only with InterBase 5 and up.
|
* + role Functional only with InterBase 5 and up.
|
||||||
*
|
*
|
||||||
* @param array $dsn the data source name
|
* @param array $dsn the data source name
|
||||||
* @param bool $persistent should the connection be persistent?
|
* @param bool $persistent should the connection be persistent?
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function connect($dsn, $persistent = false)
|
public function connect($dsn, $persistent = false)
|
||||||
{
|
{
|
||||||
|
@ -228,14 +229,14 @@ class DB_ibase extends DB_common
|
||||||
|
|
||||||
$params = array(
|
$params = array(
|
||||||
$dsn['hostspec']
|
$dsn['hostspec']
|
||||||
? ($dsn['hostspec'] . ':' . $dsn['database'])
|
? ($dsn['hostspec'] . ':' . $dsn['database'])
|
||||||
: $dsn['database'],
|
: $dsn['database'],
|
||||||
$dsn['username'] ? $dsn['username'] : null,
|
$dsn['username'] ? $dsn['username'] : null,
|
||||||
$dsn['password'] ? $dsn['password'] : null,
|
$dsn['password'] ? $dsn['password'] : null,
|
||||||
isset($dsn['charset']) ? $dsn['charset'] : null,
|
isset($dsn['charset']) ? $dsn['charset'] : null,
|
||||||
isset($dsn['buffers']) ? $dsn['buffers'] : null,
|
isset($dsn['buffers']) ? $dsn['buffers'] : null,
|
||||||
isset($dsn['dialect']) ? $dsn['dialect'] : null,
|
isset($dsn['dialect']) ? $dsn['dialect'] : null,
|
||||||
isset($dsn['role']) ? $dsn['role'] : null,
|
isset($dsn['role']) ? $dsn['role'] : null,
|
||||||
);
|
);
|
||||||
|
|
||||||
$connect_function = $persistent ? 'ibase_pconnect' : 'ibase_connect';
|
$connect_function = $persistent ? 'ibase_pconnect' : 'ibase_connect';
|
||||||
|
@ -250,6 +251,112 @@ class DB_ibase extends DB_common
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ disconnect()
|
// {{{ disconnect()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produces a DB_Error object regarding the current problem
|
||||||
|
*
|
||||||
|
* @param int $errno if the error is being manually raised pass a
|
||||||
|
* DB_ERROR* constant here. If this isn't passed
|
||||||
|
* the error information gathered from the DBMS.
|
||||||
|
*
|
||||||
|
* @return object the DB_Error object
|
||||||
|
*
|
||||||
|
* @see DB_common::raiseError(),
|
||||||
|
* DB_ibase::errorNative(), DB_ibase::errorCode()
|
||||||
|
*/
|
||||||
|
public function &ibaseRaiseError($errno = null)
|
||||||
|
{
|
||||||
|
if ($errno === null) {
|
||||||
|
$errno = $this->errorCode($this->errorNative());
|
||||||
|
}
|
||||||
|
$tmp = $this->raiseError($errno, null, null, null, @ibase_errmsg());
|
||||||
|
return $tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ simpleQuery()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps native error codes to DB's portable ones
|
||||||
|
*
|
||||||
|
* @param int $nativecode the error code returned by the DBMS
|
||||||
|
*
|
||||||
|
* @return int the portable DB error code. Return DB_ERROR if the
|
||||||
|
* current driver doesn't have a mapping for the
|
||||||
|
* $nativecode submitted.
|
||||||
|
*
|
||||||
|
* @since Method available since Release 1.7.0
|
||||||
|
*/
|
||||||
|
public function errorCode($nativecode = null)
|
||||||
|
{
|
||||||
|
if (isset($this->errorcode_map[$nativecode])) {
|
||||||
|
return $this->errorcode_map[$nativecode];
|
||||||
|
}
|
||||||
|
|
||||||
|
static $error_regexps;
|
||||||
|
if (!isset($error_regexps)) {
|
||||||
|
$error_regexps = array(
|
||||||
|
'/generator .* is not defined/'
|
||||||
|
=> DB_ERROR_SYNTAX, // for compat. w ibase_errcode()
|
||||||
|
'/violation of [\w ]+ constraint/i'
|
||||||
|
=> DB_ERROR_CONSTRAINT,
|
||||||
|
'/table.*(not exist|not found|unknown)/i'
|
||||||
|
=> DB_ERROR_NOSUCHTABLE,
|
||||||
|
'/table .* already exists/i'
|
||||||
|
=> DB_ERROR_ALREADY_EXISTS,
|
||||||
|
'/unsuccessful metadata update .* failed attempt to store duplicate value/i'
|
||||||
|
=> DB_ERROR_ALREADY_EXISTS,
|
||||||
|
'/unsuccessful metadata update .* not found/i'
|
||||||
|
=> DB_ERROR_NOT_FOUND,
|
||||||
|
'/validation error for column .* value "\*\*\* null/i'
|
||||||
|
=> DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||||
|
'/conversion error from string/i'
|
||||||
|
=> DB_ERROR_INVALID_NUMBER,
|
||||||
|
'/no permission for/i'
|
||||||
|
=> DB_ERROR_ACCESS_VIOLATION,
|
||||||
|
'/arithmetic exception, numeric overflow, or string truncation/i'
|
||||||
|
=> DB_ERROR_INVALID,
|
||||||
|
'/feature is not supported/i'
|
||||||
|
=> DB_ERROR_NOT_CAPABLE,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$errormsg = @ibase_errmsg();
|
||||||
|
foreach ($error_regexps as $regexp => $code) {
|
||||||
|
if (preg_match($regexp, $errormsg)) {
|
||||||
|
return $code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DB_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ modifyLimitQuery()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the DBMS' native error code produced by the last query
|
||||||
|
*
|
||||||
|
* @return int the DBMS' error code. NULL if there is no error code.
|
||||||
|
*
|
||||||
|
* @since Method available since Release 1.7.0
|
||||||
|
*/
|
||||||
|
public function errorNative()
|
||||||
|
{
|
||||||
|
if (function_exists('ibase_errcode')) {
|
||||||
|
return @ibase_errcode();
|
||||||
|
}
|
||||||
|
if (preg_match(
|
||||||
|
'/^Dynamic SQL Error SQL error code = ([0-9-]+)/i',
|
||||||
|
@ibase_errmsg(),
|
||||||
|
$m
|
||||||
|
)) {
|
||||||
|
return (int)$m[1];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ nextResult()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disconnects from the database server
|
* Disconnects from the database server
|
||||||
*
|
*
|
||||||
|
@ -263,7 +370,7 @@ class DB_ibase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ simpleQuery()
|
// {{{ fetchInto()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a query to the database server
|
* Sends a query to the database server
|
||||||
|
@ -297,17 +404,17 @@ class DB_ibase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ modifyLimitQuery()
|
// {{{ freeResult()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds LIMIT clauses to a query string according to current DBMS standards
|
* Adds LIMIT clauses to a query string according to current DBMS standards
|
||||||
*
|
*
|
||||||
* Only works with Firebird.
|
* Only works with Firebird.
|
||||||
*
|
*
|
||||||
* @param string $query the query to modify
|
* @param string $query the query to modify
|
||||||
* @param int $from the row to start to fetching (0 = the first row)
|
* @param int $from the row to start to fetching (0 = the first row)
|
||||||
* @param int $count the numbers of rows to fetch
|
* @param int $count the numbers of rows to fetch
|
||||||
* @param mixed $params array, string or numeric data to be used in
|
* @param mixed $params array, string or numeric data to be used in
|
||||||
* execution of the statement. Quantity of items
|
* execution of the statement. Quantity of items
|
||||||
* passed must match quantity of placeholders in
|
* passed must match quantity of placeholders in
|
||||||
* query: meaning 1 placeholder for non-array
|
* query: meaning 1 placeholder for non-array
|
||||||
|
@ -330,7 +437,7 @@ class DB_ibase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ nextResult()
|
// {{{ freeQuery()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the internal ibase result pointer to the next available result
|
* Move the internal ibase result pointer to the next available result
|
||||||
|
@ -347,7 +454,7 @@ class DB_ibase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ fetchInto()
|
// {{{ affectedRows()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Places a row from the result set into the given array
|
* Places a row from the result set into the given array
|
||||||
|
@ -359,10 +466,10 @@ class DB_ibase extends DB_common
|
||||||
* DB_result::fetchInto() instead. It can't be declared "protected"
|
* DB_result::fetchInto() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result the query result resource
|
* @param resource $result the query result resource
|
||||||
* @param array $arr the referenced array to put the data in
|
* @param array $arr the referenced array to put the data in
|
||||||
* @param int $fetchmode how the resulting array should be indexed
|
* @param int $fetchmode how the resulting array should be indexed
|
||||||
* @param int $rownum the row number to fetch (0 = first row)
|
* @param int $rownum the row number to fetch (0 = first row)
|
||||||
*
|
*
|
||||||
* @return mixed DB_OK on success, NULL when the end of a result set is
|
* @return mixed DB_OK on success, NULL when the end of a result set is
|
||||||
* reached or on failure
|
* reached or on failure
|
||||||
|
@ -399,7 +506,7 @@ class DB_ibase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ freeResult()
|
// {{{ numCols()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the result set and frees the memory occupied by the result set
|
* Deletes the result set and frees the memory occupied by the result set
|
||||||
|
@ -408,7 +515,7 @@ class DB_ibase extends DB_common
|
||||||
* DB_result::free() instead. It can't be declared "protected"
|
* DB_result::free() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return bool TRUE on success, FALSE if $result is invalid
|
* @return bool TRUE on success, FALSE if $result is invalid
|
||||||
*
|
*
|
||||||
|
@ -420,7 +527,7 @@ class DB_ibase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ freeQuery()
|
// {{{ prepare()
|
||||||
|
|
||||||
public function freeQuery($query)
|
public function freeQuery($query)
|
||||||
{
|
{
|
||||||
|
@ -428,14 +535,14 @@ class DB_ibase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ affectedRows()
|
// {{{ execute()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the number of rows affected by a data maniuplation query
|
* Determines the number of rows affected by a data maniuplation query
|
||||||
*
|
*
|
||||||
* 0 is returned for queries that don't manipulate data.
|
* 0 is returned for queries that don't manipulate data.
|
||||||
*
|
*
|
||||||
* @return int the number of rows. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function affectedRows()
|
public function affectedRows()
|
||||||
{
|
{
|
||||||
|
@ -445,9 +552,6 @@ class DB_ibase extends DB_common
|
||||||
return $this->ibaseRaiseError(DB_ERROR_NOT_CAPABLE);
|
return $this->ibaseRaiseError(DB_ERROR_NOT_CAPABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ numCols()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of columns in a result set
|
* Gets the number of columns in a result set
|
||||||
*
|
*
|
||||||
|
@ -455,9 +559,9 @@ class DB_ibase extends DB_common
|
||||||
* DB_result::numCols() instead. It can't be declared "protected"
|
* DB_result::numCols() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return int the number of columns. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @see DB_result::numCols()
|
* @see DB_result::numCols()
|
||||||
*/
|
*/
|
||||||
|
@ -471,7 +575,7 @@ class DB_ibase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ prepare()
|
// {{{ autoCommit()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares a query for multiple execution with execute().
|
* Prepares a query for multiple execution with execute().
|
||||||
|
@ -497,14 +601,14 @@ class DB_ibase extends DB_common
|
||||||
*/
|
*/
|
||||||
public function prepare($query)
|
public function prepare($query)
|
||||||
{
|
{
|
||||||
$tokens = preg_split(
|
$tokens = preg_split(
|
||||||
'/((?<!\\\)[&?!])/',
|
'/((?<!\\\)[&?!])/',
|
||||||
$query,
|
$query,
|
||||||
-1,
|
-1,
|
||||||
PREG_SPLIT_DELIM_CAPTURE
|
PREG_SPLIT_DELIM_CAPTURE
|
||||||
);
|
);
|
||||||
$token = 0;
|
$token = 0;
|
||||||
$types = array();
|
$types = array();
|
||||||
$newquery = '';
|
$newquery = '';
|
||||||
|
|
||||||
foreach ($tokens as $key => $val) {
|
foreach ($tokens as $key => $val) {
|
||||||
|
@ -527,26 +631,26 @@ class DB_ibase extends DB_common
|
||||||
$newquery = substr($newquery, 0, -1);
|
$newquery = substr($newquery, 0, -1);
|
||||||
$this->last_query = $query;
|
$this->last_query = $query;
|
||||||
$newquery = $this->modifyQuery($newquery);
|
$newquery = $this->modifyQuery($newquery);
|
||||||
$stmt = @ibase_prepare($this->connection, $newquery);
|
$stmt = @ibase_prepare(/*$this->connection,*/ $newquery);
|
||||||
|
|
||||||
if ($stmt === false) {
|
if ($stmt === false) {
|
||||||
$stmt = $this->ibaseRaiseError();
|
$stmt = $this->ibaseRaiseError();
|
||||||
} else {
|
} else {
|
||||||
$this->prepare_types[(int)$stmt] = $types;
|
$this->prepare_types[(int)$stmt] = $types;
|
||||||
$this->manip_query[(int)$stmt] = DB::isManip($query);
|
$this->manip_query[(int)$stmt] = DB::isManip($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $stmt;
|
return $stmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ execute()
|
// {{{ commit()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a DB statement prepared with prepare().
|
* Executes a DB statement prepared with prepare().
|
||||||
*
|
*
|
||||||
* @param resource $stmt a DB statement resource returned from prepare()
|
* @param resource $stmt a DB statement resource returned from prepare()
|
||||||
* @param mixed $data array, string or numeric data to be used in
|
* @param mixed $data array, string or numeric data to be used in
|
||||||
* execution of the statement. Quantity of items
|
* execution of the statement. Quantity of items
|
||||||
* passed must match quantity of placeholders in
|
* passed must match quantity of placeholders in
|
||||||
* query: meaning 1 for non-array items or the
|
* query: meaning 1 for non-array items or the
|
||||||
|
@ -613,11 +717,14 @@ class DB_ibase extends DB_common
|
||||||
return $tmp;
|
return $tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ rollback()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Frees the internal resources associated with a prepared query
|
* Frees the internal resources associated with a prepared query
|
||||||
*
|
*
|
||||||
* @param resource $stmt the prepared statement's PHP resource
|
* @param resource $stmt the prepared statement's PHP resource
|
||||||
* @param bool $free_resource should the PHP resource be freed too?
|
* @param bool $free_resource should the PHP resource be freed too?
|
||||||
* Use false if you need to get data
|
* Use false if you need to get data
|
||||||
* from the result set later.
|
* from the result set later.
|
||||||
*
|
*
|
||||||
|
@ -640,12 +747,12 @@ class DB_ibase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ autoCommit()
|
// {{{ transactionInit()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables or disables automatic commits
|
* Enables or disables automatic commits
|
||||||
*
|
*
|
||||||
* @param bool $onoff true turns it on, false turns it off
|
* @param bool $onoff true turns it on, false turns it off
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object if the driver
|
* @return int DB_OK on success. A DB_Error object if the driver
|
||||||
* doesn't support auto-committing transactions.
|
* doesn't support auto-committing transactions.
|
||||||
|
@ -657,7 +764,7 @@ class DB_ibase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ commit()
|
// {{{ nextId()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commits the current transaction
|
* Commits the current transaction
|
||||||
|
@ -670,7 +777,7 @@ class DB_ibase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ rollback()
|
// {{{ createSequence()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverts the current transaction
|
* Reverts the current transaction
|
||||||
|
@ -683,26 +790,26 @@ class DB_ibase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ transactionInit()
|
// {{{ dropSequence()
|
||||||
|
|
||||||
public function transactionInit($trans_args = 0)
|
public function transactionInit($trans_args = 0)
|
||||||
{
|
{
|
||||||
return $trans_args
|
return $trans_args
|
||||||
? @ibase_trans($trans_args, $this->connection)
|
? @ibase_trans($trans_args, $this->connection)
|
||||||
: @ibase_trans();
|
: @ibase_trans();
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ nextId()
|
// {{{ _ibaseFieldFlags()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the next free id in a sequence
|
* Returns the next free id in a sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the sequence
|
* @param string $seq_name name of the sequence
|
||||||
* @param boolean $ondemand when true, the seqence is automatically
|
* @param boolean $ondemand when true, the seqence is automatically
|
||||||
* created if it does not exist
|
* created if it does not exist
|
||||||
*
|
*
|
||||||
* @return int the next id number in the sequence.
|
* @return int|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
||||||
|
@ -715,8 +822,8 @@ class DB_ibase extends DB_common
|
||||||
do {
|
do {
|
||||||
$this->pushErrorHandling(PEAR_ERROR_RETURN);
|
$this->pushErrorHandling(PEAR_ERROR_RETURN);
|
||||||
$result = $this->query("SELECT GEN_ID(${sqn}, 1) "
|
$result = $this->query("SELECT GEN_ID(${sqn}, 1) "
|
||||||
. 'FROM RDB$GENERATORS '
|
. 'FROM RDB$GENERATORS '
|
||||||
. "WHERE RDB\$GENERATOR_NAME='${sqn}'");
|
. "WHERE RDB\$GENERATOR_NAME='${sqn}'");
|
||||||
$this->popErrorHandling();
|
$this->popErrorHandling();
|
||||||
if ($ondemand && DB::isError($result)) {
|
if ($ondemand && DB::isError($result)) {
|
||||||
$repeat = 1;
|
$repeat = 1;
|
||||||
|
@ -737,12 +844,12 @@ class DB_ibase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ createSequence()
|
// {{{ ibaseRaiseError()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new sequence
|
* Creates a new sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the new sequence
|
* @param string $seq_name name of the new sequence
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
|
@ -760,12 +867,12 @@ class DB_ibase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ dropSequence()
|
// {{{ errorNative()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a sequence
|
* Deletes a sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the sequence to be deleted
|
* @param string $seq_name name of the sequence to be deleted
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
|
@ -775,206 +882,28 @@ class DB_ibase extends DB_common
|
||||||
public function dropSequence($seq_name)
|
public function dropSequence($seq_name)
|
||||||
{
|
{
|
||||||
return $this->query('DELETE FROM RDB$GENERATORS '
|
return $this->query('DELETE FROM RDB$GENERATORS '
|
||||||
. "WHERE RDB\$GENERATOR_NAME='"
|
. "WHERE RDB\$GENERATOR_NAME='"
|
||||||
. strtoupper($this->getSequenceName($seq_name))
|
. strtoupper($this->getSequenceName($seq_name))
|
||||||
. "'");
|
. "'");
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ _ibaseFieldFlags()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the column's flags
|
|
||||||
*
|
|
||||||
* Supports "primary_key", "unique_key", "not_null", "default",
|
|
||||||
* "computed" and "blob".
|
|
||||||
*
|
|
||||||
* @param string $field_name the name of the field
|
|
||||||
* @param string $table_name the name of the table
|
|
||||||
*
|
|
||||||
* @return string the flags
|
|
||||||
*
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
public function _ibaseFieldFlags($field_name, $table_name)
|
|
||||||
{
|
|
||||||
$sql = 'SELECT R.RDB$CONSTRAINT_TYPE CTYPE'
|
|
||||||
.' FROM RDB$INDEX_SEGMENTS I'
|
|
||||||
.' JOIN RDB$RELATION_CONSTRAINTS R ON I.RDB$INDEX_NAME=R.RDB$INDEX_NAME'
|
|
||||||
.' WHERE I.RDB$FIELD_NAME=\'' . $field_name . '\''
|
|
||||||
.' AND UPPER(R.RDB$RELATION_NAME)=\'' . strtoupper($table_name) . '\'';
|
|
||||||
|
|
||||||
$result = @ibase_query($this->connection, $sql);
|
|
||||||
if (!$result) {
|
|
||||||
return $this->ibaseRaiseError();
|
|
||||||
}
|
|
||||||
|
|
||||||
$flags = '';
|
|
||||||
if ($obj = @ibase_fetch_object($result)) {
|
|
||||||
@ibase_free_result($result);
|
|
||||||
if (isset($obj->CTYPE) && trim($obj->CTYPE) == 'PRIMARY KEY') {
|
|
||||||
$flags .= 'primary_key ';
|
|
||||||
}
|
|
||||||
if (isset($obj->CTYPE) && trim($obj->CTYPE) == 'UNIQUE') {
|
|
||||||
$flags .= 'unique_key ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql = 'SELECT R.RDB$NULL_FLAG AS NFLAG,'
|
|
||||||
.' R.RDB$DEFAULT_SOURCE AS DSOURCE,'
|
|
||||||
.' F.RDB$FIELD_TYPE AS FTYPE,'
|
|
||||||
.' F.RDB$COMPUTED_SOURCE AS CSOURCE'
|
|
||||||
.' FROM RDB$RELATION_FIELDS R '
|
|
||||||
.' JOIN RDB$FIELDS F ON R.RDB$FIELD_SOURCE=F.RDB$FIELD_NAME'
|
|
||||||
.' WHERE UPPER(R.RDB$RELATION_NAME)=\'' . strtoupper($table_name) . '\''
|
|
||||||
.' AND R.RDB$FIELD_NAME=\'' . $field_name . '\'';
|
|
||||||
|
|
||||||
$result = @ibase_query($this->connection, $sql);
|
|
||||||
if (!$result) {
|
|
||||||
return $this->ibaseRaiseError();
|
|
||||||
}
|
|
||||||
if ($obj = @ibase_fetch_object($result)) {
|
|
||||||
@ibase_free_result($result);
|
|
||||||
if (isset($obj->NFLAG)) {
|
|
||||||
$flags .= 'not_null ';
|
|
||||||
}
|
|
||||||
if (isset($obj->DSOURCE)) {
|
|
||||||
$flags .= 'default ';
|
|
||||||
}
|
|
||||||
if (isset($obj->CSOURCE)) {
|
|
||||||
$flags .= 'computed ';
|
|
||||||
}
|
|
||||||
if (isset($obj->FTYPE) && $obj->FTYPE == 261) {
|
|
||||||
$flags .= 'blob ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return trim($flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ ibaseRaiseError()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Produces a DB_Error object regarding the current problem
|
|
||||||
*
|
|
||||||
* @param int $errno if the error is being manually raised pass a
|
|
||||||
* DB_ERROR* constant here. If this isn't passed
|
|
||||||
* the error information gathered from the DBMS.
|
|
||||||
*
|
|
||||||
* @return object the DB_Error object
|
|
||||||
*
|
|
||||||
* @see DB_common::raiseError(),
|
|
||||||
* DB_ibase::errorNative(), DB_ibase::errorCode()
|
|
||||||
*/
|
|
||||||
public function &ibaseRaiseError($errno = null)
|
|
||||||
{
|
|
||||||
if ($errno === null) {
|
|
||||||
$errno = $this->errorCode($this->errorNative());
|
|
||||||
}
|
|
||||||
$tmp = $this->raiseError($errno, null, null, null, @ibase_errmsg());
|
|
||||||
return $tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ errorNative()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the DBMS' native error code produced by the last query
|
|
||||||
*
|
|
||||||
* @return int the DBMS' error code. NULL if there is no error code.
|
|
||||||
*
|
|
||||||
* @since Method available since Release 1.7.0
|
|
||||||
*/
|
|
||||||
public function errorNative()
|
|
||||||
{
|
|
||||||
if (function_exists('ibase_errcode')) {
|
|
||||||
return @ibase_errcode();
|
|
||||||
}
|
|
||||||
if (preg_match(
|
|
||||||
'/^Dynamic SQL Error SQL error code = ([0-9-]+)/i',
|
|
||||||
@ibase_errmsg(),
|
|
||||||
$m
|
|
||||||
)) {
|
|
||||||
return (int)$m[1];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ errorCode()
|
// {{{ errorCode()
|
||||||
|
|
||||||
/**
|
|
||||||
* Maps native error codes to DB's portable ones
|
|
||||||
*
|
|
||||||
* @param int $nativecode the error code returned by the DBMS
|
|
||||||
*
|
|
||||||
* @return int the portable DB error code. Return DB_ERROR if the
|
|
||||||
* current driver doesn't have a mapping for the
|
|
||||||
* $nativecode submitted.
|
|
||||||
*
|
|
||||||
* @since Method available since Release 1.7.0
|
|
||||||
*/
|
|
||||||
public function errorCode($nativecode = null)
|
|
||||||
{
|
|
||||||
if (isset($this->errorcode_map[$nativecode])) {
|
|
||||||
return $this->errorcode_map[$nativecode];
|
|
||||||
}
|
|
||||||
|
|
||||||
static $error_regexps;
|
|
||||||
if (!isset($error_regexps)) {
|
|
||||||
$error_regexps = array(
|
|
||||||
'/generator .* is not defined/'
|
|
||||||
=> DB_ERROR_SYNTAX, // for compat. w ibase_errcode()
|
|
||||||
'/violation of [\w ]+ constraint/i'
|
|
||||||
=> DB_ERROR_CONSTRAINT,
|
|
||||||
'/table.*(not exist|not found|unknown)/i'
|
|
||||||
=> DB_ERROR_NOSUCHTABLE,
|
|
||||||
'/table .* already exists/i'
|
|
||||||
=> DB_ERROR_ALREADY_EXISTS,
|
|
||||||
'/unsuccessful metadata update .* failed attempt to store duplicate value/i'
|
|
||||||
=> DB_ERROR_ALREADY_EXISTS,
|
|
||||||
'/unsuccessful metadata update .* not found/i'
|
|
||||||
=> DB_ERROR_NOT_FOUND,
|
|
||||||
'/validation error for column .* value "\*\*\* null/i'
|
|
||||||
=> DB_ERROR_CONSTRAINT_NOT_NULL,
|
|
||||||
'/conversion error from string/i'
|
|
||||||
=> DB_ERROR_INVALID_NUMBER,
|
|
||||||
'/no permission for/i'
|
|
||||||
=> DB_ERROR_ACCESS_VIOLATION,
|
|
||||||
'/arithmetic exception, numeric overflow, or string truncation/i'
|
|
||||||
=> DB_ERROR_INVALID,
|
|
||||||
'/feature is not supported/i'
|
|
||||||
=> DB_ERROR_NOT_CAPABLE,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$errormsg = @ibase_errmsg();
|
|
||||||
foreach ($error_regexps as $regexp => $code) {
|
|
||||||
if (preg_match($regexp, $errormsg)) {
|
|
||||||
return $code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return DB_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ tableInfo()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns information about a table or a result set
|
* Returns information about a table or a result set
|
||||||
*
|
*
|
||||||
* NOTE: only supports 'table' and 'flags' if <var>$result</var>
|
* NOTE: only supports 'table' and 'flags' if <var>$result</var>
|
||||||
* is a table name.
|
* is a table name.
|
||||||
*
|
*
|
||||||
* @param object|string $result DB_result object from a query or a
|
* @param object|string $result DB_result object from a query or a
|
||||||
* string containing the name of a table.
|
* string containing the name of a table.
|
||||||
* While this also accepts a query result
|
* While this also accepts a query result
|
||||||
* resource identifier, this behavior is
|
* resource identifier, this behavior is
|
||||||
* deprecated.
|
* deprecated.
|
||||||
* @param int $mode a valid tableInfo mode
|
* @param int $mode a valid tableInfo mode
|
||||||
*
|
*
|
||||||
* @return array an associative array with the information requested.
|
* @return array|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::tableInfo()
|
* @see DB_common::tableInfo()
|
||||||
|
@ -1019,7 +948,7 @@ class DB_ibase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = @ibase_num_fields($id);
|
$count = @ibase_num_fields($id);
|
||||||
$res = array();
|
$res = array();
|
||||||
|
|
||||||
if ($mode) {
|
if ($mode) {
|
||||||
$res['num_fields'] = $count;
|
$res['num_fields'] = $count;
|
||||||
|
@ -1029,12 +958,12 @@ class DB_ibase extends DB_common
|
||||||
$info = @ibase_field_info($id, $i);
|
$info = @ibase_field_info($id, $i);
|
||||||
$res[$i] = array(
|
$res[$i] = array(
|
||||||
'table' => $got_string ? $case_func($result) : '',
|
'table' => $got_string ? $case_func($result) : '',
|
||||||
'name' => $case_func($info['name']),
|
'name' => $case_func($info['name']),
|
||||||
'type' => $info['type'],
|
'type' => $info['type'],
|
||||||
'len' => $info['length'],
|
'len' => $info['length'],
|
||||||
'flags' => ($got_string)
|
'flags' => ($got_string)
|
||||||
? $this->_ibaseFieldFlags($info['name'], $result)
|
? $this->_ibaseFieldFlags($info['name'], $result)
|
||||||
: '',
|
: '',
|
||||||
);
|
);
|
||||||
if ($mode & DB_TABLEINFO_ORDER) {
|
if ($mode & DB_TABLEINFO_ORDER) {
|
||||||
$res['order'][$res[$i]['name']] = $i;
|
$res['order'][$res[$i]['name']] = $i;
|
||||||
|
@ -1051,13 +980,85 @@ class DB_ibase extends DB_common
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ tableInfo()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the column's flags
|
||||||
|
*
|
||||||
|
* Supports "primary_key", "unique_key", "not_null", "default",
|
||||||
|
* "computed" and "blob".
|
||||||
|
*
|
||||||
|
* @param string $field_name the name of the field
|
||||||
|
* @param string $table_name the name of the table
|
||||||
|
*
|
||||||
|
* @return string the flags
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
public function _ibaseFieldFlags($field_name, $table_name)
|
||||||
|
{
|
||||||
|
$sql = 'SELECT R.RDB$CONSTRAINT_TYPE CTYPE'
|
||||||
|
. ' FROM RDB$INDEX_SEGMENTS I'
|
||||||
|
. ' JOIN RDB$RELATION_CONSTRAINTS R ON I.RDB$INDEX_NAME=R.RDB$INDEX_NAME'
|
||||||
|
. ' WHERE I.RDB$FIELD_NAME=\'' . $field_name . '\''
|
||||||
|
. ' AND UPPER(R.RDB$RELATION_NAME)=\'' . strtoupper($table_name) . '\'';
|
||||||
|
|
||||||
|
$result = @ibase_query($this->connection, $sql);
|
||||||
|
if (!$result) {
|
||||||
|
return $this->ibaseRaiseError();
|
||||||
|
}
|
||||||
|
|
||||||
|
$flags = '';
|
||||||
|
if ($obj = @ibase_fetch_object($result)) {
|
||||||
|
@ibase_free_result($result);
|
||||||
|
if (isset($obj->CTYPE) && trim($obj->CTYPE) == 'PRIMARY KEY') {
|
||||||
|
$flags .= 'primary_key ';
|
||||||
|
}
|
||||||
|
if (isset($obj->CTYPE) && trim($obj->CTYPE) == 'UNIQUE') {
|
||||||
|
$flags .= 'unique_key ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = 'SELECT R.RDB$NULL_FLAG AS NFLAG,'
|
||||||
|
. ' R.RDB$DEFAULT_SOURCE AS DSOURCE,'
|
||||||
|
. ' F.RDB$FIELD_TYPE AS FTYPE,'
|
||||||
|
. ' F.RDB$COMPUTED_SOURCE AS CSOURCE'
|
||||||
|
. ' FROM RDB$RELATION_FIELDS R '
|
||||||
|
. ' JOIN RDB$FIELDS F ON R.RDB$FIELD_SOURCE=F.RDB$FIELD_NAME'
|
||||||
|
. ' WHERE UPPER(R.RDB$RELATION_NAME)=\'' . strtoupper($table_name) . '\''
|
||||||
|
. ' AND R.RDB$FIELD_NAME=\'' . $field_name . '\'';
|
||||||
|
|
||||||
|
$result = @ibase_query($this->connection, $sql);
|
||||||
|
if (!$result) {
|
||||||
|
return $this->ibaseRaiseError();
|
||||||
|
}
|
||||||
|
if ($obj = @ibase_fetch_object($result)) {
|
||||||
|
@ibase_free_result($result);
|
||||||
|
if (isset($obj->NFLAG)) {
|
||||||
|
$flags .= 'not_null ';
|
||||||
|
}
|
||||||
|
if (isset($obj->DSOURCE)) {
|
||||||
|
$flags .= 'default ';
|
||||||
|
}
|
||||||
|
if (isset($obj->CSOURCE)) {
|
||||||
|
$flags .= 'computed ';
|
||||||
|
}
|
||||||
|
if (isset($obj->FTYPE) && $obj->FTYPE == 261) {
|
||||||
|
$flags .= 'blob ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return trim($flags);
|
||||||
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ getSpecialQuery()
|
// {{{ getSpecialQuery()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains the query string needed for listing a given type of objects
|
* Obtains the query string needed for listing a given type of objects
|
||||||
*
|
*
|
||||||
* @param string $type the kind of objects you want to retrieve
|
* @param string $type the kind of objects you want to retrieve
|
||||||
*
|
*
|
||||||
* @return string the SQL query string or null if the driver doesn't
|
* @return string the SQL query string or null if the driver doesn't
|
||||||
* support the object type requested
|
* support the object type requested
|
||||||
|
@ -1070,7 +1071,7 @@ class DB_ibase extends DB_common
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'tables':
|
case 'tables':
|
||||||
return 'SELECT DISTINCT R.RDB$RELATION_NAME FROM '
|
return 'SELECT DISTINCT R.RDB$RELATION_NAME FROM '
|
||||||
. 'RDB$RELATION_FIELDS R WHERE R.RDB$SYSTEM_FLAG=0';
|
. 'RDB$RELATION_FIELDS R WHERE R.RDB$SYSTEM_FLAG=0';
|
||||||
case 'views':
|
case 'views':
|
||||||
return 'SELECT DISTINCT RDB$VIEW_NAME from RDB$VIEW_RELATIONS';
|
return 'SELECT DISTINCT RDB$VIEW_NAME from RDB$VIEW_RELATIONS';
|
||||||
case 'users':
|
case 'users':
|
||||||
|
|
|
@ -27,7 +27,8 @@
|
||||||
/**
|
/**
|
||||||
* Obtain the DB_common class so it can be extended from
|
* Obtain the DB_common class so it can be extended from
|
||||||
*/
|
*/
|
||||||
require_once 'DB/common.php';
|
//require_once 'DB/common.php';
|
||||||
|
require_once 'common.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The methods PEAR DB uses to interact with PHP's ifx extension
|
* The methods PEAR DB uses to interact with PHP's ifx extension
|
||||||
|
@ -81,13 +82,13 @@ class DB_ifx extends DB_common
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $features = array(
|
public $features = array(
|
||||||
'limit' => 'emulate',
|
'limit' => 'emulate',
|
||||||
'new_link' => false,
|
'new_link' => false,
|
||||||
'numrows' => 'emulate',
|
'numrows' => 'emulate',
|
||||||
'pconnect' => true,
|
'pconnect' => true,
|
||||||
'prepare' => false,
|
'prepare' => false,
|
||||||
'ssl' => false,
|
'ssl' => false,
|
||||||
'transactions' => true,
|
'transactions' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,33 +96,33 @@ class DB_ifx extends DB_common
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $errorcode_map = array(
|
public $errorcode_map = array(
|
||||||
'-201' => DB_ERROR_SYNTAX,
|
'-201' => DB_ERROR_SYNTAX,
|
||||||
'-206' => DB_ERROR_NOSUCHTABLE,
|
'-206' => DB_ERROR_NOSUCHTABLE,
|
||||||
'-217' => DB_ERROR_NOSUCHFIELD,
|
'-217' => DB_ERROR_NOSUCHFIELD,
|
||||||
'-236' => DB_ERROR_VALUE_COUNT_ON_ROW,
|
'-236' => DB_ERROR_VALUE_COUNT_ON_ROW,
|
||||||
'-239' => DB_ERROR_CONSTRAINT,
|
'-239' => DB_ERROR_CONSTRAINT,
|
||||||
'-253' => DB_ERROR_SYNTAX,
|
'-253' => DB_ERROR_SYNTAX,
|
||||||
'-268' => DB_ERROR_CONSTRAINT,
|
'-268' => DB_ERROR_CONSTRAINT,
|
||||||
'-292' => DB_ERROR_CONSTRAINT_NOT_NULL,
|
'-292' => DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||||
'-310' => DB_ERROR_ALREADY_EXISTS,
|
'-310' => DB_ERROR_ALREADY_EXISTS,
|
||||||
'-316' => DB_ERROR_ALREADY_EXISTS,
|
'-316' => DB_ERROR_ALREADY_EXISTS,
|
||||||
'-319' => DB_ERROR_NOT_FOUND,
|
'-319' => DB_ERROR_NOT_FOUND,
|
||||||
'-329' => DB_ERROR_NODBSELECTED,
|
'-329' => DB_ERROR_NODBSELECTED,
|
||||||
'-346' => DB_ERROR_CONSTRAINT,
|
'-346' => DB_ERROR_CONSTRAINT,
|
||||||
'-386' => DB_ERROR_CONSTRAINT_NOT_NULL,
|
'-386' => DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||||
'-391' => DB_ERROR_CONSTRAINT_NOT_NULL,
|
'-391' => DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||||
'-554' => DB_ERROR_SYNTAX,
|
'-554' => DB_ERROR_SYNTAX,
|
||||||
'-691' => DB_ERROR_CONSTRAINT,
|
'-691' => DB_ERROR_CONSTRAINT,
|
||||||
'-692' => DB_ERROR_CONSTRAINT,
|
'-692' => DB_ERROR_CONSTRAINT,
|
||||||
'-703' => DB_ERROR_CONSTRAINT_NOT_NULL,
|
'-703' => DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||||
'-1202' => DB_ERROR_DIVZERO,
|
'-1202' => DB_ERROR_DIVZERO,
|
||||||
'-1204' => DB_ERROR_INVALID_DATE,
|
'-1204' => DB_ERROR_INVALID_DATE,
|
||||||
'-1205' => DB_ERROR_INVALID_DATE,
|
'-1205' => DB_ERROR_INVALID_DATE,
|
||||||
'-1206' => DB_ERROR_INVALID_DATE,
|
'-1206' => DB_ERROR_INVALID_DATE,
|
||||||
'-1209' => DB_ERROR_INVALID_DATE,
|
'-1209' => DB_ERROR_INVALID_DATE,
|
||||||
'-1210' => DB_ERROR_INVALID_DATE,
|
'-1210' => DB_ERROR_INVALID_DATE,
|
||||||
'-1212' => DB_ERROR_INVALID_DATE,
|
'-1212' => DB_ERROR_INVALID_DATE,
|
||||||
'-1213' => DB_ERROR_INVALID_NUMBER,
|
'-1213' => DB_ERROR_INVALID_NUMBER,
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -184,10 +185,10 @@ class DB_ifx extends DB_common
|
||||||
*
|
*
|
||||||
* Don't call this method directly. Use DB::connect() instead.
|
* Don't call this method directly. Use DB::connect() instead.
|
||||||
*
|
*
|
||||||
* @param array $dsn the data source name
|
* @param array $dsn the data source name
|
||||||
* @param bool $persistent should the connection be persistent?
|
* @param bool $persistent should the connection be persistent?
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function connect($dsn, $persistent = false)
|
public function connect($dsn, $persistent = false)
|
||||||
{
|
{
|
||||||
|
@ -218,6 +219,72 @@ class DB_ifx extends DB_common
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ disconnect()
|
// {{{ disconnect()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produces a DB_Error object regarding the current problem
|
||||||
|
*
|
||||||
|
* @param int $errno if the error is being manually raised pass a
|
||||||
|
* DB_ERROR* constant here. If this isn't passed
|
||||||
|
* the error information gathered from the DBMS.
|
||||||
|
*
|
||||||
|
* @return object the DB_Error object
|
||||||
|
*
|
||||||
|
* @see DB_common::raiseError(),
|
||||||
|
* DB_ifx::errorNative(), DB_ifx::errorCode()
|
||||||
|
*/
|
||||||
|
public function ifxRaiseError($errno = null)
|
||||||
|
{
|
||||||
|
if ($errno === null) {
|
||||||
|
$errno = $this->errorCode(ifx_error());
|
||||||
|
}
|
||||||
|
return $this->raiseError(
|
||||||
|
$errno,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
$this->errorNative()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ simpleQuery()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps native error codes to DB's portable ones.
|
||||||
|
*
|
||||||
|
* Requires that the DB implementation's constructor fills
|
||||||
|
* in the <var>$errorcode_map</var> property.
|
||||||
|
*
|
||||||
|
* @param string $nativecode error code returned by the database
|
||||||
|
* @return int a portable DB error code, or DB_ERROR if this DB
|
||||||
|
* implementation has no mapping for the given error code.
|
||||||
|
*/
|
||||||
|
public function errorCode($nativecode)
|
||||||
|
{
|
||||||
|
if (preg_match('/SQLCODE=(.*)]/', $nativecode, $match)) {
|
||||||
|
$code = $match[1];
|
||||||
|
if (isset($this->errorcode_map[$code])) {
|
||||||
|
return $this->errorcode_map[$code];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DB_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ nextResult()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the DBMS' native error code and message produced by the last query
|
||||||
|
*
|
||||||
|
* @return string the DBMS' error code and message
|
||||||
|
*/
|
||||||
|
public function errorNative()
|
||||||
|
{
|
||||||
|
return @ifx_error() . ' ' . @ifx_errormsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ affectedRows()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disconnects from the database server
|
* Disconnects from the database server
|
||||||
*
|
*
|
||||||
|
@ -231,7 +298,7 @@ class DB_ifx extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ simpleQuery()
|
// {{{ fetchInto()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a query to the database server
|
* Sends a query to the database server
|
||||||
|
@ -246,7 +313,7 @@ class DB_ifx extends DB_common
|
||||||
{
|
{
|
||||||
$ismanip = $this->_checkManip($query);
|
$ismanip = $this->_checkManip($query);
|
||||||
$this->last_query = $query;
|
$this->last_query = $query;
|
||||||
$this->affected = null;
|
$this->affected = null;
|
||||||
if (preg_match('/(SELECT|EXECUTE)/i', $query)) { //TESTME: Use !DB::isManip()?
|
if (preg_match('/(SELECT|EXECUTE)/i', $query)) { //TESTME: Use !DB::isManip()?
|
||||||
// the scroll is needed for fetching absolute row numbers
|
// the scroll is needed for fetching absolute row numbers
|
||||||
// in a select query result
|
// in a select query result
|
||||||
|
@ -282,7 +349,7 @@ class DB_ifx extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ nextResult()
|
// {{{ numCols()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the internal ifx result pointer to the next available result
|
* Move the internal ifx result pointer to the next available result
|
||||||
|
@ -299,7 +366,7 @@ class DB_ifx extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ affectedRows()
|
// {{{ freeResult()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the number of rows affected by a data maniuplation query
|
* Determines the number of rows affected by a data maniuplation query
|
||||||
|
@ -318,7 +385,7 @@ class DB_ifx extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ fetchInto()
|
// {{{ autoCommit()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Places a row from the result set into the given array
|
* Places a row from the result set into the given array
|
||||||
|
@ -330,10 +397,10 @@ class DB_ifx extends DB_common
|
||||||
* DB_result::fetchInto() instead. It can't be declared "protected"
|
* DB_result::fetchInto() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result the query result resource
|
* @param resource $result the query result resource
|
||||||
* @param array $arr the referenced array to put the data in
|
* @param array $arr the referenced array to put the data in
|
||||||
* @param int $fetchmode how the resulting array should be indexed
|
* @param int $fetchmode how the resulting array should be indexed
|
||||||
* @param int $rownum the row number to fetch (0 = first row)
|
* @param int $rownum the row number to fetch (0 = first row)
|
||||||
*
|
*
|
||||||
* @return mixed DB_OK on success, NULL when the end of a result set is
|
* @return mixed DB_OK on success, NULL when the end of a result set is
|
||||||
* reached or on failure
|
* reached or on failure
|
||||||
|
@ -359,14 +426,14 @@ class DB_ifx extends DB_common
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if ($fetchmode !== DB_FETCHMODE_ASSOC) {
|
if ($fetchmode !== DB_FETCHMODE_ASSOC) {
|
||||||
$i=0;
|
$i = 0;
|
||||||
$order = array();
|
$order = array();
|
||||||
foreach ($arr as $val) {
|
foreach ($arr as $val) {
|
||||||
$order[$i++] = $val;
|
$order[$i++] = $val;
|
||||||
}
|
}
|
||||||
$arr = $order;
|
$arr = $order;
|
||||||
} elseif ($fetchmode == DB_FETCHMODE_ASSOC &&
|
} elseif ($fetchmode == DB_FETCHMODE_ASSOC &&
|
||||||
$this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
|
$this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
|
||||||
$arr = array_change_key_case($arr, CASE_LOWER);
|
$arr = array_change_key_case($arr, CASE_LOWER);
|
||||||
}
|
}
|
||||||
if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
|
if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
|
||||||
|
@ -379,7 +446,7 @@ class DB_ifx extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ numCols()
|
// {{{ commit()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of columns in a result set
|
* Gets the number of columns in a result set
|
||||||
|
@ -388,9 +455,9 @@ class DB_ifx extends DB_common
|
||||||
* DB_result::numCols() instead. It can't be declared "protected"
|
* DB_result::numCols() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return int the number of columns. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @see DB_result::numCols()
|
* @see DB_result::numCols()
|
||||||
*/
|
*/
|
||||||
|
@ -403,7 +470,7 @@ class DB_ifx extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ freeResult()
|
// {{{ rollback()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the result set and frees the memory occupied by the result set
|
* Deletes the result set and frees the memory occupied by the result set
|
||||||
|
@ -412,7 +479,7 @@ class DB_ifx extends DB_common
|
||||||
* DB_result::free() instead. It can't be declared "protected"
|
* DB_result::free() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return bool TRUE on success, FALSE if $result is invalid
|
* @return bool TRUE on success, FALSE if $result is invalid
|
||||||
*
|
*
|
||||||
|
@ -424,12 +491,12 @@ class DB_ifx extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ autoCommit()
|
// {{{ ifxRaiseError()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables or disables automatic commits
|
* Enables or disables automatic commits
|
||||||
*
|
*
|
||||||
* @param bool $onoff true turns it on, false turns it off
|
* @param bool $onoff true turns it on, false turns it off
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object if the driver
|
* @return int DB_OK on success. A DB_Error object if the driver
|
||||||
* doesn't support auto-committing transactions.
|
* doesn't support auto-committing transactions.
|
||||||
|
@ -443,12 +510,12 @@ class DB_ifx extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ commit()
|
// {{{ errorNative()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commits the current transaction
|
* Commits the current transaction
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function commit()
|
public function commit()
|
||||||
{
|
{
|
||||||
|
@ -463,12 +530,12 @@ class DB_ifx extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ rollback()
|
// {{{ errorCode()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverts the current transaction
|
* Reverts the current transaction
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function rollback()
|
public function rollback()
|
||||||
{
|
{
|
||||||
|
@ -482,72 +549,6 @@ class DB_ifx extends DB_common
|
||||||
return DB_OK;
|
return DB_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ ifxRaiseError()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Produces a DB_Error object regarding the current problem
|
|
||||||
*
|
|
||||||
* @param int $errno if the error is being manually raised pass a
|
|
||||||
* DB_ERROR* constant here. If this isn't passed
|
|
||||||
* the error information gathered from the DBMS.
|
|
||||||
*
|
|
||||||
* @return object the DB_Error object
|
|
||||||
*
|
|
||||||
* @see DB_common::raiseError(),
|
|
||||||
* DB_ifx::errorNative(), DB_ifx::errorCode()
|
|
||||||
*/
|
|
||||||
public function ifxRaiseError($errno = null)
|
|
||||||
{
|
|
||||||
if ($errno === null) {
|
|
||||||
$errno = $this->errorCode(ifx_error());
|
|
||||||
}
|
|
||||||
return $this->raiseError(
|
|
||||||
$errno,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
$this->errorNative()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ errorNative()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the DBMS' native error code and message produced by the last query
|
|
||||||
*
|
|
||||||
* @return string the DBMS' error code and message
|
|
||||||
*/
|
|
||||||
public function errorNative()
|
|
||||||
{
|
|
||||||
return @ifx_error() . ' ' . @ifx_errormsg();
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ errorCode()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Maps native error codes to DB's portable ones.
|
|
||||||
*
|
|
||||||
* Requires that the DB implementation's constructor fills
|
|
||||||
* in the <var>$errorcode_map</var> property.
|
|
||||||
*
|
|
||||||
* @param string $nativecode error code returned by the database
|
|
||||||
* @return int a portable DB error code, or DB_ERROR if this DB
|
|
||||||
* implementation has no mapping for the given error code.
|
|
||||||
*/
|
|
||||||
public function errorCode($nativecode)
|
|
||||||
{
|
|
||||||
if (preg_match('/SQLCODE=(.*)]/', $nativecode, $match)) {
|
|
||||||
$code = $match[1];
|
|
||||||
if (isset($this->errorcode_map[$code])) {
|
|
||||||
return $this->errorcode_map[$code];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return DB_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ tableInfo()
|
// {{{ tableInfo()
|
||||||
|
|
||||||
|
@ -560,14 +561,14 @@ class DB_ifx extends DB_common
|
||||||
* an error will be raised saying
|
* an error will be raised saying
|
||||||
* <samp>can't distinguish duplicate field names</samp>.
|
* <samp>can't distinguish duplicate field names</samp>.
|
||||||
*
|
*
|
||||||
* @param object|string $result DB_result object from a query or a
|
* @param object|string $result DB_result object from a query or a
|
||||||
* string containing the name of a table.
|
* string containing the name of a table.
|
||||||
* While this also accepts a query result
|
* While this also accepts a query result
|
||||||
* resource identifier, this behavior is
|
* resource identifier, this behavior is
|
||||||
* deprecated.
|
* deprecated.
|
||||||
* @param int $mode a valid tableInfo mode
|
* @param int $mode a valid tableInfo mode
|
||||||
*
|
*
|
||||||
* @return array an associative array with the information requested.
|
* @return array|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::tableInfo()
|
* @see DB_common::tableInfo()
|
||||||
|
@ -618,7 +619,7 @@ class DB_ifx extends DB_common
|
||||||
$case_func = 'strval';
|
$case_func = 'strval';
|
||||||
}
|
}
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$res = array();
|
$res = array();
|
||||||
|
|
||||||
if ($mode) {
|
if ($mode) {
|
||||||
|
@ -629,9 +630,9 @@ class DB_ifx extends DB_common
|
||||||
$props = explode(';', $value);
|
$props = explode(';', $value);
|
||||||
$res[$i] = array(
|
$res[$i] = array(
|
||||||
'table' => $got_string ? $case_func($result) : '',
|
'table' => $got_string ? $case_func($result) : '',
|
||||||
'name' => $case_func($key),
|
'name' => $case_func($key),
|
||||||
'type' => $props[0],
|
'type' => $props[0],
|
||||||
'len' => $props[1],
|
'len' => $props[1],
|
||||||
'flags' => $props[4] == 'N' ? 'not_null' : '',
|
'flags' => $props[4] == 'N' ? 'not_null' : '',
|
||||||
);
|
);
|
||||||
if ($mode & DB_TABLEINFO_ORDER) {
|
if ($mode & DB_TABLEINFO_ORDER) {
|
||||||
|
@ -656,7 +657,7 @@ class DB_ifx extends DB_common
|
||||||
/**
|
/**
|
||||||
* Obtains the query string needed for listing a given type of objects
|
* Obtains the query string needed for listing a given type of objects
|
||||||
*
|
*
|
||||||
* @param string $type the kind of objects you want to retrieve
|
* @param string $type the kind of objects you want to retrieve
|
||||||
*
|
*
|
||||||
* @return string the SQL query string or null if the driver doesn't
|
* @return string the SQL query string or null if the driver doesn't
|
||||||
* support the object type requested
|
* support the object type requested
|
||||||
|
|
|
@ -30,7 +30,8 @@
|
||||||
/**
|
/**
|
||||||
* Obtain the DB_common class so it can be extended from
|
* Obtain the DB_common class so it can be extended from
|
||||||
*/
|
*/
|
||||||
require_once 'DB/common.php';
|
//require_once 'DB/common.php';
|
||||||
|
require_once 'common.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The methods PEAR DB uses to interact with PHP's msql extension
|
* The methods PEAR DB uses to interact with PHP's msql extension
|
||||||
|
@ -81,21 +82,20 @@ class DB_msql extends DB_common
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $features = array(
|
public $features = array(
|
||||||
'limit' => 'emulate',
|
'limit' => 'emulate',
|
||||||
'new_link' => false,
|
'new_link' => false,
|
||||||
'numrows' => true,
|
'numrows' => true,
|
||||||
'pconnect' => true,
|
'pconnect' => true,
|
||||||
'prepare' => false,
|
'prepare' => false,
|
||||||
'ssl' => false,
|
'ssl' => false,
|
||||||
'transactions' => false,
|
'transactions' => false,
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mapping of native error codes to DB error codes
|
* A mapping of native error codes to DB error codes
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $errorcode_map = array(
|
public $errorcode_map = array();
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The raw database connection created by PHP
|
* The raw database connection created by PHP
|
||||||
|
@ -154,15 +154,15 @@ class DB_msql extends DB_common
|
||||||
* );
|
* );
|
||||||
*
|
*
|
||||||
* $db = DB::connect($dsn, $options);
|
* $db = DB::connect($dsn, $options);
|
||||||
* if (PEAR::isError($db)) {
|
* if ((new PEAR)->isError($db)) {
|
||||||
* die($db->getMessage());
|
* die($db->getMessage());
|
||||||
* }
|
* }
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @param array $dsn the data source name
|
* @param array $dsn the data source name
|
||||||
* @param bool $persistent should the connection be persistent?
|
* @param bool $persistent should the connection be persistent?
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function connect($dsn, $persistent = false)
|
public function connect($dsn, $persistent = false)
|
||||||
{
|
{
|
||||||
|
@ -178,8 +178,8 @@ class DB_msql extends DB_common
|
||||||
$params = array();
|
$params = array();
|
||||||
if ($dsn['hostspec']) {
|
if ($dsn['hostspec']) {
|
||||||
$params[] = $dsn['port']
|
$params[] = $dsn['port']
|
||||||
? $dsn['hostspec'] . ',' . $dsn['port']
|
? $dsn['hostspec'] . ',' . $dsn['port']
|
||||||
: $dsn['hostspec'];
|
: $dsn['hostspec'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$connect_function = $persistent ? 'msql_pconnect' : 'msql_connect';
|
$connect_function = $persistent ? 'msql_pconnect' : 'msql_connect';
|
||||||
|
@ -229,6 +229,127 @@ class DB_msql extends DB_common
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ disconnect()
|
// {{{ disconnect()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produces a DB_Error object regarding the current problem
|
||||||
|
*
|
||||||
|
* @param int $errno if the error is being manually raised pass a
|
||||||
|
* DB_ERROR* constant here. If this isn't passed
|
||||||
|
* the error information gathered from the DBMS.
|
||||||
|
*
|
||||||
|
* @return object the DB_Error object
|
||||||
|
*
|
||||||
|
* @see DB_common::raiseError(),
|
||||||
|
* DB_msql::errorNative(), DB_msql::errorCode()
|
||||||
|
*/
|
||||||
|
public function msqlRaiseError($errno = null)
|
||||||
|
{
|
||||||
|
$native = $this->errorNative();
|
||||||
|
if ($errno === null) {
|
||||||
|
$errno = $this->errorCode($native);
|
||||||
|
}
|
||||||
|
return $this->raiseError($errno, null, null, null, $native);
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ simpleQuery()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the DBMS' native error message produced by the last query
|
||||||
|
*
|
||||||
|
* @return string the DBMS' error message
|
||||||
|
*/
|
||||||
|
public function errorNative()
|
||||||
|
{
|
||||||
|
return @msql_error();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ nextResult()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines PEAR::DB error code from the database's text error message
|
||||||
|
*
|
||||||
|
* @param string $errormsg the error message returned from the database
|
||||||
|
*
|
||||||
|
* @return integer the error number from a DB_ERROR* constant
|
||||||
|
*/
|
||||||
|
public function errorCode($errormsg)
|
||||||
|
{
|
||||||
|
static $error_regexps;
|
||||||
|
|
||||||
|
// PHP 5.2+ prepends the function name to $php_errormsg, so we need
|
||||||
|
// this hack to work around it, per bug #9599.
|
||||||
|
$errormsg = preg_replace('/^msql[a-z_]+\(\): /', '', $errormsg);
|
||||||
|
|
||||||
|
if (!isset($error_regexps)) {
|
||||||
|
$error_regexps = array(
|
||||||
|
'/^Access to database denied/i'
|
||||||
|
=> DB_ERROR_ACCESS_VIOLATION,
|
||||||
|
'/^Bad index name/i'
|
||||||
|
=> DB_ERROR_ALREADY_EXISTS,
|
||||||
|
'/^Bad order field/i'
|
||||||
|
=> DB_ERROR_SYNTAX,
|
||||||
|
'/^Bad type for comparison/i'
|
||||||
|
=> DB_ERROR_SYNTAX,
|
||||||
|
'/^Can\'t perform LIKE on/i'
|
||||||
|
=> DB_ERROR_SYNTAX,
|
||||||
|
'/^Can\'t use TEXT fields in LIKE comparison/i'
|
||||||
|
=> DB_ERROR_SYNTAX,
|
||||||
|
'/^Couldn\'t create temporary table/i'
|
||||||
|
=> DB_ERROR_CANNOT_CREATE,
|
||||||
|
'/^Error creating table file/i'
|
||||||
|
=> DB_ERROR_CANNOT_CREATE,
|
||||||
|
'/^Field .* cannot be null$/i'
|
||||||
|
=> DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||||
|
'/^Index (field|condition) .* cannot be null$/i'
|
||||||
|
=> DB_ERROR_SYNTAX,
|
||||||
|
'/^Invalid date format/i'
|
||||||
|
=> DB_ERROR_INVALID_DATE,
|
||||||
|
'/^Invalid time format/i'
|
||||||
|
=> DB_ERROR_INVALID,
|
||||||
|
'/^Literal value for .* is wrong type$/i'
|
||||||
|
=> DB_ERROR_INVALID_NUMBER,
|
||||||
|
'/^No Database Selected/i'
|
||||||
|
=> DB_ERROR_NODBSELECTED,
|
||||||
|
'/^No value specified for field/i'
|
||||||
|
=> DB_ERROR_VALUE_COUNT_ON_ROW,
|
||||||
|
'/^Non unique value for unique index/i'
|
||||||
|
=> DB_ERROR_CONSTRAINT,
|
||||||
|
'/^Out of memory for temporary table/i'
|
||||||
|
=> DB_ERROR_CANNOT_CREATE,
|
||||||
|
'/^Permission denied/i'
|
||||||
|
=> DB_ERROR_ACCESS_VIOLATION,
|
||||||
|
'/^Reference to un-selected table/i'
|
||||||
|
=> DB_ERROR_SYNTAX,
|
||||||
|
'/^syntax error/i'
|
||||||
|
=> DB_ERROR_SYNTAX,
|
||||||
|
'/^Table .* exists$/i'
|
||||||
|
=> DB_ERROR_ALREADY_EXISTS,
|
||||||
|
'/^Unknown database/i'
|
||||||
|
=> DB_ERROR_NOSUCHDB,
|
||||||
|
'/^Unknown field/i'
|
||||||
|
=> DB_ERROR_NOSUCHFIELD,
|
||||||
|
'/^Unknown (index|system variable)/i'
|
||||||
|
=> DB_ERROR_NOT_FOUND,
|
||||||
|
'/^Unknown table/i'
|
||||||
|
=> DB_ERROR_NOSUCHTABLE,
|
||||||
|
'/^Unqualified field/i'
|
||||||
|
=> DB_ERROR_SYNTAX,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($error_regexps as $regexp => $code) {
|
||||||
|
if (preg_match($regexp, $errormsg)) {
|
||||||
|
return $code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DB_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ fetchInto()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disconnects from the database server
|
* Disconnects from the database server
|
||||||
*
|
*
|
||||||
|
@ -242,7 +363,7 @@ class DB_msql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ simpleQuery()
|
// {{{ freeResult()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a query to the database server
|
* Sends a query to the database server
|
||||||
|
@ -272,9 +393,8 @@ class DB_msql extends DB_common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ nextResult()
|
// {{{ numCols()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the internal msql result pointer to the next available result
|
* Move the internal msql result pointer to the next available result
|
||||||
|
@ -291,7 +411,7 @@ class DB_msql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ fetchInto()
|
// {{{ numRows()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Places a row from the result set into the given array
|
* Places a row from the result set into the given array
|
||||||
|
@ -307,10 +427,10 @@ class DB_msql extends DB_common
|
||||||
* 4.3.11 and 5.0.4. Make sure your version of PHP meets or exceeds
|
* 4.3.11 and 5.0.4. Make sure your version of PHP meets or exceeds
|
||||||
* those versions.
|
* those versions.
|
||||||
*
|
*
|
||||||
* @param resource $result the query result resource
|
* @param resource $result the query result resource
|
||||||
* @param array $arr the referenced array to put the data in
|
* @param array $arr the referenced array to put the data in
|
||||||
* @param int $fetchmode how the resulting array should be indexed
|
* @param int $fetchmode how the resulting array should be indexed
|
||||||
* @param int $rownum the row number to fetch (0 = first row)
|
* @param int $rownum the row number to fetch (0 = first row)
|
||||||
*
|
*
|
||||||
* @return mixed DB_OK on success, NULL when the end of a result set is
|
* @return mixed DB_OK on success, NULL when the end of a result set is
|
||||||
* reached or on failure
|
* reached or on failure
|
||||||
|
@ -345,7 +465,7 @@ class DB_msql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ freeResult()
|
// {{{ affected()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the result set and frees the memory occupied by the result set
|
* Deletes the result set and frees the memory occupied by the result set
|
||||||
|
@ -354,7 +474,7 @@ class DB_msql extends DB_common
|
||||||
* DB_result::free() instead. It can't be declared "protected"
|
* DB_result::free() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return bool TRUE on success, FALSE if $result is invalid
|
* @return bool TRUE on success, FALSE if $result is invalid
|
||||||
*
|
*
|
||||||
|
@ -366,7 +486,7 @@ class DB_msql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ numCols()
|
// {{{ nextId()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of columns in a result set
|
* Gets the number of columns in a result set
|
||||||
|
@ -375,9 +495,9 @@ class DB_msql extends DB_common
|
||||||
* DB_result::numCols() instead. It can't be declared "protected"
|
* DB_result::numCols() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return int the number of columns. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @see DB_result::numCols()
|
* @see DB_result::numCols()
|
||||||
*/
|
*/
|
||||||
|
@ -391,7 +511,7 @@ class DB_msql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ numRows()
|
// {{{ createSequence()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of rows in a result set
|
* Gets the number of rows in a result set
|
||||||
|
@ -400,9 +520,9 @@ class DB_msql extends DB_common
|
||||||
* DB_result::numRows() instead. It can't be declared "protected"
|
* DB_result::numRows() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return int the number of rows. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @see DB_result::numRows()
|
* @see DB_result::numRows()
|
||||||
*/
|
*/
|
||||||
|
@ -416,7 +536,7 @@ class DB_msql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ affected()
|
// {{{ dropSequence()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the number of rows affected by a data maniuplation query
|
* Determines the number of rows affected by a data maniuplation query
|
||||||
|
@ -434,16 +554,16 @@ class DB_msql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ nextId()
|
// {{{ quoteIdentifier()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the next free id in a sequence
|
* Returns the next free id in a sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the sequence
|
* @param string $seq_name name of the sequence
|
||||||
* @param boolean $ondemand when true, the seqence is automatically
|
* @param boolean $ondemand when true, the seqence is automatically
|
||||||
* created if it does not exist
|
* created if it does not exist
|
||||||
*
|
*
|
||||||
* @return int the next id number in the sequence.
|
* @return int|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
||||||
|
@ -479,7 +599,7 @@ class DB_msql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ createSequence()
|
// {{{ quoteFloat()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new sequence
|
* Creates a new sequence
|
||||||
|
@ -487,7 +607,7 @@ class DB_msql extends DB_common
|
||||||
* Also creates a new table to associate the sequence with. Uses
|
* Also creates a new table to associate the sequence with. Uses
|
||||||
* a separate table to ensure portability with other drivers.
|
* a separate table to ensure portability with other drivers.
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the new sequence
|
* @param string $seq_name name of the new sequence
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
|
@ -498,7 +618,7 @@ class DB_msql extends DB_common
|
||||||
{
|
{
|
||||||
$seqname = $this->getSequenceName($seq_name);
|
$seqname = $this->getSequenceName($seq_name);
|
||||||
$res = $this->query('CREATE TABLE ' . $seqname
|
$res = $this->query('CREATE TABLE ' . $seqname
|
||||||
. ' (id INTEGER NOT NULL)');
|
. ' (id INTEGER NOT NULL)');
|
||||||
if (DB::isError($res)) {
|
if (DB::isError($res)) {
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
@ -507,12 +627,12 @@ class DB_msql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ dropSequence()
|
// {{{ escapeSimple()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a sequence
|
* Deletes a sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the sequence to be deleted
|
* @param string $seq_name name of the sequence to be deleted
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
|
@ -525,12 +645,12 @@ class DB_msql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ quoteIdentifier()
|
// {{{ msqlRaiseError()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mSQL does not support delimited identifiers
|
* mSQL does not support delimited identifiers
|
||||||
*
|
*
|
||||||
* @param string $str the identifier name to be quoted
|
* @param string $str the identifier name to be quoted
|
||||||
*
|
*
|
||||||
* @return object a DB_Error object
|
* @return object a DB_Error object
|
||||||
*
|
*
|
||||||
|
@ -543,7 +663,7 @@ class DB_msql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ quoteFloat()
|
// {{{ errorNative()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats a float value for use within a query in a locale-independent
|
* Formats a float value for use within a query in a locale-independent
|
||||||
|
@ -560,12 +680,12 @@ class DB_msql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ escapeSimple()
|
// {{{ errorCode()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Escapes a string according to the current DBMS's standards
|
* Escapes a string according to the current DBMS's standards
|
||||||
*
|
*
|
||||||
* @param string $str the string to be escaped
|
* @param string $str the string to be escaped
|
||||||
*
|
*
|
||||||
* @return string the escaped string
|
* @return string the escaped string
|
||||||
*
|
*
|
||||||
|
@ -577,140 +697,20 @@ class DB_msql extends DB_common
|
||||||
return addslashes($str);
|
return addslashes($str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ msqlRaiseError()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Produces a DB_Error object regarding the current problem
|
|
||||||
*
|
|
||||||
* @param int $errno if the error is being manually raised pass a
|
|
||||||
* DB_ERROR* constant here. If this isn't passed
|
|
||||||
* the error information gathered from the DBMS.
|
|
||||||
*
|
|
||||||
* @return object the DB_Error object
|
|
||||||
*
|
|
||||||
* @see DB_common::raiseError(),
|
|
||||||
* DB_msql::errorNative(), DB_msql::errorCode()
|
|
||||||
*/
|
|
||||||
public function msqlRaiseError($errno = null)
|
|
||||||
{
|
|
||||||
$native = $this->errorNative();
|
|
||||||
if ($errno === null) {
|
|
||||||
$errno = $this->errorCode($native);
|
|
||||||
}
|
|
||||||
return $this->raiseError($errno, null, null, null, $native);
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ errorNative()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the DBMS' native error message produced by the last query
|
|
||||||
*
|
|
||||||
* @return string the DBMS' error message
|
|
||||||
*/
|
|
||||||
public function errorNative()
|
|
||||||
{
|
|
||||||
return @msql_error();
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ errorCode()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines PEAR::DB error code from the database's text error message
|
|
||||||
*
|
|
||||||
* @param string $errormsg the error message returned from the database
|
|
||||||
*
|
|
||||||
* @return integer the error number from a DB_ERROR* constant
|
|
||||||
*/
|
|
||||||
public function errorCode($errormsg)
|
|
||||||
{
|
|
||||||
static $error_regexps;
|
|
||||||
|
|
||||||
// PHP 5.2+ prepends the function name to $php_errormsg, so we need
|
|
||||||
// this hack to work around it, per bug #9599.
|
|
||||||
$errormsg = preg_replace('/^msql[a-z_]+\(\): /', '', $errormsg);
|
|
||||||
|
|
||||||
if (!isset($error_regexps)) {
|
|
||||||
$error_regexps = array(
|
|
||||||
'/^Access to database denied/i'
|
|
||||||
=> DB_ERROR_ACCESS_VIOLATION,
|
|
||||||
'/^Bad index name/i'
|
|
||||||
=> DB_ERROR_ALREADY_EXISTS,
|
|
||||||
'/^Bad order field/i'
|
|
||||||
=> DB_ERROR_SYNTAX,
|
|
||||||
'/^Bad type for comparison/i'
|
|
||||||
=> DB_ERROR_SYNTAX,
|
|
||||||
'/^Can\'t perform LIKE on/i'
|
|
||||||
=> DB_ERROR_SYNTAX,
|
|
||||||
'/^Can\'t use TEXT fields in LIKE comparison/i'
|
|
||||||
=> DB_ERROR_SYNTAX,
|
|
||||||
'/^Couldn\'t create temporary table/i'
|
|
||||||
=> DB_ERROR_CANNOT_CREATE,
|
|
||||||
'/^Error creating table file/i'
|
|
||||||
=> DB_ERROR_CANNOT_CREATE,
|
|
||||||
'/^Field .* cannot be null$/i'
|
|
||||||
=> DB_ERROR_CONSTRAINT_NOT_NULL,
|
|
||||||
'/^Index (field|condition) .* cannot be null$/i'
|
|
||||||
=> DB_ERROR_SYNTAX,
|
|
||||||
'/^Invalid date format/i'
|
|
||||||
=> DB_ERROR_INVALID_DATE,
|
|
||||||
'/^Invalid time format/i'
|
|
||||||
=> DB_ERROR_INVALID,
|
|
||||||
'/^Literal value for .* is wrong type$/i'
|
|
||||||
=> DB_ERROR_INVALID_NUMBER,
|
|
||||||
'/^No Database Selected/i'
|
|
||||||
=> DB_ERROR_NODBSELECTED,
|
|
||||||
'/^No value specified for field/i'
|
|
||||||
=> DB_ERROR_VALUE_COUNT_ON_ROW,
|
|
||||||
'/^Non unique value for unique index/i'
|
|
||||||
=> DB_ERROR_CONSTRAINT,
|
|
||||||
'/^Out of memory for temporary table/i'
|
|
||||||
=> DB_ERROR_CANNOT_CREATE,
|
|
||||||
'/^Permission denied/i'
|
|
||||||
=> DB_ERROR_ACCESS_VIOLATION,
|
|
||||||
'/^Reference to un-selected table/i'
|
|
||||||
=> DB_ERROR_SYNTAX,
|
|
||||||
'/^syntax error/i'
|
|
||||||
=> DB_ERROR_SYNTAX,
|
|
||||||
'/^Table .* exists$/i'
|
|
||||||
=> DB_ERROR_ALREADY_EXISTS,
|
|
||||||
'/^Unknown database/i'
|
|
||||||
=> DB_ERROR_NOSUCHDB,
|
|
||||||
'/^Unknown field/i'
|
|
||||||
=> DB_ERROR_NOSUCHFIELD,
|
|
||||||
'/^Unknown (index|system variable)/i'
|
|
||||||
=> DB_ERROR_NOT_FOUND,
|
|
||||||
'/^Unknown table/i'
|
|
||||||
=> DB_ERROR_NOSUCHTABLE,
|
|
||||||
'/^Unqualified field/i'
|
|
||||||
=> DB_ERROR_SYNTAX,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($error_regexps as $regexp => $code) {
|
|
||||||
if (preg_match($regexp, $errormsg)) {
|
|
||||||
return $code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return DB_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ tableInfo()
|
// {{{ tableInfo()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns information about a table or a result set
|
* Returns information about a table or a result set
|
||||||
*
|
*
|
||||||
* @param object|string $result DB_result object from a query or a
|
* @param object|string $result DB_result object from a query or a
|
||||||
* string containing the name of a table.
|
* string containing the name of a table.
|
||||||
* While this also accepts a query result
|
* While this also accepts a query result
|
||||||
* resource identifier, this behavior is
|
* resource identifier, this behavior is
|
||||||
* deprecated.
|
* deprecated.
|
||||||
* @param int $mode a valid tableInfo mode
|
* @param int $mode a valid tableInfo mode
|
||||||
*
|
*
|
||||||
* @return array an associative array with the information requested.
|
* @return array|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::setOption()
|
* @see DB_common::setOption()
|
||||||
|
@ -755,7 +755,7 @@ class DB_msql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = @msql_num_fields($id);
|
$count = @msql_num_fields($id);
|
||||||
$res = array();
|
$res = array();
|
||||||
|
|
||||||
if ($mode) {
|
if ($mode) {
|
||||||
$res['num_fields'] = $count;
|
$res['num_fields'] = $count;
|
||||||
|
@ -775,9 +775,9 @@ class DB_msql extends DB_common
|
||||||
|
|
||||||
$res[$i] = array(
|
$res[$i] = array(
|
||||||
'table' => $case_func($tmp->table),
|
'table' => $case_func($tmp->table),
|
||||||
'name' => $case_func($tmp->name),
|
'name' => $case_func($tmp->name),
|
||||||
'type' => $tmp->type,
|
'type' => $tmp->type,
|
||||||
'len' => msql_field_len($id, $i),
|
'len' => msql_field_len($id, $i),
|
||||||
'flags' => $flags,
|
'flags' => $flags,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -802,9 +802,9 @@ class DB_msql extends DB_common
|
||||||
/**
|
/**
|
||||||
* Obtain a list of a given type of objects
|
* Obtain a list of a given type of objects
|
||||||
*
|
*
|
||||||
* @param string $type the kind of objects you want to retrieve
|
* @param string $type the kind of objects you want to retrieve
|
||||||
*
|
*
|
||||||
* @return array the array containing the list of objects requested
|
* @return array|object
|
||||||
*
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @see DB_common::getListOf()
|
* @see DB_common::getListOf()
|
||||||
|
|
|
@ -27,7 +27,8 @@
|
||||||
/**
|
/**
|
||||||
* Obtain the DB_common class so it can be extended from
|
* Obtain the DB_common class so it can be extended from
|
||||||
*/
|
*/
|
||||||
require_once 'DB/common.php';
|
//require_once 'DB/common.php';
|
||||||
|
require_once 'common.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The methods PEAR DB uses to interact with PHP's mssql extension
|
* The methods PEAR DB uses to interact with PHP's mssql extension
|
||||||
|
@ -82,13 +83,13 @@ class DB_mssql extends DB_common
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $features = array(
|
public $features = array(
|
||||||
'limit' => 'emulate',
|
'limit' => 'emulate',
|
||||||
'new_link' => false,
|
'new_link' => false,
|
||||||
'numrows' => true,
|
'numrows' => true,
|
||||||
'pconnect' => true,
|
'pconnect' => true,
|
||||||
'prepare' => false,
|
'prepare' => false,
|
||||||
'ssl' => false,
|
'ssl' => false,
|
||||||
'transactions' => true,
|
'transactions' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,39 +98,39 @@ class DB_mssql extends DB_common
|
||||||
*/
|
*/
|
||||||
// XXX Add here error codes ie: 'S100E' => DB_ERROR_SYNTAX
|
// XXX Add here error codes ie: 'S100E' => DB_ERROR_SYNTAX
|
||||||
public $errorcode_map = array(
|
public $errorcode_map = array(
|
||||||
102 => DB_ERROR_SYNTAX,
|
102 => DB_ERROR_SYNTAX,
|
||||||
110 => DB_ERROR_VALUE_COUNT_ON_ROW,
|
110 => DB_ERROR_VALUE_COUNT_ON_ROW,
|
||||||
155 => DB_ERROR_NOSUCHFIELD,
|
155 => DB_ERROR_NOSUCHFIELD,
|
||||||
156 => DB_ERROR_SYNTAX,
|
156 => DB_ERROR_SYNTAX,
|
||||||
170 => DB_ERROR_SYNTAX,
|
170 => DB_ERROR_SYNTAX,
|
||||||
207 => DB_ERROR_NOSUCHFIELD,
|
207 => DB_ERROR_NOSUCHFIELD,
|
||||||
208 => DB_ERROR_NOSUCHTABLE,
|
208 => DB_ERROR_NOSUCHTABLE,
|
||||||
245 => DB_ERROR_INVALID_NUMBER,
|
245 => DB_ERROR_INVALID_NUMBER,
|
||||||
319 => DB_ERROR_SYNTAX,
|
319 => DB_ERROR_SYNTAX,
|
||||||
321 => DB_ERROR_NOSUCHFIELD,
|
321 => DB_ERROR_NOSUCHFIELD,
|
||||||
325 => DB_ERROR_SYNTAX,
|
325 => DB_ERROR_SYNTAX,
|
||||||
336 => DB_ERROR_SYNTAX,
|
336 => DB_ERROR_SYNTAX,
|
||||||
515 => DB_ERROR_CONSTRAINT_NOT_NULL,
|
515 => DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||||
547 => DB_ERROR_CONSTRAINT,
|
547 => DB_ERROR_CONSTRAINT,
|
||||||
1018 => DB_ERROR_SYNTAX,
|
1018 => DB_ERROR_SYNTAX,
|
||||||
1035 => DB_ERROR_SYNTAX,
|
1035 => DB_ERROR_SYNTAX,
|
||||||
1913 => DB_ERROR_ALREADY_EXISTS,
|
1913 => DB_ERROR_ALREADY_EXISTS,
|
||||||
2209 => DB_ERROR_SYNTAX,
|
2209 => DB_ERROR_SYNTAX,
|
||||||
2223 => DB_ERROR_SYNTAX,
|
2223 => DB_ERROR_SYNTAX,
|
||||||
2248 => DB_ERROR_SYNTAX,
|
2248 => DB_ERROR_SYNTAX,
|
||||||
2256 => DB_ERROR_SYNTAX,
|
2256 => DB_ERROR_SYNTAX,
|
||||||
2257 => DB_ERROR_SYNTAX,
|
2257 => DB_ERROR_SYNTAX,
|
||||||
2627 => DB_ERROR_CONSTRAINT,
|
2627 => DB_ERROR_CONSTRAINT,
|
||||||
2714 => DB_ERROR_ALREADY_EXISTS,
|
2714 => DB_ERROR_ALREADY_EXISTS,
|
||||||
3607 => DB_ERROR_DIVZERO,
|
3607 => DB_ERROR_DIVZERO,
|
||||||
3701 => DB_ERROR_NOSUCHTABLE,
|
3701 => DB_ERROR_NOSUCHTABLE,
|
||||||
7630 => DB_ERROR_SYNTAX,
|
7630 => DB_ERROR_SYNTAX,
|
||||||
8134 => DB_ERROR_DIVZERO,
|
8134 => DB_ERROR_DIVZERO,
|
||||||
9303 => DB_ERROR_SYNTAX,
|
9303 => DB_ERROR_SYNTAX,
|
||||||
9317 => DB_ERROR_SYNTAX,
|
9317 => DB_ERROR_SYNTAX,
|
||||||
9318 => DB_ERROR_SYNTAX,
|
9318 => DB_ERROR_SYNTAX,
|
||||||
9331 => DB_ERROR_SYNTAX,
|
9331 => DB_ERROR_SYNTAX,
|
||||||
9332 => DB_ERROR_SYNTAX,
|
9332 => DB_ERROR_SYNTAX,
|
||||||
15253 => DB_ERROR_SYNTAX,
|
15253 => DB_ERROR_SYNTAX,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -196,10 +197,10 @@ class DB_mssql extends DB_common
|
||||||
*
|
*
|
||||||
* Don't call this method directly. Use DB::connect() instead.
|
* Don't call this method directly. Use DB::connect() instead.
|
||||||
*
|
*
|
||||||
* @param array $dsn the data source name
|
* @param array $dsn the data source name
|
||||||
* @param bool $persistent should the connection be persistent?
|
* @param bool $persistent should the connection be persistent?
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function connect($dsn, $persistent = false)
|
public function connect($dsn, $persistent = false)
|
||||||
{
|
{
|
||||||
|
@ -220,7 +221,7 @@ class DB_mssql extends DB_common
|
||||||
);
|
);
|
||||||
if ($dsn['port']) {
|
if ($dsn['port']) {
|
||||||
$params[0] .= ((substr(PHP_OS, 0, 3) == 'WIN') ? ',' : ':')
|
$params[0] .= ((substr(PHP_OS, 0, 3) == 'WIN') ? ',' : ':')
|
||||||
. $dsn['port'];
|
. $dsn['port'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$connect_function = $persistent ? 'mssql_pconnect' : 'mssql_connect';
|
$connect_function = $persistent ? 'mssql_pconnect' : 'mssql_connect';
|
||||||
|
@ -307,6 +308,80 @@ class DB_mssql extends DB_common
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ nextResult()
|
// {{{ nextResult()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produces a DB_Error object regarding the current problem
|
||||||
|
*
|
||||||
|
* @param null $code
|
||||||
|
* @return object the DB_Error object
|
||||||
|
*
|
||||||
|
* @see DB_common::raiseError(),
|
||||||
|
* DB_mssql::errorNative(), DB_mssql::errorCode()
|
||||||
|
*/
|
||||||
|
public function mssqlRaiseError($code = null)
|
||||||
|
{
|
||||||
|
$message = @mssql_get_last_message();
|
||||||
|
if (!$code) {
|
||||||
|
$code = $this->errorNative();
|
||||||
|
}
|
||||||
|
return $this->raiseError(
|
||||||
|
$this->errorCode($code, $message),
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
"$code - $message"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ fetchInto()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the DBMS' native error code produced by the last query
|
||||||
|
*
|
||||||
|
* @return int the DBMS' error code
|
||||||
|
*/
|
||||||
|
public function errorNative()
|
||||||
|
{
|
||||||
|
$res = @mssql_query('select @@ERROR as ErrorCode', $this->connection);
|
||||||
|
if (!$res) {
|
||||||
|
return DB_ERROR;
|
||||||
|
}
|
||||||
|
$row = @mssql_fetch_row($res);
|
||||||
|
return $row[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ freeResult()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines PEAR::DB error code from mssql's native codes.
|
||||||
|
*
|
||||||
|
* If <var>$nativecode</var> isn't known yet, it will be looked up.
|
||||||
|
*
|
||||||
|
* @param mixed $nativecode mssql error code, if known
|
||||||
|
* @param string $msg
|
||||||
|
* @return integer an error number from a DB error constant
|
||||||
|
* @see errorNative()
|
||||||
|
*/
|
||||||
|
public function errorCode($nativecode = null, $msg = '')
|
||||||
|
{
|
||||||
|
if (!$nativecode) {
|
||||||
|
$nativecode = $this->errorNative();
|
||||||
|
}
|
||||||
|
if (isset($this->errorcode_map[$nativecode])) {
|
||||||
|
if ($nativecode == 3701
|
||||||
|
&& preg_match('/Cannot drop the index/i', $msg)) {
|
||||||
|
return DB_ERROR_NOT_FOUND;
|
||||||
|
}
|
||||||
|
return $this->errorcode_map[$nativecode];
|
||||||
|
} else {
|
||||||
|
return DB_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ numCols()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the internal mssql result pointer to the next available result
|
* Move the internal mssql result pointer to the next available result
|
||||||
*
|
*
|
||||||
|
@ -322,7 +397,7 @@ class DB_mssql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ fetchInto()
|
// {{{ numRows()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Places a row from the result set into the given array
|
* Places a row from the result set into the given array
|
||||||
|
@ -334,10 +409,10 @@ class DB_mssql extends DB_common
|
||||||
* DB_result::fetchInto() instead. It can't be declared "protected"
|
* DB_result::fetchInto() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result the query result resource
|
* @param resource $result the query result resource
|
||||||
* @param array $arr the referenced array to put the data in
|
* @param array $arr the referenced array to put the data in
|
||||||
* @param int $fetchmode how the resulting array should be indexed
|
* @param int $fetchmode how the resulting array should be indexed
|
||||||
* @param int $rownum the row number to fetch (0 = first row)
|
* @param int $rownum the row number to fetch (0 = first row)
|
||||||
*
|
*
|
||||||
* @return mixed DB_OK on success, NULL when the end of a result set is
|
* @return mixed DB_OK on success, NULL when the end of a result set is
|
||||||
* reached or on failure
|
* reached or on failure
|
||||||
|
@ -372,7 +447,7 @@ class DB_mssql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ freeResult()
|
// {{{ autoCommit()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the result set and frees the memory occupied by the result set
|
* Deletes the result set and frees the memory occupied by the result set
|
||||||
|
@ -381,7 +456,7 @@ class DB_mssql extends DB_common
|
||||||
* DB_result::free() instead. It can't be declared "protected"
|
* DB_result::free() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return bool TRUE on success, FALSE if $result is invalid
|
* @return bool TRUE on success, FALSE if $result is invalid
|
||||||
*
|
*
|
||||||
|
@ -393,7 +468,7 @@ class DB_mssql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ numCols()
|
// {{{ commit()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of columns in a result set
|
* Gets the number of columns in a result set
|
||||||
|
@ -402,9 +477,9 @@ class DB_mssql extends DB_common
|
||||||
* DB_result::numCols() instead. It can't be declared "protected"
|
* DB_result::numCols() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return int the number of columns. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @see DB_result::numCols()
|
* @see DB_result::numCols()
|
||||||
*/
|
*/
|
||||||
|
@ -418,7 +493,7 @@ class DB_mssql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ numRows()
|
// {{{ rollback()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of rows in a result set
|
* Gets the number of rows in a result set
|
||||||
|
@ -427,9 +502,9 @@ class DB_mssql extends DB_common
|
||||||
* DB_result::numRows() instead. It can't be declared "protected"
|
* DB_result::numRows() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return int the number of rows. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @see DB_result::numRows()
|
* @see DB_result::numRows()
|
||||||
*/
|
*/
|
||||||
|
@ -443,12 +518,12 @@ class DB_mssql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ autoCommit()
|
// {{{ affectedRows()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables or disables automatic commits
|
* Enables or disables automatic commits
|
||||||
*
|
*
|
||||||
* @param bool $onoff true turns it on, false turns it off
|
* @param bool $onoff true turns it on, false turns it off
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object if the driver
|
* @return int DB_OK on success. A DB_Error object if the driver
|
||||||
* doesn't support auto-committing transactions.
|
* doesn't support auto-committing transactions.
|
||||||
|
@ -462,12 +537,12 @@ class DB_mssql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ commit()
|
// {{{ nextId()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commits the current transaction
|
* Commits the current transaction
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function commit()
|
public function commit()
|
||||||
{
|
{
|
||||||
|
@ -484,13 +559,10 @@ class DB_mssql extends DB_common
|
||||||
return DB_OK;
|
return DB_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ rollback()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverts the current transaction
|
* Reverts the current transaction
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function rollback()
|
public function rollback()
|
||||||
{
|
{
|
||||||
|
@ -508,14 +580,14 @@ class DB_mssql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ affectedRows()
|
// {{{ dropSequence()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the number of rows affected by a data maniuplation query
|
* Determines the number of rows affected by a data maniuplation query
|
||||||
*
|
*
|
||||||
* 0 is returned for queries that don't manipulate data.
|
* 0 is returned for queries that don't manipulate data.
|
||||||
*
|
*
|
||||||
* @return int the number of rows. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function affectedRows()
|
public function affectedRows()
|
||||||
{
|
{
|
||||||
|
@ -538,16 +610,16 @@ class DB_mssql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ nextId()
|
// {{{ escapeSimple()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the next free id in a sequence
|
* Returns the next free id in a sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the sequence
|
* @param string $seq_name name of the sequence
|
||||||
* @param boolean $ondemand when true, the seqence is automatically
|
* @param boolean $ondemand when true, the seqence is automatically
|
||||||
* created if it does not exist
|
* created if it does not exist
|
||||||
*
|
*
|
||||||
* @return int the next id number in the sequence.
|
* @return int|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
||||||
|
@ -593,10 +665,13 @@ class DB_mssql extends DB_common
|
||||||
return $result[0];
|
return $result[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ quoteIdentifier()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new sequence
|
* Creates a new sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the new sequence
|
* @param string $seq_name name of the new sequence
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
|
@ -606,18 +681,18 @@ class DB_mssql extends DB_common
|
||||||
public function createSequence($seq_name)
|
public function createSequence($seq_name)
|
||||||
{
|
{
|
||||||
return $this->query('CREATE TABLE '
|
return $this->query('CREATE TABLE '
|
||||||
. $this->getSequenceName($seq_name)
|
. $this->getSequenceName($seq_name)
|
||||||
. ' ([id] [int] IDENTITY (1, 1) NOT NULL,'
|
. ' ([id] [int] IDENTITY (1, 1) NOT NULL,'
|
||||||
. ' [vapor] [int] NULL)');
|
. ' [vapor] [int] NULL)');
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ dropSequence()
|
// {{{ mssqlRaiseError()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a sequence
|
* Deletes a sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the sequence to be deleted
|
* @param string $seq_name name of the sequence to be deleted
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
|
@ -630,12 +705,12 @@ class DB_mssql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ escapeSimple()
|
// {{{ errorNative()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Escapes a string in a manner suitable for SQL Server.
|
* Escapes a string in a manner suitable for SQL Server.
|
||||||
*
|
*
|
||||||
* @param string $str the string to be escaped
|
* @param string $str the string to be escaped
|
||||||
* @return string the escaped string
|
* @return string the escaped string
|
||||||
*
|
*
|
||||||
* @see DB_common::quoteSmart()
|
* @see DB_common::quoteSmart()
|
||||||
|
@ -651,12 +726,12 @@ class DB_mssql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ quoteIdentifier()
|
// {{{ errorCode()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quotes a string so it can be safely used as a table or column name
|
* Quotes a string so it can be safely used as a table or column name
|
||||||
*
|
*
|
||||||
* @param string $str identifier name to be quoted
|
* @param string $str identifier name to be quoted
|
||||||
*
|
*
|
||||||
* @return string quoted identifier string
|
* @return string quoted identifier string
|
||||||
*
|
*
|
||||||
|
@ -668,82 +743,6 @@ class DB_mssql extends DB_common
|
||||||
return '[' . str_replace(']', ']]', $str) . ']';
|
return '[' . str_replace(']', ']]', $str) . ']';
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ mssqlRaiseError()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Produces a DB_Error object regarding the current problem
|
|
||||||
*
|
|
||||||
* @param int $errno if the error is being manually raised pass a
|
|
||||||
* DB_ERROR* constant here. If this isn't passed
|
|
||||||
* the error information gathered from the DBMS.
|
|
||||||
*
|
|
||||||
* @return object the DB_Error object
|
|
||||||
*
|
|
||||||
* @see DB_common::raiseError(),
|
|
||||||
* DB_mssql::errorNative(), DB_mssql::errorCode()
|
|
||||||
*/
|
|
||||||
public function mssqlRaiseError($code = null)
|
|
||||||
{
|
|
||||||
$message = @mssql_get_last_message();
|
|
||||||
if (!$code) {
|
|
||||||
$code = $this->errorNative();
|
|
||||||
}
|
|
||||||
return $this->raiseError(
|
|
||||||
$this->errorCode($code, $message),
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
"$code - $message"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ errorNative()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the DBMS' native error code produced by the last query
|
|
||||||
*
|
|
||||||
* @return int the DBMS' error code
|
|
||||||
*/
|
|
||||||
public function errorNative()
|
|
||||||
{
|
|
||||||
$res = @mssql_query('select @@ERROR as ErrorCode', $this->connection);
|
|
||||||
if (!$res) {
|
|
||||||
return DB_ERROR;
|
|
||||||
}
|
|
||||||
$row = @mssql_fetch_row($res);
|
|
||||||
return $row[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ errorCode()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines PEAR::DB error code from mssql's native codes.
|
|
||||||
*
|
|
||||||
* If <var>$nativecode</var> isn't known yet, it will be looked up.
|
|
||||||
*
|
|
||||||
* @param mixed $nativecode mssql error code, if known
|
|
||||||
* @return integer an error number from a DB error constant
|
|
||||||
* @see errorNative()
|
|
||||||
*/
|
|
||||||
public function errorCode($nativecode = null, $msg = '')
|
|
||||||
{
|
|
||||||
if (!$nativecode) {
|
|
||||||
$nativecode = $this->errorNative();
|
|
||||||
}
|
|
||||||
if (isset($this->errorcode_map[$nativecode])) {
|
|
||||||
if ($nativecode == 3701
|
|
||||||
&& preg_match('/Cannot drop the index/i', $msg)) {
|
|
||||||
return DB_ERROR_NOT_FOUND;
|
|
||||||
}
|
|
||||||
return $this->errorcode_map[$nativecode];
|
|
||||||
} else {
|
|
||||||
return DB_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ tableInfo()
|
// {{{ tableInfo()
|
||||||
|
|
||||||
|
@ -753,14 +752,14 @@ class DB_mssql extends DB_common
|
||||||
* NOTE: only supports 'table' and 'flags' if <var>$result</var>
|
* NOTE: only supports 'table' and 'flags' if <var>$result</var>
|
||||||
* is a table name.
|
* is a table name.
|
||||||
*
|
*
|
||||||
* @param object|string $result DB_result object from a query or a
|
* @param object|string $result DB_result object from a query or a
|
||||||
* string containing the name of a table.
|
* string containing the name of a table.
|
||||||
* While this also accepts a query result
|
* While this also accepts a query result
|
||||||
* resource identifier, this behavior is
|
* resource identifier, this behavior is
|
||||||
* deprecated.
|
* deprecated.
|
||||||
* @param int $mode a valid tableInfo mode
|
* @param int $mode a valid tableInfo mode
|
||||||
*
|
*
|
||||||
* @return array an associative array with the information requested.
|
* @return array|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::tableInfo()
|
* @see DB_common::tableInfo()
|
||||||
|
@ -808,7 +807,7 @@ class DB_mssql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = @mssql_num_fields($id);
|
$count = @mssql_num_fields($id);
|
||||||
$res = array();
|
$res = array();
|
||||||
|
|
||||||
if ($mode) {
|
if ($mode) {
|
||||||
$res['num_fields'] = $count;
|
$res['num_fields'] = $count;
|
||||||
|
@ -829,9 +828,9 @@ class DB_mssql extends DB_common
|
||||||
|
|
||||||
$res[$i] = array(
|
$res[$i] = array(
|
||||||
'table' => $got_string ? $case_func($result) : '',
|
'table' => $got_string ? $case_func($result) : '',
|
||||||
'name' => $case_func(@mssql_field_name($id, $i)),
|
'name' => $case_func(@mssql_field_name($id, $i)),
|
||||||
'type' => @mssql_field_type($id, $i),
|
'type' => @mssql_field_type($id, $i),
|
||||||
'len' => @mssql_field_length($id, $i),
|
'len' => @mssql_field_length($id, $i),
|
||||||
'flags' => $flags,
|
'flags' => $flags,
|
||||||
);
|
);
|
||||||
if ($mode & DB_TABLEINFO_ORDER) {
|
if ($mode & DB_TABLEINFO_ORDER) {
|
||||||
|
@ -864,10 +863,10 @@ class DB_mssql extends DB_common
|
||||||
* not useful at all - is the behaviour of mysql_field_flags that primary
|
* not useful at all - is the behaviour of mysql_field_flags that primary
|
||||||
* keys are alway unique? is the interpretation of multiple_key correct?
|
* keys are alway unique? is the interpretation of multiple_key correct?
|
||||||
*
|
*
|
||||||
* @param string $table the table name
|
* @param string $table the table name
|
||||||
* @param string $column the field name
|
* @param string $column the field name
|
||||||
*
|
*
|
||||||
* @return string the flags
|
* @return array|string
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
* @author Joern Barthel <j_barthel@web.de>
|
* @author Joern Barthel <j_barthel@web.de>
|
||||||
|
@ -928,7 +927,7 @@ class DB_mssql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists($column, $flags)) {
|
if (array_key_exists($column, $flags)) {
|
||||||
return(implode(' ', $flags[$column]));
|
return (implode(' ', $flags[$column]));
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
@ -940,8 +939,8 @@ class DB_mssql extends DB_common
|
||||||
* Adds a string to the flags array if the flag is not yet in there
|
* Adds a string to the flags array if the flag is not yet in there
|
||||||
* - if there is no flag present the array is created
|
* - if there is no flag present the array is created
|
||||||
*
|
*
|
||||||
* @param array &$array the reference to the flag-array
|
* @param array &$array the reference to the flag-array
|
||||||
* @param string $value the flag value
|
* @param string $value the flag value
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
|
@ -963,7 +962,7 @@ class DB_mssql extends DB_common
|
||||||
/**
|
/**
|
||||||
* Obtains the query string needed for listing a given type of objects
|
* Obtains the query string needed for listing a given type of objects
|
||||||
*
|
*
|
||||||
* @param string $type the kind of objects you want to retrieve
|
* @param string $type the kind of objects you want to retrieve
|
||||||
*
|
*
|
||||||
* @return string the SQL query string or null if the driver doesn't
|
* @return string the SQL query string or null if the driver doesn't
|
||||||
* support the object type requested
|
* support the object type requested
|
||||||
|
@ -976,7 +975,7 @@ class DB_mssql extends DB_common
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'tables':
|
case 'tables':
|
||||||
return "SELECT name FROM sysobjects WHERE type = 'U'"
|
return "SELECT name FROM sysobjects WHERE type = 'U'"
|
||||||
. ' ORDER BY name';
|
. ' ORDER BY name';
|
||||||
case 'views':
|
case 'views':
|
||||||
return "SELECT name FROM sysobjects WHERE type = 'V'";
|
return "SELECT name FROM sysobjects WHERE type = 'V'";
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -27,7 +27,8 @@
|
||||||
/**
|
/**
|
||||||
* Obtain the DB_common class so it can be extended from
|
* Obtain the DB_common class so it can be extended from
|
||||||
*/
|
*/
|
||||||
require_once 'DB/common.php';
|
//require_once 'DB/common.php';
|
||||||
|
require_once 'common.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The methods PEAR DB uses to interact with PHP's mysql extension
|
* The methods PEAR DB uses to interact with PHP's mysql extension
|
||||||
|
@ -74,13 +75,13 @@ class DB_mysql extends DB_common
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $features = array(
|
public $features = array(
|
||||||
'limit' => 'alter',
|
'limit' => 'alter',
|
||||||
'new_link' => '4.2.0',
|
'new_link' => '4.2.0',
|
||||||
'numrows' => true,
|
'numrows' => true,
|
||||||
'pconnect' => true,
|
'pconnect' => true,
|
||||||
'prepare' => false,
|
'prepare' => false,
|
||||||
'ssl' => false,
|
'ssl' => false,
|
||||||
'transactions' => true,
|
'transactions' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -188,10 +189,10 @@ class DB_mysql extends DB_common
|
||||||
* Only used if PHP is at version 4.3.0 or greater.
|
* Only used if PHP is at version 4.3.0 or greater.
|
||||||
* Available since PEAR DB 1.7.0.
|
* Available since PEAR DB 1.7.0.
|
||||||
*
|
*
|
||||||
* @param array $dsn the data source name
|
* @param array $dsn the data source name
|
||||||
* @param bool $persistent should the connection be persistent?
|
* @param bool $persistent should the connection be persistent?
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function connect($dsn, $persistent = false)
|
public function connect($dsn, $persistent = false)
|
||||||
{
|
{
|
||||||
|
@ -209,7 +210,7 @@ class DB_mysql extends DB_common
|
||||||
$params[0] = ':' . $dsn['socket'];
|
$params[0] = ':' . $dsn['socket'];
|
||||||
} else {
|
} else {
|
||||||
$params[0] = $dsn['hostspec'] ? $dsn['hostspec']
|
$params[0] = $dsn['hostspec'] ? $dsn['hostspec']
|
||||||
: 'localhost';
|
: 'localhost';
|
||||||
if ($dsn['port']) {
|
if ($dsn['port']) {
|
||||||
$params[0] .= ':' . $dsn['port'];
|
$params[0] .= ':' . $dsn['port'];
|
||||||
}
|
}
|
||||||
|
@ -227,7 +228,7 @@ class DB_mysql extends DB_common
|
||||||
}
|
}
|
||||||
if (version_compare(phpversion(), '4.3.0', '>=')) {
|
if (version_compare(phpversion(), '4.3.0', '>=')) {
|
||||||
$params[] = isset($dsn['client_flags'])
|
$params[] = isset($dsn['client_flags'])
|
||||||
? $dsn['client_flags'] : null;
|
? $dsn['client_flags'] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$connect_function = $persistent ? 'mysql_pconnect' : 'mysql_connect';
|
$connect_function = $persistent ? 'mysql_pconnect' : 'mysql_connect';
|
||||||
|
@ -281,6 +282,46 @@ class DB_mysql extends DB_common
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ disconnect()
|
// {{{ disconnect()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produces a DB_Error object regarding the current problem
|
||||||
|
*
|
||||||
|
* @param int $errno if the error is being manually raised pass a
|
||||||
|
* DB_ERROR* constant here. If this isn't passed
|
||||||
|
* the error information gathered from the DBMS.
|
||||||
|
*
|
||||||
|
* @return object the DB_Error object
|
||||||
|
*
|
||||||
|
* @see DB_common::raiseError(),
|
||||||
|
* DB_mysql::errorNative(), DB_common::errorCode()
|
||||||
|
*/
|
||||||
|
public function mysqlRaiseError($errno = null)
|
||||||
|
{
|
||||||
|
if ($errno === null) {
|
||||||
|
if ($this->options['portability'] & DB_PORTABILITY_ERRORS) {
|
||||||
|
$this->errorcode_map[1022] = DB_ERROR_CONSTRAINT;
|
||||||
|
$this->errorcode_map[1048] = DB_ERROR_CONSTRAINT_NOT_NULL;
|
||||||
|
$this->errorcode_map[1062] = DB_ERROR_CONSTRAINT;
|
||||||
|
} else {
|
||||||
|
// Doing this in case mode changes during runtime.
|
||||||
|
$this->errorcode_map[1022] = DB_ERROR_ALREADY_EXISTS;
|
||||||
|
$this->errorcode_map[1048] = DB_ERROR_CONSTRAINT;
|
||||||
|
$this->errorcode_map[1062] = DB_ERROR_ALREADY_EXISTS;
|
||||||
|
}
|
||||||
|
$errno = $this->errorCode(mysql_errno($this->connection));
|
||||||
|
}
|
||||||
|
return $this->raiseError(
|
||||||
|
$errno,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
@mysql_errno($this->connection) . ' ** ' .
|
||||||
|
@mysql_error($this->connection)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ simpleQuery()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disconnects from the database server
|
* Disconnects from the database server
|
||||||
*
|
*
|
||||||
|
@ -294,7 +335,7 @@ class DB_mysql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ simpleQuery()
|
// {{{ nextResult()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a query to the database server
|
* Sends a query to the database server
|
||||||
|
@ -344,7 +385,40 @@ class DB_mysql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ nextResult()
|
// {{{ fetchInto()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes a query string for various DBMS specific reasons
|
||||||
|
*
|
||||||
|
* This little hack lets you know how many rows were deleted
|
||||||
|
* when running a "DELETE FROM table" query. Only implemented
|
||||||
|
* if the DB_PORTABILITY_DELETE_COUNT portability option is on.
|
||||||
|
*
|
||||||
|
* @param string $query the query string to modify
|
||||||
|
*
|
||||||
|
* @return string the modified query string
|
||||||
|
*
|
||||||
|
* @access protected
|
||||||
|
* @see DB_common::setOption()
|
||||||
|
*/
|
||||||
|
public function modifyQuery($query)
|
||||||
|
{
|
||||||
|
if ($this->options['portability'] & DB_PORTABILITY_DELETE_COUNT) {
|
||||||
|
// "DELETE FROM table" gives 0 affected rows in MySQL.
|
||||||
|
// This little hack lets you know how many rows were deleted.
|
||||||
|
if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $query)) {
|
||||||
|
$query = preg_replace(
|
||||||
|
'/^\s*DELETE\s+FROM\s+(\S+)\s*$/',
|
||||||
|
'DELETE FROM \1 WHERE 1=1',
|
||||||
|
$query
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ freeResult()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the internal mysql result pointer to the next available result
|
* Move the internal mysql result pointer to the next available result
|
||||||
|
@ -361,7 +435,7 @@ class DB_mysql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ fetchInto()
|
// {{{ numCols()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Places a row from the result set into the given array
|
* Places a row from the result set into the given array
|
||||||
|
@ -373,10 +447,10 @@ class DB_mysql extends DB_common
|
||||||
* DB_result::fetchInto() instead. It can't be declared "protected"
|
* DB_result::fetchInto() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result the query result resource
|
* @param resource $result the query result resource
|
||||||
* @param array $arr the referenced array to put the data in
|
* @param array $arr the referenced array to put the data in
|
||||||
* @param int $fetchmode how the resulting array should be indexed
|
* @param int $fetchmode how the resulting array should be indexed
|
||||||
* @param int $rownum the row number to fetch (0 = first row)
|
* @param int $rownum the row number to fetch (0 = first row)
|
||||||
*
|
*
|
||||||
* @return mixed DB_OK on success, NULL when the end of a result set is
|
* @return mixed DB_OK on success, NULL when the end of a result set is
|
||||||
* reached or on failure
|
* reached or on failure
|
||||||
|
@ -416,7 +490,7 @@ class DB_mysql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ freeResult()
|
// {{{ numRows()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the result set and frees the memory occupied by the result set
|
* Deletes the result set and frees the memory occupied by the result set
|
||||||
|
@ -425,7 +499,7 @@ class DB_mysql extends DB_common
|
||||||
* DB_result::free() instead. It can't be declared "protected"
|
* DB_result::free() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return bool TRUE on success, FALSE if $result is invalid
|
* @return bool TRUE on success, FALSE if $result is invalid
|
||||||
*
|
*
|
||||||
|
@ -437,7 +511,7 @@ class DB_mysql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ numCols()
|
// {{{ autoCommit()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of columns in a result set
|
* Gets the number of columns in a result set
|
||||||
|
@ -446,9 +520,9 @@ class DB_mysql extends DB_common
|
||||||
* DB_result::numCols() instead. It can't be declared "protected"
|
* DB_result::numCols() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return int the number of columns. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @see DB_result::numCols()
|
* @see DB_result::numCols()
|
||||||
*/
|
*/
|
||||||
|
@ -462,7 +536,7 @@ class DB_mysql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ numRows()
|
// {{{ commit()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of rows in a result set
|
* Gets the number of rows in a result set
|
||||||
|
@ -471,9 +545,9 @@ class DB_mysql extends DB_common
|
||||||
* DB_result::numRows() instead. It can't be declared "protected"
|
* DB_result::numRows() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return int the number of rows. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @see DB_result::numRows()
|
* @see DB_result::numRows()
|
||||||
*/
|
*/
|
||||||
|
@ -487,12 +561,12 @@ class DB_mysql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ autoCommit()
|
// {{{ rollback()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables or disables automatic commits
|
* Enables or disables automatic commits
|
||||||
*
|
*
|
||||||
* @param bool $onoff true turns it on, false turns it off
|
* @param bool $onoff true turns it on, false turns it off
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object if the driver
|
* @return int DB_OK on success. A DB_Error object if the driver
|
||||||
* doesn't support auto-committing transactions.
|
* doesn't support auto-committing transactions.
|
||||||
|
@ -506,12 +580,12 @@ class DB_mysql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ commit()
|
// {{{ affectedRows()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commits the current transaction
|
* Commits the current transaction
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function commit()
|
public function commit()
|
||||||
{
|
{
|
||||||
|
@ -532,12 +606,12 @@ class DB_mysql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ rollback()
|
// {{{ nextId()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverts the current transaction
|
* Reverts the current transaction
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function rollback()
|
public function rollback()
|
||||||
{
|
{
|
||||||
|
@ -558,7 +632,7 @@ class DB_mysql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ affectedRows()
|
// {{{ createSequence()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the number of rows affected by a data maniuplation query
|
* Determines the number of rows affected by a data maniuplation query
|
||||||
|
@ -577,16 +651,16 @@ class DB_mysql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ nextId()
|
// {{{ dropSequence()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the next free id in a sequence
|
* Returns the next free id in a sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the sequence
|
* @param string $seq_name name of the sequence
|
||||||
* @param boolean $ondemand when true, the seqence is automatically
|
* @param boolean $ondemand when true, the seqence is automatically
|
||||||
* created if it does not exist
|
* created if it does not exist
|
||||||
*
|
*
|
||||||
* @return int the next id number in the sequence.
|
* @return int|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
||||||
|
@ -598,8 +672,8 @@ class DB_mysql extends DB_common
|
||||||
do {
|
do {
|
||||||
$repeat = 0;
|
$repeat = 0;
|
||||||
$this->pushErrorHandling(PEAR_ERROR_RETURN);
|
$this->pushErrorHandling(PEAR_ERROR_RETURN);
|
||||||
$result = $this->query("UPDATE ${seqname} ".
|
$result = $this->query("UPDATE ${seqname} " .
|
||||||
'SET id=LAST_INSERT_ID(id+1)');
|
'SET id=LAST_INSERT_ID(id+1)');
|
||||||
$this->popErrorHandling();
|
$this->popErrorHandling();
|
||||||
if ($result === DB_OK) {
|
if ($result === DB_OK) {
|
||||||
// COMMON CASE
|
// COMMON CASE
|
||||||
|
@ -627,7 +701,7 @@ class DB_mysql extends DB_common
|
||||||
|
|
||||||
// Release the lock
|
// Release the lock
|
||||||
$result = $this->getOne('SELECT RELEASE_LOCK('
|
$result = $this->getOne('SELECT RELEASE_LOCK('
|
||||||
. "'${seqname}_lock')");
|
. "'${seqname}_lock')");
|
||||||
if (DB::isError($result)) {
|
if (DB::isError($result)) {
|
||||||
return $this->raiseError($result);
|
return $this->raiseError($result);
|
||||||
}
|
}
|
||||||
|
@ -643,7 +717,7 @@ class DB_mysql extends DB_common
|
||||||
$repeat = 1;
|
$repeat = 1;
|
||||||
}
|
}
|
||||||
} elseif (DB::isError($result) &&
|
} elseif (DB::isError($result) &&
|
||||||
$result->getCode() == DB_ERROR_ALREADY_EXISTS) {
|
$result->getCode() == DB_ERROR_ALREADY_EXISTS) {
|
||||||
// BACKWARDS COMPAT
|
// BACKWARDS COMPAT
|
||||||
// see _BCsequence() comment
|
// see _BCsequence() comment
|
||||||
$result = $this->_BCsequence($seqname);
|
$result = $this->_BCsequence($seqname);
|
||||||
|
@ -658,12 +732,12 @@ class DB_mysql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ createSequence()
|
// {{{ _BCsequence()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new sequence
|
* Creates a new sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the new sequence
|
* @param string $seq_name name of the new sequence
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
|
@ -674,8 +748,8 @@ class DB_mysql extends DB_common
|
||||||
{
|
{
|
||||||
$seqname = $this->getSequenceName($seq_name);
|
$seqname = $this->getSequenceName($seq_name);
|
||||||
$res = $this->query('CREATE TABLE ' . $seqname
|
$res = $this->query('CREATE TABLE ' . $seqname
|
||||||
. ' (id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL,'
|
. ' (id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL,'
|
||||||
. ' PRIMARY KEY(id))');
|
. ' PRIMARY KEY(id))');
|
||||||
if (DB::isError($res)) {
|
if (DB::isError($res)) {
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
@ -689,33 +763,15 @@ class DB_mysql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ dropSequence()
|
// {{{ quoteIdentifier()
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes a sequence
|
|
||||||
*
|
|
||||||
* @param string $seq_name name of the sequence to be deleted
|
|
||||||
*
|
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
|
||||||
*
|
|
||||||
* @see DB_common::dropSequence(), DB_common::getSequenceName(),
|
|
||||||
* DB_mysql::nextID(), DB_mysql::createSequence()
|
|
||||||
*/
|
|
||||||
public function dropSequence($seq_name)
|
|
||||||
{
|
|
||||||
return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name));
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ _BCsequence()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Backwards compatibility with old sequence emulation implementation
|
* Backwards compatibility with old sequence emulation implementation
|
||||||
* (clean up the dupes)
|
* (clean up the dupes)
|
||||||
*
|
*
|
||||||
* @param string $seqname the sequence name to clean up
|
* @param string $seqname the sequence name to clean up
|
||||||
*
|
*
|
||||||
* @return bool true on success. A DB_Error object on failure.
|
* @return bool|object
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
|
@ -742,7 +798,7 @@ class DB_mysql extends DB_common
|
||||||
// We should probably do something if $highest_id isn't
|
// We should probably do something if $highest_id isn't
|
||||||
// numeric, but I'm at a loss as how to handle that...
|
// numeric, but I'm at a loss as how to handle that...
|
||||||
$result = $this->query('DELETE FROM ' . $seqname
|
$result = $this->query('DELETE FROM ' . $seqname
|
||||||
. " WHERE id <> $highest_id");
|
. " WHERE id <> $highest_id");
|
||||||
if (DB::isError($result)) {
|
if (DB::isError($result)) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -758,7 +814,25 @@ class DB_mysql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ quoteIdentifier()
|
// {{{ escapeSimple()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a sequence
|
||||||
|
*
|
||||||
|
* @param string $seq_name name of the sequence to be deleted
|
||||||
|
*
|
||||||
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
|
*
|
||||||
|
* @see DB_common::dropSequence(), DB_common::getSequenceName(),
|
||||||
|
* DB_mysql::nextID(), DB_mysql::createSequence()
|
||||||
|
*/
|
||||||
|
public function dropSequence($seq_name)
|
||||||
|
{
|
||||||
|
return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name));
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ modifyQuery()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quotes a string so it can be safely used as a table or column name
|
* Quotes a string so it can be safely used as a table or column name
|
||||||
|
@ -767,7 +841,7 @@ class DB_mysql extends DB_common
|
||||||
* WARNING: Older versions of MySQL can't handle the backtick
|
* WARNING: Older versions of MySQL can't handle the backtick
|
||||||
* character (<kbd>`</kbd>) in table or column names.
|
* character (<kbd>`</kbd>) in table or column names.
|
||||||
*
|
*
|
||||||
* @param string $str identifier name to be quoted
|
* @param string $str identifier name to be quoted
|
||||||
*
|
*
|
||||||
* @return string quoted identifier string
|
* @return string quoted identifier string
|
||||||
*
|
*
|
||||||
|
@ -780,12 +854,12 @@ class DB_mysql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ escapeSimple()
|
// {{{ modifyLimitQuery()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Escapes a string according to the current DBMS's standards
|
* Escapes a string according to the current DBMS's standards
|
||||||
*
|
*
|
||||||
* @param string $str the string to be escaped
|
* @param string $str the string to be escaped
|
||||||
*
|
*
|
||||||
* @return string the escaped string
|
* @return string the escaped string
|
||||||
*
|
*
|
||||||
|
@ -802,48 +876,15 @@ class DB_mysql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ modifyQuery()
|
// {{{ mysqlRaiseError()
|
||||||
|
|
||||||
/**
|
|
||||||
* Changes a query string for various DBMS specific reasons
|
|
||||||
*
|
|
||||||
* This little hack lets you know how many rows were deleted
|
|
||||||
* when running a "DELETE FROM table" query. Only implemented
|
|
||||||
* if the DB_PORTABILITY_DELETE_COUNT portability option is on.
|
|
||||||
*
|
|
||||||
* @param string $query the query string to modify
|
|
||||||
*
|
|
||||||
* @return string the modified query string
|
|
||||||
*
|
|
||||||
* @access protected
|
|
||||||
* @see DB_common::setOption()
|
|
||||||
*/
|
|
||||||
public function modifyQuery($query)
|
|
||||||
{
|
|
||||||
if ($this->options['portability'] & DB_PORTABILITY_DELETE_COUNT) {
|
|
||||||
// "DELETE FROM table" gives 0 affected rows in MySQL.
|
|
||||||
// This little hack lets you know how many rows were deleted.
|
|
||||||
if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $query)) {
|
|
||||||
$query = preg_replace(
|
|
||||||
'/^\s*DELETE\s+FROM\s+(\S+)\s*$/',
|
|
||||||
'DELETE FROM \1 WHERE 1=1',
|
|
||||||
$query
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $query;
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ modifyLimitQuery()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds LIMIT clauses to a query string according to current DBMS standards
|
* Adds LIMIT clauses to a query string according to current DBMS standards
|
||||||
*
|
*
|
||||||
* @param string $query the query to modify
|
* @param string $query the query to modify
|
||||||
* @param int $from the row to start to fetching (0 = the first row)
|
* @param int $from the row to start to fetching (0 = the first row)
|
||||||
* @param int $count the numbers of rows to fetch
|
* @param int $count the numbers of rows to fetch
|
||||||
* @param mixed $params array, string or numeric data to be used in
|
* @param mixed $params array, string or numeric data to be used in
|
||||||
* execution of the statement. Quantity of items
|
* execution of the statement. Quantity of items
|
||||||
* passed must match quantity of placeholders in
|
* passed must match quantity of placeholders in
|
||||||
* query: meaning 1 placeholder for non-array
|
* query: meaning 1 placeholder for non-array
|
||||||
|
@ -862,46 +903,6 @@ class DB_mysql extends DB_common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ mysqlRaiseError()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Produces a DB_Error object regarding the current problem
|
|
||||||
*
|
|
||||||
* @param int $errno if the error is being manually raised pass a
|
|
||||||
* DB_ERROR* constant here. If this isn't passed
|
|
||||||
* the error information gathered from the DBMS.
|
|
||||||
*
|
|
||||||
* @return object the DB_Error object
|
|
||||||
*
|
|
||||||
* @see DB_common::raiseError(),
|
|
||||||
* DB_mysql::errorNative(), DB_common::errorCode()
|
|
||||||
*/
|
|
||||||
public function mysqlRaiseError($errno = null)
|
|
||||||
{
|
|
||||||
if ($errno === null) {
|
|
||||||
if ($this->options['portability'] & DB_PORTABILITY_ERRORS) {
|
|
||||||
$this->errorcode_map[1022] = DB_ERROR_CONSTRAINT;
|
|
||||||
$this->errorcode_map[1048] = DB_ERROR_CONSTRAINT_NOT_NULL;
|
|
||||||
$this->errorcode_map[1062] = DB_ERROR_CONSTRAINT;
|
|
||||||
} else {
|
|
||||||
// Doing this in case mode changes during runtime.
|
|
||||||
$this->errorcode_map[1022] = DB_ERROR_ALREADY_EXISTS;
|
|
||||||
$this->errorcode_map[1048] = DB_ERROR_CONSTRAINT;
|
|
||||||
$this->errorcode_map[1062] = DB_ERROR_ALREADY_EXISTS;
|
|
||||||
}
|
|
||||||
$errno = $this->errorCode(mysql_errno($this->connection));
|
|
||||||
}
|
|
||||||
return $this->raiseError(
|
|
||||||
$errno,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
@mysql_errno($this->connection) . ' ** ' .
|
|
||||||
@mysql_error($this->connection)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ errorNative()
|
// {{{ errorNative()
|
||||||
|
|
||||||
|
@ -921,14 +922,14 @@ class DB_mysql extends DB_common
|
||||||
/**
|
/**
|
||||||
* Returns information about a table or a result set
|
* Returns information about a table or a result set
|
||||||
*
|
*
|
||||||
* @param object|string $result DB_result object from a query or a
|
* @param object|string $result DB_result object from a query or a
|
||||||
* string containing the name of a table.
|
* string containing the name of a table.
|
||||||
* While this also accepts a query result
|
* While this also accepts a query result
|
||||||
* resource identifier, this behavior is
|
* resource identifier, this behavior is
|
||||||
* deprecated.
|
* deprecated.
|
||||||
* @param int $mode a valid tableInfo mode
|
* @param int $mode a valid tableInfo mode
|
||||||
*
|
*
|
||||||
* @return array an associative array with the information requested.
|
* @return array|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::tableInfo()
|
* @see DB_common::tableInfo()
|
||||||
|
@ -980,7 +981,7 @@ class DB_mysql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = @mysql_num_fields($id);
|
$count = @mysql_num_fields($id);
|
||||||
$res = array();
|
$res = array();
|
||||||
|
|
||||||
if ($mode) {
|
if ($mode) {
|
||||||
$res['num_fields'] = $count;
|
$res['num_fields'] = $count;
|
||||||
|
@ -989,9 +990,9 @@ class DB_mysql extends DB_common
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$res[$i] = array(
|
$res[$i] = array(
|
||||||
'table' => $case_func(@mysql_field_table($id, $i)),
|
'table' => $case_func(@mysql_field_table($id, $i)),
|
||||||
'name' => $case_func(@mysql_field_name($id, $i)),
|
'name' => $case_func(@mysql_field_name($id, $i)),
|
||||||
'type' => @mysql_field_type($id, $i),
|
'type' => @mysql_field_type($id, $i),
|
||||||
'len' => @mysql_field_len($id, $i),
|
'len' => @mysql_field_len($id, $i),
|
||||||
'flags' => @mysql_field_flags($id, $i),
|
'flags' => @mysql_field_flags($id, $i),
|
||||||
);
|
);
|
||||||
if ($mode & DB_TABLEINFO_ORDER) {
|
if ($mode & DB_TABLEINFO_ORDER) {
|
||||||
|
@ -1015,7 +1016,7 @@ class DB_mysql extends DB_common
|
||||||
/**
|
/**
|
||||||
* Obtains the query string needed for listing a given type of objects
|
* Obtains the query string needed for listing a given type of objects
|
||||||
*
|
*
|
||||||
* @param string $type the kind of objects you want to retrieve
|
* @param string $type the kind of objects you want to retrieve
|
||||||
*
|
*
|
||||||
* @return string the SQL query string or null if the driver doesn't
|
* @return string the SQL query string or null if the driver doesn't
|
||||||
* support the object type requested
|
* support the object type requested
|
||||||
|
|
|
@ -26,7 +26,8 @@
|
||||||
/**
|
/**
|
||||||
* Obtain the DB_common class so it can be extended from
|
* Obtain the DB_common class so it can be extended from
|
||||||
*/
|
*/
|
||||||
require_once 'DB/common.php';
|
//require_once 'DB/common.php';
|
||||||
|
require_once 'common.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The methods PEAR DB uses to interact with PHP's mysqli extension
|
* The methods PEAR DB uses to interact with PHP's mysqli extension
|
||||||
|
@ -77,13 +78,13 @@ class DB_mysqli extends DB_common
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $features = array(
|
public $features = array(
|
||||||
'limit' => 'alter',
|
'limit' => 'alter',
|
||||||
'new_link' => false,
|
'new_link' => false,
|
||||||
'numrows' => true,
|
'numrows' => true,
|
||||||
'pconnect' => false,
|
'pconnect' => false,
|
||||||
'prepare' => false,
|
'prepare' => false,
|
||||||
'ssl' => true,
|
'ssl' => true,
|
||||||
'transactions' => true,
|
'transactions' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -167,19 +168,19 @@ class DB_mysqli extends DB_common
|
||||||
* @since Property available since Release 1.6.5
|
* @since Property available since Release 1.6.5
|
||||||
*/
|
*/
|
||||||
public $mysqli_flags = array(
|
public $mysqli_flags = array(
|
||||||
MYSQLI_NOT_NULL_FLAG => 'not_null',
|
MYSQLI_NOT_NULL_FLAG => 'not_null',
|
||||||
MYSQLI_PRI_KEY_FLAG => 'primary_key',
|
MYSQLI_PRI_KEY_FLAG => 'primary_key',
|
||||||
MYSQLI_UNIQUE_KEY_FLAG => 'unique_key',
|
MYSQLI_UNIQUE_KEY_FLAG => 'unique_key',
|
||||||
MYSQLI_MULTIPLE_KEY_FLAG => 'multiple_key',
|
MYSQLI_MULTIPLE_KEY_FLAG => 'multiple_key',
|
||||||
MYSQLI_BLOB_FLAG => 'blob',
|
MYSQLI_BLOB_FLAG => 'blob',
|
||||||
MYSQLI_UNSIGNED_FLAG => 'unsigned',
|
MYSQLI_UNSIGNED_FLAG => 'unsigned',
|
||||||
MYSQLI_ZEROFILL_FLAG => 'zerofill',
|
MYSQLI_ZEROFILL_FLAG => 'zerofill',
|
||||||
MYSQLI_AUTO_INCREMENT_FLAG => 'auto_increment',
|
MYSQLI_AUTO_INCREMENT_FLAG => 'auto_increment',
|
||||||
MYSQLI_TIMESTAMP_FLAG => 'timestamp',
|
MYSQLI_TIMESTAMP_FLAG => 'timestamp',
|
||||||
MYSQLI_SET_FLAG => 'set',
|
MYSQLI_SET_FLAG => 'set',
|
||||||
// MYSQLI_NUM_FLAG => 'numeric', // unnecessary
|
// MYSQLI_NUM_FLAG => 'numeric', // unnecessary
|
||||||
// MYSQLI_PART_KEY_FLAG => 'multiple_key', // duplicatvie
|
// MYSQLI_PART_KEY_FLAG => 'multiple_key', // duplicatvie
|
||||||
MYSQLI_GROUP_FLAG => 'group_by'
|
MYSQLI_GROUP_FLAG => 'group_by'
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -189,34 +190,34 @@ class DB_mysqli extends DB_common
|
||||||
* @since Property available since Release 1.6.5
|
* @since Property available since Release 1.6.5
|
||||||
*/
|
*/
|
||||||
public $mysqli_types = array(
|
public $mysqli_types = array(
|
||||||
MYSQLI_TYPE_DECIMAL => 'decimal',
|
MYSQLI_TYPE_DECIMAL => 'decimal',
|
||||||
MYSQLI_TYPE_TINY => 'tinyint',
|
MYSQLI_TYPE_TINY => 'tinyint',
|
||||||
MYSQLI_TYPE_SHORT => 'int',
|
MYSQLI_TYPE_SHORT => 'int',
|
||||||
MYSQLI_TYPE_LONG => 'int',
|
MYSQLI_TYPE_LONG => 'int',
|
||||||
MYSQLI_TYPE_FLOAT => 'float',
|
MYSQLI_TYPE_FLOAT => 'float',
|
||||||
MYSQLI_TYPE_DOUBLE => 'double',
|
MYSQLI_TYPE_DOUBLE => 'double',
|
||||||
// MYSQLI_TYPE_NULL => 'DEFAULT NULL', // let flags handle it
|
// MYSQLI_TYPE_NULL => 'DEFAULT NULL', // let flags handle it
|
||||||
MYSQLI_TYPE_TIMESTAMP => 'timestamp',
|
MYSQLI_TYPE_TIMESTAMP => 'timestamp',
|
||||||
MYSQLI_TYPE_LONGLONG => 'bigint',
|
MYSQLI_TYPE_LONGLONG => 'bigint',
|
||||||
MYSQLI_TYPE_INT24 => 'mediumint',
|
MYSQLI_TYPE_INT24 => 'mediumint',
|
||||||
MYSQLI_TYPE_DATE => 'date',
|
MYSQLI_TYPE_DATE => 'date',
|
||||||
MYSQLI_TYPE_TIME => 'time',
|
MYSQLI_TYPE_TIME => 'time',
|
||||||
MYSQLI_TYPE_DATETIME => 'datetime',
|
MYSQLI_TYPE_DATETIME => 'datetime',
|
||||||
MYSQLI_TYPE_YEAR => 'year',
|
MYSQLI_TYPE_YEAR => 'year',
|
||||||
MYSQLI_TYPE_NEWDATE => 'date',
|
MYSQLI_TYPE_NEWDATE => 'date',
|
||||||
MYSQLI_TYPE_ENUM => 'enum',
|
MYSQLI_TYPE_ENUM => 'enum',
|
||||||
MYSQLI_TYPE_SET => 'set',
|
MYSQLI_TYPE_SET => 'set',
|
||||||
MYSQLI_TYPE_TINY_BLOB => 'tinyblob',
|
MYSQLI_TYPE_TINY_BLOB => 'tinyblob',
|
||||||
MYSQLI_TYPE_MEDIUM_BLOB => 'mediumblob',
|
MYSQLI_TYPE_MEDIUM_BLOB => 'mediumblob',
|
||||||
MYSQLI_TYPE_LONG_BLOB => 'longblob',
|
MYSQLI_TYPE_LONG_BLOB => 'longblob',
|
||||||
MYSQLI_TYPE_BLOB => 'blob',
|
MYSQLI_TYPE_BLOB => 'blob',
|
||||||
MYSQLI_TYPE_VAR_STRING => 'varchar',
|
MYSQLI_TYPE_VAR_STRING => 'varchar',
|
||||||
MYSQLI_TYPE_STRING => 'char',
|
MYSQLI_TYPE_STRING => 'char',
|
||||||
MYSQLI_TYPE_GEOMETRY => 'geometry',
|
MYSQLI_TYPE_GEOMETRY => 'geometry',
|
||||||
/* These constants are conditionally compiled in ext/mysqli, so we'll
|
/* These constants are conditionally compiled in ext/mysqli, so we'll
|
||||||
* define them by number rather than constant. */
|
* define them by number rather than constant. */
|
||||||
16 => 'bit',
|
16 => 'bit',
|
||||||
246 => 'decimal',
|
246 => 'decimal',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@ -272,15 +273,15 @@ class DB_mysqli extends DB_common
|
||||||
* );
|
* );
|
||||||
*
|
*
|
||||||
* $db = DB::connect($dsn, $options);
|
* $db = DB::connect($dsn, $options);
|
||||||
* if (PEAR::isError($db)) {
|
* if ((new PEAR)->isError($db)) {
|
||||||
* die($db->getMessage());
|
* die($db->getMessage());
|
||||||
* }
|
* }
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @param array $dsn the data source name
|
* @param array $dsn the data source name
|
||||||
* @param bool $persistent should the connection be persistent?
|
* @param bool $persistent should the connection be persistent?
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function connect($dsn, $persistent = false)
|
public function connect($dsn, $persistent = false)
|
||||||
{
|
{
|
||||||
|
@ -297,13 +298,13 @@ class DB_mysqli extends DB_common
|
||||||
@ini_set('track_errors', 1);
|
@ini_set('track_errors', 1);
|
||||||
$php_errormsg = '';
|
$php_errormsg = '';
|
||||||
|
|
||||||
if (((int) $this->getOption('ssl')) === 1) {
|
if (((int)$this->getOption('ssl')) === 1) {
|
||||||
$init = mysqli_init();
|
$init = mysqli_init();
|
||||||
mysqli_ssl_set(
|
mysqli_ssl_set(
|
||||||
$init,
|
$init,
|
||||||
empty($dsn['key']) ? null : $dsn['key'],
|
empty($dsn['key']) ? null : $dsn['key'],
|
||||||
empty($dsn['cert']) ? null : $dsn['cert'],
|
empty($dsn['cert']) ? null : $dsn['cert'],
|
||||||
empty($dsn['ca']) ? null : $dsn['ca'],
|
empty($dsn['ca']) ? null : $dsn['ca'],
|
||||||
empty($dsn['capath']) ? null : $dsn['capath'],
|
empty($dsn['capath']) ? null : $dsn['capath'],
|
||||||
empty($dsn['cipher']) ? null : $dsn['cipher']
|
empty($dsn['cipher']) ? null : $dsn['cipher']
|
||||||
);
|
);
|
||||||
|
@ -418,6 +419,46 @@ class DB_mysqli extends DB_common
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ nextResult()
|
// {{{ nextResult()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produces a DB_Error object regarding the current problem
|
||||||
|
*
|
||||||
|
* @param int $errno if the error is being manually raised pass a
|
||||||
|
* DB_ERROR* constant here. If this isn't passed
|
||||||
|
* the error information gathered from the DBMS.
|
||||||
|
*
|
||||||
|
* @return object the DB_Error object
|
||||||
|
*
|
||||||
|
* @see DB_common::raiseError(),
|
||||||
|
* DB_mysqli::errorNative(), DB_common::errorCode()
|
||||||
|
*/
|
||||||
|
public function mysqliRaiseError($errno = null)
|
||||||
|
{
|
||||||
|
if ($errno === null) {
|
||||||
|
if ($this->options['portability'] & DB_PORTABILITY_ERRORS) {
|
||||||
|
$this->errorcode_map[1022] = DB_ERROR_CONSTRAINT;
|
||||||
|
$this->errorcode_map[1048] = DB_ERROR_CONSTRAINT_NOT_NULL;
|
||||||
|
$this->errorcode_map[1062] = DB_ERROR_CONSTRAINT;
|
||||||
|
} else {
|
||||||
|
// Doing this in case mode changes during runtime.
|
||||||
|
$this->errorcode_map[1022] = DB_ERROR_ALREADY_EXISTS;
|
||||||
|
$this->errorcode_map[1048] = DB_ERROR_CONSTRAINT;
|
||||||
|
$this->errorcode_map[1062] = DB_ERROR_ALREADY_EXISTS;
|
||||||
|
}
|
||||||
|
$errno = $this->errorCode(mysqli_errno($this->connection));
|
||||||
|
}
|
||||||
|
return $this->raiseError(
|
||||||
|
$errno,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
@mysqli_errno($this->connection) . ' ** ' .
|
||||||
|
@mysqli_error($this->connection)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ fetchInto()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the internal mysql result pointer to the next available result.
|
* Move the internal mysql result pointer to the next available result.
|
||||||
*
|
*
|
||||||
|
@ -433,7 +474,7 @@ class DB_mysqli extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ fetchInto()
|
// {{{ freeResult()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Places a row from the result set into the given array
|
* Places a row from the result set into the given array
|
||||||
|
@ -445,10 +486,10 @@ class DB_mysqli extends DB_common
|
||||||
* DB_result::fetchInto() instead. It can't be declared "protected"
|
* DB_result::fetchInto() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result the query result resource
|
* @param resource $result the query result resource
|
||||||
* @param array $arr the referenced array to put the data in
|
* @param array $arr the referenced array to put the data in
|
||||||
* @param int $fetchmode how the resulting array should be indexed
|
* @param int $fetchmode how the resulting array should be indexed
|
||||||
* @param int $rownum the row number to fetch (0 = first row)
|
* @param int $rownum the row number to fetch (0 = first row)
|
||||||
*
|
*
|
||||||
* @return mixed DB_OK on success, NULL when the end of a result set is
|
* @return mixed DB_OK on success, NULL when the end of a result set is
|
||||||
* reached or on failure
|
* reached or on failure
|
||||||
|
@ -488,7 +529,7 @@ class DB_mysqli extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ freeResult()
|
// {{{ numCols()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the result set and frees the memory occupied by the result set
|
* Deletes the result set and frees the memory occupied by the result set
|
||||||
|
@ -497,7 +538,7 @@ class DB_mysqli extends DB_common
|
||||||
* DB_result::free() instead. It can't be declared "protected"
|
* DB_result::free() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return bool TRUE on success, FALSE if $result is invalid
|
* @return bool TRUE on success, FALSE if $result is invalid
|
||||||
*
|
*
|
||||||
|
@ -505,7 +546,7 @@ class DB_mysqli extends DB_common
|
||||||
*/
|
*/
|
||||||
public function freeResult($result)
|
public function freeResult($result)
|
||||||
{
|
{
|
||||||
if (! $result instanceof mysqli_result) {
|
if (!$result instanceof mysqli_result) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mysqli_free_result($result);
|
mysqli_free_result($result);
|
||||||
|
@ -513,7 +554,7 @@ class DB_mysqli extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ numCols()
|
// {{{ numRows()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of columns in a result set
|
* Gets the number of columns in a result set
|
||||||
|
@ -522,9 +563,9 @@ class DB_mysqli extends DB_common
|
||||||
* DB_result::numCols() instead. It can't be declared "protected"
|
* DB_result::numCols() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return int the number of columns. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @see DB_result::numCols()
|
* @see DB_result::numCols()
|
||||||
*/
|
*/
|
||||||
|
@ -538,7 +579,7 @@ class DB_mysqli extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ numRows()
|
// {{{ autoCommit()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of rows in a result set
|
* Gets the number of rows in a result set
|
||||||
|
@ -547,9 +588,9 @@ class DB_mysqli extends DB_common
|
||||||
* DB_result::numRows() instead. It can't be declared "protected"
|
* DB_result::numRows() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return int the number of rows. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @see DB_result::numRows()
|
* @see DB_result::numRows()
|
||||||
*/
|
*/
|
||||||
|
@ -563,12 +604,12 @@ class DB_mysqli extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ autoCommit()
|
// {{{ commit()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables or disables automatic commits
|
* Enables or disables automatic commits
|
||||||
*
|
*
|
||||||
* @param bool $onoff true turns it on, false turns it off
|
* @param bool $onoff true turns it on, false turns it off
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object if the driver
|
* @return int DB_OK on success. A DB_Error object if the driver
|
||||||
* doesn't support auto-committing transactions.
|
* doesn't support auto-committing transactions.
|
||||||
|
@ -582,12 +623,12 @@ class DB_mysqli extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ commit()
|
// {{{ rollback()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commits the current transaction
|
* Commits the current transaction
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function commit()
|
public function commit()
|
||||||
{
|
{
|
||||||
|
@ -608,12 +649,12 @@ class DB_mysqli extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ rollback()
|
// {{{ affectedRows()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverts the current transaction
|
* Reverts the current transaction
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function rollback()
|
public function rollback()
|
||||||
{
|
{
|
||||||
|
@ -634,7 +675,7 @@ class DB_mysqli extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ affectedRows()
|
// {{{ nextId()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the number of rows affected by a data maniuplation query
|
* Determines the number of rows affected by a data maniuplation query
|
||||||
|
@ -652,17 +693,14 @@ class DB_mysqli extends DB_common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ nextId()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the next free id in a sequence
|
* Returns the next free id in a sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the sequence
|
* @param string $seq_name name of the sequence
|
||||||
* @param boolean $ondemand when true, the seqence is automatically
|
* @param boolean $ondemand when true, the seqence is automatically
|
||||||
* created if it does not exist
|
* created if it does not exist
|
||||||
*
|
*
|
||||||
* @return int the next id number in the sequence.
|
* @return int|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
||||||
|
@ -675,7 +713,7 @@ class DB_mysqli extends DB_common
|
||||||
$repeat = 0;
|
$repeat = 0;
|
||||||
$this->pushErrorHandling(PEAR_ERROR_RETURN);
|
$this->pushErrorHandling(PEAR_ERROR_RETURN);
|
||||||
$result = $this->query('UPDATE ' . $seqname
|
$result = $this->query('UPDATE ' . $seqname
|
||||||
. ' SET id = LAST_INSERT_ID(id + 1)');
|
. ' SET id = LAST_INSERT_ID(id + 1)');
|
||||||
$this->popErrorHandling();
|
$this->popErrorHandling();
|
||||||
if ($result === DB_OK) {
|
if ($result === DB_OK) {
|
||||||
// COMMON CASE
|
// COMMON CASE
|
||||||
|
@ -689,7 +727,7 @@ class DB_mysqli extends DB_common
|
||||||
// so fill it and return 1
|
// so fill it and return 1
|
||||||
// Obtain a user-level lock
|
// Obtain a user-level lock
|
||||||
$result = $this->getOne('SELECT GET_LOCK('
|
$result = $this->getOne('SELECT GET_LOCK('
|
||||||
. "'${seqname}_lock', 10)");
|
. "'${seqname}_lock', 10)");
|
||||||
if (DB::isError($result)) {
|
if (DB::isError($result)) {
|
||||||
return $this->raiseError($result);
|
return $this->raiseError($result);
|
||||||
}
|
}
|
||||||
|
@ -699,14 +737,14 @@ class DB_mysqli extends DB_common
|
||||||
|
|
||||||
// add the default value
|
// add the default value
|
||||||
$result = $this->query('REPLACE INTO ' . $seqname
|
$result = $this->query('REPLACE INTO ' . $seqname
|
||||||
. ' (id) VALUES (0)');
|
. ' (id) VALUES (0)');
|
||||||
if (DB::isError($result)) {
|
if (DB::isError($result)) {
|
||||||
return $this->raiseError($result);
|
return $this->raiseError($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release the lock
|
// Release the lock
|
||||||
$result = $this->getOne('SELECT RELEASE_LOCK('
|
$result = $this->getOne('SELECT RELEASE_LOCK('
|
||||||
. "'${seqname}_lock')");
|
. "'${seqname}_lock')");
|
||||||
if (DB::isError($result)) {
|
if (DB::isError($result)) {
|
||||||
return $this->raiseError($result);
|
return $this->raiseError($result);
|
||||||
}
|
}
|
||||||
|
@ -726,7 +764,7 @@ class DB_mysqli extends DB_common
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} elseif (DB::isError($result) &&
|
} elseif (DB::isError($result) &&
|
||||||
$result->getCode() == DB_ERROR_ALREADY_EXISTS) {
|
$result->getCode() == DB_ERROR_ALREADY_EXISTS) {
|
||||||
// BACKWARDS COMPAT
|
// BACKWARDS COMPAT
|
||||||
// see _BCsequence() comment
|
// see _BCsequence() comment
|
||||||
$result = $this->_BCsequence($seqname);
|
$result = $this->_BCsequence($seqname);
|
||||||
|
@ -740,10 +778,13 @@ class DB_mysqli extends DB_common
|
||||||
return $this->raiseError($result);
|
return $this->raiseError($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ dropSequence()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new sequence
|
* Creates a new sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the new sequence
|
* @param string $seq_name name of the new sequence
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
|
@ -754,8 +795,8 @@ class DB_mysqli extends DB_common
|
||||||
{
|
{
|
||||||
$seqname = $this->getSequenceName($seq_name);
|
$seqname = $this->getSequenceName($seq_name);
|
||||||
$res = $this->query('CREATE TABLE ' . $seqname
|
$res = $this->query('CREATE TABLE ' . $seqname
|
||||||
. ' (id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL,'
|
. ' (id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL,'
|
||||||
. ' PRIMARY KEY(id))');
|
. ' PRIMARY KEY(id))');
|
||||||
if (DB::isError($res)) {
|
if (DB::isError($res)) {
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
@ -763,24 +804,6 @@ class DB_mysqli extends DB_common
|
||||||
return $this->query("INSERT INTO ${seqname} (id) VALUES (0)");
|
return $this->query("INSERT INTO ${seqname} (id) VALUES (0)");
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ dropSequence()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes a sequence
|
|
||||||
*
|
|
||||||
* @param string $seq_name name of the sequence to be deleted
|
|
||||||
*
|
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
|
||||||
*
|
|
||||||
* @see DB_common::dropSequence(), DB_common::getSequenceName(),
|
|
||||||
* DB_mysql::nextID(), DB_mysql::createSequence()
|
|
||||||
*/
|
|
||||||
public function dropSequence($seq_name)
|
|
||||||
{
|
|
||||||
return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name));
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ _BCsequence()
|
// {{{ _BCsequence()
|
||||||
|
|
||||||
|
@ -788,9 +811,9 @@ class DB_mysqli extends DB_common
|
||||||
* Backwards compatibility with old sequence emulation implementation
|
* Backwards compatibility with old sequence emulation implementation
|
||||||
* (clean up the dupes)
|
* (clean up the dupes)
|
||||||
*
|
*
|
||||||
* @param string $seqname the sequence name to clean up
|
* @param string $seqname the sequence name to clean up
|
||||||
*
|
*
|
||||||
* @return bool true on success. A DB_Error object on failure.
|
* @return bool|object
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
|
@ -818,7 +841,7 @@ class DB_mysqli extends DB_common
|
||||||
// We should probably do something if $highest_id isn't
|
// We should probably do something if $highest_id isn't
|
||||||
// numeric, but I'm at a loss as how to handle that...
|
// numeric, but I'm at a loss as how to handle that...
|
||||||
$result = $this->query('DELETE FROM ' . $seqname
|
$result = $this->query('DELETE FROM ' . $seqname
|
||||||
. " WHERE id <> $highest_id");
|
. " WHERE id <> $highest_id");
|
||||||
if (DB::isError($result)) {
|
if (DB::isError($result)) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -836,6 +859,24 @@ class DB_mysqli extends DB_common
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ quoteIdentifier()
|
// {{{ quoteIdentifier()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a sequence
|
||||||
|
*
|
||||||
|
* @param string $seq_name name of the sequence to be deleted
|
||||||
|
*
|
||||||
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
|
*
|
||||||
|
* @see DB_common::dropSequence(), DB_common::getSequenceName(),
|
||||||
|
* DB_mysql::nextID(), DB_mysql::createSequence()
|
||||||
|
*/
|
||||||
|
public function dropSequence($seq_name)
|
||||||
|
{
|
||||||
|
return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name));
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ escapeSimple()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quotes a string so it can be safely used as a table or column name
|
* Quotes a string so it can be safely used as a table or column name
|
||||||
* (WARNING: using names that require this is a REALLY BAD IDEA)
|
* (WARNING: using names that require this is a REALLY BAD IDEA)
|
||||||
|
@ -843,7 +884,7 @@ class DB_mysqli extends DB_common
|
||||||
* WARNING: Older versions of MySQL can't handle the backtick
|
* WARNING: Older versions of MySQL can't handle the backtick
|
||||||
* character (<kbd>`</kbd>) in table or column names.
|
* character (<kbd>`</kbd>) in table or column names.
|
||||||
*
|
*
|
||||||
* @param string $str identifier name to be quoted
|
* @param string $str identifier name to be quoted
|
||||||
*
|
*
|
||||||
* @return string quoted identifier string
|
* @return string quoted identifier string
|
||||||
*
|
*
|
||||||
|
@ -856,12 +897,12 @@ class DB_mysqli extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ escapeSimple()
|
// {{{ modifyLimitQuery()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Escapes a string according to the current DBMS's standards
|
* Escapes a string according to the current DBMS's standards
|
||||||
*
|
*
|
||||||
* @param string $str the string to be escaped
|
* @param string $str the string to be escaped
|
||||||
*
|
*
|
||||||
* @return string the escaped string
|
* @return string the escaped string
|
||||||
*
|
*
|
||||||
|
@ -874,15 +915,15 @@ class DB_mysqli extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ modifyLimitQuery()
|
// {{{ mysqliRaiseError()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds LIMIT clauses to a query string according to current DBMS standards
|
* Adds LIMIT clauses to a query string according to current DBMS standards
|
||||||
*
|
*
|
||||||
* @param string $query the query to modify
|
* @param string $query the query to modify
|
||||||
* @param int $from the row to start to fetching (0 = the first row)
|
* @param int $from the row to start to fetching (0 = the first row)
|
||||||
* @param int $count the numbers of rows to fetch
|
* @param int $count the numbers of rows to fetch
|
||||||
* @param mixed $params array, string or numeric data to be used in
|
* @param mixed $params array, string or numeric data to be used in
|
||||||
* execution of the statement. Quantity of items
|
* execution of the statement. Quantity of items
|
||||||
* passed must match quantity of placeholders in
|
* passed must match quantity of placeholders in
|
||||||
* query: meaning 1 placeholder for non-array
|
* query: meaning 1 placeholder for non-array
|
||||||
|
@ -901,46 +942,6 @@ class DB_mysqli extends DB_common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ mysqliRaiseError()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Produces a DB_Error object regarding the current problem
|
|
||||||
*
|
|
||||||
* @param int $errno if the error is being manually raised pass a
|
|
||||||
* DB_ERROR* constant here. If this isn't passed
|
|
||||||
* the error information gathered from the DBMS.
|
|
||||||
*
|
|
||||||
* @return object the DB_Error object
|
|
||||||
*
|
|
||||||
* @see DB_common::raiseError(),
|
|
||||||
* DB_mysqli::errorNative(), DB_common::errorCode()
|
|
||||||
*/
|
|
||||||
public function mysqliRaiseError($errno = null)
|
|
||||||
{
|
|
||||||
if ($errno === null) {
|
|
||||||
if ($this->options['portability'] & DB_PORTABILITY_ERRORS) {
|
|
||||||
$this->errorcode_map[1022] = DB_ERROR_CONSTRAINT;
|
|
||||||
$this->errorcode_map[1048] = DB_ERROR_CONSTRAINT_NOT_NULL;
|
|
||||||
$this->errorcode_map[1062] = DB_ERROR_CONSTRAINT;
|
|
||||||
} else {
|
|
||||||
// Doing this in case mode changes during runtime.
|
|
||||||
$this->errorcode_map[1022] = DB_ERROR_ALREADY_EXISTS;
|
|
||||||
$this->errorcode_map[1048] = DB_ERROR_CONSTRAINT;
|
|
||||||
$this->errorcode_map[1062] = DB_ERROR_ALREADY_EXISTS;
|
|
||||||
}
|
|
||||||
$errno = $this->errorCode(mysqli_errno($this->connection));
|
|
||||||
}
|
|
||||||
return $this->raiseError(
|
|
||||||
$errno,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
@mysqli_errno($this->connection) . ' ** ' .
|
|
||||||
@mysqli_error($this->connection)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ errorNative()
|
// {{{ errorNative()
|
||||||
|
|
||||||
|
@ -960,14 +961,14 @@ class DB_mysqli extends DB_common
|
||||||
/**
|
/**
|
||||||
* Returns information about a table or a result set
|
* Returns information about a table or a result set
|
||||||
*
|
*
|
||||||
* @param object|string $result DB_result object from a query or a
|
* @param object|string $result DB_result object from a query or a
|
||||||
* string containing the name of a table.
|
* string containing the name of a table.
|
||||||
* While this also accepts a query result
|
* While this also accepts a query result
|
||||||
* resource identifier, this behavior is
|
* resource identifier, this behavior is
|
||||||
* deprecated.
|
* deprecated.
|
||||||
* @param int $mode a valid tableInfo mode
|
* @param int $mode a valid tableInfo mode
|
||||||
*
|
*
|
||||||
* @return array an associative array with the information requested.
|
* @return array|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::setOption()
|
* @see DB_common::setOption()
|
||||||
|
@ -1019,7 +1020,7 @@ class DB_mysqli extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = @mysqli_num_fields($id);
|
$count = @mysqli_num_fields($id);
|
||||||
$res = array();
|
$res = array();
|
||||||
|
|
||||||
if ($mode) {
|
if ($mode) {
|
||||||
$res['num_fields'] = $count;
|
$res['num_fields'] = $count;
|
||||||
|
@ -1041,16 +1042,16 @@ class DB_mysqli extends DB_common
|
||||||
|
|
||||||
$res[$i] = array(
|
$res[$i] = array(
|
||||||
'table' => $case_func($tmp->table),
|
'table' => $case_func($tmp->table),
|
||||||
'name' => $case_func($tmp->name),
|
'name' => $case_func($tmp->name),
|
||||||
'type' => isset($this->mysqli_types[$tmp->type])
|
'type' => isset($this->mysqli_types[$tmp->type])
|
||||||
? $this->mysqli_types[$tmp->type]
|
? $this->mysqli_types[$tmp->type]
|
||||||
: 'unknown',
|
: 'unknown',
|
||||||
// http://bugs.php.net/?id=36579
|
// http://bugs.php.net/?id=36579
|
||||||
// Doc Bug #36579: mysqli_fetch_field length handling
|
// Doc Bug #36579: mysqli_fetch_field length handling
|
||||||
// https://bugs.php.net/bug.php?id=62426
|
// https://bugs.php.net/bug.php?id=62426
|
||||||
// Bug #62426: mysqli_fetch_field_direct returns incorrect
|
// Bug #62426: mysqli_fetch_field_direct returns incorrect
|
||||||
// length on UTF8 fields
|
// length on UTF8 fields
|
||||||
'len' => $tmp->length,
|
'len' => $tmp->length,
|
||||||
'flags' => $flags,
|
'flags' => $flags,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1075,7 +1076,7 @@ class DB_mysqli extends DB_common
|
||||||
/**
|
/**
|
||||||
* Obtains the query string needed for listing a given type of objects
|
* Obtains the query string needed for listing a given type of objects
|
||||||
*
|
*
|
||||||
* @param string $type the kind of objects you want to retrieve
|
* @param string $type the kind of objects you want to retrieve
|
||||||
*
|
*
|
||||||
* @return string the SQL query string or null if the driver doesn't
|
* @return string the SQL query string or null if the driver doesn't
|
||||||
* support the object type requested
|
* support the object type requested
|
||||||
|
@ -1097,7 +1098,8 @@ class DB_mysqli extends DB_common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getVersion() {
|
public function getVersion()
|
||||||
|
{
|
||||||
return mysqli_get_server_version($this->connection);
|
return mysqli_get_server_version($this->connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,8 @@
|
||||||
/**
|
/**
|
||||||
* Obtain the DB_common class so it can be extended from
|
* Obtain the DB_common class so it can be extended from
|
||||||
*/
|
*/
|
||||||
require_once 'DB/common.php';
|
//require_once 'DB/common.php';
|
||||||
|
require_once 'common.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The methods PEAR DB uses to interact with PHP's oci8 extension
|
* The methods PEAR DB uses to interact with PHP's oci8 extension
|
||||||
|
@ -80,13 +81,13 @@ class DB_oci8 extends DB_common
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $features = array(
|
public $features = array(
|
||||||
'limit' => 'alter',
|
'limit' => 'alter',
|
||||||
'new_link' => '5.0.0',
|
'new_link' => '5.0.0',
|
||||||
'numrows' => 'subquery',
|
'numrows' => 'subquery',
|
||||||
'pconnect' => true,
|
'pconnect' => true,
|
||||||
'prepare' => true,
|
'prepare' => true,
|
||||||
'ssl' => false,
|
'ssl' => false,
|
||||||
'transactions' => true,
|
'transactions' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,24 +95,24 @@ class DB_oci8 extends DB_common
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $errorcode_map = array(
|
public $errorcode_map = array(
|
||||||
1 => DB_ERROR_CONSTRAINT,
|
1 => DB_ERROR_CONSTRAINT,
|
||||||
900 => DB_ERROR_SYNTAX,
|
900 => DB_ERROR_SYNTAX,
|
||||||
904 => DB_ERROR_NOSUCHFIELD,
|
904 => DB_ERROR_NOSUCHFIELD,
|
||||||
913 => DB_ERROR_VALUE_COUNT_ON_ROW,
|
913 => DB_ERROR_VALUE_COUNT_ON_ROW,
|
||||||
921 => DB_ERROR_SYNTAX,
|
921 => DB_ERROR_SYNTAX,
|
||||||
923 => DB_ERROR_SYNTAX,
|
923 => DB_ERROR_SYNTAX,
|
||||||
942 => DB_ERROR_NOSUCHTABLE,
|
942 => DB_ERROR_NOSUCHTABLE,
|
||||||
955 => DB_ERROR_ALREADY_EXISTS,
|
955 => DB_ERROR_ALREADY_EXISTS,
|
||||||
1400 => DB_ERROR_CONSTRAINT_NOT_NULL,
|
1400 => DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||||
1401 => DB_ERROR_INVALID,
|
1401 => DB_ERROR_INVALID,
|
||||||
1407 => DB_ERROR_CONSTRAINT_NOT_NULL,
|
1407 => DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||||
1418 => DB_ERROR_NOT_FOUND,
|
1418 => DB_ERROR_NOT_FOUND,
|
||||||
1476 => DB_ERROR_DIVZERO,
|
1476 => DB_ERROR_DIVZERO,
|
||||||
1722 => DB_ERROR_INVALID_NUMBER,
|
1722 => DB_ERROR_INVALID_NUMBER,
|
||||||
2289 => DB_ERROR_NOSUCHTABLE,
|
2289 => DB_ERROR_NOSUCHTABLE,
|
||||||
2291 => DB_ERROR_CONSTRAINT,
|
2291 => DB_ERROR_CONSTRAINT,
|
||||||
2292 => DB_ERROR_CONSTRAINT,
|
2292 => DB_ERROR_CONSTRAINT,
|
||||||
2449 => DB_ERROR_CONSTRAINT,
|
2449 => DB_ERROR_CONSTRAINT,
|
||||||
12899 => DB_ERROR_INVALID,
|
12899 => DB_ERROR_INVALID,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -208,10 +209,10 @@ class DB_oci8 extends DB_common
|
||||||
* not portable to other DBMS's.
|
* not portable to other DBMS's.
|
||||||
* Available since PEAR DB 1.7.0.
|
* Available since PEAR DB 1.7.0.
|
||||||
*
|
*
|
||||||
* @param array $dsn the data source name
|
* @param array $dsn the data source name
|
||||||
* @param bool $persistent should the connection be persistent?
|
* @param bool $persistent should the connection be persistent?
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function connect($dsn, $persistent = false)
|
public function connect($dsn, $persistent = false)
|
||||||
{
|
{
|
||||||
|
@ -237,10 +238,10 @@ class DB_oci8 extends DB_common
|
||||||
$connect_function = 'oci_new_connect';
|
$connect_function = 'oci_new_connect';
|
||||||
} else {
|
} else {
|
||||||
$connect_function = $persistent ? 'oci_pconnect'
|
$connect_function = $persistent ? 'oci_pconnect'
|
||||||
: 'oci_connect';
|
: 'oci_connect';
|
||||||
}
|
}
|
||||||
if (isset($this->dsn['port']) && $this->dsn['port']) {
|
if (isset($this->dsn['port']) && $this->dsn['port']) {
|
||||||
$db = '//'.$db.':'.$this->dsn['port'];
|
$db = '//' . $db . ':' . $this->dsn['port'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$char = empty($dsn['charset']) ? null : $dsn['charset'];
|
$char = empty($dsn['charset']) ? null : $dsn['charset'];
|
||||||
|
@ -355,6 +356,68 @@ class DB_oci8 extends DB_common
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ nextResult()
|
// {{{ nextResult()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes a query string for various DBMS specific reasons
|
||||||
|
*
|
||||||
|
* "SELECT 2+2" must be "SELECT 2+2 FROM dual" in Oracle.
|
||||||
|
*
|
||||||
|
* @param string $query the query string to modify
|
||||||
|
*
|
||||||
|
* @return string the modified query string
|
||||||
|
*
|
||||||
|
* @access protected
|
||||||
|
*/
|
||||||
|
public function modifyQuery($query)
|
||||||
|
{
|
||||||
|
if (preg_match('/^\s*SELECT/i', $query) &&
|
||||||
|
!preg_match('/\sFROM\s/i', $query)) {
|
||||||
|
$query .= ' FROM dual';
|
||||||
|
}
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ fetchInto()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produces a DB_Error object regarding the current problem
|
||||||
|
*
|
||||||
|
* @param int $errno if the error is being manually raised pass a
|
||||||
|
* DB_ERROR* constant here. If this isn't passed
|
||||||
|
* the error information gathered from the DBMS.
|
||||||
|
*
|
||||||
|
* @return object the DB_Error object
|
||||||
|
*
|
||||||
|
* @see DB_common::raiseError(),
|
||||||
|
* DB_oci8::errorNative(), DB_oci8::errorCode()
|
||||||
|
*/
|
||||||
|
public function oci8RaiseError($errno = null)
|
||||||
|
{
|
||||||
|
if ($errno === null) {
|
||||||
|
$error = @OCIError($this->connection);
|
||||||
|
return $this->raiseError(
|
||||||
|
$this->errorCode($error['code']),
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
$error['message']
|
||||||
|
);
|
||||||
|
} elseif (is_resource($errno)) {
|
||||||
|
$error = @OCIError($errno);
|
||||||
|
return $this->raiseError(
|
||||||
|
$this->errorCode($error['code']),
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
$error['message']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return $this->raiseError($this->errorCode($errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ freeResult()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the internal oracle result pointer to the next available result
|
* Move the internal oracle result pointer to the next available result
|
||||||
*
|
*
|
||||||
|
@ -369,9 +432,6 @@ class DB_oci8 extends DB_common
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ fetchInto()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Places a row from the result set into the given array
|
* Places a row from the result set into the given array
|
||||||
*
|
*
|
||||||
|
@ -382,10 +442,10 @@ class DB_oci8 extends DB_common
|
||||||
* DB_result::fetchInto() instead. It can't be declared "protected"
|
* DB_result::fetchInto() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result the query result resource
|
* @param resource $result the query result resource
|
||||||
* @param array $arr the referenced array to put the data in
|
* @param array $arr the referenced array to put the data in
|
||||||
* @param int $fetchmode how the resulting array should be indexed
|
* @param int $fetchmode how the resulting array should be indexed
|
||||||
* @param int $rownum the row number to fetch (0 = first row)
|
* @param int $rownum the row number to fetch (0 = first row)
|
||||||
*
|
*
|
||||||
* @return mixed DB_OK on success, NULL when the end of a result set is
|
* @return mixed DB_OK on success, NULL when the end of a result set is
|
||||||
* reached or on failure
|
* reached or on failure
|
||||||
|
@ -398,13 +458,13 @@ class DB_oci8 extends DB_common
|
||||||
return $this->raiseError(DB_ERROR_NOT_CAPABLE);
|
return $this->raiseError(DB_ERROR_NOT_CAPABLE);
|
||||||
}
|
}
|
||||||
if ($fetchmode & DB_FETCHMODE_ASSOC) {
|
if ($fetchmode & DB_FETCHMODE_ASSOC) {
|
||||||
$moredata = @OCIFetchInto($result, $arr, OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS);
|
$moredata = @OCIFetchInto($result, $arr, OCI_ASSOC + OCI_RETURN_NULLS + OCI_RETURN_LOBS);
|
||||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE &&
|
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE &&
|
||||||
$moredata) {
|
$moredata) {
|
||||||
$arr = array_change_key_case($arr, CASE_LOWER);
|
$arr = array_change_key_case($arr, CASE_LOWER);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$moredata = OCIFetchInto($result, $arr, OCI_RETURN_NULLS+OCI_RETURN_LOBS);
|
$moredata = OCIFetchInto($result, $arr, OCI_RETURN_NULLS + OCI_RETURN_LOBS);
|
||||||
}
|
}
|
||||||
if (!$moredata) {
|
if (!$moredata) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -419,7 +479,7 @@ class DB_oci8 extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ freeResult()
|
// {{{ numRows()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the result set and frees the memory occupied by the result set
|
* Deletes the result set and frees the memory occupied by the result set
|
||||||
|
@ -428,7 +488,7 @@ class DB_oci8 extends DB_common
|
||||||
* DB_result::free() instead. It can't be declared "protected"
|
* DB_result::free() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return bool TRUE on success, FALSE if $result is invalid
|
* @return bool TRUE on success, FALSE if $result is invalid
|
||||||
*
|
*
|
||||||
|
@ -439,11 +499,14 @@ class DB_oci8 extends DB_common
|
||||||
return is_resource($result) ? OCIFreeStatement($result) : false;
|
return is_resource($result) ? OCIFreeStatement($result) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ numCols()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Frees the internal resources associated with a prepared query
|
* Frees the internal resources associated with a prepared query
|
||||||
*
|
*
|
||||||
* @param resource $stmt the prepared statement's resource
|
* @param resource $stmt the prepared statement's resource
|
||||||
* @param bool $free_resource should the PHP resource be freed too?
|
* @param bool $free_resource should the PHP resource be freed too?
|
||||||
* Use false if you need to get data
|
* Use false if you need to get data
|
||||||
* from the result set later.
|
* from the result set later.
|
||||||
*
|
*
|
||||||
|
@ -470,7 +533,7 @@ class DB_oci8 extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ numRows()
|
// {{{ prepare()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of rows in a result set
|
* Gets the number of rows in a result set
|
||||||
|
@ -482,9 +545,9 @@ class DB_oci8 extends DB_common
|
||||||
* DB_result::numRows() instead. It can't be declared "protected"
|
* DB_result::numRows() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return int the number of rows. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @see DB_result::numRows(), DB_common::setOption()
|
* @see DB_result::numRows(), DB_common::setOption()
|
||||||
*/
|
*/
|
||||||
|
@ -493,7 +556,7 @@ class DB_oci8 extends DB_common
|
||||||
// emulate numRows for Oracle. yuck.
|
// emulate numRows for Oracle. yuck.
|
||||||
if ($this->options['portability'] & DB_PORTABILITY_NUMROWS &&
|
if ($this->options['portability'] & DB_PORTABILITY_NUMROWS &&
|
||||||
$result === $this->last_stmt) {
|
$result === $this->last_stmt) {
|
||||||
$countquery = 'SELECT COUNT(*) FROM ('.$this->last_query.')';
|
$countquery = 'SELECT COUNT(*) FROM (' . $this->last_query . ')';
|
||||||
$save_query = $this->last_query;
|
$save_query = $this->last_query;
|
||||||
$save_stmt = $this->last_stmt;
|
$save_stmt = $this->last_stmt;
|
||||||
|
|
||||||
|
@ -514,7 +577,7 @@ class DB_oci8 extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ numCols()
|
// {{{ execute()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of columns in a result set
|
* Gets the number of columns in a result set
|
||||||
|
@ -523,9 +586,9 @@ class DB_oci8 extends DB_common
|
||||||
* DB_result::numCols() instead. It can't be declared "protected"
|
* DB_result::numCols() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return int the number of columns. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @see DB_result::numCols()
|
* @see DB_result::numCols()
|
||||||
*/
|
*/
|
||||||
|
@ -539,7 +602,145 @@ class DB_oci8 extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ prepare()
|
// {{{ autoCommit()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables or disables automatic commits
|
||||||
|
*
|
||||||
|
* @param bool $onoff true turns it on, false turns it off
|
||||||
|
*
|
||||||
|
* @return int DB_OK on success. A DB_Error object if the driver
|
||||||
|
* doesn't support auto-committing transactions.
|
||||||
|
*/
|
||||||
|
public function autoCommit($onoff = false)
|
||||||
|
{
|
||||||
|
$this->autocommit = (bool)$onoff;;
|
||||||
|
return DB_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ commit()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Commits the current transaction
|
||||||
|
*
|
||||||
|
* @return int|object
|
||||||
|
*/
|
||||||
|
public function commit()
|
||||||
|
{
|
||||||
|
$result = @OCICommit($this->connection);
|
||||||
|
if (!$result) {
|
||||||
|
return $this->oci8RaiseError();
|
||||||
|
}
|
||||||
|
return DB_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ rollback()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverts the current transaction
|
||||||
|
*
|
||||||
|
* @return int|object
|
||||||
|
*/
|
||||||
|
public function rollback()
|
||||||
|
{
|
||||||
|
$result = @OCIRollback($this->connection);
|
||||||
|
if (!$result) {
|
||||||
|
return $this->oci8RaiseError();
|
||||||
|
}
|
||||||
|
return DB_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ affectedRows()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines the number of rows affected by a data maniuplation query
|
||||||
|
*
|
||||||
|
* 0 is returned for queries that don't manipulate data.
|
||||||
|
*
|
||||||
|
* @return int|object
|
||||||
|
*/
|
||||||
|
public function affectedRows()
|
||||||
|
{
|
||||||
|
if ($this->last_stmt === false) {
|
||||||
|
return $this->oci8RaiseError();
|
||||||
|
}
|
||||||
|
$result = @OCIRowCount($this->last_stmt);
|
||||||
|
if ($result === false) {
|
||||||
|
return $this->oci8RaiseError($this->last_stmt);
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ modifyQuery()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds LIMIT clauses to a query string according to current DBMS standards
|
||||||
|
*
|
||||||
|
* @param string $query the query to modify
|
||||||
|
* @param int $from the row to start to fetching (0 = the first row)
|
||||||
|
* @param int $count the numbers of rows to fetch
|
||||||
|
* @param mixed $params array, string or numeric data to be used in
|
||||||
|
* execution of the statement. Quantity of items
|
||||||
|
* passed must match quantity of placeholders in
|
||||||
|
* query: meaning 1 placeholder for non-array
|
||||||
|
* parameters or 1 placeholder per array element.
|
||||||
|
*
|
||||||
|
* @return string the query string with LIMIT clauses added
|
||||||
|
*
|
||||||
|
* @access protected
|
||||||
|
*/
|
||||||
|
public function modifyLimitQuery($query, $from, $count, $params = array())
|
||||||
|
{
|
||||||
|
// Let Oracle return the name of the columns instead of
|
||||||
|
// coding a "home" SQL parser
|
||||||
|
|
||||||
|
if (count($params)) {
|
||||||
|
$result = $this->prepare("SELECT * FROM ($query) "
|
||||||
|
. 'WHERE NULL = NULL');
|
||||||
|
$tmp = $this->execute($result, $params);
|
||||||
|
} else {
|
||||||
|
$q_fields = "SELECT * FROM ($query) WHERE NULL = NULL";
|
||||||
|
|
||||||
|
if (!$result = @OCIParse($this->connection, $q_fields)) {
|
||||||
|
$this->last_query = $q_fields;
|
||||||
|
return $this->oci8RaiseError();
|
||||||
|
}
|
||||||
|
if (!@OCIExecute($result, OCI_DEFAULT)) {
|
||||||
|
$this->last_query = $q_fields;
|
||||||
|
return $this->oci8RaiseError($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$ncols = OCINumCols($result);
|
||||||
|
$cols = array();
|
||||||
|
for ($i = 1; $i <= $ncols; $i++) {
|
||||||
|
$cols[] = '"' . OCIColumnName($result, $i) . '"';
|
||||||
|
}
|
||||||
|
$fields = implode(', ', $cols);
|
||||||
|
// XXX Test that (tip by John Lim)
|
||||||
|
//if (preg_match('/^\s*SELECT\s+/is', $query, $match)) {
|
||||||
|
// // Introduce the FIRST_ROWS Oracle query optimizer
|
||||||
|
// $query = substr($query, strlen($match[0]), strlen($query));
|
||||||
|
// $query = "SELECT /* +FIRST_ROWS */ " . $query;
|
||||||
|
//}
|
||||||
|
|
||||||
|
// Construct the query
|
||||||
|
// more at: http://marc.theaimsgroup.com/?l=php-db&m=99831958101212&w=2
|
||||||
|
// Perhaps this could be optimized with the use of Unions
|
||||||
|
$query = "SELECT $fields FROM" .
|
||||||
|
" (SELECT rownum as linenum, $fields FROM" .
|
||||||
|
" ($query)" .
|
||||||
|
' WHERE rownum <= ' . ($from + $count) .
|
||||||
|
') WHERE linenum >= ' . ++$from;
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ modifyLimitQuery()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares a query for multiple execution with execute().
|
* Prepares a query for multiple execution with execute().
|
||||||
|
@ -562,7 +763,7 @@ class DB_oci8 extends DB_common
|
||||||
* "UPDATE foo SET col=? WHERE col='over \& under'"
|
* "UPDATE foo SET col=? WHERE col='over \& under'"
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @param string $query the query to be prepared
|
* @param string $query the query to be prepared
|
||||||
*
|
*
|
||||||
* @return mixed DB statement resource on success. DB_Error on failure.
|
* @return mixed DB statement resource on success. DB_Error on failure.
|
||||||
*
|
*
|
||||||
|
@ -570,15 +771,15 @@ class DB_oci8 extends DB_common
|
||||||
*/
|
*/
|
||||||
public function prepare($query)
|
public function prepare($query)
|
||||||
{
|
{
|
||||||
$tokens = preg_split(
|
$tokens = preg_split(
|
||||||
'/((?<!\\\)[&?!])/',
|
'/((?<!\\\)[&?!])/',
|
||||||
$query,
|
$query,
|
||||||
-1,
|
-1,
|
||||||
PREG_SPLIT_DELIM_CAPTURE
|
PREG_SPLIT_DELIM_CAPTURE
|
||||||
);
|
);
|
||||||
$binds = count($tokens) - 1;
|
$binds = count($tokens) - 1;
|
||||||
$token = 0;
|
$token = 0;
|
||||||
$types = array();
|
$types = array();
|
||||||
$newquery = '';
|
$newquery = '';
|
||||||
|
|
||||||
foreach ($tokens as $key => $val) {
|
foreach ($tokens as $key => $val) {
|
||||||
|
@ -617,7 +818,7 @@ class DB_oci8 extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ execute()
|
// {{{ nextId()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a DB statement prepared with prepare().
|
* Executes a DB statement prepared with prepare().
|
||||||
|
@ -626,8 +827,8 @@ class DB_oci8 extends DB_common
|
||||||
* ocisetprefetch(), see the "result_buffering" option in setOptions().
|
* ocisetprefetch(), see the "result_buffering" option in setOptions().
|
||||||
* This option was added in Release 1.7.0.
|
* This option was added in Release 1.7.0.
|
||||||
*
|
*
|
||||||
* @param resource $stmt a DB statement resource returned from prepare()
|
* @param resource $stmt a DB statement resource returned from prepare()
|
||||||
* @param mixed $data array, string or numeric data to be used in
|
* @param mixed $data array, string or numeric data to be used in
|
||||||
* execution of the statement. Quantity of items
|
* execution of the statement. Quantity of items
|
||||||
* passed must match quantity of placeholders in
|
* passed must match quantity of placeholders in
|
||||||
* query: meaning 1 for non-array items or the
|
* query: meaning 1 for non-array items or the
|
||||||
|
@ -713,179 +914,31 @@ class DB_oci8 extends DB_common
|
||||||
return $tmp;
|
return $tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ autoCommit()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables or disables automatic commits
|
* Formats a float value for use within a query in a locale-independent
|
||||||
|
* manner.
|
||||||
*
|
*
|
||||||
* @param bool $onoff true turns it on, false turns it off
|
* @param float the float value to be quoted.
|
||||||
*
|
* @return string the quoted string.
|
||||||
* @return int DB_OK on success. A DB_Error object if the driver
|
* @see DB_common::quoteSmart()
|
||||||
* doesn't support auto-committing transactions.
|
* @since Method available since release 1.7.8.
|
||||||
*/
|
*/
|
||||||
public function autoCommit($onoff = false)
|
public function quoteFloat($float)
|
||||||
{
|
{
|
||||||
$this->autocommit = (bool)$onoff;
|
return $this->escapeSimple(str_replace(',', '.', strval(floatval($float))));
|
||||||
;
|
|
||||||
return DB_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ commit()
|
// {{{ dropSequence()
|
||||||
|
|
||||||
/**
|
|
||||||
* Commits the current transaction
|
|
||||||
*
|
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
|
||||||
*/
|
|
||||||
public function commit()
|
|
||||||
{
|
|
||||||
$result = @OCICommit($this->connection);
|
|
||||||
if (!$result) {
|
|
||||||
return $this->oci8RaiseError();
|
|
||||||
}
|
|
||||||
return DB_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ rollback()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverts the current transaction
|
|
||||||
*
|
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
|
||||||
*/
|
|
||||||
public function rollback()
|
|
||||||
{
|
|
||||||
$result = @OCIRollback($this->connection);
|
|
||||||
if (!$result) {
|
|
||||||
return $this->oci8RaiseError();
|
|
||||||
}
|
|
||||||
return DB_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ affectedRows()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines the number of rows affected by a data maniuplation query
|
|
||||||
*
|
|
||||||
* 0 is returned for queries that don't manipulate data.
|
|
||||||
*
|
|
||||||
* @return int the number of rows. A DB_Error object on failure.
|
|
||||||
*/
|
|
||||||
public function affectedRows()
|
|
||||||
{
|
|
||||||
if ($this->last_stmt === false) {
|
|
||||||
return $this->oci8RaiseError();
|
|
||||||
}
|
|
||||||
$result = @OCIRowCount($this->last_stmt);
|
|
||||||
if ($result === false) {
|
|
||||||
return $this->oci8RaiseError($this->last_stmt);
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ modifyQuery()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Changes a query string for various DBMS specific reasons
|
|
||||||
*
|
|
||||||
* "SELECT 2+2" must be "SELECT 2+2 FROM dual" in Oracle.
|
|
||||||
*
|
|
||||||
* @param string $query the query string to modify
|
|
||||||
*
|
|
||||||
* @return string the modified query string
|
|
||||||
*
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
public function modifyQuery($query)
|
|
||||||
{
|
|
||||||
if (preg_match('/^\s*SELECT/i', $query) &&
|
|
||||||
!preg_match('/\sFROM\s/i', $query)) {
|
|
||||||
$query .= ' FROM dual';
|
|
||||||
}
|
|
||||||
return $query;
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ modifyLimitQuery()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds LIMIT clauses to a query string according to current DBMS standards
|
|
||||||
*
|
|
||||||
* @param string $query the query to modify
|
|
||||||
* @param int $from the row to start to fetching (0 = the first row)
|
|
||||||
* @param int $count the numbers of rows to fetch
|
|
||||||
* @param mixed $params array, string or numeric data to be used in
|
|
||||||
* execution of the statement. Quantity of items
|
|
||||||
* passed must match quantity of placeholders in
|
|
||||||
* query: meaning 1 placeholder for non-array
|
|
||||||
* parameters or 1 placeholder per array element.
|
|
||||||
*
|
|
||||||
* @return string the query string with LIMIT clauses added
|
|
||||||
*
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
public function modifyLimitQuery($query, $from, $count, $params = array())
|
|
||||||
{
|
|
||||||
// Let Oracle return the name of the columns instead of
|
|
||||||
// coding a "home" SQL parser
|
|
||||||
|
|
||||||
if (count($params)) {
|
|
||||||
$result = $this->prepare("SELECT * FROM ($query) "
|
|
||||||
. 'WHERE NULL = NULL');
|
|
||||||
$tmp = $this->execute($result, $params);
|
|
||||||
} else {
|
|
||||||
$q_fields = "SELECT * FROM ($query) WHERE NULL = NULL";
|
|
||||||
|
|
||||||
if (!$result = @OCIParse($this->connection, $q_fields)) {
|
|
||||||
$this->last_query = $q_fields;
|
|
||||||
return $this->oci8RaiseError();
|
|
||||||
}
|
|
||||||
if (!@OCIExecute($result, OCI_DEFAULT)) {
|
|
||||||
$this->last_query = $q_fields;
|
|
||||||
return $this->oci8RaiseError($result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$ncols = OCINumCols($result);
|
|
||||||
$cols = array();
|
|
||||||
for ($i = 1; $i <= $ncols; $i++) {
|
|
||||||
$cols[] = '"' . OCIColumnName($result, $i) . '"';
|
|
||||||
}
|
|
||||||
$fields = implode(', ', $cols);
|
|
||||||
// XXX Test that (tip by John Lim)
|
|
||||||
//if (preg_match('/^\s*SELECT\s+/is', $query, $match)) {
|
|
||||||
// // Introduce the FIRST_ROWS Oracle query optimizer
|
|
||||||
// $query = substr($query, strlen($match[0]), strlen($query));
|
|
||||||
// $query = "SELECT /* +FIRST_ROWS */ " . $query;
|
|
||||||
//}
|
|
||||||
|
|
||||||
// Construct the query
|
|
||||||
// more at: http://marc.theaimsgroup.com/?l=php-db&m=99831958101212&w=2
|
|
||||||
// Perhaps this could be optimized with the use of Unions
|
|
||||||
$query = "SELECT $fields FROM".
|
|
||||||
" (SELECT rownum as linenum, $fields FROM".
|
|
||||||
" ($query)".
|
|
||||||
' WHERE rownum <= '. ($from + $count) .
|
|
||||||
') WHERE linenum >= ' . ++$from;
|
|
||||||
return $query;
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ nextId()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the next free id in a sequence
|
* Returns the next free id in a sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the sequence
|
* @param string $seq_name name of the sequence
|
||||||
* @param boolean $ondemand when true, the seqence is automatically
|
* @param boolean $ondemand when true, the seqence is automatically
|
||||||
* created if it does not exist
|
* created if it does not exist
|
||||||
*
|
*
|
||||||
* @return int the next id number in the sequence.
|
* @return int|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
||||||
|
@ -917,10 +970,13 @@ class DB_oci8 extends DB_common
|
||||||
return $arr[0];
|
return $arr[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ oci8RaiseError()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new sequence
|
* Creates a new sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the new sequence
|
* @param string $seq_name name of the new sequence
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
|
@ -930,16 +986,16 @@ class DB_oci8 extends DB_common
|
||||||
public function createSequence($seq_name)
|
public function createSequence($seq_name)
|
||||||
{
|
{
|
||||||
return $this->query('CREATE SEQUENCE '
|
return $this->query('CREATE SEQUENCE '
|
||||||
. $this->getSequenceName($seq_name));
|
. $this->getSequenceName($seq_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ dropSequence()
|
// {{{ errorNative()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a sequence
|
* Deletes a sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the sequence to be deleted
|
* @param string $seq_name name of the sequence to be deleted
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
|
@ -949,50 +1005,11 @@ class DB_oci8 extends DB_common
|
||||||
public function dropSequence($seq_name)
|
public function dropSequence($seq_name)
|
||||||
{
|
{
|
||||||
return $this->query('DROP SEQUENCE '
|
return $this->query('DROP SEQUENCE '
|
||||||
. $this->getSequenceName($seq_name));
|
. $this->getSequenceName($seq_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ oci8RaiseError()
|
// {{{ tableInfo()
|
||||||
|
|
||||||
/**
|
|
||||||
* Produces a DB_Error object regarding the current problem
|
|
||||||
*
|
|
||||||
* @param int $errno if the error is being manually raised pass a
|
|
||||||
* DB_ERROR* constant here. If this isn't passed
|
|
||||||
* the error information gathered from the DBMS.
|
|
||||||
*
|
|
||||||
* @return object the DB_Error object
|
|
||||||
*
|
|
||||||
* @see DB_common::raiseError(),
|
|
||||||
* DB_oci8::errorNative(), DB_oci8::errorCode()
|
|
||||||
*/
|
|
||||||
public function oci8RaiseError($errno = null)
|
|
||||||
{
|
|
||||||
if ($errno === null) {
|
|
||||||
$error = @OCIError($this->connection);
|
|
||||||
return $this->raiseError(
|
|
||||||
$this->errorCode($error['code']),
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
$error['message']
|
|
||||||
);
|
|
||||||
} elseif (is_resource($errno)) {
|
|
||||||
$error = @OCIError($errno);
|
|
||||||
return $this->raiseError(
|
|
||||||
$this->errorCode($error['code']),
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
$error['message']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return $this->raiseError($this->errorCode($errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ errorNative()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the DBMS' native error code produced by the last query
|
* Gets the DBMS' native error code produced by the last query
|
||||||
|
@ -1014,7 +1031,7 @@ class DB_oci8 extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ tableInfo()
|
// {{{ getSpecialQuery()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns information about a table or a result set
|
* Returns information about a table or a result set
|
||||||
|
@ -1024,14 +1041,14 @@ class DB_oci8 extends DB_common
|
||||||
*
|
*
|
||||||
* NOTE: flags won't contain index information.
|
* NOTE: flags won't contain index information.
|
||||||
*
|
*
|
||||||
* @param object|string $result DB_result object from a query or a
|
* @param object|string $result DB_result object from a query or a
|
||||||
* string containing the name of a table.
|
* string containing the name of a table.
|
||||||
* While this also accepts a query result
|
* While this also accepts a query result
|
||||||
* resource identifier, this behavior is
|
* resource identifier, this behavior is
|
||||||
* deprecated.
|
* deprecated.
|
||||||
* @param int $mode a valid tableInfo mode
|
* @param int $mode a valid tableInfo mode
|
||||||
*
|
*
|
||||||
* @return array an associative array with the information requested.
|
* @return array|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::tableInfo()
|
* @see DB_common::tableInfo()
|
||||||
|
@ -1053,9 +1070,9 @@ class DB_oci8 extends DB_common
|
||||||
*/
|
*/
|
||||||
$result = strtoupper($result);
|
$result = strtoupper($result);
|
||||||
$q_fields = 'SELECT column_name, data_type, data_length, '
|
$q_fields = 'SELECT column_name, data_type, data_length, '
|
||||||
. 'nullable '
|
. 'nullable '
|
||||||
. 'FROM user_tab_columns '
|
. 'FROM user_tab_columns '
|
||||||
. "WHERE table_name='$result' ORDER BY column_id";
|
. "WHERE table_name='$result' ORDER BY column_id";
|
||||||
|
|
||||||
$this->last_query = $q_fields;
|
$this->last_query = $q_fields;
|
||||||
|
|
||||||
|
@ -1070,9 +1087,9 @@ class DB_oci8 extends DB_common
|
||||||
while (@OCIFetch($stmt)) {
|
while (@OCIFetch($stmt)) {
|
||||||
$res[$i] = array(
|
$res[$i] = array(
|
||||||
'table' => $case_func($result),
|
'table' => $case_func($result),
|
||||||
'name' => $case_func(@OCIResult($stmt, 1)),
|
'name' => $case_func(@OCIResult($stmt, 1)),
|
||||||
'type' => @OCIResult($stmt, 2),
|
'type' => @OCIResult($stmt, 2),
|
||||||
'len' => @OCIResult($stmt, 3),
|
'len' => @OCIResult($stmt, 3),
|
||||||
'flags' => (@OCIResult($stmt, 4) == 'N') ? 'not_null' : '',
|
'flags' => (@OCIResult($stmt, 4) == 'N') ? 'not_null' : '',
|
||||||
);
|
);
|
||||||
if ($mode & DB_TABLEINFO_ORDER) {
|
if ($mode & DB_TABLEINFO_ORDER) {
|
||||||
|
@ -1107,9 +1124,9 @@ class DB_oci8 extends DB_common
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$res[$i] = array(
|
$res[$i] = array(
|
||||||
'table' => '',
|
'table' => '',
|
||||||
'name' => $case_func(@OCIColumnName($result, $i+1)),
|
'name' => $case_func(@OCIColumnName($result, $i + 1)),
|
||||||
'type' => @OCIColumnType($result, $i+1),
|
'type' => @OCIColumnType($result, $i + 1),
|
||||||
'len' => @OCIColumnSize($result, $i+1),
|
'len' => @OCIColumnSize($result, $i + 1),
|
||||||
'flags' => '',
|
'flags' => '',
|
||||||
);
|
);
|
||||||
if ($mode & DB_TABLEINFO_ORDER) {
|
if ($mode & DB_TABLEINFO_ORDER) {
|
||||||
|
@ -1127,12 +1144,12 @@ class DB_oci8 extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ getSpecialQuery()
|
// {{{ quoteFloat()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains the query string needed for listing a given type of objects
|
* Obtains the query string needed for listing a given type of objects
|
||||||
*
|
*
|
||||||
* @param string $type the kind of objects you want to retrieve
|
* @param string $type the kind of objects you want to retrieve
|
||||||
*
|
*
|
||||||
* @return string the SQL query string or null if the driver doesn't
|
* @return string the SQL query string or null if the driver doesn't
|
||||||
* support the object type requested
|
* support the object type requested
|
||||||
|
@ -1154,23 +1171,6 @@ class DB_oci8 extends DB_common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ quoteFloat()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Formats a float value for use within a query in a locale-independent
|
|
||||||
* manner.
|
|
||||||
*
|
|
||||||
* @param float the float value to be quoted.
|
|
||||||
* @return string the quoted string.
|
|
||||||
* @see DB_common::quoteSmart()
|
|
||||||
* @since Method available since release 1.7.8.
|
|
||||||
*/
|
|
||||||
public function quoteFloat($float)
|
|
||||||
{
|
|
||||||
return $this->escapeSimple(str_replace(',', '.', strval(floatval($float))));
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,8 @@
|
||||||
/**
|
/**
|
||||||
* Obtain the DB_common class so it can be extended from
|
* Obtain the DB_common class so it can be extended from
|
||||||
*/
|
*/
|
||||||
require_once 'DB/common.php';
|
//require_once 'DB/common.php';
|
||||||
|
require_once 'common.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The methods PEAR DB uses to interact with PHP's odbc extension
|
* The methods PEAR DB uses to interact with PHP's odbc extension
|
||||||
|
@ -82,13 +83,13 @@ class DB_odbc extends DB_common
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $features = array(
|
public $features = array(
|
||||||
'limit' => 'emulate',
|
'limit' => 'emulate',
|
||||||
'new_link' => false,
|
'new_link' => false,
|
||||||
'numrows' => true,
|
'numrows' => true,
|
||||||
'pconnect' => true,
|
'pconnect' => true,
|
||||||
'prepare' => false,
|
'prepare' => false,
|
||||||
'ssl' => false,
|
'ssl' => false,
|
||||||
'transactions' => false,
|
'transactions' => false,
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -173,10 +174,10 @@ class DB_odbc extends DB_common
|
||||||
* PEAR DB's odbc driver supports the following extra DSN options:
|
* PEAR DB's odbc driver supports the following extra DSN options:
|
||||||
* + cursor The type of cursor to be used for this connection.
|
* + cursor The type of cursor to be used for this connection.
|
||||||
*
|
*
|
||||||
* @param array $dsn the data source name
|
* @param array $dsn the data source name
|
||||||
* @param bool $persistent should the connection be persistent?
|
* @param bool $persistent should the connection be persistent?
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function connect($dsn, $persistent = false)
|
public function connect($dsn, $persistent = false)
|
||||||
{
|
{
|
||||||
|
@ -242,10 +243,26 @@ class DB_odbc extends DB_common
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ disconnect()
|
// {{{ disconnect()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the DBMS' native error code and message produced by the last query
|
||||||
|
*
|
||||||
|
* @return string the DBMS' error code and message
|
||||||
|
*/
|
||||||
|
public function errorNative()
|
||||||
|
{
|
||||||
|
if (!is_resource($this->connection)) {
|
||||||
|
return @odbc_error() . ' ' . @odbc_errormsg();
|
||||||
|
}
|
||||||
|
return @odbc_error($this->connection) . ' ' . @odbc_errormsg($this->connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ simpleQuery()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disconnects from the database server
|
* Disconnects from the database server
|
||||||
*
|
*
|
||||||
* @return bool TRUE on success, FALSE on failure
|
* @return bool|void
|
||||||
*/
|
*/
|
||||||
public function disconnect()
|
public function disconnect()
|
||||||
{
|
{
|
||||||
|
@ -255,7 +272,7 @@ class DB_odbc extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ simpleQuery()
|
// {{{ nextResult()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a query to the database server
|
* Sends a query to the database server
|
||||||
|
@ -285,7 +302,75 @@ class DB_odbc extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ nextResult()
|
// {{{ fetchInto()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produces a DB_Error object regarding the current problem
|
||||||
|
*
|
||||||
|
* @param int $errno if the error is being manually raised pass a
|
||||||
|
* DB_ERROR* constant here. If this isn't passed
|
||||||
|
* the error information gathered from the DBMS.
|
||||||
|
*
|
||||||
|
* @return object the DB_Error object
|
||||||
|
*
|
||||||
|
* @see DB_common::raiseError(),
|
||||||
|
* DB_odbc::errorNative(), DB_common::errorCode()
|
||||||
|
*/
|
||||||
|
public function odbcRaiseError($errno = null)
|
||||||
|
{
|
||||||
|
if ($errno === null) {
|
||||||
|
switch ($this->dbsyntax) {
|
||||||
|
case 'access':
|
||||||
|
if ($this->options['portability'] & DB_PORTABILITY_ERRORS) {
|
||||||
|
$this->errorcode_map['07001'] = DB_ERROR_NOSUCHFIELD;
|
||||||
|
} else {
|
||||||
|
// Doing this in case mode changes during runtime.
|
||||||
|
$this->errorcode_map['07001'] = DB_ERROR_MISMATCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
$native_code = odbc_error($this->connection);
|
||||||
|
|
||||||
|
// S1000 is for "General Error." Let's be more specific.
|
||||||
|
if ($native_code == 'S1000') {
|
||||||
|
$errormsg = odbc_errormsg($this->connection);
|
||||||
|
static $error_regexps;
|
||||||
|
if (!isset($error_regexps)) {
|
||||||
|
$error_regexps = array(
|
||||||
|
'/includes related records.$/i' => DB_ERROR_CONSTRAINT,
|
||||||
|
'/cannot contain a Null value/i' => DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
foreach ($error_regexps as $regexp => $code) {
|
||||||
|
if (preg_match($regexp, $errormsg)) {
|
||||||
|
return $this->raiseError(
|
||||||
|
$code,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
$native_code . ' ' . $errormsg
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$errno = DB_ERROR;
|
||||||
|
} else {
|
||||||
|
$errno = $this->errorCode($native_code);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$errno = $this->errorCode(odbc_error($this->connection));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->raiseError(
|
||||||
|
$errno,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
$this->errorNative()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ freeResult()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the internal odbc result pointer to the next available result
|
* Move the internal odbc result pointer to the next available result
|
||||||
|
@ -302,7 +387,7 @@ class DB_odbc extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ fetchInto()
|
// {{{ numCols()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Places a row from the result set into the given array
|
* Places a row from the result set into the given array
|
||||||
|
@ -314,10 +399,10 @@ class DB_odbc extends DB_common
|
||||||
* DB_result::fetchInto() instead. It can't be declared "protected"
|
* DB_result::fetchInto() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result the query result resource
|
* @param resource $result the query result resource
|
||||||
* @param array $arr the referenced array to put the data in
|
* @param array $arr the referenced array to put the data in
|
||||||
* @param int $fetchmode how the resulting array should be indexed
|
* @param int $fetchmode how the resulting array should be indexed
|
||||||
* @param int $rownum the row number to fetch (0 = first row)
|
* @param int $rownum the row number to fetch (0 = first row)
|
||||||
*
|
*
|
||||||
* @return mixed DB_OK on success, NULL when the end of a result set is
|
* @return mixed DB_OK on success, NULL when the end of a result set is
|
||||||
* reached or on failure
|
* reached or on failure
|
||||||
|
@ -342,7 +427,7 @@ class DB_odbc extends DB_common
|
||||||
}
|
}
|
||||||
if ($fetchmode !== DB_FETCHMODE_ORDERED) {
|
if ($fetchmode !== DB_FETCHMODE_ORDERED) {
|
||||||
for ($i = 0; $i < count($arr); $i++) {
|
for ($i = 0; $i < count($arr); $i++) {
|
||||||
$colName = @odbc_field_name($result, $i+1);
|
$colName = @odbc_field_name($result, $i + 1);
|
||||||
$a[$colName] = $arr[$i];
|
$a[$colName] = $arr[$i];
|
||||||
}
|
}
|
||||||
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
|
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
|
||||||
|
@ -360,7 +445,7 @@ class DB_odbc extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ freeResult()
|
// {{{ affectedRows()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the result set and frees the memory occupied by the result set
|
* Deletes the result set and frees the memory occupied by the result set
|
||||||
|
@ -369,7 +454,7 @@ class DB_odbc extends DB_common
|
||||||
* DB_result::free() instead. It can't be declared "protected"
|
* DB_result::free() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return bool TRUE on success, FALSE if $result is invalid
|
* @return bool TRUE on success, FALSE if $result is invalid
|
||||||
*
|
*
|
||||||
|
@ -381,7 +466,7 @@ class DB_odbc extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ numCols()
|
// {{{ numRows()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of columns in a result set
|
* Gets the number of columns in a result set
|
||||||
|
@ -390,9 +475,9 @@ class DB_odbc extends DB_common
|
||||||
* DB_result::numCols() instead. It can't be declared "protected"
|
* DB_result::numCols() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return int the number of columns. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @see DB_result::numCols()
|
* @see DB_result::numCols()
|
||||||
*/
|
*/
|
||||||
|
@ -406,14 +491,14 @@ class DB_odbc extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ affectedRows()
|
// {{{ quoteIdentifier()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the number of rows affected by a data maniuplation query
|
* Determines the number of rows affected by a data maniuplation query
|
||||||
*
|
*
|
||||||
* 0 is returned for queries that don't manipulate data.
|
* 0 is returned for queries that don't manipulate data.
|
||||||
*
|
*
|
||||||
* @return int the number of rows. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function affectedRows()
|
public function affectedRows()
|
||||||
{
|
{
|
||||||
|
@ -428,7 +513,7 @@ class DB_odbc extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ numRows()
|
// {{{ nextId()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of rows in a result set
|
* Gets the number of rows in a result set
|
||||||
|
@ -440,9 +525,9 @@ class DB_odbc extends DB_common
|
||||||
* DB_result::numRows() instead. It can't be declared "protected"
|
* DB_result::numRows() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return int the number of rows. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @see DB_result::numRows()
|
* @see DB_result::numRows()
|
||||||
*/
|
*/
|
||||||
|
@ -458,16 +543,13 @@ class DB_odbc extends DB_common
|
||||||
return $nrows;
|
return $nrows;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ quoteIdentifier()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quotes a string so it can be safely used as a table or column name
|
* Quotes a string so it can be safely used as a table or column name
|
||||||
*
|
*
|
||||||
* Use 'mssql' as the dbsyntax in the DB DSN only if you've unchecked
|
* Use 'mssql' as the dbsyntax in the DB DSN only if you've unchecked
|
||||||
* "Use ANSI quoted identifiers" when setting up the ODBC data source.
|
* "Use ANSI quoted identifiers" when setting up the ODBC data source.
|
||||||
*
|
*
|
||||||
* @param string $str identifier name to be quoted
|
* @param string $str identifier name to be quoted
|
||||||
*
|
*
|
||||||
* @return string quoted identifier string
|
* @return string quoted identifier string
|
||||||
*
|
*
|
||||||
|
@ -491,16 +573,16 @@ class DB_odbc extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ nextId()
|
// {{{ dropSequence()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the next free id in a sequence
|
* Returns the next free id in a sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the sequence
|
* @param string $seq_name name of the sequence
|
||||||
* @param boolean $ondemand when true, the seqence is automatically
|
* @param boolean $ondemand when true, the seqence is automatically
|
||||||
* created if it does not exist
|
* created if it does not exist
|
||||||
*
|
*
|
||||||
* @return int the next id number in the sequence.
|
* @return int|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
||||||
|
@ -546,10 +628,13 @@ class DB_odbc extends DB_common
|
||||||
return $row[0];
|
return $row[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ autoCommit()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new sequence
|
* Creates a new sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the new sequence
|
* @param string $seq_name name of the new sequence
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
|
@ -559,18 +644,18 @@ class DB_odbc extends DB_common
|
||||||
public function createSequence($seq_name)
|
public function createSequence($seq_name)
|
||||||
{
|
{
|
||||||
return $this->query('CREATE TABLE '
|
return $this->query('CREATE TABLE '
|
||||||
. $this->getSequenceName($seq_name)
|
. $this->getSequenceName($seq_name)
|
||||||
. ' (id integer NOT NULL,'
|
. ' (id integer NOT NULL,'
|
||||||
. ' PRIMARY KEY(id))');
|
. ' PRIMARY KEY(id))');
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ dropSequence()
|
// {{{ commit()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a sequence
|
* Deletes a sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the sequence to be deleted
|
* @param string $seq_name name of the sequence to be deleted
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
|
@ -583,14 +668,14 @@ class DB_odbc extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ autoCommit()
|
// {{{ rollback()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables or disables automatic commits
|
* Enables or disables automatic commits
|
||||||
*
|
*
|
||||||
* @param bool $onoff true turns it on, false turns it off
|
* @param bool $onoff true turns it on, false turns it off
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object if the driver
|
* @return int|object
|
||||||
* doesn't support auto-committing transactions.
|
* doesn't support auto-committing transactions.
|
||||||
*/
|
*/
|
||||||
public function autoCommit($onoff = false)
|
public function autoCommit($onoff = false)
|
||||||
|
@ -602,12 +687,12 @@ class DB_odbc extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ commit()
|
// {{{ odbcRaiseError()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commits the current transaction
|
* Commits the current transaction
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function commit()
|
public function commit()
|
||||||
{
|
{
|
||||||
|
@ -618,12 +703,12 @@ class DB_odbc extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ rollback()
|
// {{{ errorNative()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverts the current transaction
|
* Reverts the current transaction
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function rollback()
|
public function rollback()
|
||||||
{
|
{
|
||||||
|
@ -633,104 +718,20 @@ class DB_odbc extends DB_common
|
||||||
return DB_OK;
|
return DB_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ odbcRaiseError()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Produces a DB_Error object regarding the current problem
|
|
||||||
*
|
|
||||||
* @param int $errno if the error is being manually raised pass a
|
|
||||||
* DB_ERROR* constant here. If this isn't passed
|
|
||||||
* the error information gathered from the DBMS.
|
|
||||||
*
|
|
||||||
* @return object the DB_Error object
|
|
||||||
*
|
|
||||||
* @see DB_common::raiseError(),
|
|
||||||
* DB_odbc::errorNative(), DB_common::errorCode()
|
|
||||||
*/
|
|
||||||
public function odbcRaiseError($errno = null)
|
|
||||||
{
|
|
||||||
if ($errno === null) {
|
|
||||||
switch ($this->dbsyntax) {
|
|
||||||
case 'access':
|
|
||||||
if ($this->options['portability'] & DB_PORTABILITY_ERRORS) {
|
|
||||||
$this->errorcode_map['07001'] = DB_ERROR_NOSUCHFIELD;
|
|
||||||
} else {
|
|
||||||
// Doing this in case mode changes during runtime.
|
|
||||||
$this->errorcode_map['07001'] = DB_ERROR_MISMATCH;
|
|
||||||
}
|
|
||||||
|
|
||||||
$native_code = odbc_error($this->connection);
|
|
||||||
|
|
||||||
// S1000 is for "General Error." Let's be more specific.
|
|
||||||
if ($native_code == 'S1000') {
|
|
||||||
$errormsg = odbc_errormsg($this->connection);
|
|
||||||
static $error_regexps;
|
|
||||||
if (!isset($error_regexps)) {
|
|
||||||
$error_regexps = array(
|
|
||||||
'/includes related records.$/i' => DB_ERROR_CONSTRAINT,
|
|
||||||
'/cannot contain a Null value/i' => DB_ERROR_CONSTRAINT_NOT_NULL,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
foreach ($error_regexps as $regexp => $code) {
|
|
||||||
if (preg_match($regexp, $errormsg)) {
|
|
||||||
return $this->raiseError(
|
|
||||||
$code,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
$native_code . ' ' . $errormsg
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$errno = DB_ERROR;
|
|
||||||
} else {
|
|
||||||
$errno = $this->errorCode($native_code);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$errno = $this->errorCode(odbc_error($this->connection));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this->raiseError(
|
|
||||||
$errno,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
$this->errorNative()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ errorNative()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the DBMS' native error code and message produced by the last query
|
|
||||||
*
|
|
||||||
* @return string the DBMS' error code and message
|
|
||||||
*/
|
|
||||||
public function errorNative()
|
|
||||||
{
|
|
||||||
if (!is_resource($this->connection)) {
|
|
||||||
return @odbc_error() . ' ' . @odbc_errormsg();
|
|
||||||
}
|
|
||||||
return @odbc_error($this->connection) . ' ' . @odbc_errormsg($this->connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ tableInfo()
|
// {{{ tableInfo()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns information about a table or a result set
|
* Returns information about a table or a result set
|
||||||
*
|
*
|
||||||
* @param object|string $result DB_result object from a query or a
|
* @param object|string $result DB_result object from a query or a
|
||||||
* string containing the name of a table.
|
* string containing the name of a table.
|
||||||
* While this also accepts a query result
|
* While this also accepts a query result
|
||||||
* resource identifier, this behavior is
|
* resource identifier, this behavior is
|
||||||
* deprecated.
|
* deprecated.
|
||||||
* @param int $mode a valid tableInfo mode
|
* @param int $mode a valid tableInfo mode
|
||||||
*
|
*
|
||||||
* @return array an associative array with the information requested.
|
* @return array|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::tableInfo()
|
* @see DB_common::tableInfo()
|
||||||
|
@ -776,7 +777,7 @@ class DB_odbc extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = @odbc_num_fields($id);
|
$count = @odbc_num_fields($id);
|
||||||
$res = array();
|
$res = array();
|
||||||
|
|
||||||
if ($mode) {
|
if ($mode) {
|
||||||
$res['num_fields'] = $count;
|
$res['num_fields'] = $count;
|
||||||
|
@ -786,9 +787,9 @@ class DB_odbc extends DB_common
|
||||||
$col = $i + 1;
|
$col = $i + 1;
|
||||||
$res[$i] = array(
|
$res[$i] = array(
|
||||||
'table' => $got_string ? $case_func($result) : '',
|
'table' => $got_string ? $case_func($result) : '',
|
||||||
'name' => $case_func(@odbc_field_name($id, $col)),
|
'name' => $case_func(@odbc_field_name($id, $col)),
|
||||||
'type' => @odbc_field_type($id, $col),
|
'type' => @odbc_field_type($id, $col),
|
||||||
'len' => @odbc_field_len($id, $col),
|
'len' => @odbc_field_len($id, $col),
|
||||||
'flags' => '',
|
'flags' => '',
|
||||||
);
|
);
|
||||||
if ($mode & DB_TABLEINFO_ORDER) {
|
if ($mode & DB_TABLEINFO_ORDER) {
|
||||||
|
@ -814,9 +815,9 @@ class DB_odbc extends DB_common
|
||||||
*
|
*
|
||||||
* Thanks to symbol1@gmail.com and Philippe.Jausions@11abacus.com.
|
* Thanks to symbol1@gmail.com and Philippe.Jausions@11abacus.com.
|
||||||
*
|
*
|
||||||
* @param string $type the kind of objects you want to retrieve
|
* @param string $type the kind of objects you want to retrieve
|
||||||
*
|
*
|
||||||
* @return string the list of objects requested
|
* @return array|string
|
||||||
*
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @see DB_common::getListOf()
|
* @see DB_common::getListOf()
|
||||||
|
@ -859,7 +860,7 @@ class DB_odbc extends DB_common
|
||||||
* in the odbc_tables() call because some backends choke on this:
|
* in the odbc_tables() call because some backends choke on this:
|
||||||
* odbc_tables($this->connection, '', '', '', 'TABLE')
|
* odbc_tables($this->connection, '', '', '', 'TABLE')
|
||||||
*/
|
*/
|
||||||
$res = @odbc_tables($this->connection);
|
$res = @odbc_tables($this->connection);
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
return $this->odbcRaiseError();
|
return $this->odbcRaiseError();
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,8 @@
|
||||||
/**
|
/**
|
||||||
* Obtain the DB_common class so it can be extended from
|
* Obtain the DB_common class so it can be extended from
|
||||||
*/
|
*/
|
||||||
require_once 'DB/common.php';
|
//require_once 'DB/common.php';
|
||||||
|
require_once 'common.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The methods PEAR DB uses to interact with PHP's pgsql extension
|
* The methods PEAR DB uses to interact with PHP's pgsql extension
|
||||||
|
@ -76,21 +77,20 @@ class DB_pgsql extends DB_common
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $features = array(
|
public $features = array(
|
||||||
'limit' => 'alter',
|
'limit' => 'alter',
|
||||||
'new_link' => '4.3.0',
|
'new_link' => '4.3.0',
|
||||||
'numrows' => true,
|
'numrows' => true,
|
||||||
'pconnect' => true,
|
'pconnect' => true,
|
||||||
'prepare' => false,
|
'prepare' => false,
|
||||||
'ssl' => true,
|
'ssl' => true,
|
||||||
'transactions' => true,
|
'transactions' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mapping of native error codes to DB error codes
|
* A mapping of native error codes to DB error codes
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $errorcode_map = array(
|
public $errorcode_map = array();
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The raw database connection created by PHP
|
* The raw database connection created by PHP
|
||||||
|
@ -194,15 +194,15 @@ class DB_pgsql extends DB_common
|
||||||
* );
|
* );
|
||||||
*
|
*
|
||||||
* $db = DB::connect($dsn, $options);
|
* $db = DB::connect($dsn, $options);
|
||||||
* if (PEAR::isError($db)) {
|
* if ((new PEAR)->isError($db)) {
|
||||||
* die($db->getMessage());
|
* die($db->getMessage());
|
||||||
* }
|
* }
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @param array $dsn the data source name
|
* @param array $dsn the data source name
|
||||||
* @param bool $persistent should the connection be persistent?
|
* @param bool $persistent should the connection be persistent?
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @link http://www.postgresql.org/docs/current/static/libpq.html#LIBPQ-CONNECT
|
* @link http://www.postgresql.org/docs/current/static/libpq.html#LIBPQ-CONNECT
|
||||||
*/
|
*/
|
||||||
|
@ -381,6 +381,161 @@ class DB_pgsql extends DB_common
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ nextResult()
|
// {{{ nextResult()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given query is a manipulation query. This also takes into
|
||||||
|
* account the _next_query_manip flag and sets the _last_query_manip flag
|
||||||
|
* (and resets _next_query_manip) according to the result.
|
||||||
|
*
|
||||||
|
* @param string The query to check.
|
||||||
|
*
|
||||||
|
* @return boolean true if the query is a manipulation query, false
|
||||||
|
* otherwise
|
||||||
|
*
|
||||||
|
* @access protected
|
||||||
|
*/
|
||||||
|
public function _checkManip($query)
|
||||||
|
{
|
||||||
|
return (preg_match('/^\s*(SAVEPOINT|RELEASE)\s+/i', $query)
|
||||||
|
|| parent::_checkManip($query));
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ fetchInto()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produces a DB_Error object regarding the current problem
|
||||||
|
*
|
||||||
|
* @param int $errno if the error is being manually raised pass a
|
||||||
|
* DB_ERROR* constant here. If this isn't passed
|
||||||
|
* the error information gathered from the DBMS.
|
||||||
|
*
|
||||||
|
* @return object the DB_Error object
|
||||||
|
*
|
||||||
|
* @see DB_common::raiseError(),
|
||||||
|
* DB_pgsql::errorNative(), DB_pgsql::errorCode()
|
||||||
|
*/
|
||||||
|
public function pgsqlRaiseError($errno = null)
|
||||||
|
{
|
||||||
|
$native = $this->errorNative();
|
||||||
|
if (!$native) {
|
||||||
|
$native = 'Database connection has been lost.';
|
||||||
|
$errno = DB_ERROR_CONNECT_FAILED;
|
||||||
|
}
|
||||||
|
if ($errno === null) {
|
||||||
|
$errno = $this->errorCode($native);
|
||||||
|
}
|
||||||
|
return $this->raiseError($errno, null, null, null, $native);
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ freeResult()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the DBMS' native error message produced by the last query
|
||||||
|
*
|
||||||
|
* {@internal Error messages are used instead of error codes
|
||||||
|
* in order to support older versions of PostgreSQL.}}
|
||||||
|
*
|
||||||
|
* @return string the DBMS' error message
|
||||||
|
*/
|
||||||
|
public function errorNative()
|
||||||
|
{
|
||||||
|
return @pg_errormessage($this->connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ quoteBoolean()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines PEAR::DB error code from the database's text error message.
|
||||||
|
*
|
||||||
|
* @param string $errormsg error message returned from the database
|
||||||
|
* @return integer an error number from a DB error constant
|
||||||
|
*/
|
||||||
|
public function errorCode($errormsg)
|
||||||
|
{
|
||||||
|
static $error_regexps;
|
||||||
|
if (!isset($error_regexps)) {
|
||||||
|
$error_regexps = array(
|
||||||
|
'/column .* (of relation .*)?does not exist/i'
|
||||||
|
=> DB_ERROR_NOSUCHFIELD,
|
||||||
|
'/(relation|sequence|table).*does not exist|class .* not found/i'
|
||||||
|
=> DB_ERROR_NOSUCHTABLE,
|
||||||
|
'/index .* does not exist/'
|
||||||
|
=> DB_ERROR_NOT_FOUND,
|
||||||
|
'/relation .* already exists/i'
|
||||||
|
=> DB_ERROR_ALREADY_EXISTS,
|
||||||
|
'/(divide|division) by zero$/i'
|
||||||
|
=> DB_ERROR_DIVZERO,
|
||||||
|
'/pg_atoi: error in .*: can\'t parse /i'
|
||||||
|
=> DB_ERROR_INVALID_NUMBER,
|
||||||
|
'/invalid input syntax for( type)? (integer|numeric)/i'
|
||||||
|
=> DB_ERROR_INVALID_NUMBER,
|
||||||
|
'/value .* is out of range for type \w*int/i'
|
||||||
|
=> DB_ERROR_INVALID_NUMBER,
|
||||||
|
'/integer out of range/i'
|
||||||
|
=> DB_ERROR_INVALID_NUMBER,
|
||||||
|
'/value too long for type character/i'
|
||||||
|
=> DB_ERROR_INVALID,
|
||||||
|
'/attribute .* not found|relation .* does not have attribute/i'
|
||||||
|
=> DB_ERROR_NOSUCHFIELD,
|
||||||
|
'/column .* specified in USING clause does not exist in (left|right) table/i'
|
||||||
|
=> DB_ERROR_NOSUCHFIELD,
|
||||||
|
'/parser: parse error at or near/i'
|
||||||
|
=> DB_ERROR_SYNTAX,
|
||||||
|
'/syntax error at/'
|
||||||
|
=> DB_ERROR_SYNTAX,
|
||||||
|
'/column reference .* is ambiguous/i'
|
||||||
|
=> DB_ERROR_SYNTAX,
|
||||||
|
'/permission denied/'
|
||||||
|
=> DB_ERROR_ACCESS_VIOLATION,
|
||||||
|
'/violates not-null constraint/'
|
||||||
|
=> DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||||
|
'/violates [\w ]+ constraint/'
|
||||||
|
=> DB_ERROR_CONSTRAINT,
|
||||||
|
'/referential integrity violation/'
|
||||||
|
=> DB_ERROR_CONSTRAINT,
|
||||||
|
'/more expressions than target columns/i'
|
||||||
|
=> DB_ERROR_VALUE_COUNT_ON_ROW,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
foreach ($error_regexps as $regexp => $code) {
|
||||||
|
if (preg_match($regexp, $errormsg)) {
|
||||||
|
return $code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Fall back to DB_ERROR if there was no mapping.
|
||||||
|
return DB_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ escapeSimple()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the number of rows in a result set
|
||||||
|
*
|
||||||
|
* This method is not meant to be called directly. Use
|
||||||
|
* DB_result::numRows() instead. It can't be declared "protected"
|
||||||
|
* because DB_result is a separate object.
|
||||||
|
*
|
||||||
|
* @param resource $result PHP's query result resource
|
||||||
|
*
|
||||||
|
* @return int|object
|
||||||
|
*
|
||||||
|
* @see DB_result::numRows()
|
||||||
|
*/
|
||||||
|
public function numRows($result)
|
||||||
|
{
|
||||||
|
$rows = @pg_numrows($result);
|
||||||
|
if ($rows === null) {
|
||||||
|
return $this->pgsqlRaiseError();
|
||||||
|
}
|
||||||
|
return $rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ numCols()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the internal pgsql result pointer to the next available result
|
* Move the internal pgsql result pointer to the next available result
|
||||||
*
|
*
|
||||||
|
@ -396,7 +551,7 @@ class DB_pgsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ fetchInto()
|
// {{{ numRows()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Places a row from the result set into the given array
|
* Places a row from the result set into the given array
|
||||||
|
@ -408,10 +563,10 @@ class DB_pgsql extends DB_common
|
||||||
* DB_result::fetchInto() instead. It can't be declared "protected"
|
* DB_result::fetchInto() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result the query result resource
|
* @param resource $result the query result resource
|
||||||
* @param array $arr the referenced array to put the data in
|
* @param array $arr the referenced array to put the data in
|
||||||
* @param int $fetchmode how the resulting array should be indexed
|
* @param int $fetchmode how the resulting array should be indexed
|
||||||
* @param int $rownum the row number to fetch (0 = first row)
|
* @param int $rownum the row number to fetch (0 = first row)
|
||||||
*
|
*
|
||||||
* @return mixed DB_OK on success, NULL when the end of a result set is
|
* @return mixed DB_OK on success, NULL when the end of a result set is
|
||||||
* reached or on failure
|
* reached or on failure
|
||||||
|
@ -447,7 +602,7 @@ class DB_pgsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ freeResult()
|
// {{{ autoCommit()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the result set and frees the memory occupied by the result set
|
* Deletes the result set and frees the memory occupied by the result set
|
||||||
|
@ -456,7 +611,7 @@ class DB_pgsql extends DB_common
|
||||||
* DB_result::free() instead. It can't be declared "protected"
|
* DB_result::free() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return bool TRUE on success, FALSE if $result is invalid
|
* @return bool TRUE on success, FALSE if $result is invalid
|
||||||
*
|
*
|
||||||
|
@ -474,7 +629,7 @@ class DB_pgsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ quoteBoolean()
|
// {{{ commit()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats a boolean value for use within a query in a locale-independent
|
* Formats a boolean value for use within a query in a locale-independent
|
||||||
|
@ -491,7 +646,7 @@ class DB_pgsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ escapeSimple()
|
// {{{ rollback()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Escapes a string according to the current DBMS's standards
|
* Escapes a string according to the current DBMS's standards
|
||||||
|
@ -499,7 +654,7 @@ class DB_pgsql extends DB_common
|
||||||
* {@internal PostgreSQL treats a backslash as an escape character,
|
* {@internal PostgreSQL treats a backslash as an escape character,
|
||||||
* so they are escaped as well.
|
* so they are escaped as well.
|
||||||
*
|
*
|
||||||
* @param string $str the string to be escaped
|
* @param string $str the string to be escaped
|
||||||
*
|
*
|
||||||
* @return string the escaped string
|
* @return string the escaped string
|
||||||
*
|
*
|
||||||
|
@ -526,7 +681,7 @@ class DB_pgsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ numCols()
|
// {{{ affectedRows()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of columns in a result set
|
* Gets the number of columns in a result set
|
||||||
|
@ -535,9 +690,9 @@ class DB_pgsql extends DB_common
|
||||||
* DB_result::numCols() instead. It can't be declared "protected"
|
* DB_result::numCols() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return int the number of columns. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @see DB_result::numCols()
|
* @see DB_result::numCols()
|
||||||
*/
|
*/
|
||||||
|
@ -551,37 +706,12 @@ class DB_pgsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ numRows()
|
// {{{ nextId()
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the number of rows in a result set
|
|
||||||
*
|
|
||||||
* This method is not meant to be called directly. Use
|
|
||||||
* DB_result::numRows() instead. It can't be declared "protected"
|
|
||||||
* because DB_result is a separate object.
|
|
||||||
*
|
|
||||||
* @param resource $result PHP's query result resource
|
|
||||||
*
|
|
||||||
* @return int the number of rows. A DB_Error object on failure.
|
|
||||||
*
|
|
||||||
* @see DB_result::numRows()
|
|
||||||
*/
|
|
||||||
public function numRows($result)
|
|
||||||
{
|
|
||||||
$rows = @pg_numrows($result);
|
|
||||||
if ($rows === null) {
|
|
||||||
return $this->pgsqlRaiseError();
|
|
||||||
}
|
|
||||||
return $rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ autoCommit()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables or disables automatic commits
|
* Enables or disables automatic commits
|
||||||
*
|
*
|
||||||
* @param bool $onoff true turns it on, false turns it off
|
* @param bool $onoff true turns it on, false turns it off
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object if the driver
|
* @return int DB_OK on success. A DB_Error object if the driver
|
||||||
* doesn't support auto-committing transactions.
|
* doesn't support auto-committing transactions.
|
||||||
|
@ -595,12 +725,12 @@ class DB_pgsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ commit()
|
// {{{ createSequence()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commits the current transaction
|
* Commits the current transaction
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function commit()
|
public function commit()
|
||||||
{
|
{
|
||||||
|
@ -617,12 +747,12 @@ class DB_pgsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ rollback()
|
// {{{ dropSequence()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverts the current transaction
|
* Reverts the current transaction
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function rollback()
|
public function rollback()
|
||||||
{
|
{
|
||||||
|
@ -637,7 +767,7 @@ class DB_pgsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ affectedRows()
|
// {{{ modifyLimitQuery()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the number of rows affected by a data maniuplation query
|
* Determines the number of rows affected by a data maniuplation query
|
||||||
|
@ -652,16 +782,16 @@ class DB_pgsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ nextId()
|
// {{{ pgsqlRaiseError()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the next free id in a sequence
|
* Returns the next free id in a sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the sequence
|
* @param string $seq_name name of the sequence
|
||||||
* @param boolean $ondemand when true, the seqence is automatically
|
* @param boolean $ondemand when true, the seqence is automatically
|
||||||
* created if it does not exist
|
* created if it does not exist
|
||||||
*
|
*
|
||||||
* @return int the next id number in the sequence.
|
* @return int|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
||||||
|
@ -697,12 +827,12 @@ class DB_pgsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ createSequence()
|
// {{{ errorNative()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new sequence
|
* Creates a new sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the new sequence
|
* @param string $seq_name name of the new sequence
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
|
@ -717,12 +847,12 @@ class DB_pgsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ dropSequence()
|
// {{{ errorCode()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a sequence
|
* Deletes a sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the sequence to be deleted
|
* @param string $seq_name name of the sequence to be deleted
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
|
@ -732,19 +862,19 @@ class DB_pgsql extends DB_common
|
||||||
public function dropSequence($seq_name)
|
public function dropSequence($seq_name)
|
||||||
{
|
{
|
||||||
return $this->query('DROP SEQUENCE '
|
return $this->query('DROP SEQUENCE '
|
||||||
. $this->getSequenceName($seq_name));
|
. $this->getSequenceName($seq_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ modifyLimitQuery()
|
// {{{ tableInfo()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds LIMIT clauses to a query string according to current DBMS standards
|
* Adds LIMIT clauses to a query string according to current DBMS standards
|
||||||
*
|
*
|
||||||
* @param string $query the query to modify
|
* @param string $query the query to modify
|
||||||
* @param int $from the row to start to fetching (0 = the first row)
|
* @param int $from the row to start to fetching (0 = the first row)
|
||||||
* @param int $count the numbers of rows to fetch
|
* @param int $count the numbers of rows to fetch
|
||||||
* @param mixed $params array, string or numeric data to be used in
|
* @param mixed $params array, string or numeric data to be used in
|
||||||
* execution of the statement. Quantity of items
|
* execution of the statement. Quantity of items
|
||||||
* passed must match quantity of placeholders in
|
* passed must match quantity of placeholders in
|
||||||
* query: meaning 1 placeholder for non-array
|
* query: meaning 1 placeholder for non-array
|
||||||
|
@ -760,116 +890,7 @@ class DB_pgsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ pgsqlRaiseError()
|
// {{{ _pgFieldFlags()
|
||||||
|
|
||||||
/**
|
|
||||||
* Produces a DB_Error object regarding the current problem
|
|
||||||
*
|
|
||||||
* @param int $errno if the error is being manually raised pass a
|
|
||||||
* DB_ERROR* constant here. If this isn't passed
|
|
||||||
* the error information gathered from the DBMS.
|
|
||||||
*
|
|
||||||
* @return object the DB_Error object
|
|
||||||
*
|
|
||||||
* @see DB_common::raiseError(),
|
|
||||||
* DB_pgsql::errorNative(), DB_pgsql::errorCode()
|
|
||||||
*/
|
|
||||||
public function pgsqlRaiseError($errno = null)
|
|
||||||
{
|
|
||||||
$native = $this->errorNative();
|
|
||||||
if (!$native) {
|
|
||||||
$native = 'Database connection has been lost.';
|
|
||||||
$errno = DB_ERROR_CONNECT_FAILED;
|
|
||||||
}
|
|
||||||
if ($errno === null) {
|
|
||||||
$errno = $this->errorCode($native);
|
|
||||||
}
|
|
||||||
return $this->raiseError($errno, null, null, null, $native);
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ errorNative()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the DBMS' native error message produced by the last query
|
|
||||||
*
|
|
||||||
* {@internal Error messages are used instead of error codes
|
|
||||||
* in order to support older versions of PostgreSQL.}}
|
|
||||||
*
|
|
||||||
* @return string the DBMS' error message
|
|
||||||
*/
|
|
||||||
public function errorNative()
|
|
||||||
{
|
|
||||||
return @pg_errormessage($this->connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ errorCode()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines PEAR::DB error code from the database's text error message.
|
|
||||||
*
|
|
||||||
* @param string $errormsg error message returned from the database
|
|
||||||
* @return integer an error number from a DB error constant
|
|
||||||
*/
|
|
||||||
public function errorCode($errormsg)
|
|
||||||
{
|
|
||||||
static $error_regexps;
|
|
||||||
if (!isset($error_regexps)) {
|
|
||||||
$error_regexps = array(
|
|
||||||
'/column .* (of relation .*)?does not exist/i'
|
|
||||||
=> DB_ERROR_NOSUCHFIELD,
|
|
||||||
'/(relation|sequence|table).*does not exist|class .* not found/i'
|
|
||||||
=> DB_ERROR_NOSUCHTABLE,
|
|
||||||
'/index .* does not exist/'
|
|
||||||
=> DB_ERROR_NOT_FOUND,
|
|
||||||
'/relation .* already exists/i'
|
|
||||||
=> DB_ERROR_ALREADY_EXISTS,
|
|
||||||
'/(divide|division) by zero$/i'
|
|
||||||
=> DB_ERROR_DIVZERO,
|
|
||||||
'/pg_atoi: error in .*: can\'t parse /i'
|
|
||||||
=> DB_ERROR_INVALID_NUMBER,
|
|
||||||
'/invalid input syntax for( type)? (integer|numeric)/i'
|
|
||||||
=> DB_ERROR_INVALID_NUMBER,
|
|
||||||
'/value .* is out of range for type \w*int/i'
|
|
||||||
=> DB_ERROR_INVALID_NUMBER,
|
|
||||||
'/integer out of range/i'
|
|
||||||
=> DB_ERROR_INVALID_NUMBER,
|
|
||||||
'/value too long for type character/i'
|
|
||||||
=> DB_ERROR_INVALID,
|
|
||||||
'/attribute .* not found|relation .* does not have attribute/i'
|
|
||||||
=> DB_ERROR_NOSUCHFIELD,
|
|
||||||
'/column .* specified in USING clause does not exist in (left|right) table/i'
|
|
||||||
=> DB_ERROR_NOSUCHFIELD,
|
|
||||||
'/parser: parse error at or near/i'
|
|
||||||
=> DB_ERROR_SYNTAX,
|
|
||||||
'/syntax error at/'
|
|
||||||
=> DB_ERROR_SYNTAX,
|
|
||||||
'/column reference .* is ambiguous/i'
|
|
||||||
=> DB_ERROR_SYNTAX,
|
|
||||||
'/permission denied/'
|
|
||||||
=> DB_ERROR_ACCESS_VIOLATION,
|
|
||||||
'/violates not-null constraint/'
|
|
||||||
=> DB_ERROR_CONSTRAINT_NOT_NULL,
|
|
||||||
'/violates [\w ]+ constraint/'
|
|
||||||
=> DB_ERROR_CONSTRAINT,
|
|
||||||
'/referential integrity violation/'
|
|
||||||
=> DB_ERROR_CONSTRAINT,
|
|
||||||
'/more expressions than target columns/i'
|
|
||||||
=> DB_ERROR_VALUE_COUNT_ON_ROW,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
foreach ($error_regexps as $regexp => $code) {
|
|
||||||
if (preg_match($regexp, $errormsg)) {
|
|
||||||
return $code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Fall back to DB_ERROR if there was no mapping.
|
|
||||||
return DB_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ tableInfo()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns information about a table or a result set
|
* Returns information about a table or a result set
|
||||||
|
@ -877,14 +898,14 @@ class DB_pgsql extends DB_common
|
||||||
* NOTE: only supports 'table' and 'flags' if <var>$result</var>
|
* NOTE: only supports 'table' and 'flags' if <var>$result</var>
|
||||||
* is a table name.
|
* is a table name.
|
||||||
*
|
*
|
||||||
* @param object|string $result DB_result object from a query or a
|
* @param object|string $result DB_result object from a query or a
|
||||||
* string containing the name of a table.
|
* string containing the name of a table.
|
||||||
* While this also accepts a query result
|
* While this also accepts a query result
|
||||||
* resource identifier, this behavior is
|
* resource identifier, this behavior is
|
||||||
* deprecated.
|
* deprecated.
|
||||||
* @param int $mode a valid tableInfo mode
|
* @param int $mode a valid tableInfo mode
|
||||||
*
|
*
|
||||||
* @return array an associative array with the information requested.
|
* @return array|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::tableInfo()
|
* @see DB_common::tableInfo()
|
||||||
|
@ -926,7 +947,7 @@ class DB_pgsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = @pg_numfields($id);
|
$count = @pg_numfields($id);
|
||||||
$res = array();
|
$res = array();
|
||||||
|
|
||||||
if ($mode) {
|
if ($mode) {
|
||||||
$res['num_fields'] = $count;
|
$res['num_fields'] = $count;
|
||||||
|
@ -935,12 +956,12 @@ class DB_pgsql extends DB_common
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$res[$i] = array(
|
$res[$i] = array(
|
||||||
'table' => $got_string ? $case_func($result) : '',
|
'table' => $got_string ? $case_func($result) : '',
|
||||||
'name' => $case_func(@pg_fieldname($id, $i)),
|
'name' => $case_func(@pg_fieldname($id, $i)),
|
||||||
'type' => @pg_fieldtype($id, $i),
|
'type' => @pg_fieldtype($id, $i),
|
||||||
'len' => @pg_fieldsize($id, $i),
|
'len' => @pg_fieldsize($id, $i),
|
||||||
'flags' => $got_string
|
'flags' => $got_string
|
||||||
? $this->_pgFieldFlags($id, $i, $result)
|
? $this->_pgFieldFlags($id, $i, $result)
|
||||||
: '',
|
: '',
|
||||||
);
|
);
|
||||||
if ($mode & DB_TABLEINFO_ORDER) {
|
if ($mode & DB_TABLEINFO_ORDER) {
|
||||||
$res['order'][$res[$i]['name']] = $i;
|
$res['order'][$res[$i]['name']] = $i;
|
||||||
|
@ -958,7 +979,7 @@ class DB_pgsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ _pgFieldFlags()
|
// {{{ getSpecialQuery()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a column's flags
|
* Get a column's flags
|
||||||
|
@ -967,9 +988,10 @@ class DB_pgsql extends DB_common
|
||||||
* and "multiple_key". The default value is passed through
|
* and "multiple_key". The default value is passed through
|
||||||
* rawurlencode() in case there are spaces in it.
|
* rawurlencode() in case there are spaces in it.
|
||||||
*
|
*
|
||||||
* @param int $resource the PostgreSQL result identifier
|
* @param int $resource the PostgreSQL result identifier
|
||||||
* @param int $num_field the field number
|
* @param int $num_field the field number
|
||||||
*
|
*
|
||||||
|
* @param $table_name
|
||||||
* @return string the flags
|
* @return string the flags
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
|
@ -997,7 +1019,7 @@ class DB_pgsql extends DB_common
|
||||||
AND $tableWhere");
|
AND $tableWhere");
|
||||||
if (@pg_numrows($result) > 0) {
|
if (@pg_numrows($result) > 0) {
|
||||||
$row = @pg_fetch_row($result, 0);
|
$row = @pg_fetch_row($result, 0);
|
||||||
$flags = ($row[0] == 't') ? 'not_null ' : '';
|
$flags = ($row[0] == 't') ? 'not_null ' : '';
|
||||||
|
|
||||||
if ($row[1] == 't') {
|
if ($row[1] == 't') {
|
||||||
$result = @pg_exec($this->connection, "SELECT a.adsrc
|
$result = @pg_exec($this->connection, "SELECT a.adsrc
|
||||||
|
@ -1021,7 +1043,7 @@ class DB_pgsql extends DB_common
|
||||||
AND $tableWhere");
|
AND $tableWhere");
|
||||||
$count = @pg_numrows($result);
|
$count = @pg_numrows($result);
|
||||||
|
|
||||||
for ($i = 0; $i < $count ; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$row = @pg_fetch_row($result, $i);
|
$row = @pg_fetch_row($result, $i);
|
||||||
$keys = explode(' ', $row[2]);
|
$keys = explode(' ', $row[2]);
|
||||||
|
|
||||||
|
@ -1038,12 +1060,12 @@ class DB_pgsql extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ getSpecialQuery()
|
// {{{ _checkManip()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains the query string needed for listing a given type of objects
|
* Obtains the query string needed for listing a given type of objects
|
||||||
*
|
*
|
||||||
* @param string $type the kind of objects you want to retrieve
|
* @param string $type the kind of objects you want to retrieve
|
||||||
*
|
*
|
||||||
* @return string the SQL query string or null if the driver doesn't
|
* @return string the SQL query string or null if the driver doesn't
|
||||||
* support the object type requested
|
* support the object type requested
|
||||||
|
@ -1056,37 +1078,37 @@ class DB_pgsql extends DB_common
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'tables':
|
case 'tables':
|
||||||
return 'SELECT c.relname AS "Name"'
|
return 'SELECT c.relname AS "Name"'
|
||||||
. ' FROM pg_class c, pg_user u'
|
. ' FROM pg_class c, pg_user u'
|
||||||
. ' WHERE c.relowner = u.usesysid'
|
. ' WHERE c.relowner = u.usesysid'
|
||||||
. " AND c.relkind = 'r'"
|
. " AND c.relkind = 'r'"
|
||||||
. ' AND NOT EXISTS'
|
. ' AND NOT EXISTS'
|
||||||
. ' (SELECT 1 FROM pg_views'
|
. ' (SELECT 1 FROM pg_views'
|
||||||
. ' WHERE viewname = c.relname)'
|
. ' WHERE viewname = c.relname)'
|
||||||
. " AND c.relname !~ '^(pg_|sql_)'"
|
. " AND c.relname !~ '^(pg_|sql_)'"
|
||||||
. ' UNION'
|
. ' UNION'
|
||||||
. ' SELECT c.relname AS "Name"'
|
. ' SELECT c.relname AS "Name"'
|
||||||
. ' FROM pg_class c'
|
. ' FROM pg_class c'
|
||||||
. " WHERE c.relkind = 'r'"
|
. " WHERE c.relkind = 'r'"
|
||||||
. ' AND NOT EXISTS'
|
. ' AND NOT EXISTS'
|
||||||
. ' (SELECT 1 FROM pg_views'
|
. ' (SELECT 1 FROM pg_views'
|
||||||
. ' WHERE viewname = c.relname)'
|
. ' WHERE viewname = c.relname)'
|
||||||
. ' AND NOT EXISTS'
|
. ' AND NOT EXISTS'
|
||||||
. ' (SELECT 1 FROM pg_user'
|
. ' (SELECT 1 FROM pg_user'
|
||||||
. ' WHERE usesysid = c.relowner)'
|
. ' WHERE usesysid = c.relowner)'
|
||||||
. " AND c.relname !~ '^pg_'";
|
. " AND c.relname !~ '^pg_'";
|
||||||
case 'schema.tables':
|
case 'schema.tables':
|
||||||
return "SELECT schemaname || '.' || tablename"
|
return "SELECT schemaname || '.' || tablename"
|
||||||
. ' AS "Name"'
|
. ' AS "Name"'
|
||||||
. ' FROM pg_catalog.pg_tables'
|
. ' FROM pg_catalog.pg_tables'
|
||||||
. ' WHERE schemaname NOT IN'
|
. ' WHERE schemaname NOT IN'
|
||||||
. " ('pg_catalog', 'information_schema', 'pg_toast')";
|
. " ('pg_catalog', 'information_schema', 'pg_toast')";
|
||||||
case 'schema.views':
|
case 'schema.views':
|
||||||
return "SELECT schemaname || '.' || viewname from pg_views WHERE schemaname"
|
return "SELECT schemaname || '.' || viewname from pg_views WHERE schemaname"
|
||||||
. " NOT IN ('information_schema', 'pg_catalog')";
|
. " NOT IN ('information_schema', 'pg_catalog')";
|
||||||
case 'views':
|
case 'views':
|
||||||
// Table cols: viewname | viewowner | definition
|
// Table cols: viewname | viewowner | definition
|
||||||
return 'SELECT viewname from pg_views WHERE schemaname'
|
return 'SELECT viewname from pg_views WHERE schemaname'
|
||||||
. " NOT IN ('information_schema', 'pg_catalog')";
|
. " NOT IN ('information_schema', 'pg_catalog')";
|
||||||
case 'users':
|
case 'users':
|
||||||
// cols: usename |usesysid|usecreatedb|usetrace|usesuper|usecatupd|passwd |valuntil
|
// cols: usename |usesysid|usecreatedb|usetrace|usesuper|usecatupd|passwd |valuntil
|
||||||
return 'SELECT usename FROM pg_user';
|
return 'SELECT usename FROM pg_user';
|
||||||
|
@ -1099,27 +1121,6 @@ class DB_pgsql extends DB_common
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ _checkManip()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the given query is a manipulation query. This also takes into
|
|
||||||
* account the _next_query_manip flag and sets the _last_query_manip flag
|
|
||||||
* (and resets _next_query_manip) according to the result.
|
|
||||||
*
|
|
||||||
* @param string The query to check.
|
|
||||||
*
|
|
||||||
* @return boolean true if the query is a manipulation query, false
|
|
||||||
* otherwise
|
|
||||||
*
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
public function _checkManip($query)
|
|
||||||
{
|
|
||||||
return (preg_match('/^\s*(SAVEPOINT|RELEASE)\s+/i', $query)
|
|
||||||
|| parent::_checkManip($query));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -28,7 +28,8 @@
|
||||||
/**
|
/**
|
||||||
* Obtain the DB_common class so it can be extended from
|
* Obtain the DB_common class so it can be extended from
|
||||||
*/
|
*/
|
||||||
require_once 'DB/common.php';
|
//require_once 'DB/common.php';
|
||||||
|
require_once 'common.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The methods PEAR DB uses to interact with PHP's sqlite extension
|
* The methods PEAR DB uses to interact with PHP's sqlite extension
|
||||||
|
@ -80,13 +81,13 @@ class DB_sqlite extends DB_common
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $features = array(
|
public $features = array(
|
||||||
'limit' => 'alter',
|
'limit' => 'alter',
|
||||||
'new_link' => false,
|
'new_link' => false,
|
||||||
'numrows' => true,
|
'numrows' => true,
|
||||||
'pconnect' => true,
|
'pconnect' => true,
|
||||||
'prepare' => false,
|
'prepare' => false,
|
||||||
'ssl' => false,
|
'ssl' => false,
|
||||||
'transactions' => false,
|
'transactions' => false,
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -98,8 +99,7 @@ class DB_sqlite extends DB_common
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $errorcode_map = array(
|
public $errorcode_map = array();
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The raw database connection created by PHP
|
* The raw database connection created by PHP
|
||||||
|
@ -122,22 +122,22 @@ class DB_sqlite extends DB_common
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $keywords = array(
|
public $keywords = array(
|
||||||
'BLOB' => '',
|
'BLOB' => '',
|
||||||
'BOOLEAN' => '',
|
'BOOLEAN' => '',
|
||||||
'CHARACTER' => '',
|
'CHARACTER' => '',
|
||||||
'CLOB' => '',
|
'CLOB' => '',
|
||||||
'FLOAT' => '',
|
'FLOAT' => '',
|
||||||
'INTEGER' => '',
|
'INTEGER' => '',
|
||||||
'KEY' => '',
|
'KEY' => '',
|
||||||
'NATIONAL' => '',
|
'NATIONAL' => '',
|
||||||
'NUMERIC' => '',
|
'NUMERIC' => '',
|
||||||
'NVARCHAR' => '',
|
'NVARCHAR' => '',
|
||||||
'PRIMARY' => '',
|
'PRIMARY' => '',
|
||||||
'TEXT' => '',
|
'TEXT' => '',
|
||||||
'TIMESTAMP' => '',
|
'TIMESTAMP' => '',
|
||||||
'UNIQUE' => '',
|
'UNIQUE' => '',
|
||||||
'VARCHAR' => '',
|
'VARCHAR' => '',
|
||||||
'VARYING' => '',
|
'VARYING' => '',
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -183,15 +183,15 @@ class DB_sqlite extends DB_common
|
||||||
* );
|
* );
|
||||||
*
|
*
|
||||||
* $db = DB::connect($dsn, $options);
|
* $db = DB::connect($dsn, $options);
|
||||||
* if (PEAR::isError($db)) {
|
* if ((new PEAR)->isError($db)) {
|
||||||
* die($db->getMessage());
|
* die($db->getMessage());
|
||||||
* }
|
* }
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @param array $dsn the data source name
|
* @param array $dsn the data source name
|
||||||
* @param bool $persistent should the connection be persistent?
|
* @param bool $persistent should the connection be persistent?
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function connect($dsn, $persistent = false)
|
public function connect($dsn, $persistent = false)
|
||||||
{
|
{
|
||||||
|
@ -255,10 +255,98 @@ class DB_sqlite extends DB_common
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ disconnect()
|
// {{{ disconnect()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produces a DB_Error object regarding the current problem
|
||||||
|
*
|
||||||
|
* @param int $errno if the error is being manually raised pass a
|
||||||
|
* DB_ERROR* constant here. If this isn't passed
|
||||||
|
* the error information gathered from the DBMS.
|
||||||
|
*
|
||||||
|
* @return object the DB_Error object
|
||||||
|
*
|
||||||
|
* @see DB_common::raiseError(),
|
||||||
|
* DB_sqlite::errorNative(), DB_sqlite::errorCode()
|
||||||
|
*/
|
||||||
|
public function sqliteRaiseError($errno = null)
|
||||||
|
{
|
||||||
|
$native = $this->errorNative();
|
||||||
|
if ($errno === null) {
|
||||||
|
$errno = $this->errorCode($native);
|
||||||
|
}
|
||||||
|
|
||||||
|
$errorcode = @sqlite_last_error($this->connection);
|
||||||
|
$userinfo = "$errorcode ** $this->last_query";
|
||||||
|
|
||||||
|
return $this->raiseError($errno, null, null, $userinfo, $native);
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ simpleQuery()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the DBMS' native error message produced by the last query
|
||||||
|
*
|
||||||
|
* {@internal This is used to retrieve more meaningfull error messages
|
||||||
|
* because sqlite_last_error() does not provide adequate info.}}
|
||||||
|
*
|
||||||
|
* @return string the DBMS' error message
|
||||||
|
*/
|
||||||
|
public function errorNative()
|
||||||
|
{
|
||||||
|
return $this->_lasterror;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ nextResult()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines PEAR::DB error code from the database's text error message
|
||||||
|
*
|
||||||
|
* @param string $errormsg the error message returned from the database
|
||||||
|
*
|
||||||
|
* @return integer the DB error number
|
||||||
|
*/
|
||||||
|
public function errorCode($errormsg)
|
||||||
|
{
|
||||||
|
static $error_regexps;
|
||||||
|
|
||||||
|
// PHP 5.2+ prepends the function name to $php_errormsg, so we need
|
||||||
|
// this hack to work around it, per bug #9599.
|
||||||
|
$errormsg = preg_replace('/^sqlite[a-z_]+\(\): /', '', $errormsg);
|
||||||
|
|
||||||
|
if (!isset($error_regexps)) {
|
||||||
|
$error_regexps = array(
|
||||||
|
'/^no such table:/' => DB_ERROR_NOSUCHTABLE,
|
||||||
|
'/^no such index:/' => DB_ERROR_NOT_FOUND,
|
||||||
|
'/^(table|index) .* already exists$/' => DB_ERROR_ALREADY_EXISTS,
|
||||||
|
'/PRIMARY KEY must be unique/i' => DB_ERROR_CONSTRAINT,
|
||||||
|
'/is not unique/' => DB_ERROR_CONSTRAINT,
|
||||||
|
'/columns .* are not unique/i' => DB_ERROR_CONSTRAINT,
|
||||||
|
'/uniqueness constraint failed/' => DB_ERROR_CONSTRAINT,
|
||||||
|
'/may not be NULL/' => DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||||
|
'/^no such column:/' => DB_ERROR_NOSUCHFIELD,
|
||||||
|
'/no column named/' => DB_ERROR_NOSUCHFIELD,
|
||||||
|
'/column not present in both tables/i' => DB_ERROR_NOSUCHFIELD,
|
||||||
|
'/^near ".*": syntax error$/' => DB_ERROR_SYNTAX,
|
||||||
|
'/[0-9]+ values for [0-9]+ columns/i' => DB_ERROR_VALUE_COUNT_ON_ROW,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
foreach ($error_regexps as $regexp => $code) {
|
||||||
|
if (preg_match($regexp, $errormsg)) {
|
||||||
|
return $code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Fall back to DB_ERROR if there was no mapping.
|
||||||
|
return DB_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ fetchInto()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disconnects from the database server
|
* Disconnects from the database server
|
||||||
*
|
*
|
||||||
* @return bool TRUE on success, FALSE on failure
|
* @return bool|void
|
||||||
*/
|
*/
|
||||||
public function disconnect()
|
public function disconnect()
|
||||||
{
|
{
|
||||||
|
@ -268,7 +356,7 @@ class DB_sqlite extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ simpleQuery()
|
// {{{ freeResult()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a query to the database server
|
* Sends a query to the database server
|
||||||
|
@ -313,12 +401,68 @@ class DB_sqlite extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ nextResult()
|
// {{{ numCols()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes a query string for various DBMS specific reasons
|
||||||
|
*
|
||||||
|
* This little hack lets you know how many rows were deleted
|
||||||
|
* when running a "DELETE FROM table" query. Only implemented
|
||||||
|
* if the DB_PORTABILITY_DELETE_COUNT portability option is on.
|
||||||
|
*
|
||||||
|
* @param string $query the query string to modify
|
||||||
|
*
|
||||||
|
* @return string the modified query string
|
||||||
|
*
|
||||||
|
* @access protected
|
||||||
|
* @see DB_common::setOption()
|
||||||
|
*/
|
||||||
|
public function modifyQuery($query)
|
||||||
|
{
|
||||||
|
if ($this->options['portability'] & DB_PORTABILITY_DELETE_COUNT) {
|
||||||
|
if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $query)) {
|
||||||
|
$query = preg_replace(
|
||||||
|
'/^\s*DELETE\s+FROM\s+(\S+)\s*$/',
|
||||||
|
'DELETE FROM \1 WHERE 1=1',
|
||||||
|
$query
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ numRows()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the number of rows in a result set
|
||||||
|
*
|
||||||
|
* This method is not meant to be called directly. Use
|
||||||
|
* DB_result::numRows() instead. It can't be declared "protected"
|
||||||
|
* because DB_result is a separate object.
|
||||||
|
*
|
||||||
|
* @param resource $result PHP's query result resource
|
||||||
|
*
|
||||||
|
* @return int|object
|
||||||
|
*
|
||||||
|
* @see DB_result::numRows()
|
||||||
|
*/
|
||||||
|
public function numRows($result)
|
||||||
|
{
|
||||||
|
$rows = @sqlite_num_rows($result);
|
||||||
|
if ($rows === null) {
|
||||||
|
return $this->sqliteRaiseError();
|
||||||
|
}
|
||||||
|
return $rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ affected()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the internal sqlite result pointer to the next available result
|
* Move the internal sqlite result pointer to the next available result
|
||||||
*
|
*
|
||||||
* @param resource $result the valid sqlite result resource
|
* @param resource $result the valid sqlite result resource
|
||||||
*
|
*
|
||||||
* @return bool true if a result is available otherwise return false
|
* @return bool true if a result is available otherwise return false
|
||||||
*/
|
*/
|
||||||
|
@ -328,7 +472,7 @@ class DB_sqlite extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ fetchInto()
|
// {{{ dropSequence()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Places a row from the result set into the given array
|
* Places a row from the result set into the given array
|
||||||
|
@ -340,10 +484,10 @@ class DB_sqlite extends DB_common
|
||||||
* DB_result::fetchInto() instead. It can't be declared "protected"
|
* DB_result::fetchInto() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result the query result resource
|
* @param resource $result the query result resource
|
||||||
* @param array $arr the referenced array to put the data in
|
* @param array $arr the referenced array to put the data in
|
||||||
* @param int $fetchmode how the resulting array should be indexed
|
* @param int $fetchmode how the resulting array should be indexed
|
||||||
* @param int $rownum the row number to fetch (0 = first row)
|
* @param int $rownum the row number to fetch (0 = first row)
|
||||||
*
|
*
|
||||||
* @return mixed DB_OK on success, NULL when the end of a result set is
|
* @return mixed DB_OK on success, NULL when the end of a result set is
|
||||||
* reached or on failure
|
* reached or on failure
|
||||||
|
@ -392,9 +536,6 @@ class DB_sqlite extends DB_common
|
||||||
return DB_OK;
|
return DB_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ freeResult()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the result set and frees the memory occupied by the result set
|
* Deletes the result set and frees the memory occupied by the result set
|
||||||
*
|
*
|
||||||
|
@ -402,7 +543,7 @@ class DB_sqlite extends DB_common
|
||||||
* DB_result::free() instead. It can't be declared "protected"
|
* DB_result::free() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return bool TRUE on success, FALSE if $result is invalid
|
* @return bool TRUE on success, FALSE if $result is invalid
|
||||||
*
|
*
|
||||||
|
@ -419,7 +560,7 @@ class DB_sqlite extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ numCols()
|
// {{{ nextId()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of columns in a result set
|
* Gets the number of columns in a result set
|
||||||
|
@ -428,9 +569,9 @@ class DB_sqlite extends DB_common
|
||||||
* DB_result::numCols() instead. It can't be declared "protected"
|
* DB_result::numCols() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return int the number of columns. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @see DB_result::numCols()
|
* @see DB_result::numCols()
|
||||||
*/
|
*/
|
||||||
|
@ -444,32 +585,7 @@ class DB_sqlite extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ numRows()
|
// {{{ getDbFileStats()
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the number of rows in a result set
|
|
||||||
*
|
|
||||||
* This method is not meant to be called directly. Use
|
|
||||||
* DB_result::numRows() instead. It can't be declared "protected"
|
|
||||||
* because DB_result is a separate object.
|
|
||||||
*
|
|
||||||
* @param resource $result PHP's query result resource
|
|
||||||
*
|
|
||||||
* @return int the number of rows. A DB_Error object on failure.
|
|
||||||
*
|
|
||||||
* @see DB_result::numRows()
|
|
||||||
*/
|
|
||||||
public function numRows($result)
|
|
||||||
{
|
|
||||||
$rows = @sqlite_num_rows($result);
|
|
||||||
if ($rows === null) {
|
|
||||||
return $this->sqliteRaiseError();
|
|
||||||
}
|
|
||||||
return $rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ affected()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the number of rows affected by a data maniuplation query
|
* Determines the number of rows affected by a data maniuplation query
|
||||||
|
@ -484,12 +600,12 @@ class DB_sqlite extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ dropSequence()
|
// {{{ escapeSimple()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a sequence
|
* Deletes a sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the sequence to be deleted
|
* @param string $seq_name name of the sequence to be deleted
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
|
@ -501,46 +617,17 @@ class DB_sqlite extends DB_common
|
||||||
return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name));
|
return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new sequence
|
|
||||||
*
|
|
||||||
* @param string $seq_name name of the new sequence
|
|
||||||
*
|
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
|
||||||
*
|
|
||||||
* @see DB_common::createSequence(), DB_common::getSequenceName(),
|
|
||||||
* DB_sqlite::nextID(), DB_sqlite::dropSequence()
|
|
||||||
*/
|
|
||||||
public function createSequence($seq_name)
|
|
||||||
{
|
|
||||||
$seqname = $this->getSequenceName($seq_name);
|
|
||||||
$query = 'CREATE TABLE ' . $seqname .
|
|
||||||
' (id INTEGER UNSIGNED PRIMARY KEY) ';
|
|
||||||
$result = $this->query($query);
|
|
||||||
if (DB::isError($result)) {
|
|
||||||
return($result);
|
|
||||||
}
|
|
||||||
$query = "CREATE TRIGGER ${seqname}_cleanup AFTER INSERT ON $seqname
|
|
||||||
BEGIN
|
|
||||||
DELETE FROM $seqname WHERE id<LAST_INSERT_ROWID();
|
|
||||||
END ";
|
|
||||||
$result = $this->query($query);
|
|
||||||
if (DB::isError($result)) {
|
|
||||||
return($result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ nextId()
|
// {{{ modifyLimitQuery()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the next free id in a sequence
|
* Returns the next free id in a sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the sequence
|
* @param string $seq_name name of the sequence
|
||||||
* @param boolean $ondemand when true, the seqence is automatically
|
* @param boolean $ondemand when true, the seqence is automatically
|
||||||
* created if it does not exist
|
* created if it does not exist
|
||||||
*
|
*
|
||||||
* @return int the next id number in the sequence.
|
* @return int|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
||||||
|
@ -561,7 +648,7 @@ class DB_sqlite extends DB_common
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
} elseif ($ondemand && DB::isError($result) &&
|
} elseif ($ondemand && DB::isError($result) &&
|
||||||
$result->getCode() == DB_ERROR_NOSUCHTABLE) {
|
$result->getCode() == DB_ERROR_NOSUCHTABLE) {
|
||||||
$result = $this->createSequence($seq_name);
|
$result = $this->createSequence($seq_name);
|
||||||
if (DB::isError($result)) {
|
if (DB::isError($result)) {
|
||||||
return $this->raiseError($result);
|
return $this->raiseError($result);
|
||||||
|
@ -575,7 +662,39 @@ class DB_sqlite extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ getDbFileStats()
|
// {{{ modifyQuery()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new sequence
|
||||||
|
*
|
||||||
|
* @param string $seq_name name of the new sequence
|
||||||
|
*
|
||||||
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
|
*
|
||||||
|
* @see DB_common::createSequence(), DB_common::getSequenceName(),
|
||||||
|
* DB_sqlite::nextID(), DB_sqlite::dropSequence()
|
||||||
|
*/
|
||||||
|
public function createSequence($seq_name)
|
||||||
|
{
|
||||||
|
$seqname = $this->getSequenceName($seq_name);
|
||||||
|
$query = 'CREATE TABLE ' . $seqname .
|
||||||
|
' (id INTEGER UNSIGNED PRIMARY KEY) ';
|
||||||
|
$result = $this->query($query);
|
||||||
|
if (DB::isError($result)) {
|
||||||
|
return ($result);
|
||||||
|
}
|
||||||
|
$query = "CREATE TRIGGER ${seqname}_cleanup AFTER INSERT ON $seqname
|
||||||
|
BEGIN
|
||||||
|
DELETE FROM $seqname WHERE id<LAST_INSERT_ROWID();
|
||||||
|
END ";
|
||||||
|
$result = $this->query($query);
|
||||||
|
//if (DB::isError($result)) {
|
||||||
|
return ($result);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ sqliteRaiseError()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the file stats for the current database
|
* Get the file stats for the current database
|
||||||
|
@ -584,7 +703,7 @@ class DB_sqlite extends DB_common
|
||||||
* atime, mtime, ctime, blksize, blocks or a numeric key between
|
* atime, mtime, ctime, blksize, blocks or a numeric key between
|
||||||
* 0 and 12.
|
* 0 and 12.
|
||||||
*
|
*
|
||||||
* @param string $arg the array key for stats()
|
* @param string $arg the array key for stats()
|
||||||
*
|
*
|
||||||
* @return mixed an array on an unspecified key, integer on a passed
|
* @return mixed an array on an unspecified key, integer on a passed
|
||||||
* arg and false at a stats error
|
* arg and false at a stats error
|
||||||
|
@ -600,17 +719,17 @@ class DB_sqlite extends DB_common
|
||||||
if (((int)$arg <= 12) & ((int)$arg >= 0)) {
|
if (((int)$arg <= 12) & ((int)$arg >= 0)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return $stats[$arg ];
|
return $stats[$arg];
|
||||||
}
|
}
|
||||||
if (array_key_exists(trim($arg), $stats)) {
|
if (array_key_exists(trim($arg), $stats)) {
|
||||||
return $stats[$arg ];
|
return $stats[$arg];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $stats;
|
return $stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ escapeSimple()
|
// {{{ errorNative()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Escapes a string according to the current DBMS's standards
|
* Escapes a string according to the current DBMS's standards
|
||||||
|
@ -620,7 +739,7 @@ class DB_sqlite extends DB_common
|
||||||
* containing binary data. See the
|
* containing binary data. See the
|
||||||
* {@link http://php.net/sqlite_escape_string PHP manual} for more info.
|
* {@link http://php.net/sqlite_escape_string PHP manual} for more info.
|
||||||
*
|
*
|
||||||
* @param string $str the string to be escaped
|
* @param string $str the string to be escaped
|
||||||
*
|
*
|
||||||
* @return string the escaped string
|
* @return string the escaped string
|
||||||
*
|
*
|
||||||
|
@ -633,15 +752,15 @@ class DB_sqlite extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ modifyLimitQuery()
|
// {{{ errorCode()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds LIMIT clauses to a query string according to current DBMS standards
|
* Adds LIMIT clauses to a query string according to current DBMS standards
|
||||||
*
|
*
|
||||||
* @param string $query the query to modify
|
* @param string $query the query to modify
|
||||||
* @param int $from the row to start to fetching (0 = the first row)
|
* @param int $from the row to start to fetching (0 = the first row)
|
||||||
* @param int $count the numbers of rows to fetch
|
* @param int $count the numbers of rows to fetch
|
||||||
* @param mixed $params array, string or numeric data to be used in
|
* @param mixed $params array, string or numeric data to be used in
|
||||||
* execution of the statement. Quantity of items
|
* execution of the statement. Quantity of items
|
||||||
* passed must match quantity of placeholders in
|
* passed must match quantity of placeholders in
|
||||||
* query: meaning 1 placeholder for non-array
|
* query: meaning 1 placeholder for non-array
|
||||||
|
@ -656,135 +775,16 @@ class DB_sqlite extends DB_common
|
||||||
return "$query LIMIT $count OFFSET $from";
|
return "$query LIMIT $count OFFSET $from";
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ modifyQuery()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Changes a query string for various DBMS specific reasons
|
|
||||||
*
|
|
||||||
* This little hack lets you know how many rows were deleted
|
|
||||||
* when running a "DELETE FROM table" query. Only implemented
|
|
||||||
* if the DB_PORTABILITY_DELETE_COUNT portability option is on.
|
|
||||||
*
|
|
||||||
* @param string $query the query string to modify
|
|
||||||
*
|
|
||||||
* @return string the modified query string
|
|
||||||
*
|
|
||||||
* @access protected
|
|
||||||
* @see DB_common::setOption()
|
|
||||||
*/
|
|
||||||
public function modifyQuery($query)
|
|
||||||
{
|
|
||||||
if ($this->options['portability'] & DB_PORTABILITY_DELETE_COUNT) {
|
|
||||||
if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $query)) {
|
|
||||||
$query = preg_replace(
|
|
||||||
'/^\s*DELETE\s+FROM\s+(\S+)\s*$/',
|
|
||||||
'DELETE FROM \1 WHERE 1=1',
|
|
||||||
$query
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $query;
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ sqliteRaiseError()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Produces a DB_Error object regarding the current problem
|
|
||||||
*
|
|
||||||
* @param int $errno if the error is being manually raised pass a
|
|
||||||
* DB_ERROR* constant here. If this isn't passed
|
|
||||||
* the error information gathered from the DBMS.
|
|
||||||
*
|
|
||||||
* @return object the DB_Error object
|
|
||||||
*
|
|
||||||
* @see DB_common::raiseError(),
|
|
||||||
* DB_sqlite::errorNative(), DB_sqlite::errorCode()
|
|
||||||
*/
|
|
||||||
public function sqliteRaiseError($errno = null)
|
|
||||||
{
|
|
||||||
$native = $this->errorNative();
|
|
||||||
if ($errno === null) {
|
|
||||||
$errno = $this->errorCode($native);
|
|
||||||
}
|
|
||||||
|
|
||||||
$errorcode = @sqlite_last_error($this->connection);
|
|
||||||
$userinfo = "$errorcode ** $this->last_query";
|
|
||||||
|
|
||||||
return $this->raiseError($errno, null, null, $userinfo, $native);
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ errorNative()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the DBMS' native error message produced by the last query
|
|
||||||
*
|
|
||||||
* {@internal This is used to retrieve more meaningfull error messages
|
|
||||||
* because sqlite_last_error() does not provide adequate info.}}
|
|
||||||
*
|
|
||||||
* @return string the DBMS' error message
|
|
||||||
*/
|
|
||||||
public function errorNative()
|
|
||||||
{
|
|
||||||
return $this->_lasterror;
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ errorCode()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines PEAR::DB error code from the database's text error message
|
|
||||||
*
|
|
||||||
* @param string $errormsg the error message returned from the database
|
|
||||||
*
|
|
||||||
* @return integer the DB error number
|
|
||||||
*/
|
|
||||||
public function errorCode($errormsg)
|
|
||||||
{
|
|
||||||
static $error_regexps;
|
|
||||||
|
|
||||||
// PHP 5.2+ prepends the function name to $php_errormsg, so we need
|
|
||||||
// this hack to work around it, per bug #9599.
|
|
||||||
$errormsg = preg_replace('/^sqlite[a-z_]+\(\): /', '', $errormsg);
|
|
||||||
|
|
||||||
if (!isset($error_regexps)) {
|
|
||||||
$error_regexps = array(
|
|
||||||
'/^no such table:/' => DB_ERROR_NOSUCHTABLE,
|
|
||||||
'/^no such index:/' => DB_ERROR_NOT_FOUND,
|
|
||||||
'/^(table|index) .* already exists$/' => DB_ERROR_ALREADY_EXISTS,
|
|
||||||
'/PRIMARY KEY must be unique/i' => DB_ERROR_CONSTRAINT,
|
|
||||||
'/is not unique/' => DB_ERROR_CONSTRAINT,
|
|
||||||
'/columns .* are not unique/i' => DB_ERROR_CONSTRAINT,
|
|
||||||
'/uniqueness constraint failed/' => DB_ERROR_CONSTRAINT,
|
|
||||||
'/may not be NULL/' => DB_ERROR_CONSTRAINT_NOT_NULL,
|
|
||||||
'/^no such column:/' => DB_ERROR_NOSUCHFIELD,
|
|
||||||
'/no column named/' => DB_ERROR_NOSUCHFIELD,
|
|
||||||
'/column not present in both tables/i' => DB_ERROR_NOSUCHFIELD,
|
|
||||||
'/^near ".*": syntax error$/' => DB_ERROR_SYNTAX,
|
|
||||||
'/[0-9]+ values for [0-9]+ columns/i' => DB_ERROR_VALUE_COUNT_ON_ROW,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
foreach ($error_regexps as $regexp => $code) {
|
|
||||||
if (preg_match($regexp, $errormsg)) {
|
|
||||||
return $code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Fall back to DB_ERROR if there was no mapping.
|
|
||||||
return DB_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ tableInfo()
|
// {{{ tableInfo()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns information about a table
|
* Returns information about a table
|
||||||
*
|
*
|
||||||
* @param string $result a string containing the name of a table
|
* @param string $result a string containing the name of a table
|
||||||
* @param int $mode a valid tableInfo mode
|
* @param int $mode a valid tableInfo mode
|
||||||
*
|
*
|
||||||
* @return array an associative array with the information requested.
|
* @return array|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::tableInfo()
|
* @see DB_common::tableInfo()
|
||||||
|
@ -811,7 +811,7 @@ class DB_sqlite extends DB_common
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
'This DBMS can not obtain tableInfo' .
|
'This DBMS can not obtain tableInfo' .
|
||||||
' from result sets'
|
' from result sets'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -822,7 +822,7 @@ class DB_sqlite extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = count($id);
|
$count = count($id);
|
||||||
$res = array();
|
$res = array();
|
||||||
|
|
||||||
if ($mode) {
|
if ($mode) {
|
||||||
$res['num_fields'] = $count;
|
$res['num_fields'] = $count;
|
||||||
|
@ -832,10 +832,10 @@ class DB_sqlite extends DB_common
|
||||||
if (strpos($id[$i]['type'], '(') !== false) {
|
if (strpos($id[$i]['type'], '(') !== false) {
|
||||||
$bits = explode('(', $id[$i]['type']);
|
$bits = explode('(', $id[$i]['type']);
|
||||||
$type = $bits[0];
|
$type = $bits[0];
|
||||||
$len = rtrim($bits[1], ')');
|
$len = rtrim($bits[1], ')');
|
||||||
} else {
|
} else {
|
||||||
$type = $id[$i]['type'];
|
$type = $id[$i]['type'];
|
||||||
$len = 0;
|
$len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$flags = '';
|
$flags = '';
|
||||||
|
@ -855,9 +855,9 @@ class DB_sqlite extends DB_common
|
||||||
|
|
||||||
$res[$i] = array(
|
$res[$i] = array(
|
||||||
'table' => $case_func($result),
|
'table' => $case_func($result),
|
||||||
'name' => $case_func($id[$i]['name']),
|
'name' => $case_func($id[$i]['name']),
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'len' => $len,
|
'len' => $len,
|
||||||
'flags' => $flags,
|
'flags' => $flags,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -878,8 +878,8 @@ class DB_sqlite extends DB_common
|
||||||
/**
|
/**
|
||||||
* Obtains the query string needed for listing a given type of objects
|
* Obtains the query string needed for listing a given type of objects
|
||||||
*
|
*
|
||||||
* @param string $type the kind of objects you want to retrieve
|
* @param string $type the kind of objects you want to retrieve
|
||||||
* @param array $args SQLITE DRIVER ONLY: a private array of arguments
|
* @param array $args SQLITE DRIVER ONLY: a private array of arguments
|
||||||
* used by the getSpecialQuery(). Do not use
|
* used by the getSpecialQuery(). Do not use
|
||||||
* this directly.
|
* this directly.
|
||||||
*
|
*
|
||||||
|
@ -906,13 +906,13 @@ class DB_sqlite extends DB_common
|
||||||
return 'SELECT * FROM sqlite_master;';
|
return 'SELECT * FROM sqlite_master;';
|
||||||
case 'tables':
|
case 'tables':
|
||||||
return "SELECT name FROM sqlite_master WHERE type='table' "
|
return "SELECT name FROM sqlite_master WHERE type='table' "
|
||||||
. 'UNION ALL SELECT name FROM sqlite_temp_master '
|
. 'UNION ALL SELECT name FROM sqlite_temp_master '
|
||||||
. "WHERE type='table' ORDER BY name;";
|
. "WHERE type='table' ORDER BY name;";
|
||||||
case 'schema':
|
case 'schema':
|
||||||
return 'SELECT sql FROM (SELECT * FROM sqlite_master '
|
return 'SELECT sql FROM (SELECT * FROM sqlite_master '
|
||||||
. 'UNION ALL SELECT * FROM sqlite_temp_master) '
|
. 'UNION ALL SELECT * FROM sqlite_temp_master) '
|
||||||
. "WHERE type!='meta' "
|
. "WHERE type!='meta' "
|
||||||
. 'ORDER BY tbl_name, type DESC, name;';
|
. 'ORDER BY tbl_name, type DESC, name;';
|
||||||
case 'schemax':
|
case 'schemax':
|
||||||
case 'schema_x':
|
case 'schema_x':
|
||||||
/*
|
/*
|
||||||
|
@ -921,10 +921,10 @@ class DB_sqlite extends DB_common
|
||||||
* array('table' => 'table3')));
|
* array('table' => 'table3')));
|
||||||
*/
|
*/
|
||||||
return 'SELECT sql FROM (SELECT * FROM sqlite_master '
|
return 'SELECT sql FROM (SELECT * FROM sqlite_master '
|
||||||
. 'UNION ALL SELECT * FROM sqlite_temp_master) '
|
. 'UNION ALL SELECT * FROM sqlite_temp_master) '
|
||||||
. "WHERE tbl_name LIKE '{$args['table']}' "
|
. "WHERE tbl_name LIKE '{$args['table']}' "
|
||||||
. "AND type!='meta' "
|
. "AND type!='meta' "
|
||||||
. 'ORDER BY type DESC, name;';
|
. 'ORDER BY type DESC, name;';
|
||||||
case 'alter':
|
case 'alter':
|
||||||
/*
|
/*
|
||||||
* SQLite does not support ALTER TABLE; this is a helper query
|
* SQLite does not support ALTER TABLE; this is a helper query
|
||||||
|
|
|
@ -46,33 +46,33 @@ class DB_storage extends PEAR
|
||||||
// {{{ properties
|
// {{{ properties
|
||||||
|
|
||||||
/** the name of the table (or view, if the backend database supports
|
/** the name of the table (or view, if the backend database supports
|
||||||
updates in views) we hold data from */
|
* updates in views) we hold data from */
|
||||||
public $_table = null;
|
public $_table = null;
|
||||||
|
|
||||||
/** which column(s) in the table contains primary keys, can be a
|
/** which column(s) in the table contains primary keys, can be a
|
||||||
string for single-column primary keys, or an array of strings
|
* string for single-column primary keys, or an array of strings
|
||||||
for multiple-column primary keys */
|
* for multiple-column primary keys */
|
||||||
public $_keycolumn = null;
|
public $_keycolumn = null;
|
||||||
|
|
||||||
/** DB connection handle used for all transactions */
|
/** DB connection handle used for all transactions */
|
||||||
public $_dbh = null;
|
public $_dbh = null;
|
||||||
|
|
||||||
/** an assoc with the names of database fields stored as properties
|
/** an assoc with the names of database fields stored as properties
|
||||||
in this object */
|
* in this object */
|
||||||
public $_properties = array();
|
public $_properties = array();
|
||||||
|
|
||||||
/** an assoc with the names of the properties in this object that
|
/** an assoc with the names of the properties in this object that
|
||||||
have been changed since they were fetched from the database */
|
* have been changed since they were fetched from the database */
|
||||||
public $_changes = array();
|
public $_changes = array();
|
||||||
|
|
||||||
/** flag that decides if data in this object can be changed.
|
/** flag that decides if data in this object can be changed.
|
||||||
objects that don't have their table's key column in their
|
* objects that don't have their table's key column in their
|
||||||
property lists will be flagged as read-only. */
|
* property lists will be flagged as read-only. */
|
||||||
public $_readonly = false;
|
public $_readonly = false;
|
||||||
|
|
||||||
/** function or method that implements a validator for fields that
|
/** function or method that implements a validator for fields that
|
||||||
are set, this validator function returns true if the field is
|
* are set, this validator function returns true if the field is
|
||||||
valid, false if not */
|
* valid, false if not */
|
||||||
public $_validator = null;
|
public $_validator = null;
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -107,6 +107,81 @@ class DB_storage extends PEAR
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ _makeWhere()
|
// {{{ _makeWhere()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new (empty) row in the configured table for this
|
||||||
|
* object.
|
||||||
|
* @param $newpk
|
||||||
|
* @return |null
|
||||||
|
*/
|
||||||
|
public function insert($newpk)
|
||||||
|
{
|
||||||
|
if (is_array($this->_keycolumn)) {
|
||||||
|
$primarykey = $this->_keycolumn;
|
||||||
|
} else {
|
||||||
|
$primarykey = array($this->_keycolumn);
|
||||||
|
}
|
||||||
|
settype($newpk, "array");
|
||||||
|
for ($i = 0; $i < sizeof($primarykey); $i++) {
|
||||||
|
$pkvals[] = $this->_dbh->quote($newpk[$i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sth = $this->_dbh->query("INSERT INTO $this->_table (" .
|
||||||
|
implode(",", $primarykey) . ") VALUES(" .
|
||||||
|
implode(",", $pkvals) . ")");
|
||||||
|
if (DB::isError($sth)) {
|
||||||
|
return $sth;
|
||||||
|
}
|
||||||
|
if (sizeof($newpk) == 1) {
|
||||||
|
$newpk = $newpk[0];
|
||||||
|
}
|
||||||
|
$this->setup($newpk);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ setup()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method used to initialize a DB_storage object from the
|
||||||
|
* configured table.
|
||||||
|
*
|
||||||
|
* @param $keyval mixed the key[s] of the row to fetch (string or array)
|
||||||
|
*
|
||||||
|
* @return int|object
|
||||||
|
*/
|
||||||
|
public function setup($keyval)
|
||||||
|
{
|
||||||
|
$whereclause = $this->_makeWhere($keyval);
|
||||||
|
$query = 'SELECT * FROM ' . $this->_table . ' WHERE ' . $whereclause;
|
||||||
|
$sth = $this->_dbh->query($query);
|
||||||
|
if (DB::isError($sth)) {
|
||||||
|
return $sth;
|
||||||
|
}
|
||||||
|
$row = $sth->fetchRow(DB_FETCHMODE_ASSOC);
|
||||||
|
if (DB::isError($row)) {
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
if (!$row) {
|
||||||
|
return $this->raiseError(
|
||||||
|
null,
|
||||||
|
DB_ERROR_NOT_FOUND,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
$query,
|
||||||
|
null,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
foreach ($row as $key => $value) {
|
||||||
|
$this->_properties[$key] = true;
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
return DB_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ insert()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility method to build a "WHERE" clause to locate ourselves in
|
* Utility method to build a "WHERE" clause to locate ourselves in
|
||||||
* the table.
|
* the table.
|
||||||
|
@ -114,6 +189,8 @@ class DB_storage extends PEAR
|
||||||
* XXX future improvement: use rowids?
|
* XXX future improvement: use rowids?
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
|
* @param null $keyval
|
||||||
|
* @return mixed|string|null
|
||||||
*/
|
*/
|
||||||
public function _makeWhere($keyval = null)
|
public function _makeWhere($keyval = null)
|
||||||
{
|
{
|
||||||
|
@ -153,78 +230,6 @@ class DB_storage extends PEAR
|
||||||
return $whereclause;
|
return $whereclause;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ setup()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method used to initialize a DB_storage object from the
|
|
||||||
* configured table.
|
|
||||||
*
|
|
||||||
* @param $keyval mixed the key[s] of the row to fetch (string or array)
|
|
||||||
*
|
|
||||||
* @return int DB_OK on success, a DB error if not
|
|
||||||
*/
|
|
||||||
public function setup($keyval)
|
|
||||||
{
|
|
||||||
$whereclause = $this->_makeWhere($keyval);
|
|
||||||
$query = 'SELECT * FROM ' . $this->_table . ' WHERE ' . $whereclause;
|
|
||||||
$sth = $this->_dbh->query($query);
|
|
||||||
if (DB::isError($sth)) {
|
|
||||||
return $sth;
|
|
||||||
}
|
|
||||||
$row = $sth->fetchRow(DB_FETCHMODE_ASSOC);
|
|
||||||
if (DB::isError($row)) {
|
|
||||||
return $row;
|
|
||||||
}
|
|
||||||
if (!$row) {
|
|
||||||
return $this->raiseError(
|
|
||||||
null,
|
|
||||||
DB_ERROR_NOT_FOUND,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
$query,
|
|
||||||
null,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
foreach ($row as $key => $value) {
|
|
||||||
$this->_properties[$key] = true;
|
|
||||||
$this->$key = $value;
|
|
||||||
}
|
|
||||||
return DB_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ insert()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new (empty) row in the configured table for this
|
|
||||||
* object.
|
|
||||||
*/
|
|
||||||
public function insert($newpk)
|
|
||||||
{
|
|
||||||
if (is_array($this->_keycolumn)) {
|
|
||||||
$primarykey = $this->_keycolumn;
|
|
||||||
} else {
|
|
||||||
$primarykey = array($this->_keycolumn);
|
|
||||||
}
|
|
||||||
settype($newpk, "array");
|
|
||||||
for ($i = 0; $i < sizeof($primarykey); $i++) {
|
|
||||||
$pkvals[] = $this->_dbh->quote($newpk[$i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$sth = $this->_dbh->query("INSERT INTO $this->_table (" .
|
|
||||||
implode(",", $primarykey) . ") VALUES(" .
|
|
||||||
implode(",", $pkvals) . ")");
|
|
||||||
if (DB::isError($sth)) {
|
|
||||||
return $sth;
|
|
||||||
}
|
|
||||||
if (sizeof($newpk) == 1) {
|
|
||||||
$newpk = $newpk[0];
|
|
||||||
}
|
|
||||||
$this->setup($newpk);
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ toString()
|
// {{{ toString()
|
||||||
|
|
||||||
|
@ -293,6 +298,7 @@ class DB_storage extends PEAR
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static method used to create new DB storage objects.
|
* Static method used to create new DB storage objects.
|
||||||
|
* @param $table
|
||||||
* @param $data assoc. array where the keys are the names
|
* @param $data assoc. array where the keys are the names
|
||||||
* of properties/columns
|
* of properties/columns
|
||||||
* @return object a new instance of DB_storage or a subclass of it
|
* @return object a new instance of DB_storage or a subclass of it
|
||||||
|
@ -365,6 +371,9 @@ class DB_storage extends PEAR
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modify an attriute value.
|
* Modify an attriute value.
|
||||||
|
* @param $property
|
||||||
|
* @param $newvalue
|
||||||
|
* @return bool|object
|
||||||
*/
|
*/
|
||||||
public function set($property, $newvalue)
|
public function set($property, $newvalue)
|
||||||
{
|
{
|
||||||
|
@ -469,7 +478,7 @@ class DB_storage extends PEAR
|
||||||
/**
|
/**
|
||||||
* Stores changes to this object in the database.
|
* Stores changes to this object in the database.
|
||||||
*
|
*
|
||||||
* @return DB_OK or a DB error
|
* @return DB_OK|int
|
||||||
*/
|
*/
|
||||||
public function store()
|
public function store()
|
||||||
{
|
{
|
||||||
|
@ -514,7 +523,7 @@ class DB_storage extends PEAR
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$query = 'DELETE FROM ' . $this->_table .' WHERE '.
|
$query = 'DELETE FROM ' . $this->_table . ' WHERE ' .
|
||||||
$this->_makeWhere();
|
$this->_makeWhere();
|
||||||
$res = $this->_dbh->query($query);
|
$res = $this->_dbh->query($query);
|
||||||
if (DB::isError($res)) {
|
if (DB::isError($res)) {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* @category Database
|
* @category Database
|
||||||
* @package DB
|
* @package DB
|
||||||
* @author Sterling Hughes <sterling@php.net>
|
* @author Sterling Hughes <sterling@php.net>
|
||||||
* @author Antônio Carlos Venâncio Júnior <floripa@php.net>
|
* @author Ant<EFBFBD>nio Carlos Ven<EFBFBD>ncio J<EFBFBD>nior <floripa@php.net>
|
||||||
* @author Daniel Convissor <danielc@php.net>
|
* @author Daniel Convissor <danielc@php.net>
|
||||||
* @copyright 1997-2007 The PHP Group
|
* @copyright 1997-2007 The PHP Group
|
||||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||||
|
@ -28,7 +28,8 @@
|
||||||
/**
|
/**
|
||||||
* Obtain the DB_common class so it can be extended from
|
* Obtain the DB_common class so it can be extended from
|
||||||
*/
|
*/
|
||||||
require_once 'DB/common.php';
|
//require_once 'DB/common.php';
|
||||||
|
require_once 'common.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The methods PEAR DB uses to interact with PHP's sybase extension
|
* The methods PEAR DB uses to interact with PHP's sybase extension
|
||||||
|
@ -42,7 +43,7 @@ require_once 'DB/common.php';
|
||||||
* @category Database
|
* @category Database
|
||||||
* @package DB
|
* @package DB
|
||||||
* @author Sterling Hughes <sterling@php.net>
|
* @author Sterling Hughes <sterling@php.net>
|
||||||
* @author Antônio Carlos Venâncio Júnior <floripa@php.net>
|
* @author Ant<EFBFBD>nio Carlos Ven<EFBFBD>ncio J<EFBFBD>nior <floripa@php.net>
|
||||||
* @author Daniel Convissor <danielc@php.net>
|
* @author Daniel Convissor <danielc@php.net>
|
||||||
* @copyright 1997-2007 The PHP Group
|
* @copyright 1997-2007 The PHP Group
|
||||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||||
|
@ -79,21 +80,20 @@ class DB_sybase extends DB_common
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $features = array(
|
public $features = array(
|
||||||
'limit' => 'emulate',
|
'limit' => 'emulate',
|
||||||
'new_link' => false,
|
'new_link' => false,
|
||||||
'numrows' => true,
|
'numrows' => true,
|
||||||
'pconnect' => true,
|
'pconnect' => true,
|
||||||
'prepare' => false,
|
'prepare' => false,
|
||||||
'ssl' => false,
|
'ssl' => false,
|
||||||
'transactions' => true,
|
'transactions' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mapping of native error codes to DB error codes
|
* A mapping of native error codes to DB error codes
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $errorcode_map = array(
|
public $errorcode_map = array();
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The raw database connection created by PHP
|
* The raw database connection created by PHP
|
||||||
|
@ -164,10 +164,10 @@ class DB_sybase extends DB_common
|
||||||
* + charset The character set to use on this connection.
|
* + charset The character set to use on this connection.
|
||||||
* Available since PEAR DB 1.7.0.
|
* Available since PEAR DB 1.7.0.
|
||||||
*
|
*
|
||||||
* @param array $dsn the data source name
|
* @param array $dsn the data source name
|
||||||
* @param bool $persistent should the connection be persistent?
|
* @param bool $persistent should the connection be persistent?
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function connect($dsn, $persistent = false)
|
public function connect($dsn, $persistent = false)
|
||||||
{
|
{
|
||||||
|
@ -291,6 +291,105 @@ class DB_sybase extends DB_common
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ nextResult()
|
// {{{ nextResult()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produces a DB_Error object regarding the current problem
|
||||||
|
*
|
||||||
|
* @param int $errno if the error is being manually raised pass a
|
||||||
|
* DB_ERROR* constant here. If this isn't passed
|
||||||
|
* the error information gathered from the DBMS.
|
||||||
|
*
|
||||||
|
* @return object the DB_Error object
|
||||||
|
*
|
||||||
|
* @see DB_common::raiseError(),
|
||||||
|
* DB_sybase::errorNative(), DB_sybase::errorCode()
|
||||||
|
*/
|
||||||
|
public function sybaseRaiseError($errno = null)
|
||||||
|
{
|
||||||
|
$native = $this->errorNative();
|
||||||
|
if ($errno === null) {
|
||||||
|
$errno = $this->errorCode($native);
|
||||||
|
}
|
||||||
|
return $this->raiseError($errno, null, null, null, $native);
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ fetchInto()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the DBMS' native error message produced by the last query
|
||||||
|
*
|
||||||
|
* @return string the DBMS' error message
|
||||||
|
*/
|
||||||
|
public function errorNative()
|
||||||
|
{
|
||||||
|
return @sybase_get_last_message();
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ freeResult()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines PEAR::DB error code from the database's text error message.
|
||||||
|
*
|
||||||
|
* @param string $errormsg error message returned from the database
|
||||||
|
* @return integer an error number from a DB error constant
|
||||||
|
*/
|
||||||
|
public function errorCode($errormsg)
|
||||||
|
{
|
||||||
|
static $error_regexps;
|
||||||
|
|
||||||
|
// PHP 5.2+ prepends the function name to $php_errormsg, so we need
|
||||||
|
// this hack to work around it, per bug #9599.
|
||||||
|
$errormsg = preg_replace('/^sybase[a-z_]+\(\): /', '', $errormsg);
|
||||||
|
|
||||||
|
if (!isset($error_regexps)) {
|
||||||
|
$error_regexps = array(
|
||||||
|
'/Incorrect syntax near/'
|
||||||
|
=> DB_ERROR_SYNTAX,
|
||||||
|
'/^Unclosed quote before the character string [\"\'].*[\"\']\./'
|
||||||
|
=> DB_ERROR_SYNTAX,
|
||||||
|
'/Implicit conversion (from datatype|of NUMERIC value)/i'
|
||||||
|
=> DB_ERROR_INVALID_NUMBER,
|
||||||
|
'/Cannot drop the table [\"\'].+[\"\'], because it doesn\'t exist in the system catalogs\./'
|
||||||
|
=> DB_ERROR_NOSUCHTABLE,
|
||||||
|
'/Only the owner of object [\"\'].+[\"\'] or a user with System Administrator \(SA\) role can run this command\./'
|
||||||
|
=> DB_ERROR_ACCESS_VIOLATION,
|
||||||
|
'/^.+ permission denied on object .+, database .+, owner .+/'
|
||||||
|
=> DB_ERROR_ACCESS_VIOLATION,
|
||||||
|
'/^.* permission denied, database .+, owner .+/'
|
||||||
|
=> DB_ERROR_ACCESS_VIOLATION,
|
||||||
|
'/[^.*] not found\./'
|
||||||
|
=> DB_ERROR_NOSUCHTABLE,
|
||||||
|
'/There is already an object named/'
|
||||||
|
=> DB_ERROR_ALREADY_EXISTS,
|
||||||
|
'/Invalid column name/'
|
||||||
|
=> DB_ERROR_NOSUCHFIELD,
|
||||||
|
'/does not allow null values/'
|
||||||
|
=> DB_ERROR_CONSTRAINT_NOT_NULL,
|
||||||
|
'/Command has been aborted/'
|
||||||
|
=> DB_ERROR_CONSTRAINT,
|
||||||
|
'/^Cannot drop the index .* because it doesn\'t exist/i'
|
||||||
|
=> DB_ERROR_NOT_FOUND,
|
||||||
|
'/^There is already an index/i'
|
||||||
|
=> DB_ERROR_ALREADY_EXISTS,
|
||||||
|
'/^There are fewer columns in the INSERT statement than values specified/i'
|
||||||
|
=> DB_ERROR_VALUE_COUNT_ON_ROW,
|
||||||
|
'/Divide by zero/i'
|
||||||
|
=> DB_ERROR_DIVZERO,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($error_regexps as $regexp => $code) {
|
||||||
|
if (preg_match($regexp, $errormsg)) {
|
||||||
|
return $code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DB_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ numCols()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the internal sybase result pointer to the next available result
|
* Move the internal sybase result pointer to the next available result
|
||||||
*
|
*
|
||||||
|
@ -306,7 +405,7 @@ class DB_sybase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ fetchInto()
|
// {{{ numRows()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Places a row from the result set into the given array
|
* Places a row from the result set into the given array
|
||||||
|
@ -318,10 +417,10 @@ class DB_sybase extends DB_common
|
||||||
* DB_result::fetchInto() instead. It can't be declared "protected"
|
* DB_result::fetchInto() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result the query result resource
|
* @param resource $result the query result resource
|
||||||
* @param array $arr the referenced array to put the data in
|
* @param array $arr the referenced array to put the data in
|
||||||
* @param int $fetchmode how the resulting array should be indexed
|
* @param int $fetchmode how the resulting array should be indexed
|
||||||
* @param int $rownum the row number to fetch (0 = first row)
|
* @param int $rownum the row number to fetch (0 = first row)
|
||||||
*
|
*
|
||||||
* @return mixed DB_OK on success, NULL when the end of a result set is
|
* @return mixed DB_OK on success, NULL when the end of a result set is
|
||||||
* reached or on failure
|
* reached or on failure
|
||||||
|
@ -366,7 +465,7 @@ class DB_sybase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ freeResult()
|
// {{{ affectedRows()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the result set and frees the memory occupied by the result set
|
* Deletes the result set and frees the memory occupied by the result set
|
||||||
|
@ -375,7 +474,7 @@ class DB_sybase extends DB_common
|
||||||
* DB_result::free() instead. It can't be declared "protected"
|
* DB_result::free() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return bool TRUE on success, FALSE if $result is invalid
|
* @return bool TRUE on success, FALSE if $result is invalid
|
||||||
*
|
*
|
||||||
|
@ -387,7 +486,7 @@ class DB_sybase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ numCols()
|
// {{{ nextId()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of columns in a result set
|
* Gets the number of columns in a result set
|
||||||
|
@ -396,9 +495,9 @@ class DB_sybase extends DB_common
|
||||||
* DB_result::numCols() instead. It can't be declared "protected"
|
* DB_result::numCols() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return int the number of columns. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @see DB_result::numCols()
|
* @see DB_result::numCols()
|
||||||
*/
|
*/
|
||||||
|
@ -411,9 +510,6 @@ class DB_sybase extends DB_common
|
||||||
return $cols;
|
return $cols;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ numRows()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of rows in a result set
|
* Gets the number of rows in a result set
|
||||||
*
|
*
|
||||||
|
@ -421,9 +517,9 @@ class DB_sybase extends DB_common
|
||||||
* DB_result::numRows() instead. It can't be declared "protected"
|
* DB_result::numRows() instead. It can't be declared "protected"
|
||||||
* because DB_result is a separate object.
|
* because DB_result is a separate object.
|
||||||
*
|
*
|
||||||
* @param resource $result PHP's query result resource
|
* @param resource $result PHP's query result resource
|
||||||
*
|
*
|
||||||
* @return int the number of rows. A DB_Error object on failure.
|
* @return int|object
|
||||||
*
|
*
|
||||||
* @see DB_result::numRows()
|
* @see DB_result::numRows()
|
||||||
*/
|
*/
|
||||||
|
@ -437,7 +533,7 @@ class DB_sybase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ affectedRows()
|
// {{{ dropSequence()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the number of rows affected by a data maniuplation query
|
* Determines the number of rows affected by a data maniuplation query
|
||||||
|
@ -457,16 +553,16 @@ class DB_sybase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ nextId()
|
// {{{ quoteFloat()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the next free id in a sequence
|
* Returns the next free id in a sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the sequence
|
* @param string $seq_name name of the sequence
|
||||||
* @param boolean $ondemand when true, the seqence is automatically
|
* @param boolean $ondemand when true, the seqence is automatically
|
||||||
* created if it does not exist
|
* created if it does not exist
|
||||||
*
|
*
|
||||||
* @return int the next id number in the sequence.
|
* @return int|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
* @see DB_common::nextID(), DB_common::getSequenceName(),
|
||||||
|
@ -504,10 +600,13 @@ class DB_sybase extends DB_common
|
||||||
return $result[0];
|
return $result[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ autoCommit()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new sequence
|
* Creates a new sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the new sequence
|
* @param string $seq_name name of the new sequence
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
|
@ -517,18 +616,18 @@ class DB_sybase extends DB_common
|
||||||
public function createSequence($seq_name)
|
public function createSequence($seq_name)
|
||||||
{
|
{
|
||||||
return $this->query('CREATE TABLE '
|
return $this->query('CREATE TABLE '
|
||||||
. $this->getSequenceName($seq_name)
|
. $this->getSequenceName($seq_name)
|
||||||
. ' (id numeric(10, 0) IDENTITY NOT NULL,'
|
. ' (id numeric(10, 0) IDENTITY NOT NULL,'
|
||||||
. ' vapor int NULL)');
|
. ' vapor int NULL)');
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ dropSequence()
|
// {{{ commit()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a sequence
|
* Deletes a sequence
|
||||||
*
|
*
|
||||||
* @param string $seq_name name of the sequence to be deleted
|
* @param string $seq_name name of the sequence to be deleted
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int DB_OK on success. A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
|
@ -541,7 +640,7 @@ class DB_sybase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ quoteFloat()
|
// {{{ rollback()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats a float value for use within a query in a locale-independent
|
* Formats a float value for use within a query in a locale-independent
|
||||||
|
@ -558,12 +657,12 @@ class DB_sybase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ autoCommit()
|
// {{{ sybaseRaiseError()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables or disables automatic commits
|
* Enables or disables automatic commits
|
||||||
*
|
*
|
||||||
* @param bool $onoff true turns it on, false turns it off
|
* @param bool $onoff true turns it on, false turns it off
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object if the driver
|
* @return int DB_OK on success. A DB_Error object if the driver
|
||||||
* doesn't support auto-committing transactions.
|
* doesn't support auto-committing transactions.
|
||||||
|
@ -577,12 +676,12 @@ class DB_sybase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ commit()
|
// {{{ errorNative()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commits the current transaction
|
* Commits the current transaction
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function commit()
|
public function commit()
|
||||||
{
|
{
|
||||||
|
@ -600,12 +699,12 @@ class DB_sybase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ rollback()
|
// {{{ errorCode()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverts the current transaction
|
* Reverts the current transaction
|
||||||
*
|
*
|
||||||
* @return int DB_OK on success. A DB_Error object on failure.
|
* @return int|object
|
||||||
*/
|
*/
|
||||||
public function rollback()
|
public function rollback()
|
||||||
{
|
{
|
||||||
|
@ -622,105 +721,6 @@ class DB_sybase extends DB_common
|
||||||
return DB_OK;
|
return DB_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ sybaseRaiseError()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Produces a DB_Error object regarding the current problem
|
|
||||||
*
|
|
||||||
* @param int $errno if the error is being manually raised pass a
|
|
||||||
* DB_ERROR* constant here. If this isn't passed
|
|
||||||
* the error information gathered from the DBMS.
|
|
||||||
*
|
|
||||||
* @return object the DB_Error object
|
|
||||||
*
|
|
||||||
* @see DB_common::raiseError(),
|
|
||||||
* DB_sybase::errorNative(), DB_sybase::errorCode()
|
|
||||||
*/
|
|
||||||
public function sybaseRaiseError($errno = null)
|
|
||||||
{
|
|
||||||
$native = $this->errorNative();
|
|
||||||
if ($errno === null) {
|
|
||||||
$errno = $this->errorCode($native);
|
|
||||||
}
|
|
||||||
return $this->raiseError($errno, null, null, null, $native);
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ errorNative()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the DBMS' native error message produced by the last query
|
|
||||||
*
|
|
||||||
* @return string the DBMS' error message
|
|
||||||
*/
|
|
||||||
public function errorNative()
|
|
||||||
{
|
|
||||||
return @sybase_get_last_message();
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ errorCode()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines PEAR::DB error code from the database's text error message.
|
|
||||||
*
|
|
||||||
* @param string $errormsg error message returned from the database
|
|
||||||
* @return integer an error number from a DB error constant
|
|
||||||
*/
|
|
||||||
public function errorCode($errormsg)
|
|
||||||
{
|
|
||||||
static $error_regexps;
|
|
||||||
|
|
||||||
// PHP 5.2+ prepends the function name to $php_errormsg, so we need
|
|
||||||
// this hack to work around it, per bug #9599.
|
|
||||||
$errormsg = preg_replace('/^sybase[a-z_]+\(\): /', '', $errormsg);
|
|
||||||
|
|
||||||
if (!isset($error_regexps)) {
|
|
||||||
$error_regexps = array(
|
|
||||||
'/Incorrect syntax near/'
|
|
||||||
=> DB_ERROR_SYNTAX,
|
|
||||||
'/^Unclosed quote before the character string [\"\'].*[\"\']\./'
|
|
||||||
=> DB_ERROR_SYNTAX,
|
|
||||||
'/Implicit conversion (from datatype|of NUMERIC value)/i'
|
|
||||||
=> DB_ERROR_INVALID_NUMBER,
|
|
||||||
'/Cannot drop the table [\"\'].+[\"\'], because it doesn\'t exist in the system catalogs\./'
|
|
||||||
=> DB_ERROR_NOSUCHTABLE,
|
|
||||||
'/Only the owner of object [\"\'].+[\"\'] or a user with System Administrator \(SA\) role can run this command\./'
|
|
||||||
=> DB_ERROR_ACCESS_VIOLATION,
|
|
||||||
'/^.+ permission denied on object .+, database .+, owner .+/'
|
|
||||||
=> DB_ERROR_ACCESS_VIOLATION,
|
|
||||||
'/^.* permission denied, database .+, owner .+/'
|
|
||||||
=> DB_ERROR_ACCESS_VIOLATION,
|
|
||||||
'/[^.*] not found\./'
|
|
||||||
=> DB_ERROR_NOSUCHTABLE,
|
|
||||||
'/There is already an object named/'
|
|
||||||
=> DB_ERROR_ALREADY_EXISTS,
|
|
||||||
'/Invalid column name/'
|
|
||||||
=> DB_ERROR_NOSUCHFIELD,
|
|
||||||
'/does not allow null values/'
|
|
||||||
=> DB_ERROR_CONSTRAINT_NOT_NULL,
|
|
||||||
'/Command has been aborted/'
|
|
||||||
=> DB_ERROR_CONSTRAINT,
|
|
||||||
'/^Cannot drop the index .* because it doesn\'t exist/i'
|
|
||||||
=> DB_ERROR_NOT_FOUND,
|
|
||||||
'/^There is already an index/i'
|
|
||||||
=> DB_ERROR_ALREADY_EXISTS,
|
|
||||||
'/^There are fewer columns in the INSERT statement than values specified/i'
|
|
||||||
=> DB_ERROR_VALUE_COUNT_ON_ROW,
|
|
||||||
'/Divide by zero/i'
|
|
||||||
=> DB_ERROR_DIVZERO,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($error_regexps as $regexp => $code) {
|
|
||||||
if (preg_match($regexp, $errormsg)) {
|
|
||||||
return $code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return DB_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ tableInfo()
|
// {{{ tableInfo()
|
||||||
|
|
||||||
|
@ -730,14 +730,14 @@ class DB_sybase extends DB_common
|
||||||
* NOTE: only supports 'table' and 'flags' if <var>$result</var>
|
* NOTE: only supports 'table' and 'flags' if <var>$result</var>
|
||||||
* is a table name.
|
* is a table name.
|
||||||
*
|
*
|
||||||
* @param object|string $result DB_result object from a query or a
|
* @param object|string $result DB_result object from a query or a
|
||||||
* string containing the name of a table.
|
* string containing the name of a table.
|
||||||
* While this also accepts a query result
|
* While this also accepts a query result
|
||||||
* resource identifier, this behavior is
|
* resource identifier, this behavior is
|
||||||
* deprecated.
|
* deprecated.
|
||||||
* @param int $mode a valid tableInfo mode
|
* @param int $mode a valid tableInfo mode
|
||||||
*
|
*
|
||||||
* @return array an associative array with the information requested.
|
* @return array|object
|
||||||
* A DB_Error object on failure.
|
* A DB_Error object on failure.
|
||||||
*
|
*
|
||||||
* @see DB_common::tableInfo()
|
* @see DB_common::tableInfo()
|
||||||
|
@ -786,7 +786,7 @@ class DB_sybase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = @sybase_num_fields($id);
|
$count = @sybase_num_fields($id);
|
||||||
$res = array();
|
$res = array();
|
||||||
|
|
||||||
if ($mode) {
|
if ($mode) {
|
||||||
$res['num_fields'] = $count;
|
$res['num_fields'] = $count;
|
||||||
|
@ -797,11 +797,11 @@ class DB_sybase extends DB_common
|
||||||
// column_source is often blank
|
// column_source is often blank
|
||||||
$res[$i] = array(
|
$res[$i] = array(
|
||||||
'table' => $got_string
|
'table' => $got_string
|
||||||
? $case_func($result)
|
? $case_func($result)
|
||||||
: $case_func($f->column_source),
|
: $case_func($f->column_source),
|
||||||
'name' => $case_func($f->name),
|
'name' => $case_func($f->name),
|
||||||
'type' => $f->type,
|
'type' => $f->type,
|
||||||
'len' => $f->max_length,
|
'len' => $f->max_length,
|
||||||
'flags' => '',
|
'flags' => '',
|
||||||
);
|
);
|
||||||
if ($res[$i]['table']) {
|
if ($res[$i]['table']) {
|
||||||
|
@ -835,8 +835,8 @@ class DB_sybase extends DB_common
|
||||||
* + <samp>unique_key</samp> (unique index, unique check or primary_key)
|
* + <samp>unique_key</samp> (unique index, unique check or primary_key)
|
||||||
* + <samp>multiple_key</samp> (multi-key index)
|
* + <samp>multiple_key</samp> (multi-key index)
|
||||||
*
|
*
|
||||||
* @param string $table the table name
|
* @param string $table the table name
|
||||||
* @param string $column the field name
|
* @param string $column the field name
|
||||||
*
|
*
|
||||||
* @return string space delimited string of flags. Empty string if none.
|
* @return string space delimited string of flags. Empty string if none.
|
||||||
*
|
*
|
||||||
|
@ -888,7 +888,7 @@ class DB_sybase extends DB_common
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists($column, $flags)) {
|
if (array_key_exists($column, $flags)) {
|
||||||
return(implode(' ', $flags[$column]));
|
return (implode(' ', $flags[$column]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
|
@ -901,8 +901,8 @@ class DB_sybase extends DB_common
|
||||||
* Adds a string to the flags array if the flag is not yet in there
|
* Adds a string to the flags array if the flag is not yet in there
|
||||||
* - if there is no flag present the array is created
|
* - if there is no flag present the array is created
|
||||||
*
|
*
|
||||||
* @param array $array reference of flags array to add a value to
|
* @param array $array reference of flags array to add a value to
|
||||||
* @param mixed $value value to add to the flag array
|
* @param mixed $value value to add to the flag array
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
|
@ -923,7 +923,7 @@ class DB_sybase extends DB_common
|
||||||
/**
|
/**
|
||||||
* Obtains the query string needed for listing a given type of objects
|
* Obtains the query string needed for listing a given type of objects
|
||||||
*
|
*
|
||||||
* @param string $type the kind of objects you want to retrieve
|
* @param string $type the kind of objects you want to retrieve
|
||||||
*
|
*
|
||||||
* @return string the SQL query string or null if the driver doesn't
|
* @return string the SQL query string or null if the driver doesn't
|
||||||
* support the object type requested
|
* support the object type requested
|
||||||
|
@ -936,7 +936,7 @@ class DB_sybase extends DB_common
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'tables':
|
case 'tables':
|
||||||
return "SELECT name FROM sysobjects WHERE type = 'U'"
|
return "SELECT name FROM sysobjects WHERE type = 'U'"
|
||||||
. ' ORDER BY name';
|
. ' ORDER BY name';
|
||||||
case 'views':
|
case 'views':
|
||||||
return "SELECT name FROM sysobjects WHERE type = 'V'";
|
return "SELECT name FROM sysobjects WHERE type = 'V'";
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user