Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I save an "array of record" to a TMemoryStream (to then store in a sqlite BLOB field)?
    primarykey
    data
    text
    <p>Ultimately my goal is to be able to save an array of records data structure in a sqlite BLOB field, but in the interim I am trying to serialize an array of records and store it in a TMemoryStream. In case it may be relevant, I am using <a href="http://www.itwriting.com/blog/?page_id=659" rel="nofollow">Tim Anderson's sqlite wrapper</a> (unicode) with Delphi 2010.</p> <p>This is my array of record declaration:</p> <pre><code>type TPerson = array of packed record sCountry: string[50]; sFullName: string[100]; sAddress: string[100]; sCity: string[30]; sEmployer: string[100]; end; var MyPeople : TPerson; </code></pre> <p>And here is the code I am currently using to serialize this array of record to a TMemoryStream. The problem is that it doesn't work:</p> <pre><code>var i : integer; ms : TMemoryStream: ms2 : TMemoryStream; TestPeople : TPerson; sldb : TSQLiteDatabase; begin ms := TMemoryStream.Create; ms2 := TMemoryStream.Create; sldb := TSQLiteDatabase.Create(slDBPath); //sldBPath is a global variable with path to sqlite db try i := Length(MyPeople); ms.Write(i, 4); ms.Write(pointer(MyPeople)^, i * sizeOf(MyPeople)); /// ms2.Read(i, 4); SetLength(ms2, i); ms2.Read(pointer(TestPeople)^, i * sizeOf(TestPeople)); WriteLn('#############' + ms2[0].sFullName); //check if we can read data back sQuery := 'UPDATE PersonDirectory SET fldPersonBlob = ? WHERE id = "' + 42 + '";'; sldb.UpdateBlob(sQuery, ms); finally ms.Free; ms2.Free; sqldb.Free; end; end; </code></pre> <p>Any ideas on either how to generally serialize an array of record to a TMemoryStream, or a better way to store an array of records in a sqlite BLOB field?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload