Date: 12/14/99
- Next message: ssilk: "[PHPLIB-DEV] cvs commit"
- Previous message: ssilk: "[PHPLIB-DEV] cvs commit"
- Next in thread: ssilk: "[PHPLIB-DEV] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: ssilk
Date: Tue Dec 14 06:54:25 1999
Modified files:
php-lib/php/db_mysql.inc
php-lib/php/db_oracle.inc
php-lib/php/query_sql.inc
Log message:
Added the functions dispose_vars(), (oposite function to capture_vars())
import_record_vars() - taken from db_usql.inc
dispose_next_record() - next_record() and dispose_vars()
insert_query() - inserts a query into another table (copy)
dump_query() - taken from db_usql.inc
Changed the function sql2phptype() cause the type and subtype
is now set from DB_Sql-class.
Changed the function metadata() in db_mysql.inc and db_oracle.inc
that it will now set the php-type and subtype.
All changes are currently UNTESTED (even Syntax)
Index: php-lib/php/db_mysql.inc
diff -u php-lib/php/db_mysql.inc:1.25 php-lib/php/db_mysql.inc:1.26
--- php-lib/php/db_mysql.inc:1.25 Thu Nov 11 21:41:46 1999
+++ php-lib/php/db_mysql.inc Tue Dec 14 06:54:24 1999
@@ -5,7 +5,7 @@
* Copyright (c) 1998,1999 NetUSE GmbH
* Boris Erdmann, Kristian Koehntopp
*
- * $Id: db_mysql.inc,v 1.25 1999/11/11 20:41:46 kk Exp $
+ * $Id: db_mysql.inc,v 1.26 1999/12/14 05:54:24 ssilk Exp $
*
*/
@@ -286,7 +286,7 @@
* [0]["len"] field length
* [0]["flags"] field flags
*
- * - full is true
+ * - full is true (was mainly introduced for the Query-class)
* $result[]:
* ["num_fields"] number of metadata records
* [0]["table"] table name
@@ -294,8 +294,10 @@
* [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.
+ * [0]["php_type"] the correspondig PHP-type
+ * [0]["php_subtype"] the subtype of PHP-type
+ * ["meta"][field name] index-num of field named "field name"
+ * This could used, if you have the name, but no index-num - very fast
*/
// if no $table specified, assume that we are working with a query
@@ -336,6 +338,34 @@
$res[$i]["len"] = <email protected> ($id, $i);
$res[$i]["flags"] = <email protected> ($id, $i);
$res["meta"][$res[$i]["name"]] = $i;
+ switch ($res[$i]["type"]) {
+ case "var string":
+ case "string" :
+ case "char" :
+ $res[$i][php_type]="string";
+ $res[$i][php_subtype]="";
+ break;
+ case "timestamp" :
+ case "datetime" :
+ case "date" :
+ case "time" :
+ $res[$i][php_type]="string";
+ $res[$i][php_subtype]="date";
+ break;
+ case "blob" :
+ $res[$i][php_type]="string";
+ $res[$i][php_subtype]="blob";
+ break;
+ case "real" :
+ $res[$i][php_type]="double";
+ $res[$i][php_subtype]="";
+ break;
+ case "long" :
+ default :
+ $res[$i][php_type]="int";
+ $res[$i][php_subtype]="";
+ break;
+ }
}
}
Index: php-lib/php/db_oracle.inc
diff -u php-lib/php/db_oracle.inc:1.19 php-lib/php/db_oracle.inc:1.20
--- php-lib/php/db_oracle.inc:1.19 Thu Nov 18 01:32:44 1999
+++ php-lib/php/db_oracle.inc Tue Dec 14 06:54:24 1999
@@ -4,7 +4,7 @@
*
* Copyright (c) 1998,1999 Luis Francisco Gonzalez Hernandez
*
- * $Id: db_oracle.inc,v 1.19 1999/11/18 00:32:44 ssilk Exp $
+ * $Id: db_oracle.inc,v 1.20 1999/12/14 05:54:24 ssilk Exp $
*
*/
@@ -255,8 +255,10 @@
* [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)
+ * [0]["php_type"] the correspondig PHP-type
+ * [0]["php_subtype"] the subtype of PHP-type
* ["meta"][field name] index of field named "field name"
- * The last one is used, if you have a field name, but no index.
+ * This could used, if you have the name, but no index-num - very fast
* Test: if (isset($result['meta']['myfield'])) {} ...
*/
@@ -293,6 +295,39 @@
$j=$res[$i]["name"];
$res["meta"][$j] = $i;
$res["meta"][strtoupper($j)] = $i;
+ switch ($res[$i]["type"]) {
+ case "VARCHAR2" :
+ case "VARCHAR" :
+ case "CHAR" :
+ $res["php_type"]="string";
+ $res["php_subtype"]="";
+ break;
+ case "DATE" :
+ $res["php_type"]="string";
+ $res["php_subtype"]="date";
+ break;
+ case "BLOB" :
+ case "CLOB" :
+ case "BFILE" :
+ case "RAW" :
+ case "LONG" :
+ case "LONG RAW" :
+ $res["php_type"]="string";
+ $res["php_subtype"]="blob";
+ break;
+ case "NUMBER" :
+ if ($res[$i]["format"]) {
+ $res["php_type"]="double";
+ $res["php_subtype"]="";
+ } else {
+ $res["php_type"]="int";
+ $res["php_subtype"]="";
+ }
+ break;
+ default :
+ $this->halt("metadata(): Type is not a valid value: '$res[$i][type]'");
+ break;
+ }
}
if ($full) $res["meta"][$res[$i]["name"]] = $i;
$i++;
Index: php-lib/php/query_sql.inc
diff -u php-lib/php/query_sql.inc:1.7 php-lib/php/query_sql.inc:1.8
--- php-lib/php/query_sql.inc:1.7 Thu Nov 18 01:52:07 1999
+++ php-lib/php/query_sql.inc Tue Dec 14 06:54:24 1999
@@ -9,7 +9,7 @@
* is based in November 1997,
* it was a collection of functions for PHP/FI and mSQL.
*
- * $Id: query_sql.inc,v 1.7 1999/11/18 00:52:07 ssilk Exp $
+ * $Id: query_sql.inc,v 1.8 1999/12/14 05:54:24 ssilk Exp $
*
*/
@@ -79,73 +79,11 @@
###########################
- ## 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;
- }
+ function sql2phptype ($meta) {
+ if (!$meta[php_type])
+ $this->halt("sql2phptype(): php_type is empty!");
+ return(Array($meta[php_type],$meta[php_subtype]);
}
@@ -173,7 +111,7 @@
##
function convert ($val,$meta,$special="") {
- list($type,$subtype)=$this->sql2phptype($meta["type"],$meta["format"]);
+ list($type,$subtype)=$this->sql2phptype($meta);
if (($val == "NULL" &&
($type != "string" || $type[1] != "")) ||
$special == "NULL") {
@@ -629,6 +567,93 @@
}
}
+
+ // The following part is included from db_usql
+ // This is the better place...
+
+
+ //--------------------------------------------------------------
+ // this function can be used to export all the columns of
+ // a record into *global* variables.
+ // So it is the oposite function to capture_vars()
+ // It should be used after a call to next_record().
+ //
+ // $param is an optional assoc-array-parameter:
+ // to_upper=>true - uppercases all vars, otherwise lowercase
+ //--------------------------------------------------------------
+ function dispose_vars($params='') {
+ if (!is_array($params)) $params=ARRAY();
+ reset($this->Record);
+ while (list($key, $val) = each($this->Record))
+ if (ereg("[A-Za-z_][A-Za-z0-9_]*", $key)) {
+ if ($params[to_upper]) {
+ $field_name = strtoupper($key);
+ } else {
+ # Default behavior, cause phplib
+ # uses always lowercase
+ $field_name = strtolower($key);
+ }
+ global $$field_name;
+ $$field_name=$val;
+ }
+ }
+
+ // Alias to dispose_vars for compatibility to db_usql
+ function import_record_vars($params='') {
+ $params[to_upper]=true;
+ $this->dispose_vars($params);
+ }
+
+ // Alias to dispose_vars, but next_record() is called before
+ function dispose_next_record($params='') {
+ $this->next_record();
+ $this->dispose_vars($params);
+ }
+
+
+/*--------------------------------------------
+ There is no sense in it!
+ deleted this function!
+ //--------------------------------------------------------------
+ // 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 "copy" all the records of
+ // a former query to another table
+ // you can hand over a translation-table, which is an assoc-array:
+ // this_query_column=>my_tablename_column
+ // renames this_query_column into my_table_column
+ //--------------------------------------------------------------
+ function insert_query($table,$translate='') {
+ if(!is_array($translate) $translate=Array();
+ while ($this->next_record()) {
+ $meta=$this->metadata_buffered($table);
+ for ( $i=0; $i < $meta[num_fields]; $i++) {
+ $j=$meta[$i][name];
+ if ($translate[$j]) {
+ $v[$translate[$j]] = $this->Record[$j];
+ } else {
+ $v[$j] = $this->Record[$j];
+ }
+ }
+ $this->insert_plain_clause($table,$v,ARRAY());
+ }
+ }
+
+ // compatibility function to db_usql
+ function dump_query($tablename,$bla='') {
+ $this->insert_query($tablename);
+ }
}
-
PHPLIB Developers Mailing List. Send messages to <phplib-dev <email protected>>.
To unsubscribe, send "unsubscribe" to <phplib-dev-request <email protected>> in
the body, not the subject, of your message.
- Next message: ssilk: "[PHPLIB-DEV] cvs commit"
- Previous message: ssilk: "[PHPLIB-DEV] cvs commit"
- Next in thread: ssilk: "[PHPLIB-DEV] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

