10 Replies - 583 Views - Last Post: 01 August 2014 - 04:38 PM Rate Topic: -----

#1 NullBy7e  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 30-July 14

mysql resultset is always null

Posted 30 July 2014 - 01:54 PM

The resultset is always null and the connection is alive. The VS2013 debugger says that mysqlcppconn.dll has no debugging symbols.
Tested the query on a mysql console and it worked fine, it returned 1.

  CDatabase::CDatabase(CSettings* settings)
    {
        settings = settings;
        try {
            Connection* con = get_driver_instance()->connect("", "", "");
            con->setSchema("hyperbot");
            cout << "Connected." << endl << endl;
            cout << "Verifying hyper key with database...." << endl;

        if (!verify(con, settings->get_channel(), settings->get_hyper_key()))
        {
            cout << "Verification failed." << endl;
            CFunctions::ExitWithTimeout(5000);
        }
        delete con;
    }
    catch (sql::SQLException &e) {
        cout << "# ERR: SQLException in " << __FILE__;
        cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
        cout << "# ERR: " << e.what();
        cout << " (MySQL error code: " << e.getErrorCode();
        cout << ", SQLState: " << e.getSQLState() << " )" << endl;
        CFunctions::ExitWithTimeout(5000);
    }
}

bool CDatabase::verify(Connection* con, string channel, string hyper_key)
{
    if (!con) return false;

    sql::Statement *stmt;
    sql::ResultSet *res;
    stmt = con->createStatement();
    stmt->executeQuery("SELECT COUNT(*) FROM dark_souls2_widgets");
    res = stmt->getResultSet();
    if (res == NULL)
    {
        return false;
    }
    while (res->next()) {
        cout << res->getInt(1);
    }
    delete stmt;
    delete res;
    /*sql::ResultSet *res;
    sql::PreparedStatement  *prep_stmt;

    prep_stmt = con->prepareStatement("SELECT COUNT(*) FROM dark_souls2_widgets WHERE channel=? AND hyper_key=?");
    prep_stmt->setString(1, channel);
    prep_stmt->setString(2, hyper_key);
    prep_stmt->execute();
    res = prep_stmt->getResultSet();
    delete res;
    delete prep_stmt;
    */
    return false;
}

CDatabase::~CDatabase()
{
}


I also get these strange warnings on compile:
1>c:\program files (x86)\mysql\mysql connector c++ 1.1.3\include\cppconn\sqlstring.h(38): warning C4251: 'sql::SQLString::realStr' : class 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' needs to have dll-interface to be used by clients of class 'sql::SQLString'
1>c:\program files (x86)\mysql\mysql connector c++ 1.1.3\include\mysql_driver.h(52): warning C4251: 'sql::mysql::MySQL_Driver::proxy' : class 'boost::scoped_ptr<sql::mysql::NativeAPI::NativeDriverWrapper>' needs to have dll-interface to be used by clients of class 'sql::mysql::MySQL_Driver'
1>c:\program files (x86)\mysql\mysql connector c++ 1.1.3\include\mysql_connection.h(165): warning C4251: 'sql::mysql::MySQL_Connection::proxy' : class 'boost::shared_ptr<sql::mysql::NativeAPI::NativeConnectionWrapper>' needs to have dll-interface to be used by clients of class 'sql::mysql::MySQL_Connection'
1>c:\program files (x86)\mysql\mysql connector c++ 1.1.3\include\mysql_connection.h(169): warning C4251: 'sql::mysql::MySQL_Connection::service' : class 'boost::scoped_ptr<sql::mysql::MySQL_Statement>' needs to have dll-interface to be used by clients of class 'sql::mysql::MySQL_Connection'
1>c:\program files (x86)\mysql\mysql connector c++ 1.1.3\include\cppconn\exception.h(61)


Is This A Good Question/Topic? 0
  • +

Replies To: mysql resultset is always null

#2 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1353
  • View blog
  • Posts: 4,660
  • Joined: 19-February 09

Re: mysql resultset is always null

Posted 30 July 2014 - 03:45 PM

Hi, are you trying to link to a static library or dynamic library?

Chapter 11 MySQL Connector/C++ Known bugs and issues
Was This Post Helpful? 1
  • +
  • -

#3 NullBy7e  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 30-July 14

Re: mysql resultset is always null

Posted 31 July 2014 - 04:07 AM

Hi, I am trying to build it dynamically.
I also tried this just now with 2010 and the same thing, resultset is always null.

Going to try and build mysql from source now, will reply back with the result.
Was This Post Helpful? 0
  • +
  • -

#4 NullBy7e  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 30-July 14

Re: mysql resultset is always null

Posted 31 July 2014 - 09:48 AM

View PostNullBy7e, on 31 July 2014 - 04:07 AM, said:

Hi, I am trying to build it dynamically.
I also tried this just now with 2010 and the same thing, resultset is always null.

Going to try and build mysql from source now, will reply back with the result.


So I tried to build mysql but CMake (windows) came up with 6 errors.
I decided not to try and fix these errors because itll only be more time consuming.

Why must it be such pain to get it working?
Was This Post Helpful? 0
  • +
  • -

#5 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1353
  • View blog
  • Posts: 4,660
  • Joined: 19-February 09

Re: mysql resultset is always null

Posted 31 July 2014 - 03:34 PM

Hi, perhaps the warnings are a red herring, that might explain the lack of solutions around.

How to get rid of(f) -- warning C4251: needs to have a dll-interface

Perhaps try something simpler.
Running a simple query
Was This Post Helpful? 1
  • +
  • -

#6 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 804
  • View blog
  • Posts: 2,373
  • Joined: 20-March 10

Re: mysql resultset is always null

Posted 31 July 2014 - 06:11 PM

It seems like you are mixing release builds with debug builds of your client application.

What are you compiling as MT\d ? from your client app ?

if so try MT etc..
Was This Post Helpful? 1
  • +
  • -

#7 NullBy7e  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 30-July 14

Re: mysql resultset is always null

Posted 01 August 2014 - 03:11 AM

I tried with all flags like /MT /MTd etc.
If I use the simple query from that example it starts looping and printing weird characters in the console.
Screen: http://gyazo.com/c12...d895f0ad45237c4

CODE

if (!con) return false;
	
	sql::Statement *stmt;

	stmt = con->createStatement();
	stmt->execute("USE hyperbot");
	stmt->execute("DROP TABLE IF EXISTS test");
	stmt->execute("CREATE TABLE test(id INT, label CHAR(1))");
	stmt->execute("INSERT INTO test(id, label) VALUES (1, 'a')");

	delete stmt;

Was This Post Helpful? 0
  • +
  • -

#8 NullBy7e  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 30-July 14

Re: mysql resultset is always null

Posted 01 August 2014 - 03:21 AM

I tried to catch it with a try...catch and I get this: http://gyazo.com/6cd...9e8e339094191ca
Access violation and the contents of e.what() seem to be empty, and it says unable to read memory.
Was This Post Helpful? 0
  • +
  • -

#9 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1353
  • View blog
  • Posts: 4,660
  • Joined: 19-February 09

Re: mysql resultset is always null

Posted 01 August 2014 - 07:29 AM

Hi, the code in the following link uses separate try catch blocks, you can try that. In the comments the author, r3dux, gives some advice concerning a query not working, including looking at the firewall.

Your code is compiling so you don't need to bother with his use of the boost library.

How To: Use MySQL Connector/C++ to Connect to a MySQL Database in Windows.

I noticed on stackoverflow you define mysqlcppconn_EXPORTS, don't, it's my opinion that this is for creating a DLL not for its use. So don't define it or add it to your project ... Preprocessor Definitions.

If you don't want to show us the password etc, put the data in a header file, to hide it, and include the file in your main file.

mydata.h
// use string or defines
const string username = "USER";
const string password = "PASS";



In you main file
#include "mydata.h"


Was This Post Helpful? 1
  • +
  • -

#10 NullBy7e  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 30-July 14

Re: mysql resultset is always null

Posted 01 August 2014 - 01:15 PM

I used the project from that link you posted and added my code and now it seems to work.
Don't really know why but thanks so much! :)
Was This Post Helpful? 1
  • +
  • -

#11 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1353
  • View blog
  • Posts: 4,660
  • Joined: 19-February 09

Re: mysql resultset is always null

Posted 01 August 2014 - 04:38 PM

That's good to know, thanks for telling us. :)

Maybe you will discover the reason later.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1