Class QuickCsvImporter
Module to import CSV very fast
- Import your CSV data directly into a new/existing temporary table with an RDB-specific API.
- Validation of input values and correlation record check are confirmed by executing SQL.
- To move data from the temporary table to the final table, execute a normal INSERT / UPDATE queries.
Direct known subclasses
Kanryu\QuickCsv\MySQL\QuickCsvImporter
public
|
#
__construct( array $options = array() )
Several properties can be specified here, but no arguments are required. |
public
|
|
public
|
#
setValidator( string $name, function $func )
Set a function that generates and returns a validation expression from each property value of fieldSchema. |
public
|
#
setValidatorForType( string $name, function $func )
Set function to generate and return validation expression of type from fieldSchema->type value. |
public
|
#
setFieldSchema( $schema )
Specify associative array the relationship between each column of CSV to be imported and the column of import destination table. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
array
|
|
public
array
|
#
validateBase( array $api, string $fields, $additional_tables = '' )
Execute the validation expression specified in the parameter and fetch the row that is true. |
public
array
|
#
validateNonExistForeignKey( $field, $foreignKey, $foreignTableName, $condition = '' )
Returns records where the specified field does not meet foreign key constraints |
public
array
|
|
public
|
#
getNotDefaultFormula( $field )
Returns a judgment expression that the value of the specified field is not the default value. |
public
|
#
updateFieldNumberByAutoCount( string $field, integer $baseNumber = 0, $destTableName = null )
Updates to the line where the numeric field of the specified required item is not entered with the automatically incremented value. |
public
|
#
updateFieldNumberByAutoCountWithPrefix( string $field, string $prefix, string $body = '#', integer $baseNumber = 0, $destTableName = null )
Updates to the line where the numeric field with prefix of the specified required item is not entered with the automatically incremented value. |
public
|
#
updateExistingRecords( array $immediates = array() )
Overwrite records existing in the target table with CSV |
public
|
#
insertNonExistingRecords( array $immediates = array() )
Add a new record from CSV that does not exist in the target table |
public
|
$pdo
This property is set when using PDO. Call setPdo(). |
#
null
|
public
|
$query_callback
Set this property when you want to define query execution independently. Automatically updated when using PDO. |
#
null
|
public
array
|
$fieldSchema
Give the schema defining each column of the imported CSV as an associative array. |
#
array()
|
public
array
|
$fieldMap
associative array of $fieldSchema |
#
array()
|
public
string
|
$dataTableName
Temporary table name to specify as the CSV direct import destination. |
#
'tempCsvData'
|
public
string
|
$destTableName
Destination table name where data is finally entered. |
#
'TARGET_TABLE'
|
public
string
|
$destPrimaryKey
Primary key of the target table where data is finally entered. |
#
'PRIMARY_KEY'
|
public
string
|
$csvSeparator
|
#
"','"
|
public
string
|
$csvEncloser
|
#
"'\"'"
|
public
string
|
$csvLineStart
|
#
"''"
|
public
string
|
$csvLineSep
|
#
"'\\r\\n'"
|
public
string
|
$csvRecordId
AUTO_INCREMENT field for returning row number on CSV |
#
'id'
|
public
boolean
|
$hasCsvHeader
If true, the first line of CSV is ignored when importing. |
#
true
|
public
boolean
|
$asTemporary
If true, the CSV import table is TEMPORARY TABLE. If false, the table remains after the import is complete. Although there is no practical meaning, the import result remains. |
#
true
|
public
boolean
|
$dumpSql
If true, dump sqls. |
#
false
|
public
string
|
$tableCharCode
Character code of temporary table |
#
'utf8'
|
public
string
|
$csvCharCode
CSV file character code |
#
'cp932'
|
public
array
|
$validators
An associative array of functions that return validation expressions from fieldSchema properties |
#
array()
|
public
array
|
$validatorTypes
An associative array of functions that return validation expressions from the type of fieldSchema |
#
array()
|