Example #1
0
 function executeInsertQuery(&$sqlQuery)
 {
     // Read Table
     $rs = $this->readTableForAppend($sqlQuery->tables[0]);
     if (TXTDBAPI_VERBOSE_DEBUG) {
         echo "executeInsertQuery(): Last Record read for appending:<br>";
         $rs->dump();
         echo "<br>";
     }
     if (!$rs) {
         print_error_msg("Reading the Table " . $sqlQuery->tables[0] . " failed");
         return false;
     }
     // Open Table
     $fp = $this->openTableAppend($sqlQuery->tables[0]);
     if (!$fp) {
         print_error_msg("Open the Table " . $sqlQuery->tables[0] . " (for APPEND) failed");
         return false;
     }
     // a INSERT INTO table () VALUES () query: just write the default values
     if (count($sqlQuery->colNames) == 0 && count($sqlQuery->fieldValues) == 0) {
         $rs->append();
         $this->updateLastInsertId($rs);
         $this->appendToTable($fp, $rs, 1);
         $this->closeTable($fp);
         return 1;
         // Error Handling ??
     }
     // execute functions on the values
     $colName = "";
     $colTable = "";
     $colFunc = "";
     for ($i = 0; $i < count($sqlQuery->fieldValues); ++$i) {
         split_full_colname($sqlQuery->fieldValues[$i], $colName, $colTable, $colFunc);
         if ($colFunc) {
             if ($colName && has_quotes($colName)) {
                 remove_quotes($colName);
             }
             $sqlQuery->fieldValues[$i] = execFunc($colFunc, $colName);
         } else {
             if (has_quotes($sqlQuery->fieldValues[$i])) {
                 remove_quotes($sqlQuery->fieldValues[$i]);
             }
         }
     }
     $rc = true;
     switch (count($sqlQuery->colNames)) {
         case 0:
             $rs->appendRow($sqlQuery->fieldValues);
             $this->updateLastInsertId($rs);
             $this->appendToTable($fp, $rs, 1);
             $this->closeTable($fp);
             return $rc;
             break;
         default:
             $rs->append();
             for ($i = 0; $i < count($sqlQuery->colNames); ++$i) {
                 if (!$rs->setCurrentValueByName($sqlQuery->colNames[$i], $sqlQuery->fieldValues[$i])) {
                     $rc = false;
                     break;
                 }
             }
             if ($rc) {
                 $this->updateLastInsertId($rs);
                 $this->appendToTable($fp, $rs, 1);
             }
             $this->closeTable($fp);
             return $rc;
             break;
     }
 }
Example #2
0
 function generateAdditionalColumnsFromArray($arrFullColNames)
 {
     $colNames = array();
     $colTables = array();
     $colFuncs = array();
     for ($i = 0; $i < count($arrFullColNames); ++$i) {
         $colNames[$i] = "";
         $colTables[$i] = "";
         $colFuncs[$i] = "";
         split_full_colname($arrFullColNames[$i], $colNames[$i], $colTables[$i], $colFuncs[$i]);
     }
     return $this->generateAdditionalColumnsFromArrays($colNames, $colTables, $colFuncs);
 }