Witold E Wolski
2013-10-01 09:25:37 UTC
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.
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
);
</dbschame.sql>
Any suggestions?
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.
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
);
</dbschame.sql>
Any suggestions?
--
Witold Eryk Wolski
Witold Eryk Wolski