diff --git a/phpgwapi/inc/class.db.inc.php b/phpgwapi/inc/class.db.inc.php index 748e8f5d34..6572a6037c 100644 --- a/phpgwapi/inc/class.db.inc.php +++ b/phpgwapi/inc/class.db.inc.php @@ -25,12 +25,9 @@ { $GLOBALS['phpgw_info']['server']['db_type'] = 'mysql'; } - if (!isset($GLOBALS['phpgw_info']['server']['use_adodb']) || $GLOBALS['phpgw_info']['server']['use_adodb']) - { - include_once(PHPGW_API_INC.'/adodb/adodb.inc.php'); - } + include_once(PHPGW_API_INC.'/adodb/adodb.inc.php'); - class db_ + class db { /** * @var string $type database type @@ -265,12 +262,6 @@ { return ''; } - // REMOVE-IF-ONLY-ADODB - if (isset($GLOBALS['phpgw_info']['server']['use_adodb']) && - !@$GLOBALS['phpgw_info']['server']['use_adodb']) - { - return addslashes($str); - } if (!$this->Link_ID && !$this->connect()) { return False; @@ -817,12 +808,6 @@ { return False; } - // REMOVE-IF-ONLY-ADODB - if (isset($GLOBALS['phpgw_info']['server']['use_adodb']) && - !@$GLOBALS['phpgw_info']['server']['use_adodb']) - { - return array(); - } return $this->Link_ID->MetaPrimaryKeys($tablename); } @@ -884,12 +869,6 @@ { $args = func_get_args(); - // REMOVE-IF-ONLY-ADODB - if (isset($GLOBALS['phpgw_info']['server']['use_adodb']) && - !@$GLOBALS['phpgw_info']['server']['use_adodb']) - { - return $this->Type == 'mysql' ? 'concat('.implode(',',$args).')' : implode('||',$args); - } if (!$this->Link_ID && !$this->connect()) { return False; @@ -952,12 +931,6 @@ case 'auto': return (int) $value; } - // REMOVE-IF-ONLY-ADODB - if (isset($GLOBALS['phpgw_info']['server']['use_adodb']) && - !@$GLOBALS['phpgw_info']['server']['use_adodb']) - { - return "'" . (!isset($value) || $value == '' ? '' : addslashes($value)) . "'"; - } if (!$this->Link_ID && !$this->connect()) { return False; @@ -1251,14 +1224,3 @@ return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : 0); } } - - // REMOVE-IF-ONLY-ADODB - if (isset($GLOBALS['phpgw_info']['server']['use_adodb']) && !$GLOBALS['phpgw_info']['server']['use_adodb']) - { - include(PHPGW_API_INC.'/class.db_'.$GLOBALS['phpgw_info']['server']['db_type'].'.inc.php'); - } - else - { - class db extends db_{} - } -?> diff --git a/phpgwapi/inc/class.db_msql.inc.php b/phpgwapi/inc/class.db_msql.inc.php deleted file mode 100644 index a0fe4bf23f..0000000000 --- a/phpgwapi/inc/class.db_msql.inc.php +++ /dev/null @@ -1,160 +0,0 @@ -Database; - } - if ($Host == '') - { - $Host = $this->Host; - } - if ($Port == '') - { - $Port = $this->Port; - } - if ($User == '') - { - $User = $this->User; - } - if ($Password == '') - { - $Password = $this->Password; - } - $Host = $Host.':'.$Port; - - // Not connected? Then connect? - if (! $this->Link_ID) - { - // Check for local connect - $this->Link_ID = empty($Host)? - $this->Link_ID=msql_pconnect(): - $this->Link_ID=msql_pconnect($Host); - } - - // Still not connected? Raise error. - if (! $this->Link_ID ) - { - $this->halt('Link-ID == false, pconnect failed'); - } - - // Select current database - if (!msql_select_db($Database, $this->Link_ID)) - { - $this->halt('cannot use database '.$Database); - } - } - - function query($Query_String) - { - $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 halt($msg) - { - printf("Database error: %s
\n", $msg); - printf("MSQL Error: %s
\n", $this->Error); - die('Session halted.'); - } - } -?> diff --git a/phpgwapi/inc/class.db_mssql.inc.php b/phpgwapi/inc/class.db_mssql.inc.php deleted file mode 100644 index 85af6bba6e..0000000000 --- a/phpgwapi/inc/class.db_mssql.inc.php +++ /dev/null @@ -1,412 +0,0 @@ -This is using the MSSQL class
"; */ - // ^^ really ?! :) - - class db - { - var $VEOF = -1; - var $Transaction = false; - - function connect($Database = '', $Host = '', $Port = '', $User = '', $Password = '') - { - /* Handle defaults */ - if ($Database == '') - { - $Database = $this->Database; - } - if ($Host == '') - { - $Host = $this->Host; - } - if ($Port == '') - { - $Port = $this->Port; - } - if ($User == '') - { - $User = $this->User; - } - if ($Password == '') - { - $Password = $this->Password; - } - $Host = $Host.':'.$Port; - - if (! $this->Link_ID ) - { - if ($GLOBALS['phpgw_info']['server']['db_persistent']) - { - $this->Link_ID=mssql_pconnect($Host, $User, $Password); - } - else - { - $this->Link_ID=mssql_connect($Host, $User, $Password); - } - if (!$this->Link_ID) - { - $this->halt('Link-ID == false, mssql_'.($GLOBALS['phpgw_info']['server']['db_persistent']?'p':'').'connect failed'); - } - else - { - mssql_select_db($Database, $this->Link_ID); - } - } - } - - function disconnect() - { - if($this->Link_ID <> 0) - { - @mssql_close($this->Link_ID); - $this->Link_ID = 0; - return 1; - } - else - { - return 0; - } - } - - function db_addslashes($str) - { - if (!IsSet($str) || $str == '') - { - return ''; - } - return str_replace("'", "''", $str); - } - - function free_result() - { - if ($this->Query_ID) - { - mssql_free_result($this->Query_ID); - } - $this->Query_ID = 0; - $this->VEOF = -1; - } - - function query($Query_String, $line = '', $file = '') - { - $this->VEOF = -1; - - if (!$this->Link_ID) - { - $this->connect(); - } - - $this->Query_ID = mssql_query($Query_String, $this->Link_ID); - $this->Row = 0; - if (!$this->Query_ID) - { - $this->halt("Invalid SQL: " . $Query_String, $line, $file); - } - return $this->Query_ID; - } - - // I don't have access to M$-SQL, can someone finish these 2 functions ? (jengo) - function to_timestamp($epoch) - { - return date('Y-m-d H:i:s', $epoch); - } - - function from_timestamp($timestamp) - { - return strtotime($timestamp); - } - - // public: perform a query with limited result set - function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '') - { - if (! $num_rows) - { - $num_rows = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']; - } - - if ($this->Debug) - { - printf("Debug: limit_query = %s
offset=%d, num_rows=%d
\n", $Query_String, $offset, $num_rows); - } - - $this->query($Query_String, $line, $file); - if ($this->Query_ID) - { - $this->Row = $offset; - // Push cursor to appropriate row in case next_record() is used - if ($offset > 0) - { - @mssql_data_seek($this->Query_ID, $offset); - } - $this->VEOF = $offset + $num_rows - 1; - } - - return $this->Query_ID; - } - - function next_record() - { - if (!$this->Query_ID) - { - $this->halt("next_record called with no query pending."); - return 0; - } - - if ($this->VEOF == -1 || ($this->Row++ <= $this->VEOF)) - { - // Work around for buggy mssql_fetch_array - $rec = @mssql_fetch_row($this->Query_ID); - if ($rec) - { - $this->Record = array(); - for ($i = 0; $i < count($rec); $i++) - { - $this->Record[$i] = $rec[$i]; - $o = mssql_fetch_field($this->Query_ID, $i); - $this->Record[$o->name] = $rec[$i]; - } - } - else - { - $this->Record = NULL; - } - } - else - { - $this->Record = NULL; - } - - $stat = is_array($this->Record); - if (!$stat && $this->Auto_Free) - { - $this->free(); - } - - return $stat; - } - - function transaction_begin() - { - $this->Transaction = !!mssql_query('BEGIN TRAN', $this->Link_ID); - return $this->Transaction; - } - - function transaction_commit() - { - if (!$this->Errno && $this->Transaction) - { - $this->Transaction = false; - return !!mssql_query('COMMIT TRAN', $this->Link_ID); - } - - return False; - } - - function transaction_abort() - { - if ($this->Transaction) - { - $this->Transaction = false; - return !!mssql_query('ROLLBACK TRAN', $this->Link_ID); - } - - return false; - } - - 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->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() - { - if($this->Query_ID) - { - return mssql_num_rows($this->Query_ID); - } - else - { - return 0; - } - } - - function num_fields() - { - return mssql_num_fields($this->Query_ID); - } - - function f($Field_Name) - { - if ($strip_slashes || ($this->auto_stripslashes && ! $strip_slashes)) - { - return str_replace("''", "'", $this->Record[$Name]); - } - else - { - return $this->Record[$Name]; - } - } - - function get_last_insert_id($table, $field) - { - if (!isset($table) || $table == '' || !isset($field) || $field == '') - { - return -1; - } - - $result = @mssql_query("select @@identity", $this->Link_ID); - if (!$result) - { - return -1; - } - return mssql_result($result, 0, 0); - } - - function lock($table, $mode="write") - { - // /me really, really, really hates locks - transactions serve just fine - return $this->transaction_begin(); - } - - function unlock() - { - return $this->transaction_commit(); - } - - function halt($msg, $line = '', $file = '') - { - $this->unlock(); - - $this->Errno = 1; - $this->Error = mssql_get_last_message(); - if ($this->Error == '') - { - $this->Error = "General Error (The MS-SQL interface did not return a detailed error message)."; - } - - if ($this->Halt_On_Error == "no") - { - return; - } - - $this->haltmsg($msg); - - if ($file) - { - printf("
File: %s",$file); - } - - if ($line) - { - printf("
Line: %s",$line); - } - printf("
Function: %s\n",function_backtrace()); - - if ($this->Halt_On_Error != "report") - { - echo "

Session halted."; - $GLOBALS['phpgw']->common->phpgw_exit(True); - } - } - - function haltmsg($msg) - { - printf("Database error: %s
\n", $msg); - if ($this->Errno != "0" && $this->Error != "()") - { - printf("MS-SQL Error: %s (%s)
\n", $this->Errno, $this->Error); - } - } - - function table_names() - { - $this->query("select name from sysobjects where type='u' and name != 'dtproperties'"); - $i = 0; - while ($info = @mssql_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; - } - - function create_database($adminname='', $adminpasswd='') - { - $currentUser = $this->User; - $currentPassword = $this->Password; - $currentDatabase = $this->Database; - - if($adminname != '') - { - $this->User = $adminname; - $this->Password = $adminpasswd; - $this->Database = 'master'; - } - $this->disconnect(); - $outval = $this->query("CREATE DATABASE $currentDatabase"); - $this->disconnect(); - - if(!$outval) - { - echo 'Database creation failure
'; - echo 'please setup the MSSQL database manually
'; - } - - $this->User = $currentUser; - $this->Password = $currentPassword; - $this->Database = $currentDatabase; - $this->connect(); - } - } -?> diff --git a/phpgwapi/inc/class.db_mysql.inc.php b/phpgwapi/inc/class.db_mysql.inc.php deleted file mode 100644 index a3c4080872..0000000000 --- a/phpgwapi/inc/class.db_mysql.inc.php +++ /dev/null @@ -1,542 +0,0 @@ -db_($query); - } - - /* public: connection management */ - function connect($Database = '', $Host = '', $Port = '', $User = '', $Password = '') - { - /* Handle defaults */ - if ($Database == '') - { - $Database = $this->Database; - } - if ($Host == '') - { - $Host = $this->Host; - } - if ($Port == '') - { - $Port = isset($this->Port) ? $this->Port : '3306'; - } - // Check if using local socket instead of TCP/IP - if (substr($Port,0,1) == '/') - { - $Host = ''; - } - $Host = $Host.':'.$Port; - if ($User == '') - { - $User = $this->User; - } - if ($Password == '') - { - $Password = $this->Password; - } - - /* establish connection, select database */ - if (! $this->Link_ID) - { - if ($GLOBALS['phpgw_info']['server']['db_persistent']) - { - $this->Link_ID=mysql_pconnect($Host, $User, $Password); - } - else - { - $this->Link_ID=mysql_connect($Host, $User, $Password); - } - if (!$this->Link_ID) - { - $this->halt(($GLOBALS['phpgw_info']['server']['db_persistent']?'p':'')."connect($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; - } - - /* This only affects systems not using persistant connections */ - function disconnect() - { - if($this->Link_ID <> 0) - { - @mysql_close($this->Link_ID); - $this->Link_ID = 0; - return 1; - } - else - { - return 0; - } - } - - function to_timestamp($epoch) - { - return date('Y-m-d H:i:s',$epoch); - } - - function from_timestamp($timestamp) - { - ereg('([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})',$timestamp,$parts); - - return mktime($parts[4],$parts[5],$parts[6],$parts[2],$parts[3],$parts[1]); - } - - /* public: discard the query result */ - function free() - { - @mysql_free_result($this->Query_ID); - $this->Query_ID = 0; - } - - /* public: perform a query */ - /* I added the line and file section so we can have better error reporting. (jengo) */ - function query($Query_String, $line = '', $file = '') - { - /* No empty queries, please, since PHP4 chokes on them. */ - /* 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_Subclass;' - */ - if ($Query_String == '') - { - 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, $line, $file); - } - - # Will return nada if it fails. That's fine. - return $this->Query_ID; - } - - // public: perform a query with limited result set - function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '') - { - if (! $num_rows) - { - $num_rows = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']; - } - - if ($offset == 0) - { - $Query_String .= ' LIMIT ' . $num_rows; - } - else - { - $Query_String .= ' LIMIT ' . $offset . ',' . $num_rows; - } - - if ($this->Debug) - { - printf("Debug: limit_query = %s
offset=%d, num_rows=%d
\n", $Query_String, $offset, $num_rows); - } - - return $this->query($Query_String, $line, $file); - } - - /* 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; - } - - function get_last_insert_id($table, $field) - { - /* This will get the last insert ID created on the current connection. Should only be called - * after an insert query is run on a table that has an auto incrementing field. $table and - * $field are required, but unused here since it's unnecessary for mysql. For compatibility - * with pgsql, the params must be supplied. - */ - - if (!isset($table) || $table == '' || !isset($field) || $field == '') - { - return -1; - } - - return @mysql_insert_id($this->Link_ID); - } - - /* 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: 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(); - - /* 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, $line = '', $file = '') - { - $this->Error = @mysql_error($this->Link_ID); // need to be BEFORE unlock, - $this->Errno = @mysql_errno($this->Link_ID); // else we get its error or none - - if ($this->Link_ID) // only if we have a link, else infinite loop - { - $this->unlock(); /* Just in case there is a table currently locked */ - } - if ($this->Halt_On_Error == "no") - { - return; - } - $this->haltmsg($msg); - - if ($file) - { - printf("
File: %s",$file); - } - if ($line) - { - printf("
Line: %s",$line); - } - printf("
Function: %s\n",function_backtrace()); - - if ($this->Halt_On_Error != "report") - { - echo "

Session halted."; - $GLOBALS['phpgw']->common->phpgw_exit(True); - } - } - - function haltmsg($msg) - { - printf("Database error: %s
\n", $msg); - if ($this->Errno != "0" && $this->Error != "()") - { - printf("MySQL Error: %s (%s)
\n",$this->Errno,$this->Error); - } - } - - function table_names() - { - if (!$this->Link_ID) - { - $this->connect(); - } - if (!$this->Link_ID) - { - return array(); - } - $return = Array(); - $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; - } - - function create_database($adminname = '', $adminpasswd = '') - { - $currentUser = $this->User; - $currentPassword = $this->Password; - $currentDatabase = $this->Database; - - if ($adminname != '') - { - $this->User = $adminname; - $this->Password = $adminpasswd; - $this->Database = "mysql"; - } - $this->disconnect(); - $this->query("CREATE DATABASE $currentDatabase"); - $this->query("grant all on $currentDatabase.* to $currentUser@localhost identified by '$currentPassword'"); - $this->disconnect(); - - $this->User = $currentUser; - $this->Password = $currentPassword; - $this->Database = $currentDatabase; - $this->connect(); - /*return $return; */ - } - - //some empty functions, so that adodb can be in the normal db-class - function transaction_begin() - { - return True; - } - - /** - * Complete the transaction - * - * @return bool True if sucessful, False if fails - */ - function transaction_commit() - { - return True; - } - - /** - * Rollback the current transaction - * - * @return bool True if sucessful, False if fails - */ - function transaction_abort() - { - return True; - } - - function db_addslashes($str) - { - if (!isset($str) || $str == '') - { - return ''; - } - return addslashes($str); - } - } -?> diff --git a/phpgwapi/inc/class.db_odbc.inc.php b/phpgwapi/inc/class.db_odbc.inc.php deleted file mode 100644 index 4eeb9c53ad..0000000000 --- a/phpgwapi/inc/class.db_odbc.inc.php +++ /dev/null @@ -1,208 +0,0 @@ -Database; - } - if ($Host == '') - { - $Host = $this->Host; - } - if ($User == '') - { - $User = $this->User; - } - if ($Password == '') - { - $Password = $this->Password; - } - - if (! $this->Link_ID) - { - $this->Link_ID=odbc_pconnect($Database, $User, $Password, $this->UseODBCCursor); - if (!$this->Link_ID) - { - $this->halt('Link-ID == false, odbc_pconnect failed'); - } - } - } - - function query($Query_String) - { - $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 + (int)(($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 f($Field_Name) - { - return $this->Record[strtolower($Field_Name)]; - } - - function halt($msg) - { - printf("Database error: %s
\n", $msg); - printf("ODBC Error: %s (%s)
\n", - $this->Errno, - $this->Error); - die('Session halted.'); - } - - function create_database($adminname = '', $adminpasswd = '') - { - return False; - } - } -?> diff --git a/phpgwapi/inc/class.db_oracle.inc.php b/phpgwapi/inc/class.db_oracle.inc.php deleted file mode 100644 index b9ec433b9d..0000000000 --- a/phpgwapi/inc/class.db_oracle.inc.php +++ /dev/null @@ -1,515 +0,0 @@ -db_($query); - } - - function connect($Database = '', $Host = '', $Port = '', $User = '', $Password = '') - { - /* Handle defaults */ - if ($Database == '') - { - $Database = $this->Database; - } - if ($Host == '') - { - $Host = $this->Host; - } - if ($Port == '') - { - $Port = $this->Port; - } - if ($User == '') - { - $User = $this->User; - } - if ($Password == '') - { - $Password = $this->Password; - } - - if (! $this->Link_ID) - { - if($this->Debug) - { - printf('
Connecting to ' . $Database . "...
\n"); - } - if($this->Remote) - { - if($this->Debug) - { - printf("
connect() $User/******@$Database.world
\n"); - } - if($GLOBALS['phpgw_info']['server']['db_persistent']) - { - $this->Link_ID = ora_plogon("$User/$Password@$Database",""); - /************** (comment by SSilk) - this dosn't work on my system: - $this->Link_ID = ora_plogon("$User@$Database.world","$Password"); - ***************/ - } - else - { - $this->Link_ID = ora_logon("$User/$Password@$Database",""); - /************** (comment by SSilk) - this dosn't work on my system: - $this->Link_ID=ora_logon("$User@$Database.world","$Password"); - ***************/ - } - } - else - { - if($this->Debug) - { - printf("
connect() $User, $Password
\n"); - } - if($GLOBALS['phpgw_info']['server']['db_persistent']) - { - $this->Link_ID=ora_plogon("$User","$Password"); - /* (comment by SSilk: don't know how this could work, but I leave this untouched!) */ - } - else - { - $this->Link_ID=ora_logon("$User","$Password"); - } - } - 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_".($GLOBALS['phpgw_info']['server']['db_persistent']?'p':'').'logon 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); - } - - /* 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'] = strtolower($this->Record['table_name']); - $info[$i]['tablespace_name'] = $this->Record['tablespace_name']; - $i++; - } - return $info; - } - - function create_database($adminname = '', $adminpasswd = '') - { - return False; - } - } diff --git a/phpgwapi/inc/class.db_pgsql.inc.php b/phpgwapi/inc/class.db_pgsql.inc.php deleted file mode 100644 index 1fb0344522..0000000000 --- a/phpgwapi/inc/class.db_pgsql.inc.php +++ /dev/null @@ -1,591 +0,0 @@ - 7.x - var $db_version; - - var $_byteaArray; - - function ifadd($add, $me) - { - if($add != '') - { - return ' ' . $me . $add; - } - } - - /* public: constructor */ - function db($query = '') - { - $this->db_($query); - } - - function connect($Database = '', $Host = '', $Port = '', $User = '', $Password = '') - { - /* Handle defaults */ - if ($Database == '') - { - $Database = $this->Database; - } - if ($Host == '') - { - $Host = $this->Host; - } - if ($Port == '') - { - $Port = $this->Port; - } - if ($User == '') - { - $User = $this->User; - } - if ($Password == '') - { - $Password = $this->Password; - } - if (! $this->Link_ID) - { - $cstr = 'dbname=' . $Database - . $this->ifadd($Host, 'host=') - . $this->ifadd($Port, 'port=') - . $this->ifadd($User, 'user=') - . $this->ifadd("'".$Password."'", 'password='); - if ($GLOBALS['phpgw_info']['server']['db_persistent']) - { - $this->Link_ID = pg_pconnect($cstr); - } - else - { - $this->Link_ID = pg_connect($cstr); - } - - if (! $this->Link_ID) - { - $this->halt('Link-ID == false, '.($GLOBALS['phpgw_info']['server']['db_persistent']?'p':'').'connect failed'); - } - else - { - $this->query("select version()",__LINE__,__FILE__); - $this->next_record(); - - $version = $this->f('version'); - $parts = explode(' ',$version); - $this->db_version = $parts[1]; - } - } - } - - function to_timestamp($epoch) - { - $db_version = $this->db_version; - if (floor($db_version) == 6) - { - return $this->to_timestamp_6($epoch); - } - else - { - return $this->to_timestamp_7($epoch); - } - } - - function from_timestamp($timestamp) - { - if (floor($this->db_version) == 6) - { - return $this->from_timestamp_6($timestamp); - } - else - { - return $this->from_timestamp_7($timestamp); - } - } - - // For PostgreSQL 6.x - function to_timestamp_6($epoch) - { - - } - - // For PostgreSQL 6.x - function from_timestamp_6($timestamp) - { - - } - - // For PostgreSQL 7.x - function to_timestamp_7($epoch) - { - // This needs the GMT offset! - return date('Y-m-d H:i:s-00',$epoch); - } - - // For PostgreSQL 7.x - function from_timestamp_7($timestamp) - { - ereg('([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})',$timestamp,$parts); - - return mktime($parts[4],$parts[5],$parts[6],$parts[2],$parts[3],$parts[1]); - } - - /* This only affects systems not using persistant connections */ - function disconnect() - { - return @pg_close($this->Link_ID); - } - - function query($Query_String, $line = '', $file = '') - { - if ($Query_String == '') - { - 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, $line, $file); - } - - $this->_init_bytea_array(); - - return $this->Query_ID; - } - - function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '') - { - if (! $num_rows) - { - $num_rows = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']; - } - - if ($offset == 0) - { - $Query_String .= ' LIMIT ' . $num_rows; - } - else - { - $Query_String .= ' LIMIT ' . $num_rows . ' OFFSET ' . $offset; - } - - if ($this->Debug) - { - printf("Debug: limit_query = %s
offset=%d, num_rows=%d
\n", $Query_String, $offset, $num_rows); - } - - return $this->query($Query_String, $line, $file); - } - - function free() - { - @pg_freeresult($this->Query_ID); - $this->Query_ID = 0; - } - - 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; - } - - if (isset($this->_byteaArray)) - { - $this->_fixbytea(); - } - - return $stat; - } - - function seek($pos) - { - $this->Row = $pos; - } - - function transaction_begin() - { - /* disable transactions in PG for now */ - return True; - return $this->query('begin'); - } - - function transaction_commit() - { - /* disable transactions in PG for now */ - return True; - if(!$this->Errno) - { - return pg_Exec($this->Link_ID,'commit'); - } - else - { - return False; - } - } - - function transaction_abort() - { - return True; - return pg_Exec($this->Link_ID,'rollback'); - } - - function get_last_insert_id($table, $field) - { - if (!isset($table) || $table == '' || !isset($field) || $field == '') - { - return -1; - } - - $oid = pg_getlastoid($this->Query_ID); - if ($oid == -1) - { - return -1; - } - - $result = @pg_Exec($this->Link_ID, "select $field from $table where oid=$oid"); - if (!$result) - { - return -1; - } - - $Record = @pg_fetch_array($result, 0); - @pg_freeresult($result); - if (!is_array($Record)) /* OID not found? */ - { - return -1; - } - - return $Record[0]; - } - - function lock($table, $mode = 'write') - { - // don't lock any tables in pgsql anymore - return 1; - - $result = $this->transaction_begin(); - - if ($mode == 'write') - { - if (is_array($table)) - { - while ($t = each($table)) - { - $result = pg_Exec($this->Link_ID,'lock table ' . $t[1] . ' in share mode'); - } - } - else - { - $result = pg_Exec($this->Link_ID, 'lock table ' . $table . ' in share mode'); - } - } - else - { - $result = 1; - } - - return $result; - } - - function unlock() - { - // we don't lock tables anymore in pgsql - return 1; - - return $this->transaction_commit(); - } - - - 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 where false"); - 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 halt($msg, $line = '', $file = '') - { - if ($this->Halt_On_Error == 'no') - { - return; - } - - /* Just in case there is a table currently locked */ - $this->transaction_abort(); - - - if ($this->xmlrpc || $this->soap) - { - $s = sprintf("Database error: %s\n", $msg); - $s .= sprintf("PostgreSQL Error: %s\n\n (%s)\n\n",$this->Errno,$this->Error); - } - else - { - $s = sprintf("Database error: %s
\n", $msg); - $s .= sprintf("PostgreSQL Error: %s (%s)
\n",$this->Errno,$this->Error); - } - - if ($file) - { - if ($this->xmlrpc || $this->soap) - { - $s .= sprintf("File: %s\n",$file); - } - else - { - $s .= sprintf("
File: %s",$file); - } - } - - if ($line) - { - if ($this->xmlrpc || $this->soap) - { - $s .= sprintf("Line: %s\n",$line); - } - else - { - $s .= sprintf("
Line: %s",$line); - } - } - - if ($this->xmlrpc || $this->soap) - { - $s .= sprintf("Function/Module: %s\n",function_backtrace()); - } - else - { - $s .= sprintf("
Function/Module: %s\n",function_backtrace()); - } - - if ($this->Halt_On_Error == 'yes') - { - if (! $this->xmlrpc && ! $this->soap) - { - $s .= '

Session halted.'; - } - } - - if ($this->xmlrpc) - { - xmlrpcfault($s); - } - elseif ($this->soap) - { - - } - else - { - echo $s; - if (is_object($GLOBALS['phpgw']->common)) - { - $GLOBALS['phpgw']->common->phpgw_exit(True); - } - else - { - exit(); - } - } - } - - function table_names() - { - $return = array(); - $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; - } - - function index_names() - { - $this->query("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relkind ='i' ORDER BY relname"); - $i=0; - while ($this->next_record()) - { - $return[$i]['index_name']= $this->f(0); - $return[$i]['tablespace_name']=$this->Database; - $return[$i]['database']=$this->Database; - $i++; - } - return $return; - } - - function create_database($adminname = '', $adminpasswd = '') - { - $currentUser = $this->User; - $currentPassword = $this->Password; - $currentDatabase = $this->Database; - - if ($adminname != "") - { - $this->User = $adminname; - $this->Password = $adminpasswd; - $this->Database = "template1"; - } - $this->disconnect(); - $outval = $this->query("CREATE DATABASE $currentDatabase;"); - $this->disconnect(); - - if(!$outval) - { - /* either the rights r not available or the postmaster is not running .... */ - echo 'database creation failure
'; - echo 'please setup the postreSQL database manually
'; - } - - $this->User = $currentUser; - $this->Password = $currentPassword; - $this->Database = $currentDatabase; - $this->connect(); - } - - // cache types for blob decode check in a class-member called "_byteaArray" - function _init_bytea_array() - { - unset($this->_byteaArray); - for ($i=0, $max = @pg_numfields($this->Query_ID); $i < $max; $i++) - { - if (@pg_fieldtype($this->Query_ID, $i) == 'bytea') - { - $this->_byteaArray[$i] = @pg_fieldname($this->Query_ID, $i); - } - } - } - - function _fixbytea() - { - foreach($this->_byteaArray as $v) - { - if ($v) - { - $this->Record[$v] = $this->_bytea_decode($this->Record[$v]); - } - } - } - - // fix data from bytea-fields, wich are not fully supported by PHP itself - function _bytea_decode($bytea) - { - eval('$realbytea="'.str_replace(array('"','$'),array('\"','\$'),$bytea).'";'); - return $realbytea; - } - } diff --git a/phpgwapi/inc/class.db_sybase.inc.php b/phpgwapi/inc/class.db_sybase.inc.php deleted file mode 100644 index a32e07365b..0000000000 --- a/phpgwapi/inc/class.db_sybase.inc.php +++ /dev/null @@ -1,184 +0,0 @@ - * - * metadata() contributed by Adelino Monteiro * - * ------------------------------------------------------------------------ * - * This is not part of eGroupWare, but is used by eGroupWare. * - * http://www.egroupware.org/ * - * ------------------------------------------------------------------------ * - * This program is free software; you can redistribute it and/or modify it * - * under the terms of the GNU Lesser General Public License as published * - * by the Free Software Foundation; either version 2.1 of the License, or * - * any later version. * - \**************************************************************************/ - - /* $Id$ */ - - class db - { - - function connect($Database = '', $Host = '', $Port = '', $User = '', $Password = '') - { - /* Handle defaults */ - if ($Database == '') - { - $Database = $this->Database; - } - if ($Host == '') - { - $Host = $this->Host; - } - if ($Port == '') - { - $Port = $this->Port; - } - if ($User == '') - { - $User = $this->User; - } - if ($Password == '') - { - $Password = $this->Password; - } - - if (! $this->Link_ID) - { - if ($GLOBALS['phpgw_info']['server']['db_persistent']) - { - $this->Link_ID=sybase_pconnect($Host,$User,$Password); - } - else - { - $this->Link_ID=sybase_connect($Host,$User,$Password); - } - } - if (!$this->Link_ID) - { - $this->halt('Link-ID == false, '.($GLOBALS['phpgw_info']['server']['db_persistent']?'p':'').'connect failed'); - } - if(!sybase_select_db($Database, $this->Link_ID)) - { - $this->halt('cannot use database '.$Database); - } - } - - function db_addslashes($str) - { - if (!IsSet($str) || $str == '') - { - return ''; - } - return str_replace("'", "''", $str); - } - - function query($Query_String) - { - $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 f($Name, $strip_slashes = False) - { - if ($strip_slashes || ($this->auto_stripslashes && ! $strip_slashes)) - { - return str_replace("''", "'", $this->Record[$Name]); - } - else - { - return $this->Record[$Name]; - } - } - - function halt($msg) - { - printf("Database error: %s
\n", $msg); - printf("Sybase Error
\n"); - die("Session halted."); - } - - function create_database($adminname = '', $adminpasswd = '') - { - return False; - } - } -?>