#define SQL_INSERT "INSERT INTO indexed (url,date,page) VALUES (?,?,?)"
#define SQL_UPDATE "UPDATE indexed SET page=?,date=? WHERE url=?"
int __stdcall DoQuery(char * svUrl, char * svDate, char * svUrlPage)
{
MYSQL mySql;
MYSQL_RES * myRes;
MYSQL_STMT * myStmt;
MYSQL_BIND myBind[3];
char sql[37+1024], svLog[1024];
unsigned long nData1 = strlen(svUrl), nData2 = strlen(svDate), nData3 = strlen(svUrlPage);
char * svData1 = new char [nData1+1];
char * svData2 = new char [nData2+1];
char * svData3 = new char [nData3+1];
memset(&mySql, 0, sizeof(mySql));
mysql_init(&mySql);
if(!mysql_real_connect(&mySql, stConf.mysql_host, stConf.mysql_login, stConf.mysql_pass, stConf.mysql_db, NULL, NULL, NULL))
{
sprintf(svLog, "MySQL error: %s", mysql_error(&mySql));
Log(svLog);
return 0;
}
else Log("Connected to MySQL DB");
sprintf(sql, "SELECT id FROM indexed WHERE url='%s'", (char **) svData1);
if(mysql_real_query(&mySql, sql, (int) strlen(sql)))
{
sprintf(svLog, "MySQL error: %s", mysql_error(&mySql));
Log(svLog);
return 0;
}
else Log("Sent SELECT query");
myRes = mysql_store_result(&mySql);
if(!(myStmt = mysql_stmt_init(&mySql)))
{
sprintf(svLog, "MySQL error: %s", mysql_stmt_error(myStmt));
Log(svLog);
return 0;
}
else Log("MySQL STMT init successed");
Log("MySQL STMT data set");
if(myRes->row_count == 0)
{
if(mysql_stmt_prepare(myStmt, SQL_INSERT, strlen(SQL_INSERT)))
{
sprintf(svLog, "MySQL error: %s", mysql_stmt_error(myStmt));
Log(svLog);
return 0;
}
if(mysql_stmt_param_count(myStmt) != 3)
{
Log("Bad INSERT SQL query. There is no 3 parameters");
return 0;
}
memset(svData1, 0, sizeof(svData1));
memset(svData2, 0, sizeof(svData2));
memset(svData3, 0, sizeof(svData3));
strncpy(svData1, svUrl, nData1);
strncpy(svData2, svDate, nData2);
strncpy(svData3, svUrlPage, nData3);
Log("MySQL STMT INSERT prepare successed");
}
else
{
if(mysql_stmt_prepare(myStmt, SQL_UPDATE, strlen(SQL_UPDATE)))
{
sprintf(svLog, "MySQL error: %s", mysql_stmt_error(myStmt));
Log(svLog);
return 0;
}
if(mysql_stmt_param_count(myStmt) != 3)
{
Log("Bad UPDATE SQL query. There is no 3 parameters");
return 0;
}
memset(svData1, 0, sizeof(svData1));
memset(svData2, 0, sizeof(svData2));
memset(svData3, 0, sizeof(svData3));
strncpy(svData3, svUrl, nData1);
strncpy(svData2, svDate, nData2);
strncpy(svData1, svUrlPage, nData3);
Log("MySQL STMT UPDATE prepare successed");
}
memset(myBind, 0, sizeof(myBind));
myBind[0].buffer_type = MYSQL_TYPE_BLOB;
myBind[0].buffer = svData1;
myBind[0].is_null = 0;
myBind[0].length = &nData1;
myBind[1].buffer_type = MYSQL_TYPE_BLOB;
myBind[1].buffer = svData2;
myBind[1].is_null = 0;
myBind[1].length = &nData2;
myBind[2].buffer_type = MYSQL_TYPE_BLOB;
myBind[2].buffer = svData3;
myBind[2].is_null = 0;
myBind[2].length = &nData3;
if(mysql_stmt_bind_param(myStmt, myBind))
{
sprintf(svLog, "MySQL error: %s", mysql_stmt_error(myStmt));
Log(svLog);
return 0;
}
else Log("MySQL STMT bind successed");
if(mysql_stmt_execute(myStmt))
{
sprintf(svLog, "MySQL error: %s", mysql_stmt_error(myStmt));
Log(svLog);
return 0;
}
else Log("MySQL STMT execute successed");
if(mysql_stmt_close(myStmt))
{
sprintf(svLog, "MySQL error: %s", mysql_stmt_error(myStmt));
Log(svLog);
return 0;
}
else Log("MySQL STMT close successed");
delete svData1;
delete svData2;
delete svData3;
return 1;
}
помогите с mysql_stmt
написал прогу, которая обновляет базу мускула, только вот что-то она не так делает и вылетает постоянно при mysql_stmt_execute(); без всяких объяснений. по идеи там проблемы с памятью, только вот какие - не пойму :(