0

I have an application written in "C" - debian distro (using libmysqlclient). My application is inserting a huge number of rows in to the database (around 30.000 rows/sec, row length ~ 150 B). Insertion takes many of CPU, because the client (my app) must convert binary stream (integers, blobs) in to ASCII representation in to a valid SQL insert statement. And also the MySQL must convert this values in to binary representation and store it to the file.

And my question. Is some possibility to call SQL insert without this conversation? I have been using a classical sprintf (implemented in libc). Now, I'm using optimized version and without calling sprintf (too many func calling). I thought I'll use a MySQL prepared statement, but it seems a prepared statement also convert '?' variables to the ASCII.

Jan

1 Answers1

0

See mysql_real_query().

22.8.7.56 mysql_real_query()

int mysql_real_query(MYSQL *mysql, const char *stmt_str, unsigned long length)

Apparently, something like the below should work

#define DATA "insert into atable (acolumn) values('zero\000quotes\"\'etc ...')"
if (mysql_real_query(db, DATA, sizeof DATA - 1)) /* error */;
pmg
  • 106,608
  • 13
  • 126
  • 198
  • I need something like: `unsigned int a[5000000]; mysql_query("INSERT INTO atable (bindata) VALUES (%d),(%d),(%d),...,(%d)",a);` In variable 'a' there is really integer. mysql_query or real_query needs plain ascii statement. I really needs to insert a huge number of integers, and I don't want convert ints to ascii representation - it is too slow. (MySQL must also convert ASCII to the binary representation - it is also slow. Thanks Jan – Jan Nejman Jan 03 '15 at 15:49