I am currently working on a piece of code that is giving me a lot of strife though after about an hour and a half of crawling google I am still at a loss.
The troubleing piece of code is rather straight forward in concept. I am writing a data object to a mysql database using the C mysql connector API. I have a previous version of this code working using only C code though have been rewritting it in C++.
The data object is as fallows.
/* name : dawson reid date : April 12th, 2012 */ #include <string> using namespace std; #ifndef MYOBJ_H #define MYOBJ_H class MyObj { public : // DATA MEMBERS string Field_1, Field_2, Field_3; }; #endif /* MYOBJ_H */
The method that is giving me trouble is
bool writeMyObjToDb ( MyObj obj, MYSQL *conn, MYSQL_STMT *stmt_handle ) { if (conn == NULL) return false; else if (stmt_handle == NULL) return false; MYSQL_BIND bind[3]; memset(bind, 0, sizeof(bind)); // bind all variables bind[0] = add_string_parameter((char*)obj.Field_1.c_str(), obj.Field_1.size()); bind[1] = add_string_parameter((char*)obj.Field_2.c_str(), obj.Field_2.size()); bind[2] = add_string_parameter((char*)obj.Field_3.c_str(), obj.Field_3.size()); // handle execution and errors int mysql_return_code = mysql_stmt_bind_param(stmt_handle, bind); if (0 != mysql_return_code) { cout << "Error : Stmt bind failed." << endl; mysql_stmt_close(stmt_handle); return false; } mysql_return_code = mysql_stmt_execute(stmt_handle); if (0 != mysql_return_code) { cout << "Error : Stmt execute failed." << endl; mysql_stmt_close(stmt_handle); return false; } return true; }
And the add_string_parameter method :
MYSQL_BIND add_string_parameter(char* param, long unsigned int *param_length) { MYSQL_BIND temp_bind; memset(&temp_bind, 0, sizeof (temp_bind)); temp_bind.buffer_type = MYSQL_TYPE_VAR_STRING; temp_bind.is_null = 0; temp_bind.length = param_length; temp_bind.buffer_length = *param_length; temp_bind.buffer = param; return temp_bind; }
The MyObj class also has several methods and a constructor. It can also be assumed that MYSQL *conn and MYSQL_STMT *stmt_handle have been prepaired and initialized properly and that the data members of the MyObj object have been initialized.
Further more the error I am recieving is :
"error: expected primary-expression before ‘.’ token"
Which is occuring several times and is refering to "bind[0] = add_string_parameter((char*)obj.Field_1.c_str(), obj.Field_1.SourceIP.size());" lines.