public function create() { $sqlc = new SQLCreate($this->table, $this->get_datatypes(true), $this->primaryKeyField); $sqlc->schema = $this->setSchema(); $sqlc->unique_constraints = $this->unique_constraints; $sqlc->debug = $this->debug; $sqlc->execute(); }
public function SQLInsert($table, $values = array(), $createIfNeeded = false) { $this->table = $table; $this->values = $this->add_values($values); if ($createIfNeeded) { $cols = $this->get_columns(); if (!$cols) { $create = new SQLCreate($table, $this->row_to_datatypes($values)); $create->execute(); } } }
public function reset_table($rows, $selectors = array(), $primary_key = "") { $current_cols = $this->get_columns(); // The table doesn't exist: make it if (!$current_cols || empty($current_cols)) { $datatypes = $this->get_column_datatypes(); $cr = new SQLCreate($this->table, $datatypes, $primary_key); $cr->debug = $this->debug; $cr->execute(); } if (empty($selectors)) { // No selectors: Always insert the rows foreach ($rows as $rownum => $row) { $ins = new SQLInsert($this->table, $row); $ins->debug = $this->debug; $ins->execute(); } } else { // Selectors exist: update the given rows foreach ($rows as $rownum => $row) { $row_selectors = array(); foreach ($selectors as $selkey) { if (isset($row[$selkey])) { $row_selectors[$selkey] = $row[$selkey]; } } if (!empty($row_selectors)) { $upd = new SQLUpdate($this->table, $row, $row_selectors, true); $upd->debug = $this->debug; $upd->execute(); } else { $ins = new SQLInsert($this->table, $row); $ins->debug = $this->debug; $ins->execute(); } } } }
public function getTableColumns($create = true) { global $db; // Make sure we have a table set if ($this->table == "") { error_out("No table set."); return false; } $sql = new SQLQuery($this->table); $sql->international = $this->international; $columns = $sql->get_columns(); if (!empty($columns)) { // Table exists -- return the columns $this->tablecolumns = $columns; // If table exists and create is set, add any additional columns if ($create) { $formcolumns = $this->formToTableColumns(false); $newcolumns = array_diff(array_keys($formcolumns), array_keys($columns)); if (!empty($newcolumns)) { $tablename = $this->table; if ($this->schema != "") { $tablename = $this->schema . "." . $this->table; } $alter_table_column_string = ""; foreach ($newcolumns as $colname) { if ($alter_table_column_string != "") { $alter_table_column_string .= ","; } $alter_table_column_string .= $colname . " " . $formcolumns[$colname]; $this->tablecolumns[$colname] = $formcolumns[$colname]; } $alter_table_query = "ALTER TABLE " . $tablename . " ADD(" . $alter_table_column_string . ")"; $ret = $db->execute($alter_table_query); } } return $this->tablecolumns; } else { if ($create) { // Table doesn't exist -- create it from form $this->tablecolumns = $this->formToTableColumns(); $sql_create = new SQLCreate($this->table, $this->tablecolumns); $sql_create->international = $this->international; $sql_create->execute(); return $this->tablecolumns; } else { // Table doesn't exist, 'create' set to false: return false error_out("Table doesn't exist."); return false; } } }