Beispiel #1
0
 public static function add_data_row(&$node_table, $row)
 {
     // sanity check alpha keys this table expects
     $data_columns = self::get_column_list($node_table);
     $row_data_columns = array_keys($row);
     $diff = array_diff($row_data_columns, $data_columns);
     if (count($diff) > 0) {
         throw new exception("table " . $node_table['name'] . " (" . implode(',', $data_columns) . ") does not contain all columns specified in row_data_columns (" . implode(',', $row_data_columns) . ") diff: (" . implode(',', $diff) . ")");
     }
     $pk_cols = self::primary_key_columns($node_table);
     // only check if it has primary key columns if the table has a primary key
     if (count($pk_cols) > 0) {
         $diff = array_diff($pk_cols, $row_data_columns);
         if (count($diff) > 0) {
             throw new exception("table " . $node_table['name'] . " rows element missing primary key column. diff: (" . implode(',', $diff) . ")");
         }
     }
     // collect rows to add in $new_rows, index by row_data_columns
     // @TODO: the caller then data_rows_overlay()'s these all at once
     $new_rows = array();
     // $new_rows contains all of the variants of rows collections to add to the table
     // it is expected that there is a low number of insert statement variants
     if (!isset($new_rows[$row_data_columns])) {
         $new_rows[$row_data_columns] = new SimpleXMLElement('<rows/>');
     }
     // have the xml_parser compositor add the row with it's overlay logic
     // which compensates for additional columns, missing columns
     // and all the rest of the variants for <rows> <row> elements
     $node_new_row = $new_rows[$row_data_columns]->addChild('row');
     foreach ($row as $column_name => $column_value) {
         $new_rows[$row_data_columns]['columns'] .= $column_name . ',';
         $node_new_row->addChild('col', xml_parser::ampersand_magic(sql_parser::quoted_value_strip($column_value)));
     }
     $new_rows[$row_data_columns]['columns'] = substr($new_rows[$row_data_columns]['columns'], 0, -1);
     //var_dump($new_rows[$row_data_columns]->asXML());
     //die('add_data_row tracer 115');
     // see @TODO: above caller collation
     xml_parser::data_rows_overlay($node_table, $new_rows[$row_data_columns]);
 }
 public static function parse_params($line)
 {
     if (substr($line, 0, 1) != '(') {
         throw new exception("slonik params don't start with (: " . $line);
     }
     if (substr($line, -1, 1) != ')') {
         throw new exception("slonik params don't end with ): " . $line);
     }
     // knock off the ( and ) now that we know they are there
     $param_list = explode(',', substr($line, 1, strlen($line) - 2));
     $params = array();
     for ($i = 0; $i < count($param_list); $i++) {
         // split the params at the =
         $chunks = explode('=', trim($param_list[$i]));
         // kill whitespace again
         $name = trim($chunks[0]);
         $value = trim($chunks[1]);
         // lowercase the param name
         $name = strtolower($name);
         // if data value is enclosed in '', kill it
         $value = sql_parser::quoted_value_strip($value);
         $params[$name] = $value;
     }
     return $params;
 }