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 8987597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:50:07+00:00 2026-06-15T21:50:07+00:00

Inserting binary data into an sqlite database using C/C++ interface: // Previously: create table

  • 0

Inserting binary data into an sqlite database using C/C++ interface:

  // Previously: "create table tt(i integer primary key, b blob)"
  sqlite3 *sqliteDB;
  if(sqlite3_open("example.db", &sqliteDB) == 0)
    {

    // "insert" statement
    const char *sqlText = "insert into tt (i,b) values (?,?)";
    sqlite3_stmt *preparedStatement;
    sqlite3_prepare_v2(sqliteDB, sqlText, (int)strlen(sqlText), &preparedStatement, 0);

    // add the number
    sqlite3_bind_int(preparedStatement, 1, 1);

    // add the data
    char myBlobData[] = "He\0llo world"; // sizeof(myBlobData) is 13 bytes
    sqlite3_bind_blob(preparedStatement, 2, myBlobData, sizeof(myBlobData), 0); // returns SQLITE_OK

    // store in database
    sqlite3_step(preparedStatement); // returns SQLITE_DONE

    sqlite3_close(sqliteDB);
    }

This stores a 2-byte blob containing “He”, instead of the 13-byte blob that it was asked to store. Why?

It seems to be ending at the first 0 byte, but blobs aren’t strings (hence the need for a size parameter to sqlite3_bind_blob) so why would it treat arbitrary binary data as a c-style string?

  • 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-06-15T21:50:09+00:00Added an answer on June 15, 2026 at 9:50 pm

    How are you getting the BLOB out of the DB? It may be getting truncated at that point; perhaps your code is treating it as a string after extraction.

    You can check the actual BLOB size via the BLOB APIs. sqlite3_blob_open() followed by a call to sqlite3_blob_bytes().

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

Sidebar

Related Questions

When inserting a row into a table with an auto increment primary key column,
I heard a rumor that when inserting binary data (files and such) into MySQL,
Before inserting data into table i need to check against duplicate records and report
Me again! I have a question re. inserting into a sql table using LINQ.
I'm trying to insert binary data (a whirlpool hash) into a PG table and
Can you give an example of inserting binary data in PostgreSQL database from remote
I'm currently having difficulty inserting a node into a binary tree using recursion. I've
Why is the worst case big-O for inserting N items into an empty binary
For inserting special characters in data like (,')etc., I am using mysql_real_escape_string() function &
I'm inserting the result set returned from a CLR stored procedure into a table

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.