[PHPLIB-DEV] cvs commit From: ssilk (phplib-dev <email protected>)
Date: 11/17/99

From: ssilk
Date: Thu Nov 18 01:52:38 1999
Modified files:
      php-lib/php/query_sql.inc

Log message:
Slight changes, a bugfix and a new feature (I call it "SAP compatibility",
cause it was introduced for this, but I heared now, that e.g. access stores
also spaces for NULL-values)
The inbuilt doc is now outsourced for introduction in the documentation

Index: php-lib/php/query_sql.inc
diff -u php-lib/php/query_sql.inc:1.6 php-lib/php/query_sql.inc:1.7
--- php-lib/php/query_sql.inc:1.6 Tue Jul 27 01:40:31 1999
+++ php-lib/php/query_sql.inc Thu Nov 18 01:52:07 1999
@@ -5,142 +5,18 @@
  * (C) Copyright 1998 Alex Aulbach
  * Credits: Gerard Hickey <Gerard.Hickey <email protected>>
  * I took many ideas from his SQL.inc, thanks! :-)
- * The idea is of this class is based in November 1997,
+ * The idea (and also the name, sorry for this) of this class
+ * is based in November 1997,
  * it was a collection of functions for PHP/FI and mSQL.
  *
- * $Id: query_sql.inc,v 1.6 1999/07/26 23:40:31 ssilk Exp $
+ * $Id: query_sql.inc,v 1.7 1999/11/18 00:52:07 ssilk Exp $
  *
  */
 
 
-/*
-The Query-class is an enhancement to the db_*-classes. Currently It supports
-mySQL an Oracle but it is easy expandable. See down.
+## Query-class is ALWAYS an extension to the DB_Sql-class!
+## See PHPLib-documention to use it!
 
-It always needs the class DB_Sql!
-
-Query is fully upward compatible with DB_Sql. Example:
-
-OLD: NEW:
-
-require("db_mysql.inc"); require("db_mysql.inc");
-class hugobla extends DB_sql {} require("query_sql.inc");
-$db = new hugobla; class hugobla extends Query {}
- $db = new hugobla;
-
-It just provides a number of new functions.
-
-The Query-class is inteded to help you with creating selects, inserts,
-updates, where-clauses etc. Not just *simple* selects, but longer ones. It
-is indeed a great help for tables with more than 10-20 columns. But it can
-also be used for simple and small selects. The inbuilt checks help you
-programming saver.
-
-Here is an example:
-
-file: insert.php3
-------------------
-<?
-## gets data from my form and inserts it into db
-
-require("prepend.inc"); ## here the classes are loaded and configured
-$db = new hugobla;
-$db->query($db->insert_plain_Clause("mytable",$db->capture_vars("mytable"),ARRAY()));
-echo "Values inserted";
-
-?>
-
-file: insert2.php3
--------------------
-<?
-## gets data from my form and inserts it into db with a new INDEX
-## myindex is defined as INT AUTO_INCREMENT PRIMARY KEY
-## (this is mysql, in oracle you have to define a trigger)
-## mytime is defined as DATETIME (DATE in oracle)
-
-require("prepend.inc"); ## here the classes are loaded and configured
-$db = new hugobla;
-$mytime="SYSDATE()";
-$db->query($db->insert_plain_Clause("mytable",$db->capture_vars("mytable"),
- ARRAY(myindex=>'NULL',mytime='func')));
-echo "Values inserted: "$db->last_insert_id();
-
-?>
-
-This example is nice, cause you see how easy it can be used. :-)
-
-The best thing is, that you don't have to care, if a field is a string or a
-number. The values are automatically converted into the right form. The type
-of the vars are read from the table. Stringvalues are encapsulated with '
-(configurable) and escaped (the code for this is currently not good - we are
-assuming, that PHP is configured not to encapsulate strings), int-
-and real-values are casted. It can handle "NULL"-values, function-statements
-or other values for insertion.
-
-You will make less errors.
-
-mySQL and most other DB's accept a a short form of insert-clause (INSERT
-INTO bla VALUES (...)). The Query-class will always make the longer form
-(INSERT INTO BLA (...) VALUES (...)). This makes it possible to use ALTER
-TABLE-commands without changing the program! E.g. changing a field in a
-table from NUMBER to VARCHAR(10) is fully encapsulated with this class.
-
-The class supports currently only mysql and oracle. I think the differences
-between the DBs are encapsulated enough in the db_* classes, so it is
-possible to handle the remaining small differences inside this class (this
-affects mainly the function sql2phptype() ) and it could be easiely extended
-(asuming, that the metadata()-function of the db_*-class works correctly).
-In this case it is important, that the $type-variable in the db_*.inc-class
-is correctly set.
-
-
-TODO-list:
-- A method to create querys like the LIMIT-clause in mySQL. For Oracle
- this works:
-
- select linenum, foo, bar
- from (select rownum as linenum, foo, bar from
- (select foo,bar from chaos order by bar) )
- where linenum between 11 and 20;
-
-- cleaner escaping, handling of \ and NUL (current code is bullshit)
- Some ideas?
-
-- Little Alta-Vista: add functions to create a where clause from a search
- string with rules to handle searching for more than one word.
- half automatic generating search patterns into a where-clause
- simple search engine support, simple support for semi full-text-search
-
-- automatic configurable manipulation of values, eg.
- triming of strings (delete whitespace at begin and end)
- also : TOUPPER, TOLOWER etc
-
-- SELECT-Clause (GROUP BY, HAVING, JOIN...)
-
-- make new functions insert_Clause() etc. which inserts only the
- fields they got from your call (the current will do "plain" insert)
-
-- where_Clause() - creating WHERE for select, update, exists etc.
-
-- serv all queries directly into db, return just the handle
- (hm, how to deal with the DB-handle?)
-
-- Return a 2-dimensional (Table-compatible) field from select (not so important)
-
-- The sql2phptype() can be used to help creating automatic input forms
- for a table
-
-DEPENDING:
-- db_mysql: new function metatabledata(), which returns the table-info from
- current selected table (will return multiple table-columns with a join)
-- db_mysql: perhaps the function sql2phptype() should be placed there?
-
-
-For developers of new db_*.inc: the function metadata() is very important
-for the correct work of this class. T
-
-*/
-
 class Query extends DB_Sql {
 
         ## DONT FORGET to set the variables from DB_Sql! See there!
@@ -178,6 +54,13 @@
         var $StrLengTrunc = false;
         var $StrLengWarn = false;
 
+ ## Oracle stuff
+ ## Adds the behavior that an empty string is converted to NULL
+ var $EmptyStringIsNull = false;
+ ## Adds the behavior, that NULL is converted into an single space
+ ## needed by some applications (SAP for example)
+ var $NULLIsSpace = false;
+
         ###########################
         ## _QDebug
         function _QDebug ($str) {
@@ -307,6 +190,14 @@
                 switch ($type) {
                         case "string" :
                                 $val=(string)$val;
+ if ($val=='' && $this->EmptyStringIsNull) {
+ $val='NULL';
+ $subtype='NULL';
+ }
+ if ($val=='NULL' && $this->NULLIsSpace) {
+ $val=' ';
+ $subtype='';
+ }
                                 if ($this->Quoting) {
                                         $val=AddSlashes($val);
                                 }
@@ -322,12 +213,14 @@
                                                                 echo ", TRUNCATING!";
                                                         }
                                                 }
- if ($this->StrLengTrunc) {
+ if ($this->StrLengTrunc && $subtype!='NULL') {
                                                         $val=substr($val,0,$meta[len]);
                                                 }
                                         }
+ }
+ if ($subtype!='NULL') {
+ $val=$this->Quotechar . $val . $this->Quotechar;
                                 }
- $val=$this->Quotechar . $val . $this->Quotechar;
                                 break;
                         case "int" :
                                 $val=(int)$val;
@@ -623,7 +516,7 @@
                 $q='';
 
                 if (!is_Array($op)) $op=ARRAY();
- if (!is_Array($special)) $op=ARRAY();
+ if (!is_Array($special)) $special=ARRAY();
                 if (!$andor) $andor='AND';
 
                 $i=0;

-
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.