Re: [sqlite] read sql file in c++

2012-06-16 Thread Stephan Beal
On Sat, Jun 16, 2012 at 4:32 AM, Simon Slavin  wrote:

> There is no way to do it in one command.  You can write your own C++ code
> to read the text file one line at a time and call sqlite3_exec() for that
> line.  There is an example of a C++ program which calls that function here:
>

be careful with "lines" - SQL lines end in semicolons, lines read with
C++'s std::getline() and friends end on newlines:

SELECT
  foo FROM
bar...

To copy a whole C++ stream:

std::ostringstream os;
std::istream is("filename");
is >> std::noskipws;
std::istream_iterator begin(is);
std::istream_iterator end;
std::copy(  begin, end, std::ostream_iterator(os, "")

now the contents are in os.str() resp. os.str().c_str().


-- 
- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] read sql file in c++

2012-06-15 Thread Igor Tandetnik
Simon Slavin  wrote:
> On 16 Jun 2012, at 3:01am, sohu  wrote:
> 
>> I have a sql file, and I know in sqlite use .read my.sql to run sql cmd,but 
>> I don't know how to run the sql file in c++?
> 
> There is no way to do it in one command.

Well, for a reasonably sized file, you could just read the whole thing into 
memory, and call sqlite3_exec on it. sqlite3_exec can run multiple statements 
at once.
-- 
Igor Tandetnik

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] read sql file in c++

2012-06-15 Thread Simon Slavin

On 16 Jun 2012, at 3:01am, sohu  wrote:

> I have a sql file, and I know in sqlite use .read my.sql to run sql cmd,but I 
> don't know how to run the sql file in c++?

There is no way to do it in one command.  You can write your own C++ code to 
read the text file one line at a time and call sqlite3_exec() for that line.  
There is an example of a C++ program which calls that function here:



Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] read sql file in c++

2012-06-15 Thread sohu
I have a sql file, and I know in sqlite use .read my.sql to run sql cmd,but I 
don't know how to run the sql file in c++?
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users