Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7176757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:34:24+00:00 2026-05-28T16:34:24+00:00

I have to put tons of integers and floats into a mysql database from

  • 0

I have to put tons of integers and floats into a mysql database from a c application.

Currently I am doing this by converting all those values into a string and then transfering them to the database:

char * sql_query[2048];
sprintf(sql_query, "INSERT INTO my_table VALUES (%u, %u, %d, %.7f, %u, .....");
if (mysql_real_query(&mysql, sql_query, strlen(sql_query)) {
    fprintf(stderr, "SQL Request failed: Error: %s\n", mysql_error(&mysql));
}

As this way is quite time consuming: Isn’t there a way to avoid a conversion to string which needs to be interpreted and converted back by mysql.
I’m looking for a binary API, which directly swallows my variables. Does that exist?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:34:25+00:00Added an answer on May 28, 2026 at 4:34 pm

    The overhead caused your sprintf() will be eclipsed by the gazillions of individual INSERTs that you are sending to Mysql (if you do not believe me, try profiling your application). In other words, you are very likely optimizing in the wrong place, if you are looking for higher throughput.

    A much better approach is to write all your records out to a CSV file (I use pipe-delimited myself) and then load the entire batch via LOAD DATA INFILE (which has been heavily optimized for speed). These types of tools have been used for decades, starting all the way back from Sybase’s bcp (bulk-copy) utility.

    At first, it would appear that taking two steps (writing to file and then loading) would be slower, but the low overhead of one giant load handily beats the cost of hitting the database with a flood of individual INSERT transactions.

    I have loaded millions of records quickly by using CSV and LOAD DATA INFILE, equally fast from C or from a scripting language like Ruby, since the server will be doing most of the heavy lifting.

    Otoh, if you only have a handful of records, your current approach is perfectly fine: it’s easily maintainable in case the schema changes or you decide to port to a server other than Mysql.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this trimmer function, it recursively trims all values in array (people put
I have put together a .net winform application which consumes a wcf service exposed
I have put together an image scroller using jquery, like this function rotateImages(whichHolder, start)
I have put together this little script which uses a list of words to
I have put fancybox (jquery plugin ) inside the assets/javascripts/includes/jquery.fancybox-1.3.4 Before this location i
I have put together a simple application and when I am installing the app
I have put the following in AndroidManifest.xml as described in the article : <application
I have put together this simple code for showing/hiding some content on click using
I have put some JPanels into another JPanel which its' layout is Box Layout
I have put together a navigation bar which expands a submenu on hover. See

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.