1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| //Here we do insert the data
void CBugUIPanel::InsertFile(char *localfile)
{
char query[1000];
FileHandle_t file = g_pFileSystem->Open(localfile, "rb");
// load file into a null-terminated buffer
int fileSize = g_pFileSystem->Size(file);
char *buffer = (char*)MemAllocScratch(fileSize + 1);
Assert(buffer);
g_pFileSystem->Read(buffer, fileSize, file); // read into local buffer
Q_snprintf(query, sizeof(query), "INSERT INTO attach_data(id, thedata) VALUES(%i, ?)", GetAttachId());
MYSQL_BIND bind[1];
unsigned long length;
MYSQL_STMT *stmt = mysql_stmt_init(&mysql);
mysql_stmt_prepare(stmt, query, strlen(query));
memset(bind, 0, sizeof(bind));
bind[0].buffer_type= MYSQL_TYPE_LONG_BLOB;
bind[0].length= &length;
bind[0].is_null= 0;
if( mysql_stmt_bind_param(stmt, bind) )
{
AssertMsg(0, mysql_stmt_error(stmt));
}
if ( mysql_stmt_send_long_data(stmt,0,buffer,fileSize) )
{
AssertMsg(0, mysql_stmt_error(stmt));
}
mysql_stmt_execute(stmt);
} |
Partager