Interacting with SQL databases from a win32 client

This is a discussion on Interacting with SQL databases from a win32 client within the C++ Programming forums, part of the General Programming Boards category; Hey everyone, I've been trying to make my application fire inserts to a mysql database and have been having a ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    2

    Interacting with SQL databases from a win32 client

    Hey everyone, I've been trying to make my application fire inserts to a mysql database and have been having a pretty hard time, I've tried to use the connector from mysql's website but so far its seems quite poor as my application crashes everytime i try and fire an insert.

    Could anyone show me an example of how this can be done on win32 using just the header files in visual c++?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,834
    What makes you think any example we produce will be any better than any example you've seen already.

    Maybe you should post YOUR code, so we can see what you're really doing, as opposed to what we might imagine you're doing.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    2
    Code:
    		Param * p = static_cast<Param *>(Parameters);
    		string Achievement = p->Achievement;
    		string DBName = p->DBName;
    		string Hostname = p->Hostname;
    		string Password = p->Password;
    		string Username = p->Username;
    
    	    string playername = GetUsername();
    
    		string query = "INSERT INTO tblUser (user_name, user_password) VALUES ('" + Username + "', '" + Password + "')";
    
    		sql::mysql::MySQL_Driver *driver;
    		sql::Connection	*con;
    		sql::Statement	*stmt;
    
            //Will typically crash on this line
    		driver = sql::mysql::get_mysql_driver_instance();
    		con = driver->connect(Hostname, Username, Password);
    
    		stmt = con->createStatement();
            //Or this line
    		stmt->execute("USE projectdb;");
    		stmt->execute(query);
    
    		delete stmt;
    		delete con;
    
    		cout << "Send insert finished!" << endl;
    This is the code I've been using with MySQL Connector/C++. Even inside a try catch block this will still crash the application

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,834
    > driver = sql::mysql::get_mysql_driver_instance();
    Well you don't check for success.
    So if it fails, most likely driver is NULL, and the very next line is up the creek without the paddle.

    Use a debugger, and put a breakpoint on that line. Then single step and examine your input variables to make sure all is as you expect.

    Also, does the C++ interface to MySQL accept std::string parameters?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Socket file descriptor valid and then not valid
    By Florian in forum C Programming
    Replies: 3
    Last Post: 05-22-2010, 09:23 AM
  2. Memory Leak in AppWizard-Generated Code
    By jrohde in forum Windows Programming
    Replies: 4
    Last Post: 05-19-2010, 05:24 PM
  3. Socket Programming Problem!!!!
    By bobthebullet990 in forum Networking/Device Communication
    Replies: 2
    Last Post: 02-21-2008, 07:36 PM
  4. WSAAsyncSelect Socket Model. She's Not Hot.
    By Tonto in forum Networking/Device Communication
    Replies: 2
    Last Post: 03-24-2007, 09:34 AM
  5. Embedded SQL
    By sarac in forum C Programming
    Replies: 1
    Last Post: 05-04-2006, 10:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21