I am creating a memory table TFDMemTable for a delphi form, and define the fields under FieldDefs. After I am done with the definition of the fields manually, I go to the Fields Editor to add the fields that I just defined.
Everything works perfect until I have an AutoInc type field in my FDMemTable. I am using Delphi 10.3.2 version and I was wondering if I am missing anything or this is a IDE bug.
PS: I have done couple of tests, and I think that if the AutoInc field is not defined as the last field, everything disappears. I am not %100 sure of this case, but pretty much every time I try I loose the fields under FieldDefs.
Here is the steps:
Place a FDMemTable icon
Open FieldDefs window
Create a bunch of fields (string, integer ...)
define the names, types (and sizes for strings)
Open FieldsEditor
Add fields
until here everything works as they should.
Go back to fieldDefs window
create and name a new field with autoinc type
open the fields editor screen and add the last added field.
everything is still good to go as long as there is no more changes in the structure.
Here the weird thing happens if you do the following.
open FieldDefs window
create any field ( lets say integer type )
Go to Fields Editor window to add this last created field.
and you will see that you don't see this new field to add.
when you go back to fieldDefs window to see why it is not showing,
you will see all the previous and last added fields' definitions gone..
In order for me to go around this problem, I open the form in text form and insert the new field right before the last field which is autoinc,
add field editor entry manually in the text form,
and when everything is right, I toggle to form view.
I am working on a simple database application in Delphi using FireDAC and SQLite3. Whenever I insert a new record into the database, the date format that is shown on my form is always in the format of yyyy-mm-dd and once I close and reopen the application the format changes to m/d/yyyy which is the format I was expecting and wish to always be displayed without closing and reopening my application.
The Definition Parameters and Options for the FireDAC connection are all at their default values. The DataType set for the field that holds the date in the SQLite3 database is set to DATE. Finally, the code I use to insert the record is below.
Qry.SQL.Text := 'INSERT INTO employees (HireDate) VALUES (:HiredOn)';
Qry.ParamByName('HiredOn').AsDate := DateTimePicker1.Date;
Qry.ExecSQL;
Qry.Open('SELECT * FROM employees');
Any help would be appreciated.
Make sure that any format settings for the date field in the underlying BindingSource / List / Adapter matches that of the form/grid field. It might be that the underlying binding formatting for the field is overriding your new settings for the form/grid field.
Set the format/display on your form field to "m/d/yyyy" and for good measure, *also do it through code in the InitializeGrid event handler
This is happening b/c when the date format on your form field doesn't match that in SQLite3 which is "yyyy-mm-dd". So you would need to set the format/display on your form field to match that.
Uses DateUtils ...
DateUtils.DateOf(DateTimePicker1.Date);
Try
FormatDateTime('dd/mm/yyyy', DateTimePicker1.Date);
I am creating a temp table in SQL and then adding a new field to it. It seems Firedac is caching the field list for this temp table.
The following code gives me "FDQuery5: Field 'Available' not found."
FDQuery5.Connection := FDConnection1;
FDConnection1.ExecSQL('Select StockNo into #Temp from Stock');
FDQuery5.SQL.Text := 'Select * From #Temp';
FDQuery5.open;
FDConnection1.ExecSQL('Alter Table #Temp add Available Char(1)');
FDQuery5.Close;
FDQuery5.open;
ShowMessage(FDQuery5.FieldByName('Available').AsString);
using XE5 with Firedac.
I have tried Connection.RefreshMetadataCache and I have removed fiMeta from FetchOptions.Cache.
I can get Firedac to recognise the new field if I modify the SQL.Text. This is undesirable as my application will need modifying in quite a few places.
The query remains prepared after you call FDQuery5.Close. That means, it caches also result set structure. To prepare the query replace FDQuery5.Close with FDQuery5.Disconnect.
Using an Interbase database I have an application in which I want to show the contents of an memo field.
I have created a datamodule on which I put a TIBDatabase, TIBTransaction, TDataSource and TIBTable all connected. Data comes out, no problems so far.
But when I add a TDBMemo to a form and want to show the contents all I get is this;
I have only set the DataSource and DataField on the TDBMemo so there is no further code involved.
Any thoughts?
Solved it by replacing the TDBMemo with an TMemo and adding the contents to it with;
Encoding.Unicode.GetString(myQuery.FieldByName('myField').AsBytes);
I have the following query to one of my database tables:
select count(*) as mycount
from mytable
where fieldone = :fieldone
and fieldtwo = :fieldtwo
Parameters are correctly loaded into the query (both of type String).
When I run this query outside the app (for instance, through the dbexplore) and replace the parameters with the actual values, I get the correct result. But when running it in the app, I get a Field 'fieldtwo' not found error, right on the Query.Open call.
Why would the BDE not find this field, when it actually exist?
Update: The following query, executed right after the first one (the one that fails), works fine in the app:
select *
from mytable
where fieldone = :fieldone
order by fieldone, fieldtwo
The best guess is that you have populated the field list in the query, this overrides any concept of the underlying fields that are in the query and is a cause of countless confusion.
Right click on the query, pick the fields editor clear all the values that are there and then choose 'add all fields' that should cause the missing field to appear once the query is executed.
I think it should auto-populate the fields if there are no defined fields when the query is executed, so you may not need to choose 'add all fields' after clearing the fields.
Whenever we come across a problem like this we tend to remove the query from the form and create it dynamically at run time... It depends how ingrained into the form it is...
E.g. If you have a data aware control looking at "fieldtwo" which tries to fetch some data when the underlying data set gets updated then it'll trigger an error like this, but it's more obvious when you've written code such
SomeEdit.Text = Query.FieldByName("fieldtwo").AsString;
That way it falls over on the relevant line instead of the open (triggering a related event)
Clear the query content using Query1.SQL.Clear; statement before opening it.
Other reason can be you are opening other database which may not have the specified field. Be sure that both the DatabaseName's in your app and dbexplore are same
I used to face porblems with BDE when i have SQLExplorer open and the app accesses the DB at the same time (but i had errors like ), try closing the Explorer it may help, if not i would build the SQL as text without the Parameters and try if it works then (if its possible in your situation).
I don't use parameters, so I'm just grabbing at straws here. I still use the BDE regularly, but am no expert. I find I shy away from more complex expressions (which yours is not!) because of the little "surprises" like this that the BDE throws at you.
Perhaps adding parentheses:
where (fieldone = :fieldone)
and (fieldtwo = :fieldtwo)
Or, single or double quote signs (this probably will make it worse?)
where (fieldon = ":fieldone")
and (fieldtwo = ":fieldtwo")
Or, to explore the problem, remove the "and fieldtwo = :fieldtwo" line and see if it runs.
Would it be possible for you to do your own parameter substitution with a StringReplace as in
Query1.SQL.Text := StringReplace(Query1.SQL.Text, ":fieldone", "MyVarName",[rfReplaceAll ]);
If you are creating a ClienDataSet in memory by the Create DataSet method, you should check the TFieldDefs property, which must have a different field name or not created
I was having a weird but small problem, I'll post in case it will help someone in some day.
uRegPeople.pas
with frmEditPerson do
begin
PersonID := qryPerson.FieldByName(ID).AsInteger;
...
end;
I had qryPerson both in frmRegPeople and in frmEditPerson, by using with I was referencing to frmEditPerson.qryPerson, however I wanted to reference to frmRegPeople.qryPerson. Then I need to change to the following code.
with frmEditPerson do
begin
PersonID := Self.qryPerson.FieldByName(ID).AsInteger;
...
end;
// Explanation
// qryPerson --> frmEditPerson.qryPerson;
// Self.qryPerson --> frmRegPeople.qryPerson;