From 77beaf79f8a4831601aa5aca6beb563bc342032f Mon Sep 17 00:00:00 2001 From: nbm Date: Wed, 1 Dec 2004 14:05:00 +0000 Subject: [PATCH] Remove phplib. --- phplib/be_sql.inc | 130 ---------------------------------------------------------------------------------------------------------------------------------- phplib/ct_split_sql.inc | 126 ------------------------------------------------------------------------------------------------------------------------------ phplib/ct_sql.inc | 171 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- phplib/db_msql.inc | 157 ------------------------------------------------------------------------------------------------------------------------------------------------------------- phplib/db_mssql.inc | 161 ----------------------------------------------------------------------------------------------------------------------------------------------------------------- phplib/db_mysql.inc | 399 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- phplib/db_oci8.inc | 325 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- phplib/db_odbc.inc | 186 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ phplib/db_oracle.inc | 433 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- phplib/db_pgsql.inc | 225 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- phplib/db_sybase.inc | 148 ---------------------------------------------------------------------------------------------------------------------------------------------------- phplib/db_usql.inc | 76 ---------------------------------------------------------------------------- phplib/query_sql.inc | 742 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- phplib/sqlquery.inc | 322 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 14 files changed, 0 insertions(+), 3601 deletions(-) delete mode 100755 phplib/be_sql.inc delete mode 100755 phplib/ct_split_sql.inc delete mode 100755 phplib/ct_sql.inc delete mode 100755 phplib/db_msql.inc delete mode 100755 phplib/db_mssql.inc delete mode 100755 phplib/db_mysql.inc delete mode 100755 phplib/db_oci8.inc delete mode 100755 phplib/db_odbc.inc delete mode 100755 phplib/db_oracle.inc delete mode 100755 phplib/db_pgsql.inc delete mode 100755 phplib/db_sybase.inc delete mode 100755 phplib/db_usql.inc delete mode 100755 phplib/query_sql.inc delete mode 100755 phplib/sqlquery.inc diff --git a/phplib/be_sql.inc b/phplib/be_sql.inc deleted file mode 100755 index 6034731..0000000 --- a/phplib/be_sql.inc +++ /dev/null @@ -1,130 +0,0 @@ - -## -## $Id$ -## -## PHPLIB Blob Engine using plain sql -## depends on db_sql -## -## This is a "reference" class to be used only as an example. This should -## not be used in applications. -## -## It's also a good skeleton for writing a new Blob Engine -## -## The table used by this class must contain three fields: -## be_bid 16 chars -## be_seq 6 chars -## be_data 4096 chars - - -class BE_Sql { - ## - ## Define following parameters by overwriting or by deriving - ## your own class (recommended) - ## - var $database_class = "DB_Sql"; ## access table via this class - var $database_table = "be_table"; ## write data into this table - var $split_length = 4096; ## maximum amount of data for each row - ## this value should be safe enough - ## end of configuration - - var $db; ## Internal, object used for db connection - - function start() { - $name = $this->database_class; - $this->db = new $name; - } - - function blob_create() { - if (! is_object($this->db)) { - $this->start(); - } - $bn = false; - $count = 0; - while (! $bn && ($count++ < 10)) { - $bn = uniqid(""); - $this->db->query(sprintf("INSERT INTO %s". - " (be_bid, be_seq, be_data) ". - " VALUES ". - " ('%s', '%06d', '')", $this->database_table, $bn, 0)); - if ($this->db->affected_rows() != 1) { - $bn = ""; - } - } - return $bn; - } - - function blob_open($id) { - if (! is_object($this->db)) { - $this->start(); - } - $this->db->query("SELECT count(*) FROM ". $this->database_table. - " WHERE be_bid = '$id'"); - if ($this->db->next_record()) { - return ($this->db->f(0) > 0); - } else { - return false; - } - } - - function blob_close($id) { - return true; - } - - function blob_delete($id) { - if (! is_object($this->db)) { - $this->start(); - } - $this->db->query("DELETE FROM ". $this->database_table. - " WHERE be_bid = '$id'"); - return true; - } - - function blob_read($id) { - if (! is_object($this->db)) { - $this->start(); - } - $str = ""; - $this->db->query("SELECT be_data, be_seq FROM ". $this->database_table. - " WHERE be_bid = '$id' ORDER BY be_seq"); - while ($this->db->next_record()) { - $str .= $this->db->f(0); - } - return base64_decode($str); - } - - function blob_write($id, $data) { - if (! is_object($this->db)) { - $this->start(); - } - $this->db->query("BEGIN TRANSACTION"); - $this->db->query("DELETE FROM ". $this->database_table. - " WHERE be_bid = '$id'"); - $str = base64_encode($data); - $seq = 0; - while ($part = substr($str, 0, $this->split_length)) { - $this->db->query(sprintf("INSERT INTO %s ". - "(be_bid, be_seq, be_data) ". - " VALUES ". - "('%s', '%06d', '%s')", - $this->database_table, - $id, - $seq++, - $part)); - $str = substr($str, $this->split_length); - } - $this->db->query("END TRANSACTION"); - return true; - } - - -## function halt($s) { -## echo "$s"; -## exit; -## } - -} -?> diff --git a/phplib/ct_split_sql.inc b/phplib/ct_split_sql.inc deleted file mode 100755 index 6ba89dc..0000000 --- a/phplib/ct_split_sql.inc +++ /dev/null @@ -1,126 +0,0 @@ -database_class; - $this->db = new $name; - } - - function ac_get_lock() { - if ( "" != $this->database_lock_semaphore ) { - while ( ! $this->db->query("SELECT get_lock('%s')", - $this->database_lock_semaphore) ) { - $t = 1 + time(); while ( $t > time() ) { ; } - } - } - } - - function ac_release_lock() { - if ( "" != $this->database_lock_semaphore ) { - $this->db->query("SELECT release_lock('%s')", - $this->database_lock_semaphore); - } - } - - function ac_gc($gc_time, $name) { - $timeout = time(); - $sqldate = date("YmdHis", $timeout - ($gc_time * 60)); - $this->db->query(sprintf("DELETE FROM %s ". - "WHERE ct_changed < '%s' AND ct_name = '%s'", - $this->database_table, - $sqldate, - addslashes($name))); - } - - function ac_store($id, $name, $str) { - $ret = true; - $str = base64_encode($str); - $name = addslashes($name); - $now = date("YmdHis", time()); - $this->db->query("BEGIN TRANSACTION"); - $this->db->query(sprintf("DELETE FROM %s WHERE ct_sid='%s' AND ct_name='%s'", - $this->database_table, - $id, - $name - )); - $count = 0; - while ($part = substr($str, 0, $this->split_length)) { - $this->db->query(sprintf("INSERT INTO %s ". - " (ct_sid, ct_name, ct_pos, ct_val, ct_changed) ". - " VALUES ". - " ('%s','%s','%06d','%s','%s')", - $this->database_table, - $id, - $name, - $count++, - $part, - $now - )); - $str = substr($str, $this->split_length); - } - $this->db->query("END TRANSACTION"); - return $ret; - } - - function ac_delete($id, $name) { - $this->db->query(sprintf("DELETE FROM %s ". - "WHERE ct_name = '%s' AND ct_sid = '%s'", - $this->database_table, - addslashes($name), - $id)); - } - - function ac_get_value($id, $name) { - $this->db->query(sprintf("SELECT ct_val, ct_pos FROM %s ". - "WHERE ct_sid = '%s' AND ct_name = '%s' ". - "ORDER BY ct_pos", - $this->database_table, - $id, - addslashes($name))); - $str=""; - while ($this->db->next_record()) { - $str .= $this->db->f("ct_val"); - } - if (! empty($str)) { - $str = base64_decode($str); - }; -## DEB echo $str; - return $str; - } - - function ac_newid($str, $name) { - return $str; - } - - function ac_halt($s) { - $this->db->halt($s); - } -} -?> diff --git a/phplib/ct_sql.inc b/phplib/ct_sql.inc deleted file mode 100755 index 598a5fd..0000000 --- a/phplib/ct_sql.inc +++ /dev/null @@ -1,171 +0,0 @@ - -## -## $Id$ -## -## PHPLIB Data Storage Container using a SQL database -## - -class CT_Sql { - ## - ## Define these parameters by overwriting or by - ## deriving your own class from it (recommened) - ## - - var $database_table = "active_sessions"; - var $database_class = "Owl_Sql"; - var $database_lock_semaphore = ""; - - var $encoding_mode = "base64"; - - ## end of configuration - - var $db; - - function ac_start() { - $name = $this->database_class; - $this->db = new $name; - } - - function ac_get_lock() { - if ( "" != $this->database_lock_semaphore ) { - $query = sprintf("SELECT get_lock('%s')", $this->database_lock_semaphore); - while ( ! $this->db->query($query)) { - $t = 1 + time(); while ( $t > time() ) { ; } - } - } - } - - function ac_release_lock() { - if ( "" != $this->database_lock_semaphore ) { - $query = sprintf("SELECT release_lock('%s')", $this->database_lock_semaphore); - $this->db->query($query); - } - } - - function ac_gc($gc_time, $name) { - $timeout = time(); - $sqldate = date("YmdHis", $timeout - ($gc_time * 60)); - $this->db->query(sprintf("DELETE FROM %s WHERE changed < '%s' AND name = '%s'", - $this->database_table, - $sqldate, - addslashes($name))); - } - - function ac_store($id, $name, $str) { - $ret = true; - - switch ( $this->encoding_mode ) { - case "slashes": - $str = addslashes($name . ":" . $str); - break; - - case "base64": - default: - $str = base64_encode($name . ":" . $str); - }; - - $name = addslashes($name); - - ## update duration of visit - global $HTTP_REFERER, $HTTP_USER_AGENT, $REMOTE_ADDR; - - $now = date("YmdHis", time()); - $uquery = sprintf("update %s set val='%s', changed='%s' where sid='%s' and name='%s'", - $this->database_table, - $str, - $now, - $id, - $name); - $squery = sprintf("select count(*) from %s where val='%s' and changed='%s' and sid='%s' and name='%s'", - $this->database_table, - $str, - $now, - $id, - $name); - $iquery = sprintf("insert into %s ( sid, name, val, changed ) values ('%s', '%s', '%s', '%s')", - $this->database_table, - $id, - $name, - $str, - $now); - - $this->db->query($uquery); - - # FIRST test to see if any rows were affected. - # Zero rows affected could mean either there were no matching rows - # whatsoever, OR that the update statement did match a row but made - # no changes to the table data (i.e. UPDATE tbl SET col = 'x', when - # "col" is _already_ set to 'x') so then, - # SECOND, query(SELECT...) on the sid to determine if the row is in - # fact there, - # THIRD, verify that there is at least one row present, and if there - # is not, then - # FOURTH, insert the row as we've determined that it does not exist. - - if ( $this->db->affected_rows() == 0 - && $this->db->query($squery) - && $this->db->f(1) == 0 - && !$this->db->query($iquery)) { - - $ret = false; - } - return $ret; - } - - function ac_delete($id, $name) { - $this->db->query(sprintf("delete from %s where name = '%s' and sid = '%s'", - $this->database_table, - addslashes($name), - $id)); - } - - function ac_get_value($id, $name) { - $this->db->query(sprintf("select val from %s where sid = '%s' and name = '%s'", - $this->database_table, - $id, - addslashes($name))); - if ($this->db->next_record()) { - $str = $this->db->f("val"); - $str2 = base64_decode( $str ); - - if ( ereg("^".$name.":.*", $str2) ) { - $str = ereg_replace("^".$name.":", "", $str2 ); - } else { - - $str3 = stripslashes( $str ); - - if ( ereg("^".$name.":.*", $str3) ) { - $str = ereg_replace("^".$name.":", "", $str3 ); - } else { - - switch ( $this->encoding_mode ) { - case "slashes": - $str = stripslashes($str); - break; - - case "base64": - default: - $str = base64_decode($str); - } - } - }; - return $str; - }; - return ""; - } - - function ac_newid($str, $name) { - return $str; - } - - function ac_halt($s) { - $this->db->halt($s); - } -} -?> diff --git a/phplib/db_msql.inc b/phplib/db_msql.inc deleted file mode 100755 index a069b55..0000000 --- a/phplib/db_msql.inc +++ /dev/null @@ -1,157 +0,0 @@ - - * - * $Id$ - * - */ - -class DB_Sql { - var $Host = ""; - var $Database = ""; - - var $Link_ID = 0; - var $Query_ID = 0; - var $Record = array(); - var $Row; - - var $Error = ""; - - var $Auto_Free = 0; ## Set this to 1 for automatic msql_free_result() - - /* public: constructor */ - function DB_Sql($query = "") { - $this->query($query); - } - - function connect() { - // Not connected? Then connect? - if ( 0 == $this->Link_ID ) { - // Check for local connect - $this->Link_ID = empty($this->Host)? - $this->Link_ID=msql_pconnect(): - $this->Link_ID=msql_pconnect($this->Host); - } - - // Still not connected? Raise error. - if ( 0 == $this->Link_ID ) { - $this->halt("Link-ID == false, pconnect failed"); - } - - // Select current database - if (!msql_select_db($this->Database, $this->Link_ID)) { - $this->halt("cannot use database ".$this->Database); - } - } - - function query($Query_String) { - - /* No empty queries, please, since PHP4 chokes on them. */ - if ($Query_String == "") - /* The empty query string is passed on from the constructor, - * when calling the class without a query, e.g. in situations - * like these: '$db = new DB_Sql_Subclass;' - */ - return 0; - - $this->connect(); - -# printf("Debug: query = %s
\n", $Query_String); - - $this->Query_ID = msql_query($Query_String,$this->Link_ID); - $this->Row = 0; - $this->Error = msql_error(); - if (!$this->Query_ID) { - $this->halt("Invalid SQL: ".$Query_String); - } - - return $this->Query_ID; - } - - function next_record() { - $this->Record = msql_fetch_array($this->Query_ID); - $this->Row += 1; - $this->Error = msql_error(); - - $stat = is_array($this->Record); - if (!$stat && $this->Auto_Free) { - msql_free_result($this->Query_ID); - $this->Query_ID = 0; - } - return $stat; - } - - function seek($pos) { - $status = msql_data_seek($this->Query_ID, $pos); - if ($status) - $this->Row = $pos; - return; - } - - function metadata($table) { - $count = 0; - $id = 0; - $res = array(); - - $this->connect(); - $id = @msql_list_fields($this->Database, $table); - if ($id < 0) { - $this->Error = msql_error(); - $this->halt("Metadata query failed."); - } - $count = msql_num_fields($id); - - for ($i=0; $i<$count; $i++) { - $res[$i]["table"] = msql_fieldtable ($id, $i); - $res[$i]["name"] = msql_fieldname ($id, $i); - $res[$i]["type"] = msql_fieldtype ($id, $i); - $res[$i]["len"] = msql_fieldlen ($id, $i); - $res[$i]["flags"] = msql_fieldflags ($id, $i); - $res["meta"][$res[$i]["name"]] = $i; - $res["num_fields"]= $count; - } - - msql_free_result($id); - return $res; - } - - function affected_rows() { - return msql_affected_rows($this->Query_ID); - } - - function num_rows() { - return msql_num_rows($this->Query_ID); - } - - function num_fields() { - return msql_num_fields($this->Query_ID); - } - - function nf() { - return $this->num_rows(); - } - - function np() { - print $this->num_rows(); - } - - function f($Name) { - return $this->Record[$Name]; - } - - function p($Name) { - print $this->Record[$Name]; - } - - function halt($msg) { - printf("Database error: %s
\n", $msg); - printf("MSQL Error: %s
\n", $this->Error); - die("Session halted."); - } -} -?> diff --git a/phplib/db_mssql.inc b/phplib/db_mssql.inc deleted file mode 100755 index b497db7..0000000 --- a/phplib/db_mssql.inc +++ /dev/null @@ -1,161 +0,0 @@ -This is using the MSSQL class
"; - -class DB_Sql { - var $Host = ""; - var $Database = ""; - var $User = ""; - var $Password = ""; - - var $Link_ID = 0; - var $Query_ID = 0; - var $Record = array(); - var $Row = 0; - - var $Errno = 0; - var $Error = ""; - - var $Auto_Free = 0; ## set this to 1 to automatically free results - - - /* public: constructor */ - function DB_Sql($query = "") { - $this->query($query); - } - - function connect() { - if ( 0 == $this->Link_ID ) { - $this->Link_ID=mssql_pconnect($this->Host, $this->User, $this->Password); - if (!$this->Link_ID) - $this->halt("Link-ID == false, mssql_pconnect failed"); - else - mssql_select_db($this->Database, $this->Link_ID); - } - } - function free_result(){ - mssql_free_result($this->Query_ID); - $this->Query_ID = 0; - } - - function query($Query_String) - { - - /* No empty queries, please, since PHP4 chokes on them. */ - if ($Query_String == "") - /* The empty query string is passed on from the constructor, - * when calling the class without a query, e.g. in situations - * like these: '$db = new DB_Sql_Subclass;' - */ - return 0; - - if (!$this->Link_ID) - $this->connect(); - -# printf("
Debug: query = %s
\n", $Query_String); - - $this->Query_ID = mssql_query($Query_String, $this->Link_ID); - $this->Row = 0; - if (!$this->Query_ID) { - $this->Errno = 1; - $this->Error = "General Error (The MSSQL interface cannot return detailed error messages)."; - $this->halt("Invalid SQL: ".$Query_String); - } - return $this->Query_ID; - } - - function next_record() { - - if ($this->Record = mssql_fetch_row($this->Query_ID)) { - // add to Record[] - $count = mssql_num_fields($this->Query_ID); - for ($i=0; $i<$count; $i++){ - $fieldinfo = mssql_fetch_field($this->Query_ID,$i); - $this->Record[strtolower($fieldinfo->name)] = $this->Record[$i]; - } - $this->Row += 1; - $stat = 1; - } else { - if ($this->Auto_Free) { - $this->free_result(); - } - $stat = 0; - } - return $stat; - } - - function seek($pos) { - mssql_data_seek($this->Query_ID,$pos); - $this->Row = $pos; - } - - function metadata($table) { - $count = 0; - $id = 0; - $res = array(); - - $this->connect(); - $id = mssql_query("select * from $table", $this->Link_ID); - if (!$id) { - $this->Errno = 1; - $this->Error = "General Error (The MSSQL interface cannot return detailed error messages)."; - $this->halt("Metadata query failed."); - } - $count = mssql_num_fields($id); - - for ($i=0; $i<$count; $i++) { - $info = mssql_fetch_field($id, $i); - $res[$i]["table"] = $table; - $res[$i]["name"] = $info["name"]; - $res[$i]["len"] = $info["max_length"]; - $res[$i]["flags"] = $info["numeric"]; - } - $this->free_result(); - return $res; - } - - function affected_rows() { - return mssql_affected_rows($this->Query_ID); - } - - function num_rows() { - return mssql_num_rows($this->Query_ID); - } - - function num_fields() { - return mssql_num_fields($this->Query_ID); - } - - function nf() { - return $this->num_rows(); - } - - function np() { - print $this->num_rows(); - } - - function f($Field_Name) { - return $this->Record[strtolower($Field_Name)]; - } - - function p($Field_Name) { - print $this->f($Field_Name); - } - - function halt($msg) { - printf("Database error: %s
\n", $msg); - printf("MSSQL Error: %s (%s)
\n", - $this->Errno, - $this->Error); - die("Session halted."); - } -} -?> diff --git a/phplib/db_mysql.inc b/phplib/db_mysql.inc deleted file mode 100755 index 19bbb1e..0000000 --- a/phplib/db_mysql.inc +++ /dev/null @@ -1,399 +0,0 @@ -query($query); - } - - /* public: some trivial reporting */ - function link_id() { - return $this->Link_ID; - } - - function query_id() { - return $this->Query_ID; - } - - /* public: connection management */ - function connect($Database = "", $Host = "", $User = "", $Password = "") { - /* Handle defaults */ - if ("" == $Database) - $Database = $this->Database; - if ("" == $Host) - $Host = $this->Host; - if ("" == $User) - $User = $this->User; - if ("" == $Password) - $Password = $this->Password; - - /* establish connection, select database */ - if ( 0 == $this->Link_ID ) { - - $this->Link_ID=mysql_pconnect($Host, $User, $Password); - if (!$this->Link_ID) { - $this->halt("pconnect($Host, $User, \$Password) failed."); - return 0; - } - - if (!@mysql_select_db($Database,$this->Link_ID)) { - $this->halt("cannot use database ".$this->Database); - return 0; - } - } - - return $this->Link_ID; - } - - /* public: discard the query result */ - function free() { - @mysql_free_result($this->Query_ID); - $this->Query_ID = 0; - } - - /* public: perform a query */ - function query($Query_String) { - global $default; - // only log the queries if we're in debug mode - if ($default->minimumLoggingLevel == DEBUG) { - require_once("$default->fileSystemRoot/phpSniff/phpTimer.class.php"); - $timer = new phpTimer(); - $timer->start(); - } - - /* No empty queries, please, since PHP4 chokes on them. */ - if ($Query_String == "") - /* The empty query string is passed on from the constructor, - * when calling the class without a query, e.g. in situations - * like these: '$db = new DB_Sql_Subclass;' - */ - return 0; - - if (!$this->connect()) { - return 0; /* we already complained in connect() about that. */ - }; - - # New query, discard previous result. - if ($this->Query_ID) { - $this->free(); - } - - if ($this->Debug) - printf("Debug: query = %s
\n", $Query_String); - - $this->Query_ID = @mysql_query($Query_String,$this->Link_ID); - $this->Row = 0; - $this->Errno = mysql_errno(); - $this->Error = mysql_error(); - if (!$this->Query_ID) { - $this->halt("Invalid SQL: ".$Query_String); - } - - # Will return nada if it fails. That's fine. - if ($default->minimumLoggingLevel == DEBUG) { - $timer->stop(); - if ($fp = fopen($default->fileSystemRoot . "/log/queryLog.txt", "a")) { - fwrite($fp, $timer->get_current() . ": $Query_String\n"); - } - fclose($fp); - } - return $this->Query_ID; - } - - // BEGIN wes addition - function insert_id() { - return mysql_insert_id($this->Link_ID); - } - // END wes addition - - /* public: walk result set */ - function next_record() { - if (!$this->Query_ID) { - $this->halt("next_record called with no query pending."); - return 0; - } - - $this->Record = @mysql_fetch_array($this->Query_ID); - $this->Row += 1; - $this->Errno = mysql_errno(); - $this->Error = mysql_error(); - - $stat = is_array($this->Record); - if (!$stat && $this->Auto_Free) { - $this->free(); - } - return $stat; - } - - /* public: position in result set */ - function seek($pos = 0) { - $status = @mysql_data_seek($this->Query_ID, $pos); - if ($status) - $this->Row = $pos; - else { - $this->halt("seek($pos) failed: result has ".$this->num_rows()." rows"); - - /* half assed attempt to save the day, - * but do not consider this documented or even - * desireable behaviour. - */ - @mysql_data_seek($this->Query_ID, $this->num_rows()); - $this->Row = $this->num_rows; - return 0; - } - - return 1; - } - - /* public: table locking */ - function lock($table, $mode="write") { - $this->connect(); - - $query="lock tables "; - if (is_array($table)) { - while (list($key,$value)=each($table)) { - if ($key=="read" && $key!=0) { - $query.="$value read, "; - } else { - $query.="$value $mode, "; - } - } - $query=substr($query,0,-2); - } else { - $query.="$table $mode"; - } - $res = @mysql_query($query, $this->Link_ID); - if (!$res) { - $this->halt("lock($table, $mode) failed."); - return 0; - } - return $res; - } - - function unlock() { - $this->connect(); - - $res = @mysql_query("unlock tables"); - if (!$res) { - $this->halt("unlock() failed."); - return 0; - } - return $res; - } - - - /* public: evaluate the result (size, width) */ - function affected_rows() { - return @mysql_affected_rows($this->Link_ID); - } - - function num_rows() { - return @mysql_num_rows($this->Query_ID); - } - - function num_fields() { - return @mysql_num_fields($this->Query_ID); - } - - /* public: shorthand notation */ - function nf() { - return $this->num_rows(); - } - - function np() { - print $this->num_rows(); - } - - function f($Name) { - return $this->Record[$Name]; - } - - function p($Name) { - print $this->Record[$Name]; - } - - /* public: sequence numbers */ - function nextid($seq_name) { - $this->connect(); - - if ($this->lock($this->Seq_Table)) { - /* get sequence number (locked) and increment */ - $q = sprintf("select nextid from %s where seq_name = '%s'", - $this->Seq_Table, - $seq_name); - $id = @mysql_query($q, $this->Link_ID); - $res = @mysql_fetch_array($id); - - /* No current value, make one */ - if (!is_array($res)) { - $currentid = 0; - $q = sprintf("insert into %s values('%s', %s)", - $this->Seq_Table, - $seq_name, - $currentid); - $id = @mysql_query($q, $this->Link_ID); - } else { - $currentid = $res["nextid"]; - } - $nextid = $currentid + 1; - $q = sprintf("update %s set nextid = '%s' where seq_name = '%s'", - $this->Seq_Table, - $nextid, - $seq_name); - $id = @mysql_query($q, $this->Link_ID); - $this->unlock(); - } else { - $this->halt("cannot lock ".$this->Seq_Table." - has it been created?"); - return 0; - } - return $nextid; - } - - /* public: return table metadata */ - function metadata($table='',$full=false) { - $count = 0; - $id = 0; - $res = array(); - - /* - * Due to compatibility problems with Table we changed the behavior - * of metadata(); - * depending on $full, metadata returns the following values: - * - * - full is false (default): - * $result[]: - * [0]["table"] table name - * [0]["name"] field name - * [0]["type"] field type - * [0]["len"] field length - * [0]["flags"] field flags - * - * - full is true - * $result[]: - * ["num_fields"] number of metadata records - * [0]["table"] table name - * [0]["name"] field name - * [0]["type"] field type - * [0]["len"] field length - * [0]["flags"] field flags - * ["meta"][field name] index of field named "field name" - * The last one is used, if you have a field name, but no index. - * Test: if (isset($result['meta']['myfield'])) { ... - */ - - // if no $table specified, assume that we are working with a query - // result - if ($table) { - $this->connect(); - $id = @mysql_list_fields($this->Database, $table); - if (!$id) - $this->halt("Metadata query failed."); - } else { - $id = $this->Query_ID; - if (!$id) - $this->halt("No query specified."); - } - - $count = @mysql_num_fields($id); - - // made this IF due to performance (one if is faster than $count if's) - if (!$full) { - for ($i=0; $i<$count; $i++) { - $res[$i]["table"] = @mysql_field_table ($id, $i); - $res[$i]["name"] = @mysql_field_name ($id, $i); - $res[$i]["type"] = @mysql_field_type ($id, $i); - $res[$i]["len"] = @mysql_field_len ($id, $i); - $res[$i]["flags"] = @mysql_field_flags ($id, $i); - } - } else { // full - $res["num_fields"]= $count; - - for ($i=0; $i<$count; $i++) { - $res[$i]["table"] = @mysql_field_table ($id, $i); - $res[$i]["name"] = @mysql_field_name ($id, $i); - $res[$i]["type"] = @mysql_field_type ($id, $i); - $res[$i]["len"] = @mysql_field_len ($id, $i); - $res[$i]["flags"] = @mysql_field_flags ($id, $i); - $res["meta"][$res[$i]["name"]] = $i; - } - } - - // free the result only if we were called on a table - if ($table) @mysql_free_result($id); - return $res; - } - - /* private: error handling */ - function halt($msg) { - $this->Error = @mysql_error($this->Link_ID); - $this->Errno = @mysql_errno($this->Link_ID); - if ($this->Halt_On_Error == "no") - return; - - $this->haltmsg($msg); - - if ($this->Halt_On_Error != "report") - die("Session halted."); - } - - function haltmsg($msg) { - printf("Database error: %s
\n", $msg); - printf("MySQL Error: %s (%s)
\n", - $this->Errno, - $this->Error); - } - - function table_names() { - $this->query("SHOW TABLES"); - $i=0; - while ($info=mysql_fetch_row($this->Query_ID)) - { - $return[$i]["table_name"]= $info[0]; - $return[$i]["tablespace_name"]=$this->Database; - $return[$i]["database"]=$this->Database; - $i++; - } - return $return; - } -} -?> diff --git a/phplib/db_oci8.inc b/phplib/db_oci8.inc deleted file mode 100755 index 768e72e..0000000 --- a/phplib/db_oci8.inc +++ /dev/null @@ -1,325 +0,0 @@ -query($query); - } - - function connect() { - if ( 0 == $this->Link_ID ) { - if($this->Debug) { - printf("
Connecting to $this->Database...
\n"); - } - $this->Link_ID=OCIplogon - ("$this->User","$this->Password","$this->Database"); - - if (!$this->Link_ID) { - $this->halt("Link-ID == false " . - "($this->Link_ID), OCILogon failed"); - } - - if($this->Debug) { - printf("
Obtained the Link_ID: $this->Link_ID
\n"); - } - } - } - - function query($Query_String) { - - /* No empty queries, please, since PHP4 chokes on them. */ - if ($Query_String == "") - /* The empty query string is passed on from the constructor, - * when calling the class without a query, e.g. in situations - * like these: '$db = new DB_Sql_Subclass;' - */ - return 0; - - - $this->connect(); - - $this->Parse=OCIParse($this->Link_ID,$Query_String); - if(!$this->Parse) { - $this->Error=OCIError($this->Parse); - } else { OCIExecute($this->Parse); - $this->Error=OCIError($this->Parse); - } - - $this->Row=0; - - if($this->Debug) { - printf("Debug: query = %s
\n", $Query_String); - } - - if ($this->Error["code"]!=1403 && $this->Error["code"]!=0 && $this->sqoe) - echo "
".$this->Error["message"]."
Query :\"$Query_String\"
"; - return $this->Parse; - } - - function next_record() { - if(0 == OCIFetchInto($this->Parse,$result,OCI_ASSOC+OCI_RETURN_NULLS)) { - if ($this->Debug) { - printf("
ID: %d,Rows: %d
\n", - $this->Link_ID,$this->num_rows()); - } - $this->Row +=1; - - $errno=OCIError($this->Parse); - if(1403 == $errno) { # 1043 means no more records found - $this->Error=""; - $this->disconnect(); - $stat=0; - } else { - $this->Error=OCIError($this->Parse); - if($this->Debug) { - printf("
Error: %s", - $this->Error["message"]); - } - $stat=0; - } - } else { - for($ix=1;$ix<=OCINumcols($this->Parse);$ix++) { - $col=strtoupper(OCIColumnname($this->Parse,$ix)); - $colreturn=strtolower($col); - $this->Record[ "$colreturn" ] = $result["$col"]; - if($this->Debug) echo"[$col]:".$result["$col"]."
\n"; - } - $stat=1; - } - - return $stat; - } - - function seek($pos) { - $this->Row=$pos; - } - - function metadata($table,$full=false) { - $count = 0; - $id = 0; - $res = array(); - - /* - * Due to compatibility problems with Table we changed the behavior - * of metadata(); - * depending on $full, metadata returns the following values: - * - * - full is false (default): - * $result[]: - * [0]["table"] table name - * [0]["name"] field name - * [0]["type"] field type - * [0]["len"] field length - * [0]["flags"] field flags ("NOT NULL", "INDEX") - * [0]["format"] precision and scale of number (eg. "10,2") or empty - * [0]["index"] name of index (if has one) - * [0]["chars"] number of chars (if any char-type) - * - * - full is true - * $result[]: - * ["num_fields"] number of metadata records - * [0]["table"] table name - * [0]["name"] field name - * [0]["type"] field type - * [0]["len"] field length - * [0]["flags"] field flags ("NOT NULL", "INDEX") - * [0]["format"] precision and scale of number (eg. "10,2") or empty - * [0]["index"] name of index (if has one) - * [0]["chars"] number of chars (if any char-type) - * ["meta"][field name] index of field named "field name" - * The last one is used, if you have a field name, but no index. - * Test: if (isset($result['meta']['myfield'])) {} ... - */ - - $this->connect(); - - ## This is a RIGHT OUTER JOIN: "(+)", if you want to see, what - ## this query results try the following: - ## $table = new Table; $db = new my_DB_Sql; # you have to make - ## # your own class - ## $table->show_results($db->query(see query vvvvvv)) - ## - $this->query("SELECT T.table_name,T.column_name,T.data_type,". - "T.data_length,T.data_precision,T.data_scale,T.nullable,". - "T.char_col_decl_length,I.index_name". - " FROM ALL_TAB_COLUMNS T,ALL_IND_COLUMNS I". - " WHERE T.column_name=I.column_name (+)". - " AND T.table_name=I.table_name (+)". - " AND T.table_name=UPPER('$table') ORDER BY T.column_id"); - - $i=0; - while ($this->next_record()) { - $res[$i]["table"] = $this->Record[table_name]; - $res[$i]["name"] = strtolower($this->Record[column_name]); - $res[$i]["type"] = $this->Record[data_type]; - $res[$i]["len"] = $this->Record[data_length]; - if ($this->Record[index_name]) $res[$i]["flags"] = "INDEX "; - $res[$i]["flags"] .= ( $this->Record[nullable] == 'N') ? '' : 'NOT NULL'; - $res[$i]["format"]= (int)$this->Record[data_precision].",". - (int)$this->Record[data_scale]; - if ("0,0"==$res[$i]["format"]) $res[$i]["format"]=''; - $res[$i]["index"] = $this->Record[index_name]; - $res[$i]["chars"] = $this->Record[char_col_decl_length]; - if ($full) { - $j=$res[$i]["name"]; - $res["meta"][$j] = $i; - $res["meta"][strtoupper($j)] = $i; - } - if ($full) $res["meta"][$res[$i]["name"]] = $i; - $i++; - } - if ($full) $res["num_fields"]=$i; -# $this->disconnect(); - return $res; - } - - - function affected_rows() { - return $this->num_rows(); - } - - function num_rows() { - return OCIrowcount($this->Parse); - } - - function num_fields() { - return OCINumcols($this->Parse); - } - - function nf() { - return $this->num_rows(); - } - - function np() { - print $this->num_rows(); - } - - function f($Name) { - if (is_object($this->Record[$Name])) - { - return $this->Record[$Name]->load(); - } else - { - return $this->Record[$Name]; - } - } - - function p($Name) { - print $this->f($Name); - } - - function nextid($seqname) - { - $this->connect(); - - $Query_ID=@ociparse($this->Link_ID,"SELECT $seqname.NEXTVAL FROM DUAL"); - - if(!@ociexecute($Query_ID)) - { - $this->Error=@OCIError($Query_ID); - if($this->Error["code"]==2289) - { - $Query_ID=ociparse($this->Link_ID,"CREATE SEQUENCE $seqname"); - if(!ociexecute($Query_ID)) - { - $this->Error=OCIError($Query_ID); - $this->halt("
nextid() function - unable to create sequence
".$this->Error["message"]); - } else - { - $Query_ID=ociparse($this->Link_ID,"SELECT $seqname.NEXTVAL FROM DUAL"); - ociexecute($Query_ID); - } - } - } - - if (ocifetch($Query_ID)) - { - $next_id = ociresult($Query_ID,"NEXTVAL"); - } else - { - $next_id = 0; - } - ocifreestatement($Query_ID); - return $next_id; - } - - function disconnect() { - if($this->Debug) { - printf("Disconnecting...
\n"); - } - OCILogoff($this->Link_ID); - } - - function halt($msg) { - printf("Database error: %s
\n", $msg); - printf("ORACLE Error: %s
\n", - $this->Error["message"]); - die("Session halted."); - } - - function lock($table, $mode = "write") { - $this->connect(); - if ($mode == "write") { - $Parse=OCIParse($this->Link_ID,"lock table $table in row exclusive mode"); - OCIExecute($Parse); - } else { - $result = 1; - } - return $result; - } - - function unlock() { - return $this->query("commit"); - } - - function table_names() { - $this->connect(); - $this->query(" - SELECT table_name,tablespace_name - FROM user_tables"); - $i=0; - while ($this->next_record()) - { - $info[$i]["table_name"] =$this->Record["table_name"]; - $info[$i]["tablespace_name"]=$this->Record["tablespace_name"]; - $i++; - } - return $info; - } - - function add_specialcharacters($query) - { - return str_replace("'","''",$query); - } - - function split_specialcharacters($query) - { - return str_replace("''","'",$query); - } -} -?> diff --git a/phplib/db_odbc.inc b/phplib/db_odbc.inc deleted file mode 100755 index 840896a..0000000 --- a/phplib/db_odbc.inc +++ /dev/null @@ -1,186 +0,0 @@ -query($query); - } - - function connect() { - if ( 0 == $this->Link_ID ) { - $this->Link_ID=odbc_pconnect($this->Database, $this->User, $this->Password, $this->UseODBCCursor); - if (!$this->Link_ID) { - $this->halt("Link-ID == false, odbc_pconnect failed"); - } - } - } - - function query($Query_String) { - - /* No empty queries, please, since PHP4 chokes on them. */ - if ($Query_String == "") - /* The empty query string is passed on from the constructor, - * when calling the class without a query, e.g. in situations - * like these: '$db = new DB_Sql_Subclass;' - */ - return 0; - - $this->connect(); - -# printf("
Debug: query = %s
\n", $Query_String); - -# rei@netone.com.br suggested that we use this instead of the odbc_exec(). -# He is on NT, connecting to a Unix MySQL server with ODBC. -- KK -# $this->Query_ID = odbc_prepare($this->Link_ID,$Query_String); -# $this->Query_Ok = odbc_execute($this->Query_ID); - - $this->Query_ID = odbc_exec($this->Link_ID,$Query_String); - $this->Row = 0; - odbc_binmode($this->Query_ID, 1); - odbc_longreadlen($this->Query_ID, 4096); - - if (!$this->Query_ID) { - $this->Errno = 1; - $this->Error = "General Error (The ODBC interface cannot return detailed error messages)."; - $this->halt("Invalid SQL: ".$Query_String); - } - return $this->Query_ID; - } - - function next_record() { - $this->Record = array(); - $stat = odbc_fetch_into($this->Query_ID, ++$this->Row, &$this->Record); - if (!$stat) { - if ($this->Auto_Free) { - odbc_free_result($this->Query_ID); - $this->Query_ID = 0; - }; - } else { - // add to Record[] - $count = odbc_num_fields($this->Query_ID); - for ($i=1; $i<=$count; $i++) - $this->Record[strtolower(odbc_field_name ($this->Query_ID, $i)) ] = $this->Record[ $i - 1 ]; - } - return $stat; - } - - function seek($pos) { - $this->Row = $pos; - } - - function metadata($table) { - $count = 0; - $id = 0; - $res = array(); - - $this->connect(); - $id = odbc_exec($this->Link_ID, "select * from $table"); - if (!$id) { - $this->Errno = 1; - $this->Error = "General Error (The ODBC interface cannot return detailed error messages)."; - $this->halt("Metadata query failed."); - } - $count = odbc_num_fields($id); - - for ($i=1; $i<=$count; $i++) { - $res[$i]["table"] = $table; - $name = odbc_field_name ($id, $i); - $res[$i]["name"] = $name; - $res[$i]["type"] = odbc_field_type ($id, $name); - $res[$i]["len"] = 0; // can we determine the width of this column? - $res[$i]["flags"] = ""; // any optional flags to report? - } - - odbc_free_result($id); - return $res; - } - - function affected_rows() { - return odbc_num_rows($this->Query_ID); - } - - function num_rows() { - # Many ODBC drivers don't support odbc_num_rows() on SELECT statements. - $num_rows = odbc_num_rows($this->Query_ID); - //printf ($num_rows."
"); - - # This is a workaround. It is intended to be ugly. - if ($num_rows < 0) { - $i=10; - while (odbc_fetch_row($this->Query_ID, $i)) - $i*=10; - - $j=0; - while ($i!=$j) { - $k= $j+intval(($i-$j)/2); - if (odbc_fetch_row($this->Query_ID, $k)) - $j=$k; - else - $i=$k; - if (($i-$j)==1) { - if (odbc_fetch_row($this->Query_ID, $i)) - $j=$i; - else - $i=$j; - }; - //printf("$i $j $k
"); - }; - $num_rows=$i; - } - - return $num_rows; - } - - function num_fields() { - return count($this->Record)/2; - } - - function nf() { - return $this->num_rows(); - } - - function np() { - print $this->num_rows(); - } - - function f($Field_Name) { - return $this->Record[strtolower($Field_Name)]; - } - - function p($Field_Name) { - print $this->f($Field_Name); - } - - function halt($msg) { - printf("Database error: %s
\n", $msg); - printf("ODBC Error: %s (%s)
\n", - $this->Errno, - $this->Error); - die("Session halted."); - } -} -?> diff --git a/phplib/db_oracle.inc b/phplib/db_oracle.inc deleted file mode 100755 index 90469ae..0000000 --- a/phplib/db_oracle.inc +++ /dev/null @@ -1,433 +0,0 @@ -query($query); - } - - /* public: some trivial reporting */ - function link_id() { - return $this->Link_ID; - } - - function query_id() { - return $this->Query_ID; - } - - function connect() { - ## see above why we do this - if ($this->OraPutEnv) { - PutEnv("ORACLE_SID=$this->Database"); - PutEnv("ORACLE_HOME=$this->Home"); - } - if ( 0 == $this->Link_ID ) { - if($this->Debug) { - printf("
Connect()ing to $this->Database...
\n"); - } - if($this->Remote) { - if($this->Debug) { - printf("
connect() $this->User/******@$this->Database.world
\n"); - } - $this->Link_ID=ora_plogon - ("$this->User/$this->Password@$this->Database",""); - /************** (comment by SSilk) - this dosn't work on my system: - $this->Link_ID=ora_plogon - ("$this->User@$this->Database.world","$this->Password"); - ***************/ - } else { - if($this->Debug) { - printf("
connect() $this->User, $this->Password
\n"); - } - $this->Link_ID=ora_plogon("$this->User","$this->Password"); - /* (comment by SSilk: don't know how this could work, but I leave this untouched!) */ - } - if($this->Debug) { - printf("
connect() Link_ID: $this->Link_ID
\n"); - } - if (!$this->Link_ID) { - $this->halt("connect() Link-ID == false " . - "($this->Link_ID), ora_plogon failed"); - } else { - //echo "commit on

"; - ora_commiton($this->Link_ID); - } - if($this->Debug) { - printf("
connect() Obtained the Link_ID: $this->Link_ID
\n"); - } - } - } - - ## In order to increase the # of cursors per system/user go edit the - ## init.ora file and increase the max_open_cursors parameter. Yours is on - ## the default value, 100 per user. - ## We tried to change the behaviour of query() in a way, that it tries - ## to safe cursors, but on the other side be carefull with this, that you - ## don't use an old result. - ## - ## You can also make extensive use of ->disconnect()! - ## The unused QueryIDs will be recycled sometimes. - - function query($Query_String) { - - /* No empty queries, please, since PHP4 chokes on them. */ - if ($Query_String == "") - /* The empty query string is passed on from the constructor, - * when calling the class without a query, e.g. in situations - * like these: '$db = new DB_Sql_Subclass;' - */ - return 0; - - $this->connect(); - $this->lastQuery=$Query_String; - - if (!$this->Query_ID) { - $this->Query_ID= ora_open($this->Link_ID); - } - if($this->Debug) { - printf("Debug: query = %s
\n", $Query_String); - printf("
Debug: Query_ID: %d
\n", $this->Query_ID); - } - - if(!@ora_parse($this->Query_ID,$Query_String)) { - $this->Errno=ora_errorcode($this->Query_ID); - $this->Error=ora_error($this->Query_ID); - $this->halt("
ora_parse() failed:
$Query_String
Snap & paste this to sqlplus!"); - } elseif (!@ora_exec($this->Query_ID)) { - $this->Errno=ora_errorcode($this->Query_ID); - $this->Error=ora_error($this->Query_ID); - $this->halt("
\n$Query_String\n
Snap & paste this to sqlplus!"); - } - - $this->Row=0; - - if(!$this->Query_ID) { - $this->halt("Invalid SQL: ".$Query_String); - } - - return $this->Query_ID; - } - - function next_record() { - if (!$this->no_next_fetch && - 0 == ora_fetch($this->Query_ID)) { - if ($this->Debug) { - printf("
next_record(): ID: %d,Rows: %d
\n", - $this->Query_ID,$this->num_rows()); - } - $this->Row +=1; - - $errno=ora_errorcode($this->Query_ID); - if(1403 == $errno) { # 1043 means no more records found - $this->Errno=0; - $this->Error=""; - $this->disconnect(); - $stat=0; - } else { - $this->Error=ora_error($this->Query_ID); - $this->Errno=$errno; - if($this->Debug) { - printf("
%d Error: %s", - $this->Errno, - $this->Error); - } - $stat=0; - } - } else { - $this->no_next_fetch=false; - for($ix=0;$ixQuery_ID);$ix++) { - $col=strtolower(ora_columnname($this->Query_ID,$ix)); - $value=ora_getcolumn($this->Query_ID,$ix); - $this->Record[ "$col" ] = $value; -# echo"[$col]: $value
\n"; - } - $stat=1; - } - - return $stat; - } - - ## seek() works only for $pos - 1 and $pos - ## Perhaps I make a own implementation, but my - ## opinion is, that this should be done by PHP3 - function seek($pos) { - if ($this->Row - 1 == $pos) { - $this->no_next_fetch=true; - } elseif ($this->Row == $pos ) { - ## do nothing - } else { - $this->halt("Invalid seek(): Position is cannot be handled by API.
". - "Difference too big. Wanted: $pos Current pos: $this->Row"); - } - if ($Debug) echo "
Debug: seek = $pos
"; - $this->Row=$pos; - } - - function lock($table, $mode = "write") { - if ($mode == "write") { - $result = ora_do($this->Link_ID, "lock table $table in row exclusive mode"); - } else { - $result = 1; - } - return $result; - } - - function unlock() { - return ora_do($this->Link_ID, "commit"); - } - - function metadata($table,$full=false) { - $count = 0; - $id = 0; - $res = array(); - - /* - * Due to compatibility problems with Table we changed the behavior - * of metadata(); - * depending on $full, metadata returns the following values: - * - * - full is false (default): - * $result[]: - * [0]["table"] table name - * [0]["name"] field name - * [0]["type"] field type - * [0]["len"] field length - * [0]["flags"] field flags ("NOT NULL", "INDEX") - * [0]["format"] precision and scale of number (eg. "10,2") or empty - * [0]["index"] name of index (if has one) - * [0]["chars"] number of chars (if any char-type) - * - * - full is true - * $result[]: - * ["num_fields"] number of metadata records - * [0]["table"] table name - * [0]["name"] field name - * [0]["type"] field type - * [0]["len"] field length - * [0]["flags"] field flags ("NOT NULL", "INDEX") - * [0]["format"] precision and scale of number (eg. "10,2") or empty - * [0]["index"] name of index (if has one) - * [0]["chars"] number of chars (if any char-type) - * ["meta"][field name] index of field named "field name" - * The last one is used, if you have a field name, but no index. - * Test: if (isset($result['meta']['myfield'])) {} ... - */ - - $this->connect(); - - ## This is a RIGHT OUTER JOIN: "(+)", if you want to see, what - ## this query results try the following: - ## $table = new Table; $db = new my_DB_Sql; # you have to make - ## # your own class - ## $table->show_results($db->query(see query vvvvvv)) - ## - $this->query("SELECT T.table_name,T.column_name,T.data_type,". - "T.data_length,T.data_precision,T.data_scale,T.nullable,". - "T.char_col_decl_length,I.index_name". - " FROM ALL_TAB_COLUMNS T,ALL_IND_COLUMNS I". - " WHERE T.column_name=I.column_name (+)". - " AND T.table_name=I.table_name (+)". - " AND T.table_name=UPPER('$table') ORDER BY T.column_id"); - - $i=0; - while ($this->next_record()) { - $res[$i]["table"] = $this->Record[table_name]; - $res[$i]["name"] = strtolower($this->Record[column_name]); - $res[$i]["type"] = $this->Record[data_type]; - $res[$i]["len"] = $this->Record[data_length]; - if ($this->Record[index_name]) $res[$i]["flags"] = "INDEX "; - $res[$i]["flags"] .= ( $this->Record[nullable] == 'N') ? '' : 'NOT NULL'; - $res[$i]["format"]= (int)$this->Record[data_precision].",". - (int)$this->Record[data_scale]; - if ("0,0"==$res[$i]["format"]) $res[$i]["format"]=''; - $res[$i]["index"] = $this->Record[index_name]; - $res[$i]["chars"] = $this->Record[char_col_decl_length]; - if ($full) { - $j=$res[$i]["name"]; - $res["meta"][$j] = $i; - $res["meta"][strtoupper($j)] = $i; - } - if ($full) $res["meta"][$res[$i]["name"]] = $i; - $i++; - } - if ($full) $res["num_fields"]=$i; -# $this->disconnect(); - return $res; - } - - ## THIS FUNCTION IS UNSTESTED! - function affected_rows() { - if ($Debug) echo "
Debug: affected_rows=". ora_numrows($this->Query_ID)."
"; - return ora_numrows($this->Query_ID); - } - - ## Known bugs: It will not work for SELECT DISTINCT and any - ## other constructs which are depending on the resulting rows. - ## So you *really need* to check every query you make, if it - ## will work with it. - ## - ## Also, for a qualified replacement you need to parse the - ## selection, cause this will fail: "SELECT id, from FROM ..."). - ## "FROM" is - as far as I know a keyword in Oracle, so it can - ## only be used in this way. But you have been warned. - function num_rows() { - $curs=ora_open($this->Link_ID); - - ## this is the important part and it is also the HACK! - if (eregi("^[[:space:]]*SELECT[[:space:]]",$this->lastQuery) ) { - $from_pos = strpos(strtoupper($this->lastQuery),"FROM"); - $q = "SELECT count(*) ". substr($this->lastQuery, $from_pos); - - ORA_parse($curs,$q); - ORA_exec($curs); - ORA_fetch($curs); - if ($Debug) echo "
Debug: num_rows=". ORA_getcolumn($curs,0)."
"; - return(ORA_getcolumn($curs,0)); - } else { - $this->halt("Last Query was not a SELECT: $this->lastQuery"); - } - } - - function num_fields() { - if ($Debug) echo "
Debug: num_fields=". ora_numcols($this->Query_ID) . "
"; - return ora_numcols($this->Query_ID); - } - - function nf() { - return $this->num_rows(); - } - - function np() { - print $this->num_rows(); - } - - function f($Name) { - return $this->Record[$Name]; - } - - function p($Name) { - print $this->Record[$Name]; - } - - /* public: sequence number */ - function nextid($seq_name) - { - $this->connect(); - - /* Independent Query_ID */ - $Query_ID = ora_open($this->Link_ID); - - if(!@ora_parse($Query_ID,"SELECT $seq_name.NEXTVAL FROM DUAL")) - { - // There is no such sequence yet, then create it - if(!@ora_parse($Query_ID,"CREATE SEQUENCE $seq_name") - || - !@ora_exec($Query_ID) - ) - { - $this->halt("
nextid() function - unable to create sequence"); - return 0; - } - @ora_parse($Query_ID,"SELECT $seq_name.NEXTVAL FROM DUAL"); - } - if (!@ora_exec($Query_ID)) { - $this->halt("
ora_exec() failed:
nextID function"); - } - if (@ora_fetch($Query_ID) ) { - $next_id = ora_getcolumn($Query_ID, 0); - } - else { - $next_id = 0; - } - if ( Query_ID > 0 ) { - ora_close(Query_ID); - } - - return $next_id; - } - - function disconnect() { - if($this->Debug) { - echo "Debug: Disconnecting $this->Query_ID...
\n"; - } - if ( $this->Query_ID < 1 ) { - echo "Warning: disconnect(): Cannot free ID $this->Query_ID\n"; -# return(); - } - ora_close($this->Query_ID); - $this->Query_ID=0; - } - - /* private: error handling */ - function halt($msg) { - if ($this->Halt_On_Error == "no") - return; - - $this->haltmsg($msg); - - if ($this->Halt_On_Error != "report") - die("Session halted."); - } - - function haltmsg($msg) { - printf("Database error: %s
\n", $msg); - printf("Oracle Error: %s (%s)
\n", - $this->Errno, - $this->Error); - } - - function table_names() { - $this->connect(); - $this->query(" - SELECT table_name,tablespace_name - FROM user_tables"); - $i=0; - while ($this->next_record()) - { - $info[$i]["table_name"] =$this->Record["table_name"]; - $info[$i]["tablespace_name"]=$this->Record["tablespace_name"]; - $i++; - } - return $info; - } -} -?> diff --git a/phplib/db_pgsql.inc b/phplib/db_pgsql.inc deleted file mode 100755 index 039defa..0000000 --- a/phplib/db_pgsql.inc +++ /dev/null @@ -1,225 +0,0 @@ -query($query); - } - - function connect() { - if ( 0 == $this->Link_ID ) { - $cstr = "dbname=".$this->Database. - $this->ifadd($this->Host, "host="). - $this->ifadd($this->Port, "port="). - $this->ifadd($this->User, "user="). - $this->ifadd($this->Password, "password="); - $this->Link_ID=pg_pconnect($cstr); - if (!$this->Link_ID) { - $this->halt("Link-ID == false, pconnect failed"); - } - } - } - - function query($Query_String) { - /* No empty queries, please, since PHP4 chokes on them. */ - if ($Query_String == "") - /* The empty query string is passed on from the constructor, - * when calling the class without a query, e.g. in situations - * like these: '$db = new DB_Sql_Subclass;' - */ - return 0; - - $this->connect(); - -# printf("
Debug: query = %s
\n", $Query_String); - - $this->Query_ID = pg_Exec($this->Link_ID, $Query_String); - $this->Row = 0; - - $this->Error = pg_ErrorMessage($this->Link_ID); - $this->Errno = ($this->Error == "")?0:1; - if (!$this->Query_ID) { - $this->halt("Invalid SQL: ".$Query_String); - } - - return $this->Query_ID; - } - - function next_record() { - $this->Record = @pg_fetch_array($this->Query_ID, $this->Row++); - - $this->Error = pg_ErrorMessage($this->Link_ID); - $this->Errno = ($this->Error == "")?0:1; - - $stat = is_array($this->Record); - if (!$stat && $this->Auto_Free) { - pg_freeresult($this->Query_ID); - $this->Query_ID = 0; - } - return $stat; - } - - function seek($pos) { - $this->Row = $pos; - } - - function lock($table, $mode = "write") { - if ($mode == "write") { - $result = pg_Exec($this->Link_ID, "lock table $table"); - } else { - $result = 1; - } - return $result; - } - - function unlock() { - return pg_Exec($this->Link_ID, "commit"); - } - - - /* public: sequence numbers */ - function nextid($seq_name) { - $this->connect(); - - if ($this->lock($this->Seq_Table)) { - /* get sequence number (locked) and increment */ - $q = sprintf("select nextid from %s where seq_name = '%s'", - $this->Seq_Table, - $seq_name); - $id = @pg_Exec($this->Link_ID, $q); - $res = @pg_Fetch_Array($id, 0); - - /* No current value, make one */ - if (!is_array($res)) { - $currentid = 0; - $q = sprintf("insert into %s values('%s', %s)", - $this->Seq_Table, - $seq_name, - $currentid); - $id = @pg_Exec($this->Link_ID, $q); - } else { - $currentid = $res["nextid"]; - } - $nextid = $currentid + 1; - $q = sprintf("update %s set nextid = '%s' where seq_name = '%s'", - $this->Seq_Table, - $nextid, - $seq_name); - $id = @pg_Exec($this->Link_ID, $q); - $this->unlock(); - } else { - $this->halt("cannot lock ".$this->Seq_Table." - has it been created?"); - return 0; - } - return $nextid; - } - - - - function metadata($table) { - $count = 0; - $id = 0; - $res = array(); - - $this->connect(); - $id = pg_exec($this->Link_ID, "select * from $table"); - if ($id < 0) { - $this->Error = pg_ErrorMessage($id); - $this->Errno = 1; - $this->halt("Metadata query failed."); - } - $count = pg_NumFields($id); - - for ($i=0; $i<$count; $i++) { - $res[$i]["table"] = $table; - $res[$i]["name"] = pg_FieldName ($id, $i); - $res[$i]["type"] = pg_FieldType ($id, $i); - $res[$i]["len"] = pg_FieldSize ($id, $i); - $res[$i]["flags"] = ""; - } - - pg_FreeResult($id); - return $res; - } - - function affected_rows() { - return pg_cmdtuples($this->Query_ID); - } - - function num_rows() { - return pg_numrows($this->Query_ID); - } - - function num_fields() { - return pg_numfields($this->Query_ID); - } - - function nf() { - return $this->num_rows(); - } - - function np() { - print $this->num_rows(); - } - - function f($Name) { - return $this->Record[$Name]; - } - - function p($Name) { - print $this->Record[$Name]; - } - - function halt($msg) { - printf("Database error: %s
\n", $msg); - printf("PostgreSQL Error: %s (%s)
\n", - $this->Errno, - $this->Error); - die("Session halted."); - } - - function table_names() { - $this->query("select relname from pg_class where relkind = 'r' and not relname like 'pg_%'"); - $i=0; - while ($this->next_record()) - { - $return[$i]["table_name"]= $this->f(0); - $return[$i]["tablespace_name"]=$this->Database; - $return[$i]["database"]=$this->Database; - $i++; - } - return $return; - } -} -?> diff --git a/phplib/db_sybase.inc b/phplib/db_sybase.inc deleted file mode 100755 index 63f9e15..0000000 --- a/phplib/db_sybase.inc +++ /dev/null @@ -1,148 +0,0 @@ - - * - * metadata() contributed by Adelino Monteiro - * - * $Id$ - * - */ - -class DB_Sql { - var $Host = ""; - var $Database = ""; - var $User = ""; - var $Password = ""; - - var $Link_ID = 0; - var $Query_ID = 0; - var $Record = array(); - var $Row; - - var $Auto_Free = 0; ## Set this to 1 for automatic sybase_free_result() - - /* public: constructor */ - function DB_Sql($query = "") { - $this->query($query); - } - - function connect() { - if ( 0 == $this->Link_ID ) { - $this->Link_ID=sybase_pconnect($this->Host,$this->User,$this->Password); - if (!$this->Link_ID) { - $this->halt("Link-ID == false, pconnect failed"); - } - if(!sybase_select_db($this->Database, $this->Link_ID)) { - $this->halt("cannot use database ".$this->Database); - } - } - } - - function query($Query_String) { - - - /* No empty queries, please, since PHP4 chokes on them. */ - if ($Query_String == "") - /* The empty query string is passed on from the constructor, - * when calling the class without a query, e.g. in situations - * like these: '$db = new DB_Sql_Subclass;' - */ - return 0; - - $this->connect(); - -# printf("Debug: query = %s
\n", $Query_String); - - $this->Query_ID = sybase_query($Query_String,$this->Link_ID); - $this->Row = 0; - if (!$this->Query_ID) { - $this->halt("Invalid SQL: ".$Query_String); - } - - return $this->Query_ID; - } - - function next_record() { - $this->Record = sybase_fetch_array($this->Query_ID); - $this->Row += 1; - - $stat = is_array($this->Record); - if (!$stat && $this->Auto_Free) { - sybase_free_result($this->Query_ID); - $this->Query_ID = 0; - } - return $stat; - } - - function seek($pos) { - $status = sybase_data_seek($this->Query_ID, $pos); - if ($status) - $this->Row = $pos; - return; - } - - function metadata($table) { - $count = 0; - $id = 0; - $res = array(); - - $this->connect(); - $result = $this->query("exec sp_columns $table"); - if ($result < 0) { - $this->Errno = 1; - $this->Error = "Metadata query failed"; - $this->halt("Metadata query failed."); - } - $count = sybase_num_rows($result); - - for ($i=0; $i<$count; $i++) { - $res[$i]["table"] = $table ; - $res[$i]["name"] = sybase_result ($result, $i, "COLUMN_NAME"); - $res[$i]["type"] = sybase_result ($result, $i, "TYPE_NAME"); - $res[$i]["len"] = sybase_result ($result, $i, "LENGTH"); - $res[$i]["position"] = sybase_result ($result, $i, "ORDINAL_POSITION"); - $res[$i]["flags"] = sybase_result ($result, $i, "REMARKS"); - - } - } - - function affected_rows() { - return sybase_affected_rows($this->Query_ID); - } - - function num_rows() { - return sybase_num_rows($this->Query_ID); - } - - function num_fields() { - return sybase_num_fields($this->Query_ID); - } - - function nf() { - return $this->num_rows(); - } - - function np() { - print $this->num_rows(); - } - - function f($Name) { - return $this->Record[$Name]; - } - - function p($Name) { - print $this->Record[$Name]; - } - - function halt($msg) { - printf("Database error: %s
\n", $msg); - printf("Sybase Error
\n"); - die("Session halted."); - } -} -?> diff --git a/phplib/db_usql.inc b/phplib/db_usql.inc deleted file mode 100755 index 3bf5987..0000000 --- a/phplib/db_usql.inc +++ /dev/null @@ -1,76 +0,0 @@ -Record)) - if (ereg("[A-Za-z][A-Za-z0-9_]*", $key)) { - $field_name = strtoupper($key); - global $$field_name; - $$field_name=$val; - }; - } - -//-------------------------------------------------------------- -// this function can be used to export all the records of -// a table on the output in the form of a call to the db_sql -// query function with an insert statement. -//-------------------------------------------------------------- - function dump_table($tablename, $filter="") { - $this->query(sprintf("select * from %s", $tablename)); - while ($this->next_record()) { - $this->dump_record($tablename, $filter); - }; - } - -//-------------------------------------------------------------- -// this function can be used to export all the records of -// a query on the output in the form of a call to the db_sql -// query function with an insert statement. -//-------------------------------------------------------------- - function dump_query($tablename, $filter="") { - //$this->query(sprintf("select * from %s", $tablename)); - while ($this->next_record()) { - $this->dump_record($tablename, $filter); - }; - } - - function dump_record($tablename, $filter="") { - $fields=""; - $values=""; - while (list($key, $val) = each($this->Record)) - if (ereg("[A-Za-z][A-Za-z0-9_]*", $key)) { - $field_name = strtoupper($key); - if (!empty($val)) - if (strstr( $filter, $field_name )=="") { - $fields.="$field_name ,"; - $val=ereg_replace("'","''",$val); - $val=ereg_replace("\"","\\\"",$val); - //addslashes($val); - $values.="'$val' ,"; - }; - } - $fields=substr($fields, 0, strlen($fields)-1); - $values=substr($values, 0, strlen($values)-1); - $insert=sprintf("insert into %s(%s) values(%s)", $tablename, $fields, $values); - echo "\$db->query(\"$insert\");\n"; - } - }; - -?> diff --git a/phplib/query_sql.inc b/phplib/query_sql.inc deleted file mode 100755 index d029e94..0000000 --- a/phplib/query_sql.inc +++ /dev/null @@ -1,742 +0,0 @@ - - * I took many ideas from his SQL.inc, thanks! :-) - * The idea is of this class is based in November 1997, - * it was a collection of functions for PHP/FI and mSQL. - * - * $Id$ - * - */ - - -/* -The Query-class is an enhancement to the db_*-classes. Currently It supports -mySQL an Oracle but it is easy expandable. See down. - -It always needs the class DB_Sql! - -Query is fully upward compatible with DB_Sql. Example: - -OLD: NEW: - -require("db_mysql.inc"); require("db_mysql.inc"); -class hugobla extends DB_sql {} require("query_sql.inc"); -$db = new hugobla; class hugobla extends Query {} - $db = new hugobla; - -It just provides a number of new functions. - -The Query-class is inteded to help you with creating selects, inserts, -updates, where-clauses etc. Not just *simple* selects, but longer ones. It -is indeed a great help for tables with more than 10-20 columns. But it can -also be used for simple and small selects. The inbuilt checks help you -programming saver. - -Here is an example: - -file: insert.php3 ------------------- -query($db->insert_plain_Clause("mytable",$db->capture_vars("mytable"),ARRAY())); -echo "Values inserted"; - -?> - -file: insert2.php3 -------------------- -query($db->insert_plain_Clause("mytable",$db->capture_vars("mytable"), - ARRAY(myindex=>'NULL',mytime='func'))); -echo "Values inserted: "$db->last_insert_id(); - -?> - -This example is nice, cause you see how easy it can be used. :-) - -The best thing is, that you don't have to care, if a field is a string or a -number. The values are automatically converted into the right form. The type -of the vars are read from the table. Stringvalues are encapsulated with ' -(configurable) and escaped (the code for this is currently not good - we are -assuming, that PHP is configured not to encapsulate strings), int- -and real-values are casted. It can handle "NULL"-values, function-statements -or other values for insertion. - -You will make less errors. - -mySQL and most other DB's accept a a short form of insert-clause (INSERT -INTO bla VALUES (...)). The Query-class will always make the longer form -(INSERT INTO BLA (...) VALUES (...)). This makes it possible to use ALTER -TABLE-commands without changing the program! E.g. changing a field in a -table from NUMBER to VARCHAR(10) is fully encapsulated with this class. - -The class supports currently only mysql and oracle. I think the differences -between the DBs are encapsulated enough in the db_* classes, so it is -possible to handle the remaining small differences inside this class (this -affects mainly the function sql2phptype() ) and it could be easiely extended -(asuming, that the metadata()-function of the db_*-class works correctly). -In this case it is important, that the $type-variable in the db_*.inc-class -is correctly set. - - -TODO-list: -- A method to create querys like the LIMIT-clause in mySQL. For Oracle - this works: - - select linenum, foo, bar - from (select rownum as linenum, foo, bar from - (select foo,bar from chaos order by bar) ) - where linenum between 11 and 20; - -- cleaner escaping, handling of \ and NUL (current code is bullshit) - Some ideas? - -- Little Alta-Vista: add functions to create a where clause from a search - string with rules to handle searching for more than one word. - half automatic generating search patterns into a where-clause - simple search engine support, simple support for semi full-text-search - -- automatic configurable manipulation of values, eg. - triming of strings (delete whitespace at begin and end) - also : TOUPPER, TOLOWER etc - -- SELECT-Clause (GROUP BY, HAVING, JOIN...) - -- make new functions insert_Clause() etc. which inserts only the - fields they got from your call (the current will do "plain" insert) - -- where_Clause() - creating WHERE for select, update, exists etc. - -- serv all queries directly into db, return just the handle - (hm, how to deal with the DB-handle?) - -- Return a 2-dimensional (Table-compatible) field from select (not so important) - -- The sql2phptype() can be used to help creating automatic input forms - for a table - -DEPENDING: -- db_mysql: new function metatabledata(), which returns the table-info from - current selected table (will return multiple table-columns with a join) -- db_mysql: perhaps the function sql2phptype() should be placed there? - - -For developers of new db_*.inc: the function metadata() is very important -for the correct work of this class. T - -*/ - -class Query extends DB_Sql { - - ## DONT FORGET to set the variables from DB_Sql! See there! - - ## For debugging: if set to TRUE the Query is printed out, - ## before executing or returning - var $Q_Debug=false; - - ## set this to another value, if you want to hide it - ## in your HTML-code - ## example: var $Q_Debug_print="\n\n"; - var $Q_Debug_print="
QDebug:\n%s\n
\n"; - - ## Set this to TRUE if you only want to test, which query - ## will be created (ideal in combination with $Q_Debug) - ## This depends only functions which will make changes - var $No_Write=false; - - ## currently unused, this var is just an idea for later use. - var $Backslash_N_is_NULL = false; - - ## Metacache: see funtcion metadata_buffered() - var $meta_cache_off = false; - - ## This is the char, which will be replaced by \char. - ## PHP3 seems to be NOT binary-safe, so not quoting - ## for \0 (some ideas?) - ## we use ereg_replace to do the replacements. - ## with PHP3.0.6 you should replace this with str_replace()! - ## Quoting = 1 -> normal quoting using AddSlashes - ## 2 -> Replace \' to '' - needed eg. for sybase or oracle - var $Quoting=1; - var $Quotechar="'"; - - var $StrLengTrunc = false; - var $StrLengWarn = false; - - ########################### - ## _QDebug - function _QDebug ($str) { - if ($this->Q_Debug) { - printf($this->Q_Debug_print,$str); - } - } - - ########################### - ## Set DB-Classname - ## This is only a 3rd posibility for setting the classname - ## - function set_db_class ($db_class) { - $this->Database=$db_class; - } - - - ########################### - ## This function gets a datatype from the DB and returns an - ## equivalent datatype for PHP - ## - ## It returns also a subtype for a string - ## - function sql2phptype ($type,$format='') { - ## $this->type is currently either "mysql" or "oracle" - switch ($this->type) { - case "mysql": - switch ($type) { - case "var string": - case "string" : - case "char" : - return(Array("string","")); - break; - case "timestamp" : - case "datetime" : - case "date" : - case "time" : - return(Array("string","date")); - break; - case "blob" : - return(Array("string","blob")); - break; - case "real" : - return(Array("double","")); - break; - case "long" : - default : - return(Array("int","")); - break; - } - break; - case "oracle": - switch ($type) { - case "VARCHAR2" : - case "VARCHAR" : - case "CHAR" : - return(Array("string","")); - break; - case "DATE" : - return(Array("string","date")); - break; - case "BLOB" : - case "CLOB" : - case "BFILE" : - case "RAW" : - case "LONG" : - case "LONG RAW" : - return(Array("string","blob")); - break; - case "NUMBER" : - if ($format) { - return(Array("double","")); - } else { - return(Array("int","")); - } - break; - default : - $this->halt("sql2phptype(): Type is not a valid value: '$type'"); - break; - } - break; - default: - $this->halt("sql2phptype(): DB-type is not a valid value: ".$this->type); - break; - } - } - - - ####################################### - ## This function returns a PHP-variable depending - ## on type. E.g. a string is returned as 'string' - ## - ## The parameters mean - ## $val - the value - ## There is a special case: If value is "NULL" and - ## the type is not "string" or subtype is empty, then - ## a value "NULL" is inserted. This let you just spare - ## a little bit work with $special - ## - ## $meta - the meta information for this field (that's what - ## is returned by metadata() from DB_sql-class, but just one - ## single row, e.g. $meta[2], not hole $meta). - ## - ## $special - Overwrites the type of the var if set. Some special - ## meanings: - ## "NULL" means, that this value must be set to "NULL" - ## "func" means, that $val should be untouched - - ## e.g. to insert the value of a SQL-function - ## [ INSERT INTO bla VALUES ( time=NOW() ) ] - ## - - function convert ($val,$meta,$special="") { - list($type,$subtype)=$this->sql2phptype($meta["type"],$meta["format"]); - if (($val == "NULL" && - ($type != "string" || $type[1] != "")) || - $special == "NULL") { - $type="NULL"; - } else { - if ($special) { - $type=$special; - if ($type!="func") { - $val=$type; - $type="func"; - } - } - } - switch ($type) { - case "string" : - $val=(string)$val; - if ($this->Quoting) { - $val=AddSlashes($val); - } - if ($this->Quoting==2) { - $val=str_replace("\\'","''",$val); - } - if ($subtype!='date' && - ( $this->StrLengTrunc || $this->StrLengWarn ) ) { - if ( strlen($val) > $meta[len] ) { - if ($this->StrLengWarn) { - echo "
STRING TOO LONG: '$meta[name]'"; - if ($this->StrLengTrunc) { - echo ", TRUNCATING!"; - } - } - if ($this->StrLengTrunc) { - $val=substr($val,0,$meta[len]); - } - } - } - $val=$this->Quotechar . $val . $this->Quotechar; - break; - case "int" : - $val=(int)$val; - break; - case "double" : - $val=(double)$val; - break; - case "NULL" : - $val="NULL"; - break; - case "func" : - $val=(string)$val; - break; - default : - echo "UNKNOWN TYPE: $type
"; - } - $this->_QDebug("Val: $meta[name] => $val
"); - return(Array($val,$meta["name"])); - } - - - ## - ## Function to generate a plain INSERT-Clause - ## ("plain" means, that every field in the table will - ## be set to a value, default is '' or 0 if nothing said - ## in $special) - ## - ## $fields is an assoc. Array consisting out of - ## table_name => value-pairs - ## $special is an assoc. field which will commit special - ## handling to convert() (See there) - ## $check could be "strong" or "soft". - ## "soft" won't tell you if there were to less - ## or too much fields (good for debuging) - ## - ## returns the insert clause. It's on you to modify it - ## and send it to your DB - ## - function insert_plain_Clause ($table,$fields,$special,$check="soft") { - $meta=$this->metadata_buffered($table); - - for ($i=0; $i < $meta["num_fields"]; $i++) { - $j=$meta[$i]["name"]; - ## NOT IMPLEMENTED: SEARCHING FOR $fields[$i] - list($val["val"][$i],$val["name"][$i])= - $this->convert($fields[$j],$meta[$i],$special[$j]); - } - if (Count($fields)!=Count($val["name"]) && $check=="strong") { - echo "WARNING: insert_plain_clause(): There are not the same number of". - " fields as in table for INSERT
"; - } - $q=sprintf("INSERT INTO %s (%s) VALUES (%s)", - $table,join($val["name"],","), - join($val["val"],",")); - $this->_QDebug($q); - return($q); - } - - # Replace, a special mySQL-function, same as INSERT - function replace_plain_Clause ($table,$fields,$special,$check="soft") { - $meta=$this->metadata_buffered($table); - - for ($i=0; $i < $meta["num_fields"]; $i++) { - $j=$meta[$i]["name"]; - ## NOT IMPLEMENTED: SEARCHING FOR $fields[$i] - list($val["val"][$i],$val["name"][$i])= - $this->convert($fields[$j],$meta[$i],$special[$j]); - } - if (Count($fields)!=Count($val["name"]) && $check=="strong") { - echo "WARNING: replace_plain_Clause(): There are not the same number of". - " fields as in table for INSERT
"; - } - $q=sprintf("REPLACE %s (%s) VALUES (%s)", - $table,join($val["name"],","), - join($val["val"],",")); - $this->_QDebug($q); - return($q); - } - - ## - ## This function is nearly the same, as insert_plain_Clause, - ## The where parameter is new and should be generated by yourself - ## The check parameter knows 3 values: strong, soft and weak - ## weak enables you to sent a query without $where (enables you - ## to update the hole table) - ## - function update_plain_Clause ($table,$fields,$special,$where,$check="soft") { - $meta=$this->metadata_buffered($table); - if (!$where && $check!="weak") { - echo "ERROR: update_plain_Clause(): Parameter \$where is empty!
"; - return(false); - } - - for ($i=0; $i < $meta["num_fields"]; $i++) { - $j=$meta[$i]["name"]; - ## NOT IMPLEMENTED: SEARCHING FOR $fields[$i] - list($val["val"][$i],$val["name"][$i])= - $this->convert($fields[$j],$meta[$i],$special[$j]); -#echo "V: ".$val["name"][$i]." : ". $val["val"][$i]." - ".$fields[$j]."
"; - } - if (Count($fields)!=Count($val["name"]) && $check=="strong") { - echo "WARNING: update_plain_Clause(): There are not the same number of". - " fields for INSERT
"; - } - for ($i=0 ; $i < Count ($val["name"]); $i++ ) { - $s[]=$val["name"][$i]."=".$val["val"][$i]; - } - $q=sprintf("UPDATE %s SET %s",$table,join($s,",")); - if ($where) { - if (!eregi("^[[:space:]]*WHERE",$where)) { - ## insert "WHERE" if not set - $where="WHERE $where"; - } - $q.=" $where"; - } - $this->_QDebug($q); - return($q); - } - - - ## - ## This function is nearly the same, as insert_Clause, - ## The where parameter is new and should be generated by yourself - ## The check parameter knows 3 values: strong, soft and weak - ## weak enables you to sent a query without $where (enables you - ## to update the hole table) - ## - function update_Clause ($table,$fields,$special,$where,$check="soft") { - $meta=$this->metadata_buffered($table); - if (!$where && $check!="weak") { - echo "ERROR: update_Clause(): Parameter \$where is empty!
"; - return(false); - } - - $i=0; - for (reset($fields); list($key,$val)=each($fields); $i++) { - if ( isset($meta[meta][$key]) ) { - $j=$meta[meta][$key]; - list($v["val"][$i],$v["name"][$i])= - $this->convert($val,$meta[$j],$special[$key]); - } - } - for ($i=0 ; $i < Count ($v["name"]); $i++ ) { - $s[]=$v["name"][$i]."=".$v["val"][$i]; - } - if (Count($s)) { - $q=sprintf("UPDATE %s SET %s",$table,join($s,",")); - if ($where) { - if (!eregi("^[[:space:]]*WHERE",$where)) { - ## insert "WHERE" if not set - $where="WHERE $where"; - } - $q.=" $where"; - } - } - $this->_QDebug($q); - return($q); - } - - - - ## - ## DELETE - ## deletes the selected Table - ## $check can be "soft" and "weak". Weak let's you delete the - ## hole table, if you want - ## - function delete_Clause ($table,$where,$check="soft") { - if (!$where && $check!="weak") { - echo "ERROR: delete_Clause(): Parameter \$where is empty!
"; - return(false); - } - - $q=sprintf("DELETE FROM %s",$table); - if ($where) { - if (!eregi("^[[:space:]]*WHERE",$where)) { - ## insert "WHERE" if not set - $where="WHERE $where"; - } - $q.=" $where"; - } - $this->_QDebug($q); - return($q); - } - - - ## - ## This function checks wether in table $table a - ## field $name is set with value $val - ## - ## it returns the number of found matches or zero - ## - function exists ($table,$name,$val) { - $meta=$this->metadata_buffered($table); - $j=$meta["meta"][$name]; - list($k)=$this->convert($val,$meta[$j]); - $q=sprintf("SELECT COUNT(%s) as c FROM %s WHERE %s=%s", - $name,$table,$name,$k); - $this->_QDebugs($q); - $this->query($q); - $this->next_record(); - return($this->f("c")); - } - - ## - ## This function creates a query like exists, but returns - ## an assoc array of the first found row, or false if nothing found - ## field $name is set with value $val - ## - function getrow ($table,$name,$val) { - $meta=$this->metadata_buffered($table); - $j=$meta[meta][$name]; - list($k)=$this->convert($val,$meta[$j]); - $q=sprintf("SELECT * FROM %s WHERE %s=%s", - $table,$name,$k); - $this->_QDebug($q); - $this->query($q); - if ($this->next_record()) { - return($this->Record); - } else { - echo "
WARNING: getrow(): KEY: $name VAL: $val not found
"; - return(false); - } - } - - - - ## - ## WHERE-PLAIN-CLAUSE - ## Let you generate a WHERE-Clause with a Loop. - ## - ## Returns a where-clause beginning with " WHERE " - ## - ## This function generates a where-clause - ## $mywhere An array of simple expressions, eg. "firstname='Alex'" - ## $andor This string is printed bewtween the where-Array - ## default is 'AND'. It will handle an existing - ## $oldwhere correctly. You can set this to '', but then - ## the correct operator must be set by you in the where - ## $where an existing WHERE-clause. Default is empty. - ## $check if 'strong', it will stop, if an empty where-clause - ## will be returned, to avoid "full" selects. Default is soft - ## - function where_plain_Clause ($mywhere,$andor='AND',$where='',$check="soft") { - $meta=$this->metadata_buffered($table); - $q=''; - - for ($i=0; $i"; - } - $q=ereg_Replace("^ $andor "," WHERE ",$q); - $this->_QDebug("where_plain_Clause(): $q"); - return($q); - } - - ## - ## ANOTHER-WHERE-CLAUSE - ## - ## This function generates a where-clause beginning with " WHERE " - ## Different form where_plain_Clause() this function is fully automated - ## It can handle NULL-Values (IS NULL) in a special manner: - ## if a value of $fields is 'NULL', we are looking, if the - ## operator is '='. In this case the operator is changed into "IS" - ## in any other case it is changed into "IS NOT". - ## - ## $tables table - ## $fields Assoc name=>value-fields - ## $op Assoc name=>operator. If empty, '=' is taken. it is printed - ## *between* the name/value pairs. - ## if $op is 'func' the name is taken as function name, - ## inside the brakets is the value. - ## $special Affects the calculation of value. - ## See INSERT_CLAUSE() for more about this. - ## $andor This string is printed bewtween the name/value-pairs, - ## default is 'AND'. If $where is set, it prints - ## it directly at the end before concatenating - ## $where an existing WHERE-clause. Default is empty. - ## $check if 'strong', it will stop, if an empty where-clause - ## will be returned, to avoid "full" selects. Default is soft - ## - ## Returns a where-clause beginning with " WHERE " - ## - function where_Clause ($table,$fields,$op='',$special='', - $andor='AND',$where='',$check="soft") { - $meta=$this->metadata_buffered($table); - $q=''; - - if (!is_Array($op)) $op=ARRAY(); - if (!is_Array($special)) $op=ARRAY(); - if (!$andor) $andor='AND'; - - $i=0; - for (reset($fields); list($key,$val)=each($fields); $i++) { - list($k[val],$k[name])= - $this->convert($fields[$key],$meta[$meta[meta][$key]],$special[$key]); - if (!$op[$key]) $o='='; else $o=$op[$key]; - if ('NULL'==strval($k[val])) { - if ($o=='=' || strtoupper($o)=='IS') $o = 'IS'; - else $o = 'IS NOT'; - } - $q.=" $andor $k[name] $o $k[val]"; - } - if ($where) { - $where=eregi_Replace("^[[:space:]]*WHERE","",$where); - $q.=" $andor $where"; - } - if (!$q && $ckeck=='full') { - echo "WARNING: where_Clause(): WHERE-clause is empty!
"; - } - $q=ereg_Replace("^ $andor "," WHERE ",$q); - $this->_QDebug("where_Clause(): $q"); - return($q); - } - - - ## - ## capture-vars - ## - ## This function returns an assoc. Array consisting out of - ## name=>value-pairs needed by all the other functions. It reads - ## the name of the vars from the fields in $table and the values - ## from the $GLOBALS-var-field. - ## This has the sense, that you can name the variables in your - ## Input-Form exactly like the names in your table. This again - ## let make you less errors and less side effects. - ## - ## $table The name of the table - ## - function capture_vars ($table) { - $meta=$this->metadata_buffered($table); - $r=Array(); - for ($i=0; $i < $meta["num_fields"]; $i++) { - $j=$meta[$i]["name"]; - if (isset($GLOBALS[$j])) { - $r[$j] = $GLOBALS[$j]; - $this->_QDebug("Found $j: $r[$j]"); - } - } - return($r); - } - - ## - ## all_changed_vars - ## - ## This function returns an assoc. Array consisting out of - ## name=>value-pairs which have a different value from the value - ## currently existing in your table. This is needed by - ## update_Clause(), cause with this, the update-query can be shortened - ## to the maximum needed max. Can also be used for much other things, - ## e.g. checking if something in your form has been changed (in this - ## case it returns an empty array) - ## - ## $table The name of the table - ## $fields Your assoc value field, which you want to check for - ## $where The where-clause, which matches your row. - ## This functions writes warnings, if your where-clause - ## returns more than one row or nothing - ## - function all_changed_vars ($table,$fields,$where,$check='soft') { - $meta=$this->metadata_buffered($table); - - $q1="SELECT * FROM $table $where"; - $this->query($q1); - $r=Array(); - if ($this->next_record()) { - for ($i=0; $i < $meta["num_fields"]; $i++) { - $j=$meta[$i]["name"]; - if ($this->Record[$j]!=$fields[$j]) { - $r[$j]=$fields[$j]; - $this->_QDebug("Changed $j: ".$fields[$j]." -> ".$this->Record[$j]); - } - } - if ($this->next_record()) { - echo "ERROR: all_changed_vars(): Found more than one row!
"; - } - } elseif ($check!='soft') { - echo "
WARNING: all_changed_vars(): No row found!
"; - } - $this->_QDebug("WHERE: $where"); - return($r); - } - - ## - ## metadata_buffered (internal) - ## - ## This function calls metadata() if it won't find the buffer, - ## this speeds the Query-class strongly up, cause it is needed in nearly - ## every function - ## - ## $table the name of the table - ## - ## Returns the metadata-field - ## - function metadata_buffered($table) { - if ( !is_Array($this->meta_buf[$table]) || $this->meta_cache_off) { - return ($this->meta_buf[$table]=$this->metadata($table,true)); - } else { - return ($this->meta_buf[$table]); - } - } - - -} - -?> diff --git a/phplib/sqlquery.inc b/phplib/sqlquery.inc deleted file mode 100755 index cd47158..0000000 --- a/phplib/sqlquery.inc +++ /dev/null @@ -1,322 +0,0 @@ - array( - "searchfor" => "Suchen nach:", - "and" => "und", - "or" => "oder", - "like" => "enthält", - "reset" => "Neu", - "submit" => "Ausführen", - "less" => "Weniger", - "more" => "Mehr" - ), - - "en" => array( - "searchfor" => "Search for:", - "and" => "and", - "or" => "or", - "like" => "contains", - "reset" => "Reset Query", - "submit" => "Submit Query", - "less" => "Fewer", - "more" => "More" - ) - ); - - ## SQL comparision dictionary - var $compare = array( - "like" => "like", - ">" => ">", - "<" => "<", - - ">=" => ">=", - "<=" => "<=", - "=" => "=", - "<>" => "<>" - ); - - - function start($class = "") { - } - - ## selection: - ## - ## Create a "); - - return $res; - } - - ## fieldname: - ## - ## Given a basename $base, and attribute name $att and an attribute - ## number $num, this functions returns an input field name - ## $base[$name_$num]. - ## - ## This construct can be imported into a function namespace with a - ## single global instruction and the field name can be easily - ## exploded into component names and numbers. - - function makename($base, $att, $num) { - return sprintf("%s[%s_%d]", $base, $att, $num); - } - - ## form: - ## - ## Draw SQL Query selection form. - ## - function form($base, $option, $class = "", $target = "") { - global $sess; - - ## - ## load the HTML results of this function into $res. - ## - $res = ""; - - ## A hack. We cannot do language dependent initialisation of - ## static values. - if (isset($this->compare["like"])) { - $this->compare["like"] = $this->dict[$this->lang]["like"]; - } - - ## Prepare a self-directed container form - if ($this->container) { - $res .= sprintf("\n", - ($class)?" class=$class":"", - $this->dict[$this->lang]["searchfor"]); - } else { - $res .= sprintf(" %s\n", - ($class)?" class=$class":"", - $this->selection($this->makename($base, "conj", $i), - array("and" => $this->dict[$this->lang]["and"], "or" => $this->dict[$this->lang]["or"]), - $GLOBALS[$base]["conj_".$i], - "on", - $class)); - } - - ## Build field selection - $res .= sprintf(" %s\n", - ($class)?" class=$class":"", - $this->selection( - $this->makename($base, "sel", $i), - $option, - $GLOBALS[$base]["sel_".$i], - $this->translate, - $class)); - - ## Build comparison selection - $res .= sprintf(" %s\n", - ($class)?" class=$class":"", - $this->selection( - $this->makename($base, "comp", $i), - $this->compare, - $GLOBALS[$base]["comp_".$i], - "on", - $class)); - ## Create text input field. - $res .= sprintf(" \n", - ($class)?" class=$class":"", - $this->makename($base, "input", $i), - $GLOBALS[$base]["input_".$i], - $this->input_size, - $this->input_max, - ($class)?" class=$class":""); - - $res .= sprintf(" \n"); - } - - ## Create variable size buttons - $res .= sprintf(" \n", ($class)?" class=$class":""); - $res .= sprintf("  \n", ($class)?" class=$class":""); - - if ($this->variable) { - $res .= sprintf("  ", - ($class)?" class=$class":"", - $this->makename($base, "more", 0), - $this->dict[$this->lang]["more"]); - $res .= sprintf("\n", - $this->makename($base, "less", 0), - $this->dict[$this->lang]["less"]); - } else { - $res .= sprintf("  \n", ($class)?" class=$class":""); - } - - $res .= sprintf("  \n", ($class)?" class=$class":""); - $res .= sprintf("  ", - ($class)?" class=$class":"", - $this->dict[$this->lang]["reset"]); - $res .= sprintf("\n", - $this->makename($base, "submit", 0), - $this->dict[$this->lang]["submit"]); - - $res .= sprintf(" \n"); - $res .= sprintf("
\n", - ($class)?" class=$class":"", - ($class)?" class=$class":"", - ($class)?" class=$class":""); - } - $res .= sprintf("
\n", - $this->method, - ($target)?$target:$sess->self_url()); - - ## Prepare the inner table, laying out the selection elements - $res .= sprintf("\n", ($class)?" class=$class":""); - - ## Build $this->conditions many selection elements - for ($i=1; $i<= $this->conditions; $i++) { - $res .= sprintf(" \n", ($class)?" class=$class":""); - - ## Build conjunction (first row does not have a conjunction) - if ($i == 1) { - $res .= sprintf(" %s
\n"); - - $res .= sprintf("\n"); - if ($this->container) { - $res .= sprintf("\n"); - } - $res .= sprintf("\n", $this->classname); - - return $res; - } - - ## plain_where: - ## - ## Given a base variable name, creates a condition suitable for - ## the where clause of a SQL query. - ## - function plain_where($base) { - for($i=1; $i<=$this->conditions; $i++) { - ## Only create conditions for used input fields - if ($GLOBALS[$base]["input_".$i] == "") - continue; - - ## If necessary, add conjunction - if ($q != "") - $q .= sprintf(" %s ", $GLOBALS[$base]["conj_".$i]); - - ## Handle "like" - if ($GLOBALS[$base]["comp_".$i] == "like") - $v = "%".$GLOBALS[$base]["input_".$i]."%"; - else - $v = $GLOBALS[$base]["input_".$i]; - - ## Create subcondition - $q .= sprintf("%s %s '%s'", - $GLOBALS[$base]["sel_".$i], - $GLOBALS[$base]["comp_".$i], - $v); - } - - if (!$q) { - $q = "1=0"; - } - - return "( $q )"; - } - - ## translated_plain_where: - ## - ## Given a base variable name, creates a translated version of - ## the where clause of a SQL query. - ## - function translated_plain_where($base, $field) { - for($i=1; $i<=$this->conditions; $i++) { - ## Only create conditions for used input fields - if ($GLOBALS[$base]["input_".$i] == "") - continue; - - ## If necessary, add conjunction - if ($q != "") - $q .= sprintf(" %s ", $this->dict[$this->lang][$GLOBALS[$base]["conj_".$i]]); - - ## Handle "like" - if ($GLOBALS[$base]["comp_".$i] == "like") - $c = $this->dict[$this->lang][$GLOBALS[$base]["comp_".$i]]; - else - $c = $this->compare[$GLOBALS[$base]["comp_".$i]]; - - ## Create subcondition - $q .= sprintf("%s %s '%s'", - $field[$GLOBALS[$base]["sel_".$i]], - $c, - $GLOBALS[$base]["input_".$i]); - } - - if (!$q) { - $q = "1=0"; - } - - return "( $q )"; - } - - ## where: - ## - ## Same as plain_where(), but also inspects the submit button - ## used to submit the query. Changes $this->conditions appropriately. - function where($base, $incr = 1) { - if (isset($GLOBALS[$base]["less_0"])) - $this->conditions -= $incr; - - if (isset($GLOBALS[$base]["more_0"])) - $this->conditions += $incr; - - if ($this->conditions < 1) - $this->conditions = 1; - - return $this->plain_where($base); - } -} -?> -- libgit2 0.21.4