function backup_migrate_source_db_mysql::_dump_table_data_sql_to_file in Backup and Migrate 6.3
Same name and namespace in other branches
- 8.3 includes/sources.db.mysql.inc \backup_migrate_source_db_mysql::_dump_table_data_sql_to_file()
- 7.3 includes/sources.db.mysql.inc \backup_migrate_source_db_mysql::_dump_table_data_sql_to_file()
Get the sql to insert the data for a given table
1 call to backup_migrate_source_db_mysql::_dump_table_data_sql_to_file()
- backup_migrate_source_db_mysql::_backup_db_to_file in includes/
sources.db.mysql.inc - Backup the databases to a file.
File
- includes/
sources.db.mysql.inc, line 285 - Functions to handle the direct to database source.
Class
- backup_migrate_source_db_mysql
- A source type for backing up from database server.
Code
function _dump_table_data_sql_to_file($file, $table) {
$rows_per_line = variable_get('backup_migrate_data_rows_per_line', 30);
$bytes_per_line = variable_get('backup_migrate_data_bytes_per_line', 2000);
$lines = 0;
$data = db_query("SELECT * FROM `" . $table['Name'] . "`");
$rows = $bytes = 0;
$line = array();
while ($row = db_fetch_array($data)) {
// DB Escape the values.
$items = array();
foreach ($row as $key => $value) {
$items[] = is_null($value) ? "null" : "'" . db_escape_string($value) . "'";
}
// If there is a row to be added.
if ($items) {
// Start a new line if we need to.
if ($rows == 0) {
$file
->write("INSERT INTO `" . $table['Name'] . "` VALUES ");
$bytes = $rows = 0;
}
else {
$file
->write(",");
}
// Write the data itself.
$sql = implode(',', $items);
$file
->write('(' . $sql . ')');
$bytes += strlen($sql);
$rows++;
// Finish the last line if we've added enough items
if ($rows >= $rows_per_line || $bytes >= $bytes_per_line) {
$file
->write(";\n");
$lines++;
$bytes = $rows = 0;
}
}
}
// Finish any unfinished insert statements.
if ($rows > 0) {
$file
->write(";\n");
$lines++;
}
return $lines;
}