Пример #1
0
 /**
  *  Gets the column names and column types of the current table for bulk insert.
  */
 private function getBulkInsertTableColumnsInfo()
 {
     // Check if table is a temporary table or a non-temporary table.
     $table_is_non_temporary = MetaDataLayer::checkTableExists($this->tableName);
     // Create temporary table if table is non-temporary table.
     if (!$table_is_non_temporary) {
         MetaDataLayer::callProcedure($this->routineName);
     }
     // Get information about the columns of the table.
     $columns = MetaDataLayer::describeTable($this->tableName);
     // Drop temporary table if table is non-temporary.
     if (!$table_is_non_temporary) {
         MetaDataLayer::dropTemporaryTable($this->tableName);
     }
     // Check number of columns in the table match the number of fields given in the designation type.
     $n1 = count($this->columns);
     $n2 = count($columns);
     if ($n1 != $n2) {
         throw new RuntimeException("Number of fields %d and number of columns %d don't match.", $n1, $n2);
     }
     // Fill arrays with column names and column types.
     $tmp_column_types = [];
     $tmp_fields = [];
     foreach ($columns as $column) {
         preg_match('(\\w+)', $column['Type'], $type);
         $tmp_column_types[] = $type['0'];
         $tmp_fields[] = $column['Field'];
     }
     $this->columnsTypes = $tmp_column_types;
     $this->fields = $tmp_fields;
 }