[Cppcms-users] CppDB import from file
Brought to you by:
artyom-beilis
|
From: SIMON A. <All...@su...> - 2013-01-07 07:11:01
|
Hello
I'm currently using CppDB and would like to have a function that takes in parameter a .sql file and that import it into a sqlite database
I've tried to do it like this (see the code below) , but it seems that when CppDB does not like when you try to execute several Sqlrequest with only one cppdb::exec
Of course I can't read the file and split it by lines (some requests are on several lines) and also no by splitting on ";" as my SQL file contains some ; inside string values.
Does anyone already find a solution for this ?
int SqliteModel::import_sql_file(
const std::string &sqlFilePath
) {
try {
std::ifstream f(sqlFilePath.c_str());
std::string fileStr(
(std::istreambuf_iterator<char>(f)),
std::istreambuf_iterator<char>()
);
sqliteDb << fileStr << cppdb::exec;
} catch(std::exception const &e) {
BOOSTER_ERROR("cppcms") << e.what();
return 1;
}
return 0;
}
Regards,
Allan SIMON
Tatoeba.org Administrator (Sysko)
|