Hi,
I wrote this code to read blob data from a SQLite DB:
public static byte[] GetBlobData(string Query){
byte[] BlobContent = new byte[0];
dbcmd = dbcon.CreateCommand();
dbcmd.CommandText = Query;
reader = dbcmd.ExecuteReader();
while (reader.Read()) {
BlobContent = (byte[])reader["blob"];
}
return BlobContent;
}
Where query is like “SELECT blob FROM ‘blobfield’ WHERE id=”…
How about storing blob data?
Any suggestion?
Thanks!
Gius
So, the correct code is:
public static bool SaveBlobData(String tableName, byte[] BlobContent) {
string query;
query = "INSERT INTO " + tableName + "(blob) VALUES (@BlobContent)";
try {
dbcmd = dbcon.CreateCommand();
dbcmd.CommandText = query;
SqliteParameter setParam = new SqliteParameter("@BlobContent", BlobContent);
dbcmd.Parameters.Add(setParam);
dbcmd.ExecuteNonQuery ();
} catch(Exception exception) {
Debug.LogError(exception.Message);
return false;
}
return true;
}
Don’t you forget to open the DB before saving data in.
Hope this help!