Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function write_data($table_name)
 {
     if (!$this->is_initialized) {
         throw new extractor_not_initialized_exception();
     }
     $result = $this->db->sql_query("PRAGMA table_info('" . $this->db->sql_escape($table_name) . "');");
     $col_types = array();
     while ($row = $this->db->sql_fetchrow($result)) {
         $col_types[$row['name']] = $row['type'];
     }
     $this->db->sql_freeresult($result);
     $sql_insert = 'INSERT INTO ' . $table_name . ' (' . implode(', ', array_keys($col_types)) . ') VALUES (';
     $sql = "SELECT *\n\t\t\tFROM {$table_name}";
     $result = $this->db->sql_query($sql);
     while ($row = $this->db->sql_fetchrow($result)) {
         foreach ($row as $column_name => $column_data) {
             if (is_null($column_data)) {
                 $row[$column_name] = 'NULL';
             } else {
                 if ($column_data === '') {
                     $row[$column_name] = "''";
                 } else {
                     if (stripos($col_types[$column_name], 'text') !== false || stripos($col_types[$column_name], 'char') !== false || stripos($col_types[$column_name], 'blob') !== false) {
                         $row[$column_name] = sanitize_data_generic(str_replace("'", "''", $column_data));
                     }
                 }
             }
         }
         $this->flush($sql_insert . implode(', ', $row) . ");\n");
     }
 }
Ejemplo n.º 2
0
 function write_data($table_name)
 {
     global $db;
     $ary_type = $ary_name = array();
     // Grab all of the data from current table.
     $sql = "SELECT *\n\t\t\tFROM {$table_name}";
     $result = $db->sql_query($sql);
     $i_num_fields = ibase_num_fields($result);
     for ($i = 0; $i < $i_num_fields; $i++) {
         $info = ibase_field_info($result, $i);
         $ary_type[$i] = $info['type'];
         $ary_name[$i] = $info['name'];
     }
     while ($row = $db->sql_fetchrow($result)) {
         $schema_vals = $schema_fields = array();
         // Build the SQL statement to recreate the data.
         for ($i = 0; $i < $i_num_fields; $i++) {
             $str_val = $row[strtolower($ary_name[$i])];
             if (preg_match('#char|text|bool|varbinary|blob#i', $ary_type[$i])) {
                 $str_quote = '';
                 $str_empty = "''";
                 $str_val = sanitize_data_generic(str_replace("'", "''", $str_val));
             } else {
                 if (preg_match('#date|timestamp#i', $ary_type[$i])) {
                     if (empty($str_val)) {
                         $str_quote = '';
                     } else {
                         $str_quote = "'";
                     }
                 } else {
                     $str_quote = '';
                     $str_empty = 'NULL';
                 }
             }
             if (empty($str_val) && $str_val !== '0') {
                 $str_val = $str_empty;
             }
             $schema_vals[$i] = $str_quote . $str_val . $str_quote;
             $schema_fields[$i] = '"' . $ary_name[$i] . '"';
         }
         // Take the ordered fields and their associated data and build it
         // into a valid sql statement to recreate that field in the data.
         $sql_data = "INSERT INTO {$table_name} (" . implode(', ', $schema_fields) . ') VALUES (' . implode(', ', $schema_vals) . ");\n";
         $this->flush($sql_data);
     }
     $db->sql_freeresult($result);
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function write_data($table_name)
 {
     if (!$this->is_initialized) {
         throw new extractor_not_initialized_exception();
     }
     $col_types = sqlite_fetch_column_types($this->db->get_db_connect_id(), $table_name);
     $sql = "SELECT *\n\t\t\tFROM {$table_name}";
     $result = sqlite_unbuffered_query($this->db->get_db_connect_id(), $sql);
     $rows = sqlite_fetch_all($result, SQLITE_ASSOC);
     $sql_insert = 'INSERT INTO ' . $table_name . ' (' . implode(', ', array_keys($col_types)) . ') VALUES (';
     foreach ($rows as $row) {
         foreach ($row as $column_name => $column_data) {
             if (is_null($column_data)) {
                 $row[$column_name] = 'NULL';
             } else {
                 if ($column_data == '') {
                     $row[$column_name] = "''";
                 } else {
                     if (strpos($col_types[$column_name], 'text') !== false || strpos($col_types[$column_name], 'char') !== false || strpos($col_types[$column_name], 'blob') !== false) {
                         $row[$column_name] = sanitize_data_generic(str_replace("'", "''", $column_data));
                     }
                 }
             }
         }
         $this->flush($sql_insert . implode(', ', $row) . ");\n");
     }
 }