2

I try to insert a slice of bytes into a sqlite3 database, using github.com/mattn/go-sqlite3.

Data:

thmbnail := [255 216 255 219 0 132 ...]

Create statement:

sqlStmt := `
create table result (id INTEGER NOT NULL PRIMARY KEY, fname TEXT, path TEXT, 
size INTEGER, fMDate TEXT, fUUID TEXT, fSHA1 TEXT, fPRONOM TEXT, fNSRL INTEGER, fTHMB BLOB);
pragma journal_mode=WAL;
delete from result;
`

Insert:

func addEntryDB(stmt *sql.Stmt, entry fileMD) {

    _, err := stmt.Exec(nil, entry.fName, entry.fPath, entry.fSize, entry.fMDate,
    entry.fUUID, entry.fSHA1, entry.fPRONOM, entry.fNSRL, entry.fTHMB)
    if err != nil {
        log.Fatal(err)
    }
}

Problem: Only the first four bytes of thmbnail are inserted. I suppose this might be related to the 0 byte on the fifth position.

How can the whole []byte be inserted?

1

1 Answer 1

1

I found the problem. It sat before the monitor.The data was inserted actually. Sqlite client handles the blob as text and terminates printing at the "0". Inspecting the database with sqlitebrowser showed the complete entry.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.