SCHEMA :
CREATE TABLE checksums
(i INTEGER,c VARCHAR(20) PRIMARY KEY) ;

CODE :

// Generates a Random string
QByteArray Randstr_B(int len) {
    char chars[36] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
    QByteArray str;
    for (int i = 0; i < len; i++) {
        str.append(chars[qrand() % 35]);
    }
    return str;
}

// Converts  quint64 to Little Endian bytes
QByteArray toLE(quint64 num){
    unsigned char bytes[8];
    bytes[0] = (unsigned char)num;
    bytes[1] = (unsigned char)(num >> 8);
    bytes[2] = (unsigned char)(num >> 16);
    bytes[3] = (unsigned char)(num >> 24);
    bytes[4] = (unsigned char)(num >> 32);
    bytes[5] = (unsigned char)(num >> 40);
    bytes[6] = (unsigned char)(num >> 48);
    bytes[7] = (unsigned char)(num >> 56);

    return QByteArray((const char *)bytes, 8);
}

insQ->prepare("INSERT INTO checksums (i, c) VALUES (?, ?)");

I then do inserts in the loop (I am using QT) :
for(quint64 i = 1; i <= 10000000; i++){
        // Create the data RANDOMLY
        QByteArray block = Randstr_B(4088).append(toLE(i)); // "toLE" is a
function which converts quint64 to Little Endian Bytes i.e. 8 bytes. I used
this to make each block unique
        QByteArray csum = QCryptographicHash::hash(block,
QCryptographicHash::Sha1);
        unsigned char C = (unsigned char)csum.at(0);

        // Insert into the MAP
        insQ->bindValue(0, i); // insQ is a QSqlQuery *
        insQ->bindValue(1, csum);
        if(!insQ->exec()){
            qDebug() << "Error Inserting :" << i << csum.toHex().toUpper()
<< insQ->lastError().text();
            //exit(0);
        }
        if((i % 10000) == 0){
            mapconn.commit(); // Database Connection "mapconn"
            Q.exec("PRAGMA wal_checkpoint;"); // Checkpointing the WAL and
"Q" is also another QSqlQuery.
            mapconn.transaction(); // Restarting Transaction
            qDebug() "Committed :" << i << csum.toHex() << time();
        }
    }
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to