]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/adodb/adodb-lib.inc.php
elseif
[SourceForge/phpwiki.git] / lib / WikiDB / adodb / adodb-lib.inc.php
1 <?php
2
3 global $ADODB_INCLUDED_LIB;
4 $ADODB_INCLUDED_LIB = 1;
5
6 /*
7  @version V4.22 15 Apr 2004 (c) 2000-2004 John Lim (jlim\@natsoft.com.my). All rights reserved.
8   Released under both BSD license and Lesser GPL library license.
9   Whenever there is any discrepancy between the two licenses,
10   the BSD license will take precedence. See License.txt.
11   Set tabs to 4 for best viewing.
12
13   Less commonly used functions are placed here to reduce size of adodb.inc.php.
14 */
15
16 // Force key to upper.
17 // See also http://www.php.net/manual/en/function.array-change-key-case.php
18 function _array_change_key_case($an_array)
19 {
20     if (is_array($an_array)) {
21         foreach($an_array as $key=>$value)
22             $new_array[strtoupper($key)] = $value;
23
24            return $new_array;
25    }
26
27     return $an_array;
28 }
29
30 function _adodb_replace(&$zthis, $table, $fieldArray, $keyCol, $autoQuote, $has_autoinc)
31 {
32         if (count($fieldArray) == 0) return 0;
33         $first = true;
34         $uSet = '';
35
36         if (!is_array($keyCol)) {
37             $keyCol = array($keyCol);
38         }
39         foreach($fieldArray as $k => $v) {
40             if ($autoQuote && !is_numeric($v) and strncmp($v,"'",1) !== 0 and strcasecmp($v,'null')!=0) {
41                 $v = $zthis->qstr($v);
42                 $fieldArray[$k] = $v;
43             }
44             if (in_array($k,$keyCol)) continue; // skip UPDATE if is key
45
46             if ($first) {
47                 $first = false;
48                 $uSet = "$k=$v";
49             } else
50                 $uSet .= ",$k=$v";
51         }
52
53         $where = false;
54         foreach ($keyCol as $v) {
55             if ($where) $where .= " and $v=$fieldArray[$v]";
56             else $where = "$v=$fieldArray[$v]";
57         }
58
59         if ($uSet && $where) {
60             $update = "UPDATE $table SET $uSet WHERE $where";
61
62             $rs = $zthis->Execute($update);
63             if ($rs) {
64                 if ($zthis->poorAffectedRows) {
65                 /*
66                  The Select count(*) wipes out any errors that the update would have returned.
67                 http://phplens.com/lens/lensforum/msgs.php?id=5696
68                 */
69                     if ($zthis->ErrorNo()<>0) return 0;
70
71                 # affected_rows == 0 if update field values identical to old values
72                 # for mysql - which is silly.
73
74                     $cnt = $zthis->GetOne("select count(*) from $table where $where");
75                     if ($cnt > 0) return 1; // record already exists
76                 } else
77                      if (($zthis->Affected_Rows()>0)) return 1;
78             }
79         }
80     //  print "<p>Error=".$this->ErrorNo().'<p>';
81         $first = true;
82         foreach($fieldArray as $k => $v) {
83             if ($has_autoinc && in_array($k,$keyCol)) continue; // skip autoinc col
84
85             if ($first) {
86                 $first = false;
87                 $iCols = "$k";
88                 $iVals = "$v";
89             } else {
90                 $iCols .= ",$k";
91                 $iVals .= ",$v";
92             }
93         }
94         $insert = "INSERT INTO $table ($iCols) VALUES ($iVals)";
95         $rs = $zthis->Execute($insert);
96         return ($rs) ? 2 : 0;
97 }
98
99 // Requires $ADODB_FETCH_MODE = ADODB_FETCH_NUM
100 function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=false,
101             $size=0, $selectAttr='',$compareFields0=true)
102 {
103     $hasvalue = false;
104
105     if ($multiple or is_array($defstr)) {
106         if ($size==0) $size=5;
107         $attr = " multiple size=$size";
108         if (!strpos($name,'[]')) $name .= '[]';
109     } elseif ($size) $attr = " size=$size";
110     else $attr ='';
111
112     $s = "<select name=\"$name\"$attr $selectAttr>";
113     if ($blank1stItem)
114         if (is_string($blank1stItem))  {
115             $barr = explode(':',$blank1stItem);
116             if (sizeof($barr) == 1) $barr[] = '';
117             $s .= "\n<option value=\"".$barr[0]."\">".$barr[1]."</option>";
118         } else $s .= "\n<option></option>";
119
120     if ($zthis->FieldCount() > 1) $hasvalue=true;
121     else $compareFields0 = true;
122
123     $value = '';
124     while(!$zthis->EOF) {
125         $zval = rtrim(reset($zthis->fields));
126         if (sizeof($zthis->fields) > 1) {
127             if (isset($zthis->fields[1]))
128                 $zval2 = rtrim($zthis->fields[1]);
129             else
130                 $zval2 = rtrim(next($zthis->fields));
131         }
132         $selected = ($compareFields0) ? $zval : $zval2;
133
134         if ($blank1stItem && $zval=="") {
135             $zthis->MoveNext();
136             continue;
137         }
138         if ($hasvalue)
139             $value = ' value="'.htmlspecialchars($zval2).'"';
140
141         if (is_array($defstr))  {
142
143             if (in_array($selected,$defstr))
144                 $s .= "<option selected$value>".htmlspecialchars($zval).'</option>';
145             else
146                 $s .= "\n<option".$value.'>'.htmlspecialchars($zval).'</option>';
147         }
148         else {
149             if (strcasecmp($selected,$defstr)==0)
150                 $s .= "<option selected$value>".htmlspecialchars($zval).'</option>';
151             else
152                 $s .= "\n<option".$value.'>'.htmlspecialchars($zval).'</option>';
153         }
154         $zthis->MoveNext();
155     } // while
156
157     return $s ."\n</select>\n";
158 }
159
160 /*
161     Count the number of records this sql statement will return by using
162     query rewriting techniques...
163
164     Does not work with UNIONs.
165 */
166 function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0)
167 {
168     $qryRecs = 0;
169
170      if (preg_match("/^\s*SELECT\s+DISTINCT/is", $sql) || preg_match('/\s+GROUP\s+BY\s+/is',$sql)) {
171         // ok, has SELECT DISTINCT or GROUP BY so see if we can use a table alias
172         // but this is only supported by oracle and postgresql...
173         if ($zthis->dataProvider == 'oci8') {
174
175             $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql);
176             $rewritesql = "SELECT COUNT(*) FROM ($rewritesql)";
177
178         } elseif ( $zthis->databaseType == 'postgres' || $zthis->databaseType == 'postgres7')  {
179
180             $info = $zthis->ServerInfo();
181             if (substr($info['version'],0,3) >= 7.1) { // good till version 999
182                 $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql);
183                 $rewritesql = "SELECT COUNT(*) FROM ($rewritesql) _ADODB_ALIAS_";
184             }
185         }
186     } else {
187         // now replace SELECT ... FROM with SELECT COUNT(*) FROM
188
189         $rewritesql = preg_replace(
190                     '/^\s*SELECT\s.*\s+FROM\s/Uis','SELECT COUNT(*) FROM ',$sql);
191
192         // fix by alexander zhukov, alex#unipack.ru, because count(*) and 'order by' fails
193         // with mssql, access and postgresql. Also a good speedup optimization - skips sorting!
194         $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$rewritesql);
195     }
196
197     if (isset($rewritesql) && $rewritesql != $sql) {
198         if ($secs2cache) {
199             // we only use half the time of secs2cache because the count can quickly
200             // become inaccurate if new records are added
201             $qryRecs = $zthis->CacheGetOne($secs2cache/2,$rewritesql,$inputarr);
202
203         } else {
204             $qryRecs = $zthis->GetOne($rewritesql,$inputarr);
205           }
206         if ($qryRecs !== false) return $qryRecs;
207     }
208
209     //--------------------------------------------
210     // query rewrite failed - so try slower way...
211
212     // strip off unneeded ORDER BY
213     $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql);
214     $rstest = &$zthis->Execute($rewritesql,$inputarr);
215     if ($rstest) {
216               $qryRecs = $rstest->RecordCount();
217         if ($qryRecs == -1) {
218         global $ADODB_EXTENSION;
219         // some databases will return -1 on MoveLast() - change to MoveNext()
220             if ($ADODB_EXTENSION) {
221                 while(!$rstest->EOF) {
222                     adodb_movenext($rstest);
223                 }
224             } else {
225                 while(!$rstest->EOF) {
226                     $rstest->MoveNext();
227                 }
228             }
229             $qryRecs = $rstest->_currentRow;
230         }
231         $rstest->Close();
232         if ($qryRecs == -1) return 0;
233     }
234
235     return $qryRecs;
236 }
237
238 /*
239      Code originally from "Cornel G" <conyg@fx.ro>
240
241     This code will not work with SQL that has UNION in it
242
243     Also if you are using CachePageExecute(), there is a strong possibility that
244     data will get out of synch. use CachePageExecute() only with tables that
245     rarely change.
246 */
247 function &_adodb_pageexecute_all_rows(&$zthis, $sql, $nrows, $page,
248                         $inputarr=false, $secs2cache=0)
249 {
250     $atfirstpage = false;
251     $atlastpage = false;
252     $lastpageno=1;
253
254     // If an invalid nrows is supplied,
255     // we assume a default value of 10 rows per page
256     if (!isset($nrows) || $nrows <= 0) $nrows = 10;
257
258     $qryRecs = false; //count records for no offset
259
260     $qryRecs = _adodb_getcount($zthis,$sql,$inputarr,$secs2cache);
261     $lastpageno = (int) ceil($qryRecs / $nrows);
262     $zthis->_maxRecordCount = $qryRecs;
263
264     // If page number <= 1, then we are at the first page
265     if (!isset($page) || $page <= 1) {
266         $page = 1;
267         $atfirstpage = true;
268     }
269
270     // ***** Here we check whether $page is the last page or
271     // whether we are trying to retrieve
272     // a page number greater than the last page number.
273     if ($page >= $lastpageno) {
274         $page = $lastpageno;
275         $atlastpage = true;
276     }
277
278     // We get the data we want
279     $offset = $nrows * ($page-1);
280     if ($secs2cache > 0)
281         $rsreturn = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr);
282     else
283         $rsreturn = &$zthis->SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache);
284
285     // Before returning the RecordSet, we set the pagination properties we need
286     if ($rsreturn) {
287         $rsreturn->_maxRecordCount = $qryRecs;
288         $rsreturn->rowsPerPage = $nrows;
289         $rsreturn->AbsolutePage($page);
290         $rsreturn->AtFirstPage($atfirstpage);
291         $rsreturn->AtLastPage($atlastpage);
292         $rsreturn->LastPageNo($lastpageno);
293     }
294     return $rsreturn;
295 }
296
297 // Iván Oliva version
298 function &_adodb_pageexecute_no_last_page(&$zthis, $sql, $nrows, $page, $inputarr=false, $secs2cache=0)
299 {
300
301     $atfirstpage = false;
302     $atlastpage = false;
303
304     if (!isset($page) || $page <= 1) {  // If page number <= 1, then we are at the first page
305         $page = 1;
306         $atfirstpage = true;
307     }
308     if ($nrows <= 0) $nrows = 10;       // If an invalid nrows is supplied, we assume a default value of 10 rows per page
309
310     // ***** Here we check whether $page is the last page or whether we are trying to retrieve a page number greater than
311     // the last page number.
312     $pagecounter = $page + 1;
313     $pagecounteroffset = ($pagecounter * $nrows) - $nrows;
314     if ($secs2cache>0) $rstest = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr);
315     else $rstest = &$zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $secs2cache);
316     if ($rstest) {
317         while ($rstest && $rstest->EOF && $pagecounter>0) {
318             $atlastpage = true;
319             $pagecounter--;
320             $pagecounteroffset = $nrows * ($pagecounter - 1);
321             $rstest->Close();
322             if ($secs2cache>0) $rstest = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr);
323             else $rstest = &$zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $secs2cache);
324         }
325         if ($rstest) $rstest->Close();
326     }
327     if ($atlastpage) {  // If we are at the last page or beyond it, we are going to retrieve it
328         $page = $pagecounter;
329         if ($page == 1) $atfirstpage = true;    // We have to do this again in case the last page is the same as the first
330             //... page, that is, the recordset has only 1 page.
331     }
332
333     // We get the data we want
334     $offset = $nrows * ($page-1);
335     if ($secs2cache > 0) $rsreturn = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr);
336     else $rsreturn = &$zthis->SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache);
337
338     // Before returning the RecordSet, we set the pagination properties we need
339     if ($rsreturn) {
340         $rsreturn->rowsPerPage = $nrows;
341         $rsreturn->AbsolutePage($page);
342         $rsreturn->AtFirstPage($atfirstpage);
343         $rsreturn->AtLastPage($atlastpage);
344     }
345     return $rsreturn;
346 }
347
348 function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq=false)
349 {
350         if (!$rs) {
351             printf(ADODB_BAD_RS,'GetUpdateSQL');
352             return false;
353         }
354
355         $fieldUpdatedCount = 0;
356         $arrFields = _array_change_key_case($arrFields);
357
358         $hasnumeric = isset($rs->fields[0]);
359         $setFields = '';
360
361         // Loop through all of the fields in the recordset
362         for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++) {
363             // Get the field from the recordset
364             $field = $rs->FetchField($i);
365
366             // If the recordset field is one
367             // of the fields passed in then process.
368             $upperfname = strtoupper($field->name);
369             if (adodb_key_exists($upperfname,$arrFields)) {
370
371                 // If the existing field value in the recordset
372                 // is different from the value passed in then
373                 // go ahead and append the field name and new value to
374                 // the update query.
375
376                 if ($hasnumeric) $val = $rs->fields[$i];
377                 else if (isset($rs->fields[$upperfname])) $val = $rs->fields[$upperfname];
378                 else if (isset($rs->fields[$field->name])) $val =  $rs->fields[$field->name];
379                 else if (isset($rs->fields[strtolower($upperfname)])) $val =  $rs->fields[strtolower($upperfname)];
380                 else $val = '';
381
382                 if ($forceUpdate || strcmp($val, $arrFields[$upperfname])) {
383                     // Set the counter for the number of fields that will be updated.
384                     $fieldUpdatedCount++;
385
386                     // Based on the datatype of the field
387                     // Format the value properly for the database
388                 $type = $rs->MetaType($field->type);
389
390                     // is_null requires php 4.0.4
391                 if ((defined('ADODB_FORCE_NULLS') && is_null($arrFields[$upperfname])) ||
392                     $arrFields[$upperfname] === 'null') {
393                     $setFields .= $field->name . " = null, ";
394                 } else {
395                     if ($type == 'null') {
396                         $type = 'C';
397                     }
398                     //we do this so each driver can customize the sql for
399                     //DB specific column types.
400                     //Oracle needs BLOB types to be handled with a returning clause
401                     //postgres has special needs as well
402                     $setFields .= _adodb_column_sql($zthis, 'U', $type, $upperfname,
403                                                       $arrFields, $magicq);
404                 }
405             }
406         }
407     }
408
409         // If there were any modified fields then build the rest of the update query.
410         if ($fieldUpdatedCount > 0 || $forceUpdate) {
411                     // Get the table name from the existing query.
412             preg_match("/FROM\s+".ADODB_TABLE_REGEX."/is", $rs->sql, $tableName);
413
414             // Get the full where clause excluding the word "WHERE" from
415             // the existing query.
416             preg_match('/\sWHERE\s(.*)/is', $rs->sql, $whereClause);
417
418             $discard = false;
419             // not a good hack, improvements?
420             if ($whereClause)
421                 preg_match('/\s(LIMIT\s.*)/is', $whereClause[1], $discard);
422             else
423                 $whereClause = array(false,false);
424
425             if ($discard)
426                 $whereClause[1] = substr($whereClause[1], 0, strlen($whereClause[1]) - strlen($discard[1]));
427
428         $sql = 'UPDATE '.$tableName[1].' SET '.substr($setFields, 0, -2);
429         if (strlen($whereClause[1]) > 0)
430             $sql .= ' WHERE '.$whereClause[1];
431
432         return $sql;
433
434         } else {
435             return false;
436     }
437 }
438
439 function adodb_key_exists($key, &$arr)
440 {
441     if (!defined('ADODB_FORCE_NULLS')) {
442         // the following is the old behaviour where null or empty fields are ignored
443         return (!empty($arr[$key])) || (isset($arr[$key]) && strlen($arr[$key])>0);
444     }
445
446     if (isset($arr[$key])) return true;
447     ## null check below
448     if (ADODB_PHPVER >= 0x4010) return array_key_exists($key,$arr);
449     return false;
450 }
451
452 /**
453  * There is a special case of this function for the oci8 driver.
454  * The proper way to handle an insert w/ a blob in oracle requires
455  * a returning clause with bind variables and a descriptor blob.
456  *
457  *
458  */
459 function _adodb_getinsertsql(&$zthis,&$rs,$arrFields,$magicq=false)
460 {
461     $tableName = '';
462     $values = '';
463     $fields = '';
464     $recordSet = null;
465     $arrFields = _array_change_key_case($arrFields);
466     $fieldInsertedCount = 0;
467
468     if (is_string($rs)) {
469         //ok we have a table name
470         //try and get the column info ourself.
471         $tableName = $rs;
472
473         //we need an object for the recordSet
474         //because we have to call MetaType.
475         //php can't do a $rsclass::MetaType()
476         $rsclass = $zthis->rsPrefix.$zthis->databaseType;
477         $recordSet =& new $rsclass(-1,$zthis->fetchMode);
478         $recordSet->connection = &$zthis;
479
480         $columns = $zthis->MetaColumns( $tableName );
481     } elseif (is_subclass_of($rs, 'adorecordset')) {
482         for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++)
483             $columns[] = $rs->FetchField($i);
484         $recordSet =& $rs;
485
486     } else {
487         printf(ADODB_BAD_RS,'GetInsertSQL');
488         return false;
489     }
490
491     // Loop through all of the fields in the recordset
492     foreach( $columns as $field ) {
493         $upperfname = strtoupper($field->name);
494         if (adodb_key_exists($upperfname,$arrFields)) {
495
496             // Set the counter for the number of fields that will be inserted.
497             $fieldInsertedCount++;
498
499             // Get the name of the fields to insert
500             $fields .= $field->name . ", ";
501
502             $type = $recordSet->MetaType($field->type);
503
504             if ((defined('ADODB_FORCE_NULLS') && is_null($arrFields[$upperfname])) ||
505                 $arrFields[$upperfname] === 'null') {
506                 $values  .= "null, ";
507             } else {
508                 //we do this so each driver can customize the sql for
509                 //DB specific column types.
510                 //Oracle needs BLOB types to be handled with a returning clause
511                 //postgres has special needs as well
512                 $values .= _adodb_column_sql($zthis, 'I', $type, $upperfname,
513                                                $arrFields, $magicq);
514             }
515         }
516     }
517
518
519     // If there were any inserted fields then build the rest of the insert query.
520     if ($fieldInsertedCount <= 0)  return false;
521
522     // Get the table name from the existing query.
523     if (!$tableName) {
524         preg_match("/FROM\s+".ADODB_TABLE_REGEX."/is", $rs->sql, $tableName);
525             $tableName = $tableName[1];
526     }
527
528     // Strip off the comma and space on the end of both the fields
529     // and their values.
530     $fields = substr($fields, 0, -2);
531     $values = substr($values, 0, -2);
532
533     // Append the fields and their values to the insert query.
534     return 'INSERT INTO '.$tableName.' ( '.$fields.' ) VALUES ( '.$values.' )';
535 }
536
537
538 /**
539  * This private method is used to help construct
540  * the update/sql which is generated by GetInsertSQL and GetUpdateSQL.
541  * It handles the string construction of 1 column -> sql string based on
542  * the column type.  We want to do 'safe' handling of BLOBs
543  *
544  * @param string the type of sql we are trying to create
545  *                'I' or 'U'.
546  * @param string column data type from the db::MetaType() method
547  * @param string the column name
548  * @param array the column value
549  *
550  * @return string
551  *
552  */
553 function _adodb_column_sql_oci8(&$zthis,$action, $type, $fname, $arrFields, $magicq)
554 {
555     $sql = '';
556
557     // Based on the datatype of the field
558     // Format the value properly for the database
559     switch($type) {
560     case 'B':
561         //in order to handle Blobs correctly, we need
562         //to do some magic for Oracle
563
564         //we need to create a new descriptor to handle
565         //this properly
566         if (!empty($zthis->hasReturningInto)) {
567             if ($action == 'I') {
568                 $sql = 'empty_blob(), ';
569             } else {
570                 $sql = $fname. '=empty_blob(), ';
571             }
572             //add the variable to the returning clause array
573             //so the user can build this later in
574             //case they want to add more to it
575             $zthis->_returningArray[$fname] = ':xx'.$fname.'xx';
576         } else {
577             //this is to maintain compatibility
578             //with older adodb versions.
579             $sql = _adodb_column_sql($zthis, $action, $type, $fname, $arrFields, $magicq,false);
580         }
581         break;
582
583     case "X":
584         //we need to do some more magic here for long variables
585         //to handle these correctly in oracle.
586
587         //create a safe bind var name
588         //to avoid conflicts w/ dupes.
589        if (!empty($zthis->hasReturningInto)) {
590             if ($action == 'I') {
591                 $sql = ':xx'.$fname.'xx, ';
592             } else {
593                 $sql = $fname.'=:xx'.$fname.'xx, ';
594             }
595             //add the variable to the returning clause array
596             //so the user can build this later in
597             //case they want to add more to it
598             $zthis->_returningArray[$fname] = ':xx'.$fname.'xx';
599         } else {
600             //this is to maintain compatibility
601             //with older adodb versions.
602             $sql = _adodb_column_sql($zthis, $action, $type, $fname, $arrFields, $magicq,false);
603         }
604         break;
605
606     default:
607         $sql = _adodb_column_sql($zthis, $action, $type, $fname, $arrFields, $magicq,false);
608         break;
609     }
610
611     return $sql;
612 }
613
614 function _adodb_column_sql(&$zthis, $action, $type, $fname, $arrFields, $magicq, $recurse=true)
615 {
616
617     if ($recurse) {
618         switch($zthis->dataProvider)  {
619         case 'postgres':
620             if ($type == 'L') $type = 'C';
621             break;
622         case 'oci8':
623             return _adodb_column_sql_oci8($zthis, $action, $type, $fname, $arrFields, $magicq);
624
625         }
626     }
627
628     $sql = '';
629
630     switch($type) {
631         case "C":
632         case "X":
633         case 'B':
634             if ($action == 'I') {
635                 $sql = $zthis->qstr($arrFields[$fname],$magicq) . ", ";
636             } else {
637                 $sql .= $fname . "=" . $zthis->qstr($arrFields[$fname],$magicq) . ", ";
638             }
639           break;
640
641         case "D":
642             if ($action == 'I') {
643                 $sql = $zthis->DBDate($arrFields[$fname]) . ", ";
644             } else {
645                 $sql .= $fname . "=" . $zthis->DBDate($arrFields[$fname]) . ", ";
646             }
647             break;
648
649         case "T":
650             if ($action == 'I') {
651                 $sql = $zthis->DBTimeStamp($arrFields[$fname]) . ", ";
652             } else {
653                 $sql .= $fname . "=" . $zthis->DBTimeStamp($arrFields[$fname]) . ", ";
654             }
655             break;
656
657         default:
658             $val = $arrFields[$fname];
659             if (empty($val)) $val = '0';
660
661
662             if ($action == 'I') {
663                 $sql .= $val . ", ";
664             } else {
665                 $sql .= $fname . "=" . $val  . ", ";
666             }
667             break;
668     }
669
670     return $sql;
671 }
672 ?>