|
|
Choosing A Webhost: |
Re: Running a SQL source file from API: msg#00032db.mysql.c++
You could also try this, which would be slicker. #include <fstream.h> #include <iostream> /*add mysql++ junk*/ Connection con("database","/*host address goes here*/","user","password"); Query query = con.query(); ifstream infile; infile.open(/*Filename goes here as a char * */); if( !infile ) { /*panic, because you cant open your file*/ } char buff[2000]; infile.getline(buff, sizeof(buff)); while( !infile.eof() ) { query << buff << " "; infile.getline(buff, sizeof(buff)); } infile.close(); Result res = query.store(); Darren >>> "Darren McDonald" <Dmcdonald@xxxxxxxxxxxxxx> 11/05/04 11:46:11 >>> Why not just use fstream? Ive been coding MySQL++ for two days, (Thanks to all, managed to get it compiling without linker errors yesterday) But its something along the lines of.... #include <fstream.h> #include <iostream> /*add mysql++ junk*/ ifstream infile; infile.open(/*Filename goes here as a char * */); if( !infile ) { /*panic, because you cant open your file*/ } char buff[2000]; std::string code = ""; infile.getline(buff, sizeof(buff)); while( !infile.eof() ) { code = code + buff; code = code + " "; //as getline gets rid of \n (newline), which will leave some words without gaps, and screw things up infile.getline(buff, sizeof(buff)); } infile.close(); //then just open your connection, and pass the file over. Connection con("database","/*host address goes here*/","user","password"); Query query = con.query(); query << code.c_str(); //or you might be able to get away with query << code; I havnt stuck that in to a compiler, so it will certainly need some tweaking, and you might want to use namespaces, and lose the .h of fstream.h Im a mysqp++ newbie too, so that might not be the best way of going about it.... Darren >>> "Howard Cole" <howard.cole@xxxxxxxxxxxxx> 11/05/04 11:20:45 >>> Hi, How can I execute the contents of a SQL file using the API? I am looking for the equivalent of typing "source file.sql;" from the mysql command prompt. Thanks. Howard Cole http://www.selestial.com -- MySQL++ Mailing List For list archives: http://lists.mysql.com/plusplus To unsubscribe: http://lists.mysql.com/plusplus?unsub=dmcdonald@xxxxxxxxxxxxxx -- MySQL++ Mailing List For list archives: http://lists.mysql.com/plusplus To unsubscribe: http://lists.mysql.com/plusplus?unsub=gcdmc-plusplus@xxxxxxxxxxx
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Running a SQL source file from API, Darren McDonald |
|---|---|
| Next by Date: | simpl example in builder, tojatomek |
| Previous by Thread: | Re: Running a SQL source file from API, Darren McDonald |
| Next by Thread: | simpl example in builder, tojatomek |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
Free MagazinesCisco NewsReceive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business. subscribe Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field. subscribe The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business. subscribe Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. subscribe Total Telecom Total Telecom is "The Economist of the communications industry". subscribe |