I figured I'd put this question out there for the experts.
I have a table designated for logging events in our software program, and this table has a few ntext type columns for storing text specific to that event. Because this text can sometimes be quite long, I can't really embed it in a simple SQL INSERT command, so I'm forced to find an alternative method for appending these types of records.
With that being said, what's the best way to do this? I know I can use the TMSTable or TMSQuery components to directly append a row using the standard VCL TDataset methods, but how efficient is this? I obviously don't need to query or retrieve any of the existing records, so how should I go about simply and quickly appending a new record so I can write long text strings to the underlying ntext columns?
Most efficient way to append records containing lots of text
-
AndreyZ
Thanks for the fast reply! 
The TMSLoader was looking like a good solution, but then I realized its Connection property is of type TMSConnection, which means I can't use a TMSCompactConnection object (for SQL Server Compact). We're planning on supporting both SQL Server Express and Compact, so the TMSLoader option probably won't work, at least not for Compact databases.
With that being said, what's the next best option? We're really not looking at adding tons of rows at once either, but do keep in mind that this table will fill up pretty quickly, so I hate to do any sort of query that has to fetch this data before I can start appending a new row.
The TMSLoader was looking like a good solution, but then I realized its Connection property is of type TMSConnection, which means I can't use a TMSCompactConnection object (for SQL Server Compact). We're planning on supporting both SQL Server Express and Compact, so the TMSLoader option probably won't work, at least not for Compact databases.
With that being said, what's the next best option? We're really not looking at adding tons of rows at once either, but do keep in mind that this table will fill up pretty quickly, so I hate to do any sort of query that has to fetch this data before I can start appending a new row.
-
AndreyZ
You can use the following code:
In this case the TMSQuery component doesn't fetch data from database.
Also you can use the TMSQuery.CashedUpdates and TMSQuery.Options.UpdateBatchSize options to implement quick insertion of data into the table.
You can look at the example of using this options in SDACDemo.
Code: Select all
MSQuery.SQL.Add('insert into tbl_ntext(id, bigtext) values(:id, :bigtext)');
MSQuery.ParamByName('id').AsInteger := 1;
MSQuery.ParamByName('bigtext').AsString := 'bigtext';
MSQuery.Execute;Also you can use the TMSQuery.CashedUpdates and TMSQuery.Options.UpdateBatchSize options to implement quick insertion of data into the table.
You can look at the example of using this options in SDACDemo.