To confirm that the database is working, I wrote a simple program to try to retrieve the data from the database.
main.cpp:
#include \"data.h\"
#include
#include
void main()
{
MYSQL *conn;
MYSQL_RES *rs;
MYSQL_ROW rr;
MYSQL_FIELD *fields;
char *querystr;
conn = mysql_init(NULL);
conn = mysql_real_connect(conn,
\"127.0.0.1\", // host
\"planeshift\",// user
\"planeshift\", //pwd
\"planeshift\", //database
0, NULL, 0);
querystr = \"Select * from sector_info\";
mysql_query(conn, querystr);
rs = mysql_store_result(conn);
fields = mysql_fetch_fields(rs);
for(int row=0; row < mysql_num_rows(rs); row++)
{
mysql_data_seek(rs, row);
rr = mysql_fetch_row(rs);
for(unsigned int field=0; field < mysql_num_fields(rs); field++)
{
printf(\"Row %d: Field %d is %s\\n\", row+1, field+1, rr[field]);
}
}
mysql_free_result(rs);
mysql_close(conn);
}
data.h:
#define __LCC__
#define __WIN__
No suprise. The database works very well.
But then I modified the function printf() like this:
printf(\"Row %d: Field [%s] is %s\\n\", row+1, fields[row].name, rr[field]);
The program crashes!! How comes \"fields[row].name\" can not do its job??
So there is a strong hint that a bug hides in the original code in psResultRow::operator[] in the dal.cpp, although it seems logical:
const char *psResultRow::operator[](const char *fieldname)
{
CS_ASSERT(fieldname);
CS_ASSERT(max); // trying to access when no fields returned in row! probably empty resultset.
if (!fields)
{
fields = mysql_fetch_fields(rs);
}
for (int i=0; i {
if (fields.name && !strcasecmp(fields.name, fieldname))
{
return rr;
}
}
return \"\"; // Illegal name.
}