On 1 October 2013 10:25, Witold E Wolski <[email protected]> wrote:
> I have a text file with the db schema definition
> dbschema.sql
>
> Is there a way to let my application to set up the db using soci?
> I am using sqlite.
>
> my idea (which I could not get working) was to read in the file by
> line and than to run a loop
> i.e. to execute the sql.

You need to provide such feature of file-based SQL on your own
as there is no such thing in SOCI.

> std::string bla = "heresql.sqlite";
>
>     try{
>       soci::session sql_( soci::sqlite3 , bla );
>       std::vector<std::string> lines;
>       ralab::base::utils::readLines("../sql/dbschema.sql",lines);
>       for(size_t i = 0 ; i < lines.size() ; ++i)
>         {
>           sql_<< lines[i];
>         }
> catch( ...
>
> soci throws a error:
>
> No sqlite statement created
> ...
>
> Here is how the txt file with the schema looks.
> <dbschame.sql>
> -- basic sample information
> PRAGMA foreign_keys = ON;
>
> drop table if exists sample;
> CREATE TABLE sample (
> id integer primary key,
> name text,
> file text,
> description text
> );

I presume, the error is caused by the fact that
you read and execute with SOCI individual lines,
but your file contains multi-line statements.
IOW, your code seem to be equivalent of:

sql_ << "CREATE TABLE sample (";
sql_ << "id integer primary key,";
sql_ << "name text,";
sql_ << "file text,";
sql_ << "description text";

This must fail, obviously.

Best regards,
-- 
Mateusz  Loskot, http://mateusz.loskot.net

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk
_______________________________________________
soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users

Reply via email to