version 1.21, 1999/02/17 22:06:03
|
version 1.48, 2000/03/13 05:20:12
|
Line 13 class metabase_database_class
|
Line 13 class metabase_database_class
|
var $host=""; |
var $host=""; |
var $user=""; |
var $user=""; |
var $password=""; |
var $password=""; |
var $port=""; |
var $options=array(); |
|
var $supported=array(); |
var $persistent=1; |
var $persistent=1; |
var $database_name=""; |
var $database_name=""; |
var $warning=""; |
var $warning=""; |
|
var $affected_rows=-1; |
|
var $auto_commit=1; |
|
var $prepared_queries=array(); |
|
var $decimal_places=2; |
|
var $first_selected_row=0; |
|
var $selected_row_limit=0; |
|
|
/* PRIVATE DATA */ |
/* PRIVATE DATA */ |
|
|
Line 24 class metabase_database_class
|
Line 31 class metabase_database_class
|
|
|
/* PUBLIC METHODS */ |
/* PUBLIC METHODS */ |
|
|
Function Connect() |
Function Close() |
{ |
{ |
return(1); |
|
} |
} |
|
|
Function Close() |
Function CreateDatabase($database) |
{ |
{ |
|
$this->last_error="database creation is not supported"; |
|
return(0); |
} |
} |
|
|
Function CreateDatabase($database) |
Function DropDatabase($database) |
{ |
{ |
$this->last_error="method not implemented"; |
$this->last_error="database dropping is not supported"; |
return(0); |
return(0); |
} |
} |
|
|
Function AlterTable($name,$changes,$check) |
Function AlterTable($name,$changes,$check) |
{ |
{ |
$this->last_error="method not implemented"; |
$this->last_error="database table alterations are not supported"; |
return(0); |
return(0); |
} |
} |
|
|
Function Query($query) |
Function Query($query) |
{ |
{ |
$this->last_error="method not implemented"; |
$this->last_error="database queries are not implemented"; |
return(0); |
return(0); |
} |
} |
|
|
|
Function PrepareQuery($query) |
|
{ |
|
$positions=array(); |
|
for($position=-1;GetType($position=strpos($query,"?",$position+1))=="integer";) |
|
$positions[]=$position; |
|
$this->prepared_queries[]=array( |
|
"Query"=>$query, |
|
"Positions"=>$positions, |
|
"Values"=>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 ExecuteQuery($prepared_query) |
|
{ |
|
if(!$this->ValidatePreparedQuery($prepared_query)) |
|
return(0); |
|
$index=$prepared_query-1; |
|
for($query="",$last_position=$position=0;$position<count($this->prepared_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).$this->prepared_queries[$index]["Values"][$position]; |
|
$last_position=$current_position+1; |
|
} |
|
$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; |
|
return($this->Query($query)); |
|
} |
|
|
|
Function QuerySet($prepared_query,$parameter,$type,$value) |
|
{ |
|
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; |
|
return(1); |
|
} |
|
|
|
Function QuerySetNull($prepared_query,$parameter,$type) |
|
{ |
|
return($this->QuerySet($prepared_query,$parameter,$type,"NULL")); |
|
} |
|
|
|
Function QuerySetText($prepared_query,$parameter,$value) |
|
{ |
|
return($this->QuerySet($prepared_query,$parameter,"text",$this->GetTextFieldValue($value))); |
|
} |
|
|
|
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) |
Function FetchResult($result,$row,$field) |
{ |
{ |
$this->warning="method not implemented"; |
$this->warning="method not implemented"; |
Line 63 class metabase_database_class
|
Line 224 class metabase_database_class
|
return(!IsSet($value)); |
return(!IsSet($value)); |
} |
} |
|
|
Function FetchDateResult($result,$row,$field,$time) |
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)); |
return($this->ResultIsNull($result,$row,$field) ? "NULL" : $this->FetchResult($result,$row,$field)); |
} |
} |
|
|
Function FetchBooleanResult($result,$row,$field) |
Function FetchBooleanResult($result,$row,$field) |
{ |
{ |
return($this->FetchResult($result,$row,$field)=="Y"); |
return($this->ResultIsNull($result,$row,$field) ? "NULL" : !strcmp($this->FetchResult($result,$row,$field),"Y")); |
|
} |
|
|
|
Function FetchFloatResult($result,$row,$field) |
|
{ |
|
return($this->ResultIsNull($result,$row,$field) ? "NULL" : $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) |
Function NumberOfRows($result) |
Line 82 class metabase_database_class
|
Line 263 class metabase_database_class
|
Function FreeResult($result) |
Function FreeResult($result) |
{ |
{ |
$this->warning="method not implemented"; |
$this->warning="method not implemented"; |
|
return(0); |
} |
} |
|
|
Function Error() |
Function Error() |
Line 89 class metabase_database_class
|
Line 271 class metabase_database_class
|
return($this->last_error); |
return($this->last_error); |
} |
} |
|
|
Function GetIntegerFieldDeclaration($name,$unsigned) |
Function GetIntegerFieldTypeDeclaration($name,&$field) |
{ |
{ |
return($name); |
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 GetIntegerFieldTypeDeclaration($name,&$field) |
Function GetTextFieldTypeDeclaration($name,&$field) |
{ |
{ |
if(IsSet($field["UNSIGNED"])) |
return((IsSet($field["length"]) ? "$name CHAR (".$field["length"].")" : "$name TEXT").(IsSet($field["default"]) ? " DEFAULT ".$this->GetTextFieldValue($field["default"]) : "").(IsSet($field["notnull"]) ? " NOT NULL" : "")); |
$warning="unsigned integer field \"$name\" is being declared as signed integer"; |
|
return("$name INT".(IsSet($field["DEFAULT"]) ? " DEFAULT ".$field["DEFAULT"] : "")); |
|
} |
} |
|
|
Function GetTextFieldDeclaration($name,$length) |
Function GetBooleanFieldTypeDeclaration($name,&$field) |
{ |
{ |
return($name); |
return("$name CHAR (1)".(IsSet($field["default"]) ? " DEFAULT ".$this->GetBooleanFieldValue($field["default"]) : "").(IsSet($field["notnull"]) ? " NOT NULL" : "")); |
} |
} |
|
|
Function GetTextFieldTypeDeclaration($name,&$field) |
Function GetDateFieldTypeDeclaration($name,&$field) |
{ |
{ |
return((IsSet($field["LENGTH"]) ? "$name CHAR (".$field["LENGTH"].")" : "$name TEXT").(IsSet($field["DEFAULT"]) ? " DEFAULT '".$field["DEFAULT"]."'" : "")); |
return("$name CHAR (".strlen("YYYY-MM-DD").")".(IsSet($field["default"]) ? " DEFAULT ".$this->GetDateFieldValue($field["default"]) : "").(IsSet($field["notnull"]) ? " NOT NULL" : "")); |
} |
} |
|
|
Function GetBooleanFieldDeclaration($name) |
Function GetTimestampFieldTypeDeclaration($name,&$field) |
{ |
{ |
return($name); |
return("$name CHAR (".strlen("YYYY-MM-DD HH:MM:SS").")".(IsSet($field["default"]) ? " DEFAULT ".$this->GetTimestampFieldValue($field["default"]) : "").(IsSet($field["notnull"]) ? " NOT NULL" : "")); |
} |
} |
|
|
Function GetBooleanFieldTypeDeclaration($name,&$field) |
Function GetTimeFieldTypeDeclaration($name,&$field) |
{ |
{ |
return("$name CHAR (1)".(IsSet($field["DEFAULT"]) ? " DEFAULT '".$field["DEFAULT"]."'" : "")); |
return("$name CHAR (".strlen("HH:MM:SS").")".(IsSet($field["default"]) ? " DEFAULT ".$this->GetTimeFieldValue($field["default"]) : "").(IsSet($field["notnull"]) ? " NOT NULL" : "")); |
} |
} |
|
|
Function GetDateFieldDeclaration($name,$time) |
Function GetFloatFieldTypeDeclaration($name,&$field) |
{ |
{ |
return($name); |
return("$name TEXT ".(IsSet($field["default"]) ? " DEFAULT ".$this->GetFloatFieldValue($field["default"]) : "").(IsSet($field["notnull"]) ? " NOT NULL" : "")); |
} |
} |
|
|
Function GetDateFieldTypeDeclaration($name,&$field) |
Function GetDecimalTypeDeclaration($name,&$field) |
{ |
{ |
return("$name CHAR (".strlen(IsSet($field["TIME"]) ? "YYYY-MM-DD HH:MM:SS" : "YYYY-MM-DD").")".(IsSet($field["DEFAULT"]) ? " DEFAULT '".$field["DEFAULT"]."'" : "")); |
return("$name TEXT ".(IsSet($field["default"]) ? " DEFAULT ".$this->GetDecimalFieldValue($field["default"]) : "").(IsSet($field["notnull"]) ? " NOT NULL" : "")); |
} |
} |
|
|
Function GetIntegerFieldValue($value) |
Function GetIntegerFieldValue($value) |
{ |
{ |
return("$value"=="NULL" ? "NULL" : "$value"); |
return(!strcmp($value,"NULL") ? "NULL" : "$value"); |
} |
} |
|
|
Function GetTextFieldValue($value) |
Function GetTextFieldValue($value) |
Line 143 class metabase_database_class
|
Line 325 class metabase_database_class
|
|
|
Function GetBooleanFieldValue($value) |
Function GetBooleanFieldValue($value) |
{ |
{ |
return("$value"=="NULL" ? "NULL" : $value ? "'Y'" : "'N'"); |
return(!strcmp($value,"NULL") ? "NULL" : ($value ? "'Y'" : "'N'")); |
} |
} |
|
|
Function GetDateFieldValue($value,$time) |
Function GetDateFieldValue($value) |
{ |
{ |
return($value=="NULL" ? "NULL" : "'$value'"); |
return(!strcmp($value,"NULL") ? "NULL" : "'$value'"); |
} |
} |
|
|
Function SetDateFieldValue($name,$value,$time) |
Function GetTimestampFieldValue($value) |
{ |
{ |
return($this->GetDateFieldDeclaration($name,$time)."=".$this->GetDateFieldValue($value,$time)); |
return(!strcmp($value,"NULL") ? "NULL" : "'$value'"); |
} |
} |
|
|
Function SupportCountFunction() |
Function GetTimeFieldValue($value) |
{ |
{ |
return(0); |
return(!strcmp($value,"NULL") ? "NULL" : "'$value'"); |
} |
} |
|
|
Function SupportMaxFunction() |
Function GetFloatFieldValue($value) |
{ |
{ |
return(0); |
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) |
Function CreateSequence($name,$start) |
{ |
{ |
$this->last_error="method not implemented"; |
$this->last_error="sequence creation is not supported"; |
return(0); |
return(0); |
} |
} |
|
|
Function DropSequence($name) |
Function DropSequence($name) |
{ |
{ |
$this->last_error="method not implemented"; |
$this->last_error="sequence dropping is not supported"; |
return(0); |
return(0); |
} |
} |
|
|
Function GetSequenceNextValue($name,&$value) |
Function GetSequenceNextValue($name,&$value) |
{ |
{ |
$this->last_error="method not implemented"; |
$this->last_error="getting sequence next value is not supported"; |
return(0); |
return(0); |
} |
} |
|
|
|
Function GetSequenceCurrentValue($name,&$value) |
|
{ |
|
$this->last_error="getting sequence current value is not supported"; |
|
return(0); |
|
} |
|
|
|
Function AutoCommitTransaction() |
|
{ |
|
$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"]);$field<count($definition["FIELDS"]);$field++,Next($definition["FIELDS"])) |
|
{ |
|
if($field>0) |
|
$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); |
|
} |
}; |
}; |
|
|
?> |
?> |
|
|