Jump to content
JohnLM

[FireDAC](Comp)[DS]-306. Command [FDTable] text must be not empty. (solved)

Recommended Posts

I'm trying really hard to figure this message out, but can't. 

 

What part of the TFDTable 'text must not be empty' that i need to fill in ?

 

1. I have a form with a memtable and stringgrid on left side of form.

2. Also have a dbgrid with (con, table, query, datasource) components on right side of form.

3. a button to [import] the data from the stringgrid into the dbgrid.

 

Below, is code to import data into the FDTable. I am just trying to learn how to import data through this method. Not trying to do it another method or way. So, I want to know what is the meaning and solution to the 'text must not be empty' part. I don't know what text the message is refering to when i run this code and click on the [import] button, below... thanks.

procedure TForm1.btnImportClick(Sender: TObject);
begin
  //
  ftable.CopyDataSet(memtable, [coStructure, coRestart, coAppend]);
end;

 

solved... (partially) - see my posts below, I explained why it was happening and what I did to resolve it. -- 12/29/2022 Friday pm 

Edited by JohnLM

Share this post


Link to post

John

look, StringGrid (FMX/VCL) /Grids (in FMX) works like a mem-Repository! All data, in fact, will be "string" values!

Then, if you need export data to "FDTable", you'll go needs a "converter"!

You can use "TBatchMove" components: BatchMove, BatchMove(Dataset/Text)Writer, BatchMove(Dataset/Text)Reader to work "directly" on Datasets: TFDMemTable and FDTables!

So, in FDMemTable you create the same "fields" that you need export to FDTable: same names (or not), same types.

BatchMove do the magic: read data-sources on FDMemtable and write on target-FDTable

see sample on 

https://en.delphipraxis.net/topic/7991-batchmove-using-firedac-missing-fieldnames-and-tablename-solved/?tab=comments#comment-67218

 

NOTE: FDMemTable can store your data in XML, JSON and FD binary... and you can define it using property:

  • ResourceOptions ->PersistentFileName ....  (check the property Persistent[x] ) and right-click on component and save to file...  (before, you need create your fields)
Edited by programmerdelphi2k

Share this post


Link to post

After some more investigating, it seems that which ever component I use, (fdquery or fdtable), I have the have its SQL text filled out, as in something like "select * from tblBarcodes" for instance. 

 

So, the CopyDataSet(memtable, [coStructure, coRestart, coAppend]) feature is not compatible with the TFDMemTable in some way. 

 

I already know about and how to use batchmove and other methods for this process above.  I was simply trying the copydataset() to see how that works because I've read about it many times and being in this particular case/situation I thought I would try it out. 

 

So, working with the TMemTable and FDQuery/FDTable together, is not a good idea for any projects then, if you can't copy from it, the table structure, etc., if I want to then create a actual database file, i.e., SQLite db. 

Edited by JohnLM

Share this post


Link to post
15 minutes ago, JohnLM said:

So, working with the TMemTable and FDQuery/FDTable together, is not a good idea for any projects then, if you can't copy from it, the table structure, etc., if I want to then create a actual database file, i.e., SQLite db. 

 

From what I gather, you were assuming CopyDataSet would automatically create a new table in an SQLite database. Is that correct?

Share this post


Link to post

Not quite. 

 

The goal was to have a stringgrid and populate it with barcodes that I would scan with my smartphone (android). Then, if I need the data finalized (stored) then I would export it out to a sqlite database on the phone.  But first, I would need to visualize the data in some similar grid. And if I like it, I would [save] to a sqlite db on the phone. I might want to edit the data before I export it out, so the second grid would serve that purpose. 

 

Yes, I know, I could and should do it in one table/grid but I will be doing a lot of what-ifs and not needing to export or update data in real-time. I feel, in my opinion, that this is my prefered route for this project, until I decide otherwise.., this will do. 

 

 

Share this post


Link to post

And, by the way, I found the solution, just before you posted before my previous post above.

Share this post


Link to post

The solution I found (through trial and error) through the steps below, works. 

 

In the fdquery->SQL I added the following: 

 

drop table if exists tblBarcodes;
create table if not exists tblBarcodes (
IDNo integer,
Barcode varchar(255),
isle integer,
LFRT varchar(2),
Row integer,
Type varchar(2),
Date varchar(21),
Desc varchar(255)
)

 

In my form create section, I have this bit of code: 

var
  DATABASE_FILE: string;
begin
  DATABASE_FILE := TPath.Combine(TPath.GetDocumentsPath, 'mydb.db');
  DATABASE_FILE := 'f:\datasets\mydb.db'; // <-- rem this line out when compiling over to android. <-- 
  Con.Params.Clear;
  Con.Params.Add('DriverID=SQLite');
  Con.Params.Add('Database=' + DATABASE_FILE); //DATABASE_FILE);
  con.Params.Add('create database'+database_file);
  Con.ResourceOptions.DefaultParamType := ptOutput;
  Con.Connected := True;

 

In my [import] tbutton, I have following code:

procedure TForm1.btnImportClick(Sender: TObject);
begin
  // import the database into the second grid for review.
  qry.Close;
  qry.data := mtable.Data;
  qry.open;
end;

Note, the second grid is a dbgrid.  Once I convert this portion of code over to the FMX platform (and then Android) the grid will be a stringgrid.

 

praxis_011_memtable_demo2_vcl.thumb.png.f9e10e0080deb065ff6892d3eb21ccc5.png

 

The left side grid is the scanned barcodes, the right side grid is the copied grid/contents from the left side grid.

 

Thus, while I debug my actual mobile barcode scanner app (at my job site), I will be running various scanning tests. So, I will be creating and deleting a number of times the contents in the left side grid, and sometimes I may be import it to right side grid, and then posibly save it out to an sqlite db for further review.

 

Note, I have not tested it for mobile. But I plan to soon. 

 

Edited by JohnLM

Share this post


Link to post
On 12/29/2022 at 3:33 PM, JohnLM said:

In my [import] tbutton, I have following code:


procedure TForm1.btnImportClick(Sender: TObject);
begin
  // import the database into the second grid for review.
  qry.Close;
  qry.data := mtable.Data;
  qry.open;
end;

 

 

I was going to point out the Data property but you said you only wanted to discuss CopyDataSet() 😄 Good to hear you've got a solution.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×