I'm trying to display products belonging to a selected supplier from supplier grid on another grid but cannot?
Also my calculated field for calculating of product total purchase amount in products DB Table doesn't seems to be functioning too?


Please see the attached sample project.

327

(18 replies, posted in General)

Hi EHW,


My apologies, error was due to me trying to import wrong database.


I only tested it on sample project DB I have uploaded here.
Looking forward to your update you mentioned when replying to wenchester21.


I understand it's not an alternative to back up. As far as I know having data  in csv format would be useful. Especially, when data needs to be migrated to a different DB app which is using different DB system.


ps/. Is it possible to use win save dialog instead of the one you have used when exporting?

328

(18 replies, posted in General)

Hi EHW,


Thank you very much for your kind help....................


At my end, when I try to import exported csv file I get an error message:
"Variant of safe array index out of bounds."


Hi Wenchester21,

I do not know if it is my PC or if it is the example, but when I import the CSV it does not restore the images of the companies.

As EHW pointed out, images cannot be exported in .csv file, as it's a text file.

329

(18 replies, posted in General)

Hi Math,


I have a project for you but it is nearly 1 in the morning and I have to clean and comment the code.
Tomorrow is a day of for me, I’ll clean up everything and post it for you first thing with morning coffee smile


Export, import with duplicate check via stringlists and progressbar.


Thanks a lot...... Looking forward to it

330

(18 replies, posted in General)

Hi Mathias,


you refer to a file which name is composed of the date and time of your search, probably a few seconds after the export, so the systme can not find it because it does not exist. The export file was generated a few seconds earlier, thus the name is different. The problem here is the 'now' variable you are using.

I didn't realize that. Thanks...


I took out date and time from file name but still got same  "...The system cannot find the file specified." error tho

// EXPORT ///////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure Form1_bExport_OnClick (Sender: string; var Cancel: boolean);
var Sl : TstringList;
begin
Sl := TstringList.Create;
sFileName := 'ExportedData.csv';
SaveDialog := TSaveDialog.Create(Form1);
SaveDialog.FileName := sFileName;
SaveDialog.DefaultExt := 'csv';
SaveDialog.Filter := 'Database|*.csv|Any file|*.*';
SaveDialog.Options := ofOverwritePrompt+ofHideReadOnly+ofEnableSizing;

if SaveDialog.Execute then
   begin
       ExportToSl('SELECT lastname, firstname, salary, dateofbirth, isSmoke, comment FROM employees', Sl);
       ExportToSl('SELECT coDate,  coName, coActive FROM Company', Sl);
       Sl.SavetoFile('.\ExportedData.csv');

       ShowMessage('Data has been exported in to the specified folder');
   end;
SaveDialog.Free;
Sl.Free;
end;
                      

// IMPORT //////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure Form1_bImport_OnClick (Sender: string; var Cancel: boolean);
begin
sFileName := 'ExportedData.csv';
OpenDialog := TOpenDialog.Create(Form1);
OpenDialog.FileName := sFileName;
OpenDialog.DefaultExt := 'csv';
OpenDialog.Filter := 'Database|*.csv|Any file|*.*';
OpenDialog.Options := ofOverwritePrompt+ofHideReadOnly+ofEnableSizing;

if OpenDialog.Execute then
   begin
   Import('employees', 'lastname,firstname,salary,dateofbirth,isSmoke,comment'+#13#10+
          'Company', 'coDate, coLogo, coName, coActive');

   CopyFile(ExtractFilePath(Application.ExeName)+'ExportedData.csv', OpenDialog.FileName);
   ShowMessage('Data has been imported.');
   end;
OpenDialog.Free;
end;

331

(18 replies, posted in General)

Hi Mathias,


Thank you for the detailed info but it seems I'm not there yet.


I was hoping to make it work with bit of less script when exporting multiple tables fields without the use of StringList  but I couldn't get it working in syntax front - I think?

Export('SELECT lastname, firstname, salary, dateofbirth, isSmoke, comment FROM employees')+#13#10+
       ('SELECT coDate, coName, coActive FROM Company', 'ExportedData-' + FormatDateTime('dd-mm-yyyy hh-nn-ss', now)+'.csv');

Anyhow, I tried to get import working but sadly failed in that front too. It returns error saying "...The system cannot find the file specified." after attempting to import exported csv file.

var SaveDialog: TSaveDialog;
    OpenDialog: TOpenDialog;
    sFileName: string;
    Results: TDataSet;
    i,c: integer;
    sValue, sValues: string;

Procedure ExportToSl (SQL: string; Sl: TstringList);
begin
SQLQuery(sql, Results);
c := Results.FieldCount-1;

  while not Results.eof do
  begin
  sValues := '';
  for i := 0 to c do
      begin
      sValue := Results.Fields.Fields[i].AsString;
      if (Results.Fields.Fields[i].DataType = ftFloat) or (Results.Fields.Fields[i].DataType = ftLargeint) then
          sValue := ReplaceStr(sValue, ',', '.')
          else
          begin
          sValue := ReplaceStr(sValue, ',', ',');
          sValue := ReplaceStr(sValue, #13#10, '|');
          sValue := '''' + escape_special_characters(sValue) + '''';
          end;

          sValues := sValues + sValue+',';
        end;

  if sValues <> '' then SetLength(sValues, Length(sValues)-1);
  sl.Add(sValues);
  Results.next;
  end;
Results.Close;
end;


// EXPORT ///////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure Form1_bExport_OnClick (Sender: string; var Cancel: boolean);
var Sl : TstringList;
begin
Sl := TstringList.Create;
sFileName := 'ExportedData-' + FormatDateTime('dd-mm-yyyy hh-nn-ss', now)+'.csv';
SaveDialog := TSaveDialog.Create(Form1);
SaveDialog.FileName := sFileName;
SaveDialog.DefaultExt := 'csv';
SaveDialog.Filter := 'Database|*.csv|Any file|*.*';
SaveDialog.Options := ofOverwritePrompt+ofHideReadOnly+ofEnableSizing;

if SaveDialog.Execute then
   begin
       ExportToSl('SELECT lastname, firstname, salary, dateofbirth, isSmoke, comment FROM employees', Sl);
       ExportToSl('SELECT coDate,  coName, coActive FROM Company', Sl);
       Sl.SavetoFile('.\ExportedData.csv' + FormatDateTime('dd-mm-yyyy hh-nn-ss', now)+'.csv');

       ShowMessage('Data has been exported in to the specified folder');
   end;
SaveDialog.Free;
Sl.Free;
end;


// IMPORT //////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure Form1_bImport_OnClick (Sender: string; var Cancel: boolean);
begin
sFileName := 'ExportedData-' + FormatDateTime('dd-mm-yyyy hh-nn-ss', now)+'.csv';
OpenDialog := TOpenDialog.Create(Form1);
OpenDialog.FileName := sFileName;
OpenDialog.DefaultExt := 'csv';
OpenDialog.Filter := 'Database|*.csv|Any file|*.*';
OpenDialog.Options := ofOverwritePrompt+ofHideReadOnly+ofEnableSizing;

if OpenDialog.Execute then
   begin
   Import('employees', 'lastname,firstname,salary,dateofbirth,isSmoke,comment'+#13#10+
          'Company', 'coDate, coLogo, coName, coActive', 'ExportedData-' + FormatDateTime('dd-mm-yyyy hh-nn-ss', now)+'.csv');

   CopyFile(ExtractFilePath(Application.ExeName)+'ExportedData.csv' + FormatDateTime('dd-mm-yyyy hh-nn-ss', now)+'.csv', OpenDialog.FileName);
   ShowMessage('Data has been imported.');
   end;
OpenDialog.Free;
end; 

332

(18 replies, posted in General)

Hi Mathias,


Thank you very much...........................
I have tried few things to apply your code to import beside export but couldn't get it working.
Please see the attached sample project.

333

(18 replies, posted in General)

Dmitry has posted an import export script in FAQ category of MVD forums.


I wanted to add a bit of user control and friendliness to it, such as ability to specify file name, location etc via windows open and save dialogs. I think I have done this part (hopefully correctly) thanks to Dmitry's kind help providing such script earlier.


Three issues I have faced and couldn't resolve:
1. I wanted include multiple tables data (in this case 2) in export and import to build an understanding of exporting and importing the whole database, but couldn't get it working?. More often than not database file will have multiple tables.


2. I wanted to add duplicate counts on info message (after import process finish) when importing with duplicate check, but no idea how to do it. I put a comment in the script too about it.


3. Adding a dialog with progress bar which would be displayed during import export process running. This would be very helpful when exporting and importing larger databases.


Could anybody have a look at the sample project attached here and implement the above mentioned features and correct my mistakes if there is any please?

334

(24 replies, posted in General)

jonibek wrote:

where can i find conversion script?


If you mean SQLiteCompare utility that generates the script, link is on Math's excellent utility SCT - bottom of the form - Assumung you have downloaded from his post above.
For your convenience here is the same link:
https://www.codeproject.com/Articles/22 … re-Utility

335

(4 replies, posted in General)

Hi Derek,


Thank you very much for the parts example.............
Very useful, especially achieving the task with no or minimal script.

Truly appreciated................


Hopefully other members and Dmitry posts more grid filters.

336

(24 replies, posted in General)

Hi Mathias,


Wooow....... However much I thank you for the excellent job yo have done here is not enough.........................
I tested it with one DB and it worked like a charm.


Using this wonderful utility is not a problem for us.
I was wondering is it possible to improve end user experience further by reducing down to use of your utility SCT only...


I'm thinking that it may be done in ways perhaps:
1. SCT compares  DBs and converts without the need to use additional application. I understand, this wouldn't be an easy option.
2. SCT uses SQLite Compare utility in the background. SCT gets SQLite Compare to do the comparing and generating the script and using generated script to convert as it does currently somehow. In this case we'd include SQLite Compare within SCT package and pass to end user. End user would only need to run SCT to convert their old DB.


Once again, thank you very much for the great work you have done.............................

337

(4 replies, posted in General)

Hi Derek,


Thank you very much..........
Truly appreciated.........................


I was thinking using filter too but I couldn't get it working. I was trying something like table.field1+table.field2 etc. Silly me.
It'd be great if somebody could put together all various filters samples for grid for different situations. Kind of grid filters cheat sheet.

338

(4 replies, posted in General)

I was trying to display data from one table on multiple grids (in this case two, phones and mobile)
I'm getting a blank line on secondary grid when partial data saved and vice versa. Even though each grid specified to display certain fields only.
Is there any solution without using additional DB Table?


Please see the attached sample project file:

339

(24 replies, posted in General)

Hi Mathias,


Thank you very much for your patience and extremely kind help.......................................................


Still couldn't get it working fully. Script syntax errors are corrected. However I get error on running the script. Most likely I'm doing things wrong.
1. I rename old db (with data) to sqliteData
2. On SQLite Compare utility, I put the old db that's renamed to sqliteData to left and new db (blank) sqlite to right.
3. Generate script left --> to right.


https://s17.postimg.org/ya2j6irxb/z_Temp103b.png
Is "Comparison error" something to be concerned about?


Here is the script generated by SQLite Compare:

BEGIN TRANSACTION;

CREATE TABLE issueFilter
(
    id INTEGER PRIMARY KEY ASC AUTOINCREMENT,
    issueFilter TEXT
);

-- Creating table Issues from scratch (simple ALTER TABLE is not enough)

CREATE TABLE temp_Issues_1848543519
(
    id INTEGER PRIMARY KEY ASC AUTOINCREMENT,
    issueDate TEXT,
    issueName TEXT NOT NULL,
    issueReoprted TEXT,
    issueDesc TEXT,
    id_Application INTEGER,
    id_issueFilter INTEGER,
    issueFilterValue TEXT,
    FOREIGN KEY (id_Application) REFERENCES Application(id) ON DELETE CASCADE,
    FOREIGN KEY (id_issueFilter) REFERENCES issueFilter(id)
);

-- Copying rows from original table to the new table

INSERT INTO temp_Issues_1848543519 (id,issueDate,issueName,issueReoprted,issueDesc,id_Application,id_issueFilter,issueFilterValue) SELECT id,issueDate,issueName,issueReoprted,issueDesc,id_Application,id_issueFilter,issueFilterValue FROM Issues;

-- Droping the original table and renaming the temporary table

DROP TABLE Issues;
ALTER TABLE temp_Issues_1848543519 RENAME TO Issues;

COMMIT TRANSACTION;

And here is the MVD version of the above script:

procedure Form1_Button7_OnClick (Sender: TObject; var Cancel: boolean);
var SqliteTr: TDBXSqliteTransaction;
begin
    //Initiate the transaction
    SqliteTr := BeginSQLiteTransaction;

    //SQL command 1
    SQLExecute('CREATE TABLE issueFilter'+
    '('+
    'issueFilter TEXT'+
    ')');

    //SQL command 2
    SQLExecute('CREATE TABLE temp_Issues_1848543519'+
    '('+
    'id INTEGER PRIMARY KEY ASC AUTOINCREMENT,'+
    'issueDate TEXT,'+
    'issueName TEXT NOT NULL,'+
    'issueReoprted TEXT,'+
    'issueDesc TEXT,'+
    'id_Application INTEGER,'+
    'id_issueFilter INTEGER,'+
    'issueFilterValue TEXT,'+
    'FOREIGN KEY (id_Application) REFERENCES Application(id) ON DELETE CASCADE,'+
    'FOREIGN KEY (id_issueFilter) REFERENCES issueFilter(id'+
    '))');

    //SQL command 3
    SQLExecute('INSERT INTO temp_Issues_1848543519 (id,issueDate,issueName,issueReoprted,issueDesc,id_Application,id_issueFilter,issueFilterValue) '
              +'SELECT id,issueDate,issueName,issueReoprted,issueDesc,id_Application,id_issueFilter,issueFilterValue FROM Issues;');

    //SQL command 4
    SQLExecute('DROP TABLE Issues;');

    //SQL command 5
    SQLExecute('ALTER TABLE temp_Issues_1848543519 RENAME TO Issues;');

    //Commit the SQLTransaction
    CommitSQLiteTransaction(SqliteTr);
end;

When I run it and click on db update button (Button7) I get the following error:
https://s17.postimg.org/g79gey13z/z_Temp102.png


I comment out :

SQLExecute('CREATE TABLE issueFilter'+
    '('+
    'issueFilter TEXT'+
    ')');

Then script runs without error. After, I rename sqliteData.db to sqlite.db and copy over blank (new app db). This time I get error saying there is no such table  issueFilter....

340

(24 replies, posted in General)

MVD's way of handling SQL usually gives me some issues that I cannot resolve myself. There are so many punctuations used and it's rules. On the other hand SQLite Compare uses much more easy to read and understand SQLite. I assume that's the difference of C# handling and Pascal/Delphi.


I was trying to translate SQLite Compare script to MVD. I've already spend almost 5 hours and still couldn't resolve it. I got about 4 errors atm:
https://s17.postimg.org/47nudhqmn/z_Temp101.png


Here is the script that producing errors:

procedure Form1_Button7_OnClick (Sender: TObject; var Cancel: boolean);
var SqliteTr: TDBXSqliteTransaction;
begin
    //Initiate the transaction
    SqliteTr := BeginSQLiteTransaction;

    //SQL command 1
    SQLExecute('CREATE TABLE temp_Application_534011718'+
    '('+
    'id INTEGER PRIMARY KEY ASC AUTOINCREMENT,'+
    'appName TEXT NOT NULL,'+
    'code TEXT,'+
    'issues TEXT,'+
    'todo TEXT,'+
    'notes TEXT,'+
    'id_Status INTEGER,'+
    'id_Groups INTEGER,'+
    'id_Categories INTEGER,'+
    'FOREIGN KEY (id_Status) REFERENCES Status(id),'+
    'FOREIGN KEY (id_Groups) REFERENCES Groups(id),'+
    'FOREIGN KEY (id_Categories) REFERENCES Categories(id)'+
    ')');

    //SQL command 2 (line break used after id_Categories) ' +'
    SQLExecute('INSERT INTO temp_Application_534011718 (id,appName,code,issues,todo,notes,id_Status,id_Groups,id_Categories)'
              +'SELECT id,appName,code,issues,todo,notes,id_Status,id_Groups,id_Categories FROM Application;');

    //SQL command 3
    SQLExecute('DROP TABLE Application;');

    //SQL command 4
    SQLExecute('ALTER TABLE temp_Application_534011718 RENAME TO Application;');

    //SQL command 5////
    SQLExecute('CREATE TABLE issueFilter;'+
    '('+
    'id INTEGER PRIMARY KEY ASC AUTOINCREMENT,'+
    'issueFilter TEXT,'
    ')');

    //SQL command 6
    SQLExecute('CREATE TABLE temp_Issues_1655911537'+
    '('+
    'id INTEGER PRIMARY KEY ASC AUTOINCREMENT,'+
    'issueDate TEXT,'+
    'issueName TEXT NOT NULL,'+
    'issueReoprted TEXT,'+
    'issueDesc TEXT,'+
    'id_Application INTEGER,'+
    'id_issueFilter INTEGER,'+
    'issueFilterValue TEXT,'+
    'FOREIGN KEY (id_Application) REFERENCES Application(id) ON DELETE CASCADE,'+
    'FOREIGN KEY (id_issueFilter) REFERENCES issueFilter(id'+
    ')');

    //SQL command 7
    SQLExecute('INSERT INTO temp_Issues_1655911537 (id,issueDate,issueName,issueReoprted,issueDesc,id_Application,id_issueFilter,issueFilterValue)'
              +'SELECT id,issueDate,issueName,issueReoprted,issueDesc,id_Application,NULL AS id_issueFilter,NULL AS issueFilterValue FROM Issues;');

    //SQL command 8
    SQLExecute('DROP TABLE Issues;');

    //SQL command 9
    SQLExecute('ALTER TABLE temp_Issues_1655911537 RENAME TO Issues;');

    //Commit the SQLTransaction
    CommitSQLiteTransaction(SqliteTr);
end;

341

(24 replies, posted in General)

Hi Mathias,


Sorry, it's my bad. I didn't think of checking email. Now I got it.


Looks great and comprehensive.......................
Very kind of you................
Thank you very much.................................................................
Truly appreciated ...............................................................................


I'll be looking and exploring it with a great joy...

342

(24 replies, posted in General)

Sounds great Math !!!


Looks like, attachment missed or failed to upload.
Looking forward for it...

343

(24 replies, posted in General)

Hi Mathias,


Indeed, it did.
Thank you so much for the quick help .......................


If I understood this correctly, after we run the  db update script on new app, we'd take out update db button, compile and send it to end user with a blank sqlite.db file. All end user needs to do is overwrite blank db file with the one he has containing his data. Am I correct?

344

(1 replies, posted in General)

I vaguely remember that I posted something similar before but I just couldn't find it. Perhaps I remember wrong.


I wanted to use a combobox as filter for a specific grid. I got one of Derek's sample project where combo values entered into DB file which works fine. I wanted to have combo values in script as I delete and start with blank DB file many times in the course development process. It works fine on source form (SaleInvItem) but couldn't get it working on Form1, where it'd be used as a filter.


Please see the attached sample project.

345

(24 replies, posted in General)

Hi Mathias,


I hope life is treating you well and you are enjoying it.


Thank you very much for your kind help...................
Truly appreciated.........................


I have tried to apply it a smaller test project but couldn't get it right properly. It returns an error....

 { SQLite Compare script::::
BEGIN TRANSACTION;
-- Adding missing table columns

ALTER TABLE company ADD COLUMN coPhone TEXT;

CREATE TABLE products
(
    id INTEGER PRIMARY KEY ASC AUTOINCREMENT,
    pName TEXT,
    pPrice REAL,
    id_company INTEGER,
    FOREIGN KEY (id_company) REFERENCES company(id) ON DELETE CASCADE
);
COMMIT TRANSACTION;
   }

//////////////////////////////////////////////////////////////////////////

procedure Form1_Button8_OnClick (Sender: TObject; var Cancel: boolean);
var SqliteTr: TDBXSqliteTransaction;
begin
//Initiate the transaction
SqliteTr := BeginSQLiteTransaction;

SQLExecute('ALTER TABLE company ADD COLUMN coPhone TEXT;');

SQLExecute('CREATE TABLE products'+
    '('+
'id INTEGER PRIMARY KEY ASC AUTOINCREMENT,'+
'pName TEXT,'+
'pPrice REAL,'+
'id_company INTEGER REFERENCES company(id) ON DELETE CASCADE,'+
')');

//Commit the SQLTransaction
CommitSQLiteTransaction(SqliteTr);
end;

346

(24 replies, posted in General)

Hi EHW,


Thank you very much...........


Unfortunately, I couldn't do it.


Please see the attached sample project.

347

(11 replies, posted in FAQ)

Hi Dmitry,


Completely universal script to export/import data from a table. Just specify database fields in parameters of procedure.

Great stuff.................
I was looking for it as it's quite important for me.


I wanted to add a bit of user control, as to specify file name, location etc via windows open and save dialogs. I think I have done it (hopefully correctly) thanks to your kind help providing such script earlier.


Two issues I have faced and couldn't resolve.
1. I wanted include second table data in export and import but couldn't get it working?
2. I wanted to add duplicate counts on info message when importing with duplicate check, but no idea how to do it. I put a comment in the script too about it.


I'd deeply appreciate if you could please fix the attached sample project in respect of the issues stated above.

348

(5 replies, posted in General)

Hi EHW,


Thank you so much...................
Looks like my single cell brain missed form1.width bit.

349

(5 replies, posted in General)

Hi Dmitry,


Could you correct the following couple of line please?

procedure Form1_btnHideLeftPanel_OnClick (Sender: TObject; var Cancel: boolean); // Hide <<
begin
//Form1.Width := - Form1.Panel1.Width;
end;

procedure Form1_btnShowLeftPanel_OnClick (Sender: TObject; var Cancel: boolean); // Show >>
begin
//Form1.Width := + Form1.Panel1.Width;
end;

What I'm trying to achieve is to;
on a sizable form with a vertical splitter, re-size the window according to panel visibility.

350

(24 replies, posted in General)

Hi Mathias,


Happy New Year to you too...............


Thank you very much for the link and info...............


Script created by SQLite Compare utility, seems to be not compatible with MVD.
How can I convert the following SQLite Compare script to MVD script?

BEGIN TRANSACTION;
-- Creating table Application from scratch (simple ALTER TABLE is not enough)

CREATE TABLE temp_Application_534011718
(
    id INTEGER PRIMARY KEY ASC AUTOINCREMENT,
    appName TEXT NOT NULL,
    code TEXT,
    issues TEXT,
    todo TEXT,
    notes TEXT,
    id_Status INTEGER,
    id_Groups INTEGER,
    id_Categories INTEGER,
    FOREIGN KEY (id_Status) REFERENCES Status(id),
    FOREIGN KEY (id_Groups) REFERENCES Groups(id),
    FOREIGN KEY (id_Categories) REFERENCES Categories(id)
);

-- Copying rows from original table to the new table

INSERT INTO temp_Application_534011718 (id,appName,code,issues,todo,notes,id_Status,id_Groups,id_Categories) SELECT id,appName,code,issues,todo,notes,id_Status,id_Groups,id_Categories FROM Application;

-- Droping the original table and renaming the temporary table

DROP TABLE Application;
ALTER TABLE temp_Application_534011718 RENAME TO Application;

DROP TABLE Issues;

COMMIT TRANSACTION;