PEAR and autoExecute - newbie to PHP
| From: | Peter | Date: | Sun, 04 Jan 2004 19:54:55 +0000 |
| Subject: | PEAR and autoExecute - newbie to PHP | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-9953@lists.php.net to get a copy of this message | ||
Hello, I am trying to write a generalised DB browser/updater using PEAR, and have hit a problem I
hope someone can help me with!
All is going well untill I try and write an update using this code:
23 $row = array();
24 foreach ($_REQUEST as $name => $value) {
25 if (substr($name,0,8) == 'pdbedit_') {
26 $name = substr($name,8);
27 $row[$name] = $value;
28 } /* if */
29 } /* foreach */
30
31 $autores = $db->autoExecute($pdb_table,$row, DB_AUTOQUERY_UPDATE,$pdb_where);
32 if (!ifErrorEchoDo('Cannot update '.$pdb_table,$autores))
Which results in:
Cannot update runs -1 DB Error: unknown error
UPDATE runs SET runid = '2',runhorse = '1',...[nativecode=ERROR: Bad boolean
external representation '' ]
This looks strange as the numeric values are enclosed in quotes. Surely PEAR should be looking at
the column types and quoting or not as is appropriate? Eg. for pgsql:
507 int need_quote(const int ti) {
508 return (IS_PGCHAR(ti) || IS_PGDATE(ti));
509 /* mysql return ((strncmp(ts,"char",4) == 0) ||
510 (strncmp(ts,"date",4) == 0) ||
511 (strncmp(ts,"text",4) == 0) ||
512 (strncmp(ts,"varchar",7) == 0)); */
513 }
514...
1062 else if ((strlen(var->value) == 0) && (!IS_PGCHAR(PQftype(res,cnt)))) {
1063 strcat(qry,"=null,"); /* Blank numeric = null */ <--- SAME FOR
BOOLEAN?
1064 }
1065 else if (need_quote(PQftype(res,cnt))) {
1066 strcat(qry,"='");
1067 strcat(qry,var->value);
1068 strcat(qry,"',");
1069 }
1070 else {
1071 strcat(qry,"=");
1072 strcat(qry,var->value);
1073 strcat(qry,",");
But the problem that breaks it is a null value of '' for a boolean column.
I seem to remember seeing something somewhere about translating nulls to eg. '(null)', but
can't find it again. Any hints much appreciated!
Peter