class Import (View source)

Library that provides common import functions that are used by import plugins

Methods

__construct()

No description

bool
checkTimeout()

Checks whether timeout is getting close

void
executeQuery(string $sql, array $sqlData)

Runs query inside import buffer. This is needed to allow displaying of last SELECT, SHOW or HANDLER results and similar nice stuff.

void
runQuery(string $sql, array $sqlData)

Runs query inside import buffer. This is needed to allow displaying of last SELECT, SHOW or HANDLER results and similar nice stuff.

string
lookForUse(string $buffer)

Looks for the presence of USE to possibly change current db

string|bool
getNextChunk(File|null $importHandle = null, int $size = 32768)

Returns next part of imported file/buffer

string
skipByteOrderMarksFromContents(string $contents)

Skip possible byte order marks (I do not think we need more charsets, but feel free to add more, you can use wikipedia for reference: https://en.wikipedia.org/wiki/Byte_Order_Mark)

string
getColumnAlphaName(int $num)

Returns the "Excel" column name (i.e. 1 = "A", 26 = "Z", 27 = "AA", etc.)

int
getColumnNumberFromName(string $name)

Returns the column number based on the Excel name.

ColumnType
detectType(ColumnType|null $lastCumulativeType, string|null $cell)

No description

array
analyzeTable(ImportTable $table)

Determines if the column types are int, decimal, or string

void
buildSql(string $dbName, array $tables, array|null $analyses = null, array|null $additionalSql = null, array $sqlData = [])

Builds and executes SQL statements to create the database and tables as necessary, as well as insert all the data.

void
handleRollbackRequest(string $sqlQuery)

No description

bool
checkIfRollbackPossible(string $sqlQuery)

Checks if ROLLBACK is possible for a SQL query or not.

bool
isTableTransactional(string $table)

Checks if a table is 'InnoDB' or not.

static array
getCompressions()

No description

static false|string
getLocalFiles(array $importList)

No description

string
getNextAvailableTableName(string $databaseName, string $proposedTableName)

No description

array
createDatabase(string $dbName, string $charset, string $collation, array $sqlData)

No description

Details

__construct()

No description

bool checkTimeout()

Checks whether timeout is getting close

Return Value

bool

void executeQuery(string $sql, array $sqlData)

Runs query inside import buffer. This is needed to allow displaying of last SELECT, SHOW or HANDLER results and similar nice stuff.

Parameters

string $sql

query to run

array $sqlData

SQL parse data storage

Return Value

void

void runQuery(string $sql, array $sqlData)

Runs query inside import buffer. This is needed to allow displaying of last SELECT, SHOW or HANDLER results and similar nice stuff.

Parameters

string $sql

query to run

array $sqlData

SQL parse data storage

Return Value

void

string lookForUse(string $buffer)

Looks for the presence of USE to possibly change current db

Parameters

string $buffer

Return Value

string

string|bool getNextChunk(File|null $importHandle = null, int $size = 32768)

Returns next part of imported file/buffer

Parameters

File|null $importHandle
int $size

size of buffer to read (this is maximal size function will return)

Return Value

string|bool

part of file/buffer

string skipByteOrderMarksFromContents(string $contents)

Skip possible byte order marks (I do not think we need more charsets, but feel free to add more, you can use wikipedia for reference: https://en.wikipedia.org/wiki/Byte_Order_Mark)

BOM could be used for charset autodetection

Parameters

string $contents

Return Value

string

string getColumnAlphaName(int $num)

Returns the "Excel" column name (i.e. 1 = "A", 26 = "Z", 27 = "AA", etc.)

This functions uses recursion to build the Excel column name.

The column number (1-26) is converted to the responding ASCII character (A-Z) and returned.

If the column number is bigger than 26 (= num of letters in alphabet), an extra character needs to be added. To find this extra character, the number is divided by 26 and this value is passed to another instance of the same function (hence recursion). In that new instance the number is evaluated again, and if it is still bigger than 26, it is divided again and passed to another instance of the same function. This continues until the number is smaller than 26. Then the last called function returns the corresponding ASCII character to the function that called it. Each time a called function ends an extra character is added to the column name. When the first function is reached, the last character is added and the complete column name is returned.

Parameters

int $num

the column number

Return Value

string

The column's "Excel" name

int getColumnNumberFromName(string $name)

Returns the column number based on the Excel name.

So "A" = 1, "Z" = 26, "AA" = 27, etc.

Basically this is a base26 (A-Z) to base10 (0-9) conversion. It iterates through all characters in the column name and calculates the corresponding value, based on character value (A = 1, ..., Z = 26) and position in the string.

Parameters

string $name

column name(i.e. "A", or "BC", etc.)

Return Value

int

The column number

ColumnType detectType(ColumnType|null $lastCumulativeType, string|null $cell)

No description

Parameters

ColumnType|null $lastCumulativeType
string|null $cell

Return Value

ColumnType

array analyzeTable(ImportTable $table)

Determines if the column types are int, decimal, or string

Parameters

ImportTable $table

Return Value

array

void buildSql(string $dbName, array $tables, array|null $analyses = null, array|null $additionalSql = null, array $sqlData = [])

Builds and executes SQL statements to create the database and tables as necessary, as well as insert all the data.

Parameters

string $dbName
array $tables
array|null $analyses

Analyses of the tables

array|null $additionalSql

Additional SQL to be executed

array $sqlData

List of SQL to be executed

Return Value

void

void handleRollbackRequest(string $sqlQuery)

No description

Parameters

string $sqlQuery

Return Value

void

bool checkIfRollbackPossible(string $sqlQuery)

Checks if ROLLBACK is possible for a SQL query or not.

Parameters

string $sqlQuery

SQL query

Return Value

bool

bool isTableTransactional(string $table)

Checks if a table is 'InnoDB' or not.

Parameters

string $table

Table details

Return Value

bool

static array getCompressions()

No description

Return Value

array

static false|string getLocalFiles(array $importList)

No description

Parameters

array $importList

List of plugin instances.

Return Value

false|string

string getNextAvailableTableName(string $databaseName, string $proposedTableName)

No description

Parameters

string $databaseName
string $proposedTableName

Return Value

string

array createDatabase(string $dbName, string $charset, string $collation, array $sqlData)

No description

Parameters

string $dbName
string $charset
string $collation
array $sqlData

List of SQL statements to be executed

Return Value

array