Create a gist now

Instantly share code, notes, and snippets.

@mojeld /conf.h
Created Feb 14, 2017

What would you like to do?
How to copy a Dataset using C++Builder in TFDBatchMove(FireDAC)
#include <Data.DB.hpp>
#include <FireDAC.Comp.BatchMove.DataSet.hpp>
#include <FireDAC.Comp.BatchMove.hpp>
#include <FireDAC.Comp.BatchMove.SQL.hpp>
#include <FireDAC.Comp.BatchMove.Text.hpp>
#include <FireDAC.Comp.Client.hpp>
#include <FireDAC.Comp.DataSet.hpp>
#include <FireDAC.DApt.hpp>
#include <FireDAC.DApt.Intf.hpp>
#include <FireDAC.DatS.hpp>
#include <FireDAC.Phys.hpp>
#include <FireDAC.Phys.Intf.hpp>
#include <FireDAC.Phys.MySQL.hpp>
#include <FireDAC.Phys.MySQLDef.hpp>
#include <FireDAC.Phys.SQLite.hpp>
#include <FireDAC.Phys.SQLiteDef.hpp>
#include <FireDAC.Stan.Async.hpp>
#include <FireDAC.Stan.Def.hpp>
#include <FireDAC.Stan.Error.hpp>
#include <FireDAC.Stan.ExprFuncs.hpp>
#include <FireDAC.Stan.Intf.hpp>
#include <FireDAC.Stan.Option.hpp>
#include <FireDAC.Stan.Param.hpp>
#include <FireDAC.Stan.Pool.hpp>
#include <memory>
namespace dbparam_
#include <vcl.h>
#include <windows.h>
#pragma hdrstop
#pragma argsused
#include <tchar.h>
#include <iostream>
#include "conf.h"
int _tmain(int argc, _TCHAR* argv[])
TFDPhysMySQLDriverLink *mysql_driver = new TFDPhysMySQLDriverLink(nullptr);
TFDPhysSQLiteDriverLink *sqlite_driver = new TFDPhysSQLiteDriverLink(nullptr);
TFDConnection *mysql_connect = new TFDConnection(nullptr);
TFDConnection *sqlite_connect = new TFDConnection(nullptr);
TFDQuery *mysql_query = new TFDQuery(nullptr);
TFDQuery *sqlite_query = new TFDQuery(nullptr);
//Set MySQL driver. libmysql.dll
mysql_driver->VendorLib = dbparam_::mysql_libdll;
//Set SQLite driver. sqlite3.dll
sqlite_driver->VendorLib = dbparam_::sqlite_libdll;
mysql_connect->DriverName = "MySQL";
sqlite_connect->DriverName = "SQLite";
mysql_connect->Params->Text = dbparam_::mysql_param;
sqlite_connect->Params->Text = dbparam_::sqlite_param;
mysql_connect->LoginPrompt = false;
sqlite_connect->LoginPrompt = false;
mysql_connect->Connected = true;
sqlite_connect->Connected = true;
mysql_query->Connection = mysql_connect;
sqlite_query->Connection = sqlite_connect;
//Prepare the same table in advance.
mysql_query->SQL->Text = "select * from t_MotoGP";
//Prepare an empty table.
sqlite_query->SQL->Text = "select * from t_MotoGP";
//Activate the table of differences.
mysql_query->Active = true;
sqlite_query->Active = true;
std::unique_ptr<TFDBatchMove> batch_move = std::make_unique<TFDBatchMove>(nullptr);
TFDBatchMoveDataSetReader *mysql_ds_read = new TFDBatchMoveDataSetReader(batch_move.get());
TFDBatchMoveDataSetWriter *sqlite_ds_write = new TFDBatchMoveDataSetWriter(batch_move.get());
//Read side is MySQL
mysql_ds_read->DataSet = mysql_query;
//Write side is SQLite
sqlite_ds_write->DataSet = sqlite_query;
//Copy the table data from MySQL to SQLite.
std::cout <<
"batch_move->Execute();" << std::endl;
sqlite_query->Active = false;
sqlite_connect->Connected = false;
catch (Exception& e1)
std::cout <<
e1.Message.c_str() << std::endl;
delete mysql_ds_read;
delete sqlite_ds_write;
delete mysql_query;
delete sqlite_query;
delete mysql_connect;
delete sqlite_connect;
delete mysql_driver;
delete sqlite_driver;
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment