Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 27th, 2006, 7:03 PM   #21
Ade
Hobbyist Programmer
 
Ade's Avatar
 
Join Date: Oct 2004
Location: England, UK
Posts: 139
Rep Power: 0 Ade is an unknown quantity at this point
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
Ade is offline   Reply With Quote
Old Apr 27th, 2006, 7:23 PM   #22
Ade
Hobbyist Programmer
 
Ade's Avatar
 
Join Date: Oct 2004
Location: England, UK
Posts: 139
Rep Power: 0 Ade is an unknown quantity at this point
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
Ade is offline   Reply With Quote
Old Apr 28th, 2006, 5:15 AM   #23
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
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 5:26 AM.
nnxion is offline   Reply With Quote
Old Apr 28th, 2006, 7:20 AM   #24
Ade
Hobbyist Programmer
 
Ade's Avatar
 
Join Date: Oct 2004
Location: England, UK
Posts: 139
Rep Power: 0 Ade is an unknown quantity at this point
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
Ade is offline   Reply With Quote
Old Apr 28th, 2006, 7:23 AM   #25
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Apr 28th, 2006, 8:35 AM   #26
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by DaWei
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.
@David: You don't have to do that.

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
nnxion is offline   Reply With Quote
Old Apr 28th, 2006, 8:49 AM   #27
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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:
If you're building on Windows with Visual C++, you can install
the native Win32 port of MySQL from mysql.com. You should do
a custom install, as the MySQL++ build system expects MySQL to
be installed in c:\mysql, and not the directory-du-jour used
by the changing installer versions.
At that point, I ceased to investigate further. While you may be entirely correct, neither your installation nor the OP's is working.
__________________
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
DaWei is offline   Reply With Quote
Old Apr 28th, 2006, 9:14 AM   #28
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by DaWei
At that point, I ceased to investigate further. While you may be entirely correct, neither your installation nor the OP's is working.
That's entirely true, although I did get it to work just using the standard mysql library (which is not OO), without installing mysql++. I suggest the OP do the same.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Apr 28th, 2006, 10:40 AM   #29
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 850
Rep Power: 4 The Dark is on a distinguished road
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().
The Dark is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:15 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC