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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:55:42+00:00 2026-06-06T03:55:42+00:00

Not able to store all binary data values into sqlite3 table using QT. For

  • 0

Not able to store all binary data values into sqlite3 table using QT.

For this I have created a BLOB data column to store binary data table named as logTable.
I am trying to insert binary data to binary_data[] buffer, with values as 0x1 to 0xFF and 0x00 to 0xFF and so on till 1024 bytes. But when I execute the query to store the data, the table shows only 0x1 to 0xFF, but remaining character are not getting stored (since next immediate value is 0x00). I want to store all the binary data values?

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    conect_to_log_db("./log.db");

    unsigned char binary_data[1024];

    for(unsigned int i = 0, value = 1; i < 1024; i++, value++)
    {
        binary_data[i] = value;
    }
    store_to_log_db("01/02/2012,13:03:58", binary_data, 1024);
    ......
}


bool store_to_log_db(QString dateTime, unsigned char *data, unsigned int dataLength)
{
    QSqlQuery objQuery(objLogsDB);

    QString query = "CREATE TABLE IF NOT EXISTS logTable(logDateTime VARCHAR(19), packet BLOB, direction INTEGER)";
    objQuery.exec(query);

    QByteArray dataArr;
    dataArr.resize(dataLength);
    for(unsigned int i = 0; i < dataLength; i++)
    {
        dataArr[i] = data[i];
    }

    QVariant blobData = dataArr.data();

    objQuery.prepare("INSERT INTO logTable VALUES(:logDateTime,:packet,:direction)");
    objQuery.bindValue(":logDateTime",dateTime);
    objQuery.bindValue(":packet",blobData,QSql::In | QSql::Binary);
    objQuery.bindValue(":direction",1);

    qDebug() << objQuery.exec();

    return true;
}

after executing this code, the result of the table is till 254 characters when I output from sqlite using

$sqlite3 log.db

sqlite>.output try.txt

sqlite>select * from logTable;

$ls -l try.txt

size is 406 bytes

  • 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-06T03:55:44+00:00Added an answer on June 6, 2026 at 3:55 am

    You must use .dump. The sqlite3 interactive client doesn’t output BLOB columns.

    $sqlite3 log.db
    sqlite> .output try.txt
    sqlite> .dump
    sqlite> .quit
    

    The code below is a self contained example of creating a simple blob-containing database.

    // https://github.com/KubaO/stackoverflown/tree/master/questions/sqlite-blob-11062145
    #include <QtSql>
    
    int main()
    {
        QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
        db.setDatabaseName("./log.db");
    
        if (!db.open()) { qDebug() << "can't open the database"; return 1; }
    
        QSqlQuery query{db};
    
        query.exec("DROP TABLE log");
    
        if (!query.exec("CREATE TABLE log(packet BLOB)"))
            qDebug() << "create table failed";
    
        QVariant data[2] = {QByteArray{1024, 1}, QByteArray{2048, 2}};
    
        query.prepare("INSERT INTO log VALUES(:packet)");
    
        query.bindValue(":packet", data[0], QSql::In | QSql::Binary);
        if (!query.exec()) qDebug() << "insert failed";
    
        query.bindValue(":packet", data[1], QSql::In | QSql::Binary);
        if (!query.exec()) qDebug() << "insert failed";
    
        db.close();
    
        if (!db.open()) { qDebug() << "can't reopen the database"; return 2; }
    
        query.prepare("SELECT (packet) FROM log");
        if (!query.exec()) qDebug() << "select failed";
    
        for (auto const & d : data) if (query.next()) {
            qDebug() << query.value(0).toByteArray().size() << d.toByteArray().size();
            if (d != query.value(0)) qDebug() << "mismatched readback value";
        }
    
        db.close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ASP.NET MVC , and I wish to store all my DateTime values
Im not able to load the page with circlepageindicator. This is the xml <FrameLayout
I am not able to make a clear decision on this one. I am
I am not able to make this out: Between eliminates use of >= and
I am not even sure how to ask. I do this all the time
I am using DirectX 9 in C# I store all my vertices in a
this problem is not really uncommon, but i don't really have an idea how
I have a base class and 4 derived classes. I store all my derived
EDIT 1 I do not exclude at all this might be caused by something
Let's say we're having an application which should be able to store all kind

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.