Which data structure to use? lazarus / 16-Databases ---------------------------------------------------------------------- Vodnik · 2020-02-11 09:48 My application read data to DBGrid from the database with phone calls. I want to add information about the cities to the output of my application. The data with city names is not contained in original DB and it is not allowed to add new tables to it. So I plan to store data about cities somewhere else (495, Moscow; 812, St. Petersburg and so on) and to insert it to DBGrid with OnGetText. Question is: what are data structures available in Lazarus, that are suitable for this case? Arrays? Files? Additional database? ---------------------------------------------------------------------- AlexTP · 2020-02-11 09:59 It may be TCSVDataset, or maybe TStringList, which have Objects items pointing to TStringLists. ---------------------------------------------------------------------- garlar27 · 2020-02-11 14:08 Create a new DB to hold this kind of data (let's call it system level tables) and attach it to the main db. Thus you can join the city table with the phone calls or whatsoever. ---------------------------------------------------------------------- sash · 2020-02-11 17:33 When using db-aware controls, the first thing I'd consider is to use Dataset (Lookup). Easiest one: TBuffDataset stored in XML. Another option (if you need a display in Grid only) - DBGrid's Picklists. ---------------------------------------------------------------------- Vodnik · 2020-02-11 20:54 Quote from: garlar27 on February 11, 2020, 03:08:23 pmCreate a new DB to hold this kind of data (let's call it system level tables) and attach it to the main db. Thus you can join the city table with the phone calls or whatsoever. This sounds intriguing! How is it possible to attach one DB to another? Can you please provide a bit more detailes or links? ---------------------------------------------------------------------- Vodnik · 2020-02-11 21:09 Quote from: sash on February 11, 2020, 06:33:00 pmWhen using db-aware controls, the first thing I'd consider is to use Dataset (Lookup). Easiest one: TBuffDataset stored in XML. Another option (if you need a display in Grid only) - DBGrid's Picklists. I can't find any description neither for TBuffDataset nor for DBGrid's Picklists, only questions and discussions. Not documented, but well-known features... Can you please provide some ideas where to find any info or examples? ---------------------------------------------------------------------- sash · 2020-02-12 08:38 TBufDataset (yes, both well-known and not well documented, and also a parent for TSQLQuery) is generally following Delphi's TClientDataset paradigm: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses db, BufDataset, XMLDatapacketReader;var  bds, bds2 : TBufDataset;begin  bds := TBufDataset.Create(YourForm);  with bds  do begin    // define fields    FieldDefs.Add('id', ftInteger);    FieldDefs.Add('name', ftString, 30);    CreateDataset;     // add data    AppendRecord([1, 'val1']);    AppendRecord([2, 'val2']);    SaveToFile('dataset.xml', dfXML); // save    // save    MergeChangeLog; // Mostly we don't need persistent changelog    SaveToFile('dataset.xml', dfXML);  end;   bds2 := TBufDataset.Create(YourForm);  bds2.LoadFromFile('dataset.xml', dfXML);                         end; ---------------------------------------------------------------------- garlar27 · 2020-02-12 16:44 Quote from: Vodnik on February 11, 2020, 09:54:07 pmQuote from: garlar27 on February 11, 2020, 03:08:23 pmCreate a new DB to hold this kind of data (let's call it system level tables) and attach it to the main db. Thus you can join the city table with the phone calls or whatsoever. This sounds intriguing! How is it possible to attach one DB to another? Can you please provide a bit more detailes or links? If you are using relational DB then you have the ATTACH statement and it is something like this: Code: SQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ATTACH DATABASE 'C:\MyPrj\data\sysdata.db' AS SYS_DATA; ---------------------------------------------------------------------- Vodnik · 2020-02-13 20:44 Thanks, garlar. I didn't find description of similar construction for Informix. And I guess this will break the rule: "Do not modify DB structure". ---------------------------------------------------------------------- garlar27 · 2020-02-17 16:36 Quote from: Vodnik on February 13, 2020, 09:44:15 pmThanks, garlar. I didn't find description of similar construction for Informix. And I guess this will break the rule: "Do not modify DB structure". Maybe you could use CREATE TEMP TABLE or CREATE EXTERNAL TABLE statement As I understand they DO NOT MODIFY the working DB. ---------------------------------------------------------------------- Vodnik · 2020-02-19 19:41 Thanks, garlar, I have succeeded with CREATE TEMP TABLE option. Now I'm looking for convenient way to store the data for TEMP TABLE creation. E.g. I load CSV file, then CREATE TEMP TABLE from it, afterwards give the job to DB's SQL engine. ---------------------------------------------------------------------- egsuh · 2020-02-25 05:05 I think you may use CSVDataSet itself, without creating TEMP TABLE, by linking two datasets from  Informix and CSVDataSet.