![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#21 |
|
Hobbyist Programmer
Join Date: Oct 2004
Location: England, UK
Posts: 139
Rep Power: 0
![]() |
Ok, I'll knock up something small that draws on the resources of both librarys at once, gimme 5 minutes
.
__________________
Don't wound what you can't kill |
|
|
|
|
|
#22 |
|
Hobbyist Programmer
Join Date: Oct 2004
Location: England, UK
Posts: 139
Rep Power: 0
![]() |
OK, the seperate parts of this work when placed in their individual projects. It's pretty much as simple as it can be. The database requires a databse running on localhost with the username root and no password.
#include <windows.h>
#include <iostream>
#include <sqlplus.hh> //the mysql++ library files
#include "gwin.h" //the gwin library files
int main (int argc, char *argv[]) {
Gwin.showConsole(); //gwin
Gwin.text(10,10,"Hello World"); //gwin
Keyboard.getch(); // this is the end of gwin, everything after is mysql++ stuff
Connection connection(use_exceptions);
try {
if (argc == 1) connection.connect("");
else if (argc == 2) connection.connect("",argv[1]);
else if (argc == 3) connection.connect("",argv[1],argv[2]);
else if (argc <= 4) connection.connect("",argv[1],argv[2],argv[3]);
try {
connection.select_db("AdesTestDatabase");
} catch (BadQuery er) {
connection.create_db("AdesTestDatabase");
connection.select_db("AdesTestDatabase");
}
Query query = connection.query();
try {
query.execute("drop table stuff");
} catch (BadQuery er) {}
query << "create table stuff (item char(20) not null)";
query.execute(RESET_QUERY);
query << "insert into %5:table values (%0q)";;
query.parse();
query.def["table"] = "Stuff";
query.execute ("Amanda", 56);
} catch (BadQuery er) {
cerr << "Error: " << er.error << endl;
return -1;
}
}I know i've not commented the mysql stuff but it's pretty much normal sql statments. In order for this to work it must draw on both librarys. at the same time Ta Ade
__________________
Don't wound what you can't kill |
|
|
|
|
|
#23 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
I could not even get either to work seperately.
EDIT: I got Gwin working after changing it to "Multi-threaded Debug DLL (/MDd)" I don't seem to have a slqplus.hh though, I have mysql++.h though. You also forgot to use the right namespace. Maybe someone wants to try it with this: #include <iostream>
#include "mysql++.h"
#include "gwin.h"
using std::cout;
using std::cerr;
using std::endl;
using namespace mysqlpp;
#define def_db_name "mysql_cpp_data"
#define def_host_name "localhost"
#define def_user_name "admin"
#define def_password ""
#define def_svr_port "3066"
int main()
{
// gwin
Gwin.showConsole();
Gwin.text(10,10,"Hello World");
Keyboard.getch();
// mysql++
Connection conn (def_db_name, def_host_name, def_user_name, def_password);
Query q = conn.query();
try
{
conn.create_db(def_db_name);
conn.select_db(def_db_name);
}
catch(BadQuery er)
{
cerr << er.what() << endl;
}
q << "DROP TABLE IF EXISTS testtable";
q.execute();
q << "CREATE TABLE testtable (ID VARCHAR(7) NOT NULL PRIMARY KEY, "
<< "nick_name VARCHAR(20), "
<< "f_name VARCHAR(20))";
q.execute();
q << "INSERT INTO testtable (ID, f_name) VALUES ('1', 'Ruben')";
q.execute();
q << "INSERT INTO testtable VALUES ('2', 'DaWei', 'David')";
q.execute();
q << "show tables" << endl;
cout << "Query : " << q.preview() << endl;
Result res = q.store();
if (!res.empty())
{
Row row = res[0];
cout << "Table is : " << res[0] << endl;
}
conn.close();
return 0;
}
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates Last edited by nnxion; Apr 28th, 2006 at 6:26 AM. |
|
|
|
|
|
#24 |
|
Hobbyist Programmer
Join Date: Oct 2004
Location: England, UK
Posts: 139
Rep Power: 0
![]() |
both parts worked when they were in their own projects.
All I did was add the GWin lines to the mysql code. I'm so lost on this it's not even funny, I might cry.
__________________
Don't wound what you can't kill |
|
|
|
|
|
#25 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Sorry, I can't install this and participate further. MySql is a working installation on my machine; I can't blow all that off just because MySql++ wants it to be in C:\mysql instead of where I have it.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#26 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
![]() You just unzip mysql++ to somewhere like C:\mysql++ Start a VC project, in project properties you'll have to specify that you want to include the directories C:\mysql++\include and C:\program files\mysql\mysql 4.1\include\ (or whatever other folder mysql is in) Then you can #include <mysql.h> (with <) you can also just specify full paths. @Ade: That's all I did, I think, but I'm getting loads of linker errors just using mysql++ alone. You'll have to tell me how to get it work separately, and I'll try again.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
|
#27 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Ruben, there is no question in my mind that "I don't have to do that." I'm sure I could dink around for some period ranging from an hour to a couple days. I'm just paying attention to the author's caveat:
Quote:
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
|
#28 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
|
#29 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 893
Rep Power: 4
![]() |
Hmm, I installed gwin and installed and built mysql++, copied in your code. As nnxion said, I had to change the header file and the namespace. I also had to change the exception handling code as "error" was not defined, byt what() was. Perhaps you are using an old version of gwin?
After setting the project settings as described here adding the .libs to the project, it all compiled and linked fine. I had to copy the mysql++ and gwin DLLs in to get it to run, but it ran OK. After that I ended up getting an exception because I don't have the actual database. Are you absolutely sure you selected "Windows Application" as the project type and not "Console Application". Even though your code has a main() function, this is called from the gwin library, not the C runtime library. Also note that as far as I can tell gwin does not pass argc and argv parameters into main(). |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|