Re: [Cppcms-users] CppDB import from file
Brought to you by:
artyom-beilis
|
From: Artyom B. <art...@ya...> - 2013-01-07 15:12:05
|
Why wouldn't you run the sqlite executable as is? Most of SQL clients would do SQL import much better job. Also note that you can quite easily use ';' as separator. Sqlite3 does not support escape sequences but rather use ANSI SQL double quote 'can''t' == can't So if you split the file according to ";" outsidethe quotes you will be fine. Also note: don't use prepared statements (or use prepared_uncached ones)... Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ >________________________________ > From: SIMON Allan <All...@su...> >To: "cpp...@li..." <cpp...@li...> >Sent: Monday, January 7, 2013 8:55 AM >Subject: [Cppcms-users] CppDB import from file > > > > > >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) > >------------------------------------------------------------------------------ >Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS, >MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current >with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft >MVPs and experts. SALE $99.99 this month only -- learn more at: >http://p.sf.net/sfu/learnmore_122412 >_______________________________________________ >Cppcms-users mailing list >Cpp...@li... >https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > |