protected function getTableColumnDefs() { return first_val($this->getTableDefs()); }
/** * Makes every attempt to succeed at doing the query you ask it to do. * This function will attempt the query and react by modifying the database to match your definitions if the query fails */ protected function makeQueryHappen($query) { $tableDefs = $this->table_defs; $tableName = $this->getTableName(); dbm_debug("regular query", $query); $sql = $this->getSQLConnection(); $result = amtz_query($query, $sql); if (!$result) { // We have a problem here dbm_debug("system error", mysql_error()); if (!$this->table_exists()) { dbm_debug("error", "Query Failed . . . table {$tableName} doesn't exist."); $this->createTable(); } else { if ($tableDefs[$tableName] != $this->getActualTableDefs()) { dbm_debug("error", "Query Failed . . . table {$tableName} needs updating."); $this->updateTable($tableDefs); } } dbm_debug("regular query", $query); $result = amtz_query($query, $sql); if (!$result) { // We tried :( dbm_debug("error", "Query Retry Failed . . . table {$tableName} could not be fixed."); return FALSE; } } // If we got to here, that means we have got a valid result! switch (strtoupper(first_val(explode(' ', $query)))) { case 'SELECT': $returnVal = array(); while ($row = mysql_fetch_assoc($result)) { $returnVal[] = $row; } return $returnVal; break; case 'INSERT': case 'REPLACE': return mysql_insert_id($sql); break; } }