escape_quotes,"'")) $text=str_replace($this->escape_quotes,$this->escape_quotes.$this->escape_quotes,$text); $text=str_replace("'",$this->escape_quotes."'",$text); } /* PUBLIC METHODS */ Function Close() { } Function CreateDatabase($database) { $this->last_error="database creation is not supported"; return(0); } Function DropDatabase($database) { $this->last_error="database dropping is not supported"; return(0); } Function GetField(&$field,$field_name,&$query) { if(!strcmp($field_name,"")) { $this->last_error="it was not specified a valid field name (\"$field_name\")"; return(0); } switch($field["type"]) { case "integer": $query=MetabaseGetIntegerFieldTypeDeclaration($this->database,$field_name,$field); break; case "text": $query=MetabaseGetTextFieldTypeDeclaration($this->database,$field_name,$field); break; case "clob": $query=MetabaseGetCLOBFieldTypeDeclaration($this->database,$field_name,$field); break; case "blob": $query=MetabaseGetBLOBFieldTypeDeclaration($this->database,$field_name,$field); break; case "boolean": $query=MetabaseGetBooleanFieldTypeDeclaration($this->database,$field_name,$field); break; case "date": $query=MetabaseGetDateFieldTypeDeclaration($this->database,$field_name,$field); break; case "timestamp": $query=MetabaseGetTimestampFieldTypeDeclaration($this->database,$field_name,$field); break; case "time": $query=MetabaseGetTimeFieldTypeDeclaration($this->database,$field_name,$field); break; case "float": $query=MetabaseGetFloatFieldTypeDeclaration($this->database,$field_name,$field); break; case "decimal": $query=MetabaseGetDecimalFieldTypeDeclaration($this->database,$field_name,$field); break; default: $this->last_error="type \"".$field["type"]."\" is not yet supported"; return(0); } return(1); } Function GetFieldList(&$fields,&$query_fields) { for($query_fields="",Reset($fields),$field_number=0;$field_number0) $query_fields.=","; $field_name=Key($fields); if(!$this->GetField($fields[$field_name],$field_name,$query)) return(0); $query_fields.=$query; } return(1); } Function CreateTable($name,&$fields) { if(!IsSet($name) || !strcmp($name,"")) return("it was not specified a valid table name"); if(count($fields)==0) return("it were not specified any fields for table \"$name\""); $query_fields=""; if(!$this->GetFieldList($fields,$query_fields)) return(0); return($this->Query("CREATE TABLE $name ($query_fields)")); } Function DropTable($name) { return($this->Query("DROP TABLE $name")); } Function AlterTable($name,&$changes,$check) { $this->last_error="database table alterations are not supported"; return(0); } Function Query($query) { $this->last_error="database queries are not implemented"; return(0); } Function PrepareQuery($query) { $positions=array(); for($position=0;$positionlast_error="it was specified a query with an unterminated text string"; return(0); } switch($this->escape_quotes) { case "": case "'": $position=$end_quote+1; break; default: if($end_quote==$quote+1) $position=$end_quote+1; else { if($query[$end_quote-1]==$this->escape_quotes) $position=$end_quote; else $position=$end_quote+1; } break; } } else { $positions[]=$question; $position=$question+1; } } $this->prepared_queries[]=array( "Query"=>$query, "Positions"=>$positions, "Values"=>array(), "Types"=>array() ); $prepared_query=count($this->prepared_queries); if($this->selected_row_limit>0) { $this->prepared_queries[$prepared_query-1]["First"]=$this->first_selected_row; $this->prepared_queries[$prepared_query-1]["Limit"]=$this->selected_row_limit; } return($prepared_query); } Function ValidatePreparedQuery($prepared_query) { if($prepared_query<1 || $prepared_query>count($this->prepared_queries)) { $this->last_error="invalid prepared query"; return(0); } if(GetType($this->prepared_queries[$prepared_query-1])!="array") { $this->last_error="prepared query was already freed"; return(0); } return(1); } Function FreePreparedQuery($prepared_query) { if(!$this->ValidatePreparedQuery($prepared_query)) return(0); $this->prepared_queries[$prepared_query-1]=""; return(1); } Function ExecutePreparedQuery($prepared_query,$query) { return(MetabaseQuery($this->database,$query)); } Function ExecuteQuery($prepared_query) { if(!$this->ValidatePreparedQuery($prepared_query)) return(0); $index=$prepared_query-1; for($this->clobs[$prepared_query]=$this->blobs[$prepared_query]=array(),$success=1,$query="",$last_position=$position=0;$positionprepared_queries[$index]["Positions"]);$position++) { if(!IsSet($this->prepared_queries[$index]["Values"][$position])) { $this->last_error="it was not defined query argument ".($position+1); return(0); } $current_position=$this->prepared_queries[$index]["Positions"][$position]; $query.=substr($this->prepared_queries[$index]["Query"],$last_position,$current_position-$last_position); $value=$this->prepared_queries[$index]["Values"][$position]; if($this->prepared_queries[$index]["IsNULL"][$position]) $query.=$value; else { switch($this->prepared_queries[$index]["Types"][$position]) { case "clob": if(!($success=$this->GetCLOBFieldValue($prepared_query,$position+1,$value,$this->clobs[$prepared_query][$position+1]))) { Unset($this->clobs[$prepared_query][$position+1]); break; } $query.=$this->clobs[$prepared_query][$position+1]; break; case "blob": if(!($success=$this->GetBLOBFieldValue($prepared_query,$position+1,$value,$this->blobs[$prepared_query][$position+1]))) { Unset($this->blobs[$prepared_query][$position+1]); break; } $query.=$this->blobs[$prepared_query][$position+1]; break; default: $query.=$value; break; } } $last_position=$current_position+1; } if($success) { $query.=substr($this->prepared_queries[$index]["Query"],$last_position); if($this->selected_row_limit>0) { $this->prepared_queries[$index]["First"]=$this->first_selected_row; $this->prepared_queries[$index]["Limit"]=$this->selected_row_limit; } if(IsSet($this->prepared_queries[$index]["Limit"]) && $this->prepared_queries[$index]["Limit"]>0) { $this->first_selected_row=$this->prepared_queries[$index]["First"]; $this->selected_row_limit=$this->prepared_queries[$index]["Limit"]; } else $this->first_selected_row=$this->selected_row_limit=0; MetabaseDebug($this->database,"Prepared query: ".$this->prepared_queries[$index]["Query"]); $success=$this->ExecutePreparedQuery($prepared_query,$query); } for(Reset($this->clobs[$prepared_query]),$clob=0;$clobclobs[$prepared_query]);$clob++,Next($this->clobs[$prepared_query])) $this->FreeCLOBValue($prepared_query,Key($this->clobs[$prepared_query]),$this->clobs[$prepared_query][Key($this->clobs[$prepared_query])],$success); UnSet($this->clobs[$prepared_query]); for(Reset($this->blobs[$prepared_query]),$blob=0;$blobblobs[$prepared_query]);$blob++,Next($this->blobs[$prepared_query])) $this->FreeBLOBValue($prepared_query,Key($this->blobs[$prepared_query]),$this->blobs[$prepared_query][Key($this->blobs[$prepared_query])],$success); UnSet($this->blobs[$prepared_query]); return($success); } Function QuerySet($prepared_query,$parameter,$type,$value,$is_null=0,$field="") { if(!$this->ValidatePreparedQuery($prepared_query)) return(0); $index=$prepared_query-1; if($parameter<1 || $parameter>count($this->prepared_queries[$index]["Positions"])) { $this->last_error="it was not specified a valid argument number"; return(0); } $this->prepared_queries[$index]["Values"][$parameter-1]=$value; $this->prepared_queries[$index]["Types"][$parameter-1]=$type; $this->prepared_queries[$index]["Fields"][$parameter-1]=$field; $this->prepared_queries[$index]["IsNULL"][$parameter-1]=$is_null; return(1); } Function QuerySetNull($prepared_query,$parameter,$type) { return($this->QuerySet($prepared_query,$parameter,$type,"NULL",1,"")); } Function QuerySetText($prepared_query,$parameter,$value) { return($this->QuerySet($prepared_query,$parameter,"text",$this->GetTextFieldValue($value))); } Function QuerySetCLOB($prepared_query,$parameter,$value,$field) { return($this->QuerySet($prepared_query,$parameter,"clob",$value,0,$field)); } Function QuerySetBLOB($prepared_query,$parameter,$value,$field) { return($this->QuerySet($prepared_query,$parameter,"blob",$value,0,$field)); } Function QuerySetInteger($prepared_query,$parameter,$value) { return($this->QuerySet($prepared_query,$parameter,"integer",$this->GetIntegerFieldValue($value))); } Function QuerySetBoolean($prepared_query,$parameter,$value) { return($this->QuerySet($prepared_query,$parameter,"boolean",$this->GetBooleanFieldValue($value))); } Function QuerySetDate($prepared_query,$parameter,$value) { return($this->QuerySet($prepared_query,$parameter,"date",$this->GetDateFieldValue($value))); } Function QuerySetTimestamp($prepared_query,$parameter,$value) { return($this->QuerySet($prepared_query,$parameter,"timestamp",$this->GetTimestampFieldValue($value))); } Function QuerySetTime($prepared_query,$parameter,$value) { return($this->QuerySet($prepared_query,$parameter,"time",$this->GetTimeFieldValue($value))); } Function QuerySetFloat($prepared_query,$parameter,$value) { return($this->QuerySet($prepared_query,$parameter,"float",$this->GetFloatFieldValue($value))); } Function QuerySetDecimal($prepared_query,$parameter,$value) { return($this->QuerySet($prepared_query,$parameter,"decimal",$this->GetDecimalFieldValue($value))); } Function AffectedRows(&$affected_rows) { if($this->affected_rows==-1) { $this->last_error="there was no previous valid query to determine the number of affected rows"; return(0); } $affected_rows=$this->affected_rows; return(1); } Function EndOfResult($result) { $this->last_error="end of result method not implemented"; return(-1); } Function FetchResult($result,$row,$field) { $this->warning="fetch result method not implemented"; return(""); } Function FetchLOBResult($result,$row,$field) { $lob=count($this->lobs)+1; $this->lobs[$lob]=array( "Result"=>$result, "Row"=>$row, "Field"=>$field, "Position"=>0 ); $character_lob=array( "Database"=>$this->database, "Error"=>"", "Type"=>"resultlob", "ResultLOB"=>$lob ); if(!MetabaseCreateLOB($character_lob,$clob)) { $this->last_error=$character_lob["Error"]; return(0); } return($clob); } Function RetrieveLOB($lob) { if(!IsSet($this->lobs[$lob])) { $this->last_error="it was not specified a valid lob"; return(0); } if(!IsSet($this->lobs[$lob]["Value"])) $this->lobs[$lob]["Value"]=$this->FetchResult($this->lobs[$lob]["Result"],$this->lobs[$lob]["Row"],$this->lobs[$lob]["Field"]); return(1); } Function EndOfResultLOB($lob) { if(!$this->RetrieveLOB($lob)) return(0); return($this->lobs[$lob]["Position"]>=strlen($this->lobs[$lob]["Value"])); } Function ReadResultLOB($lob,&$data,$length) { if(!$this->RetrieveLOB($lob)) return(-1); $length=min($length,strlen($this->lobs[$lob]["Value"])-$this->lobs[$lob]["Position"]); $data=substr($this->lobs[$lob]["Value"],$this->lobs[$lob]["Position"],$length); $this->lobs[$lob]["Position"]+=$length; return($length); } Function DestroyResultLOB($lob) { if(IsSet($this->lobs[$lob])) $this->lobs[$lob]=""; } Function FetchCLOBResult($result,$row,$field) { $this->last_error="fetch clob result method is not implemented"; return(0); } Function FetchBLOBResult($result,$row,$field) { $this->last_error="fetch blob result method is not implemented"; return(0); } Function ResultIsNull($result,$row,$field) { $value=$this->FetchResult($result,$row,$field); return(!IsSet($value)); } Function FetchDateResult($result,$row,$field) { return($this->ResultIsNull($result,$row,$field) ? "NULL" : $this->FetchResult($result,$row,$field)); } Function FetchTimestampResult($result,$row,$field) { return($this->ResultIsNull($result,$row,$field) ? "NULL" : $this->FetchResult($result,$row,$field)); } Function FetchTimeResult($result,$row,$field) { return($this->ResultIsNull($result,$row,$field) ? "NULL" : $this->FetchResult($result,$row,$field)); } Function FetchBooleanResult($result,$row,$field) { return($this->ResultIsNull($result,$row,$field) ? "NULL" : (strcmp($this->FetchResult($result,$row,$field),"Y") ? 0 : 1)); } Function FetchFloatResult($result,$row,$field) { return($this->ResultIsNull($result,$row,$field) ? "NULL" : doubleval($this->FetchResult($result,$row,$field))); } Function FetchDecimalResult($result,$row,$field) { return($this->ResultIsNull($result,$row,$field) ? "NULL" : $this->FetchResult($result,$row,$field)); } Function NumberOfRows($result) { $this->warning="number of rows method not implemented"; return(0); } Function FreeResult($result) { $this->warning="free result method not implemented"; return(0); } Function Error() { return($this->last_error); } Function GetIntegerFieldTypeDeclaration($name,&$field) { if(IsSet($field["unsigned"])) $this->warning="unsigned integer field \"$name\" is being declared as signed integer"; return("$name INT".(IsSet($field["default"]) ? " DEFAULT ".$field["default"] : "").(IsSet($field["notnull"]) ? " NOT NULL" : "")); } Function GetTextFieldTypeDeclaration($name,&$field) { return((IsSet($field["length"]) ? "$name CHAR (".$field["length"].")" : "$name TEXT").(IsSet($field["default"]) ? " DEFAULT ".$this->GetTextFieldValue($field["default"]) : "").(IsSet($field["notnull"]) ? " NOT NULL" : "")); } Function GetCLOBFieldTypeDeclaration($name,&$field) { return((IsSet($field["length"]) ? "$name CHAR (".$field["length"].")" : "$name TEXT").(IsSet($field["default"]) ? " DEFAULT ".$this->GetTextFieldValue($field["default"]) : "").(IsSet($field["notnull"]) ? " NOT NULL" : "")); } Function GetBLOBFieldTypeDeclaration($name,&$field) { return((IsSet($field["length"]) ? "$name CHAR (".$field["length"].")" : "$name TEXT").(IsSet($field["default"]) ? " DEFAULT ".$this->GetTextFieldValue($field["default"]) : "").(IsSet($field["notnull"]) ? " NOT NULL" : "")); } Function GetBooleanFieldTypeDeclaration($name,&$field) { return("$name CHAR (1)".(IsSet($field["default"]) ? " DEFAULT ".$this->GetBooleanFieldValue($field["default"]) : "").(IsSet($field["notnull"]) ? " NOT NULL" : "")); } Function GetDateFieldTypeDeclaration($name,&$field) { return("$name CHAR (".strlen("YYYY-MM-DD").")".(IsSet($field["default"]) ? " DEFAULT ".$this->GetDateFieldValue($field["default"]) : "").(IsSet($field["notnull"]) ? " NOT NULL" : "")); } Function GetTimestampFieldTypeDeclaration($name,&$field) { return("$name CHAR (".strlen("YYYY-MM-DD HH:MM:SS").")".(IsSet($field["default"]) ? " DEFAULT ".$this->GetTimestampFieldValue($field["default"]) : "").(IsSet($field["notnull"]) ? " NOT NULL" : "")); } Function GetTimeFieldTypeDeclaration($name,&$field) { return("$name CHAR (".strlen("HH:MM:SS").")".(IsSet($field["default"]) ? " DEFAULT ".$this->GetTimeFieldValue($field["default"]) : "").(IsSet($field["notnull"]) ? " NOT NULL" : "")); } Function GetFloatFieldTypeDeclaration($name,&$field) { return("$name TEXT ".(IsSet($field["default"]) ? " DEFAULT ".$this->GetFloatFieldValue($field["default"]) : "").(IsSet($field["notnull"]) ? " NOT NULL" : "")); } Function GetDecimalFieldTypeDeclaration($name,&$field) { return("$name TEXT ".(IsSet($field["default"]) ? " DEFAULT ".$this->GetDecimalFieldValue($field["default"]) : "").(IsSet($field["notnull"]) ? " NOT NULL" : "")); } Function GetIntegerFieldValue($value) { return(!strcmp($value,"NULL") ? "NULL" : "$value"); } Function GetTextFieldValue($value) { $this->EscapeText($value); return("'$value'"); } Function GetCLOBFieldValue($prepared_query,$parameter,$clob,&$value) { $this->last_error="prepared queries with values of type \"clob\" are not yet supported"; return(0); } Function FreeCLOBValue($prepared_query,$clob,&$value,$success) { } Function GetBLOBFieldValue($prepared_query,$parameter,$blob,&$value) { $this->last_error="prepared queries with values of type \"blob\" are not yet supported"; return(0); } Function FreeBLOBValue($prepared_query,$blob,&$value,$success) { } Function GetBooleanFieldValue($value) { return(!strcmp($value,"NULL") ? "NULL" : ($value ? "'Y'" : "'N'")); } Function GetDateFieldValue($value) { return(!strcmp($value,"NULL") ? "NULL" : "'$value'"); } Function GetTimestampFieldValue($value) { return(!strcmp($value,"NULL") ? "NULL" : "'$value'"); } Function GetTimeFieldValue($value) { return(!strcmp($value,"NULL") ? "NULL" : "'$value'"); } Function GetFloatFieldValue($value) { return(!strcmp($value,"NULL") ? "NULL" : "'$value'"); } Function GetDecimalFieldValue($value) { return(!strcmp($value,"NULL") ? "NULL" : "'$value'"); } Function GetFieldValue($type,$value) { switch($type) { case "integer": return($this->GetIntegerFieldValue($value)); case "text": return($this->GetTextFieldValue($value)); case "boolean": return($this->GetBooleanFieldValue($value)); case "date": return($this->GetDateFieldValue($value)); case "timestamp": return($this->GetTimestampFieldValue($value)); case "time": return($this->GetTimeFieldValue($value)); case "float": return($this->GetFloatFieldValue($value)); case "decimal": return($this->GetDecimalFieldValue($value)); } return(""); } Function Support($feature) { return(IsSet($this->supported[$feature])); } Function CreateSequence($name,$start) { $this->last_error="sequence creation is not supported"; return(0); } Function DropSequence($name) { $this->last_error="sequence dropping is not supported"; return(0); } Function GetSequenceNextValue($name,&$value) { $this->last_error="getting sequence next value is not supported"; return(0); } Function GetSequenceCurrentValue($name,&$value) { $this->last_error="getting sequence current value is not supported"; return(0); } Function AutoCommitTransactions() { $this->last_error="transactions are not supported"; return(0); } Function CommitTransaction() { $this->last_error="commiting transactions are not supported"; return(0); } Function RollbackTransaction() { $this->last_error="rolling back transactions are not supported"; return(0); } Function CreateIndex($table,$name,$definition) { $query="CREATE"; if(IsSet($definition["unique"])) $query.=" UNIQUE"; $query.=" INDEX $name ON $table ("; for($field=0,Reset($definition["FIELDS"]);$field0) $query.=","; $field_name=Key($definition["FIELDS"]); $query.=$field_name; if($this->Support("IndexSorting") && IsSet($definition["FIELDS"][$field_name]["sorting"])) { switch($definition["FIELDS"][$field_name]["sorting"]) { case "ascending": $query.=" ASC"; break; case "descending": $query.=" DESC"; break; } } } $query.=")"; return($this->Query($query)); } Function DropIndex($table,$name) { return($this->Query("DROP INDEX $name")); } Function Setup() { return(""); } Function SetSelectedRowRange($first,$limit) { if(!IsSet($this->supported["SelectRowRanges"])) { $this->last_error="selecting row ranges is not supported by this driver"; return(0); } if(GetType($first)!="integer" || $first<0) { $this->last_error="it was not specified a valid first selected range row"; return(0); } if(GetType($limit)!="integer" || $limit<1) { $this->last_error="it was not specified a valid selected range row limit"; return(0); } $this->first_selected_row=$first; $this->selected_row_limit=$limit; return(1); } Function GetColumnNames($result,&$columns) { $columns=array(); $this->last_error="obtaining result column names is not implemented"; return(0); } Function NumberOfColumns($result) { $this->last_error="obtaining the number of result columns is not implemented"; return(-1); } }; ?>