doulao2916 2014-06-09 21:07
浏览 49

从MySQL生成SQLite 3数据库的一种好的,可维护的方法吗?

I have to generate on-the-fly (and let the user download) an SQLite 3 encrypted database, starting/cloning part of the current running MySQL database.

I need to export only a subset of the tables (i.e. products, categories, users), and I'd like to make the procedure dynamic, meaning that adding a field in MySQL shouldn't require changes in the procedure.

I need to some high-level "tips" to make the procedure as robust as possible.

Questions: how do I map column types in MySQL to SQLite types? How can I fetch metadata to determine the correct INSERT statements order? Should I need to lock MySQL database while dumping it into SQLite?

<?php

$sqlite = new PDO('sqlite::memory:', null, null, [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);

$mysql = new PDO('mysql:host=127.0.0.1;dbname=database', 'root', 'root', [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);

// Enable foreign keys in SQLite
$sqlite->exec('PRAGMA foreign_keys = 1');

// 1) Getting meta information from MySQL

// 2) CREATE TABLE ... in the SQLite schema, dynamically

// 3) INSERT INTO ... statements of SQLite (in the correct order)

// 4) Save the in-memory database to filesystem and send it to the browser
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法