Automatic update sql using field aliases
-
betadevart
- Posts: 18
- Joined: Tue 20 Mar 2012 17:42
Automatic update sql using field aliases
Is it possible to use simple automatic updates with UniDAC, when I use fields aliases in the basic select sql?
For example:
select partner.id as partner_id, partner.name as partner_name
where partner.id=:partner_id
I usually generate select statements runtime, and in case of joined tables naming the fields like above seems to be necessary for me.
In the example above, query->ApplyUpdates() does nothing for my evaluation so far. (CachedUpdates=true, hacked AutoCommit=false)
I tried to specify KeyFields with no success so far.
Thanks in advance
For example:
select partner.id as partner_id, partner.name as partner_name
where partner.id=:partner_id
I usually generate select statements runtime, and in case of joined tables naming the fields like above seems to be necessary for me.
In the example above, query->ApplyUpdates() does nothing for my evaluation so far. (CachedUpdates=true, hacked AutoCommit=false)
I tried to specify KeyFields with no success so far.
Thanks in advance
Hello,
We cannot reproduce the problem. The code below works correctly
Please specify your UniDAC and IDE versions, the DB name and version. Besides, plese check the SQL query sent to the server when ApplyUpdates is executed (for this, the Debug option must be set to true and the UniDACVcl module must be added to the Uses section)
We cannot reproduce the problem. The code below works correctly
Code: Select all
UniQuery1.SQL.Text := 'SELECT e.empno e_empno, e.ename e_name FROM emp e where e.empno = :e_empno';
UniQuery1.ParamByName('e_empno').AsInteger := 7934;
UniQuery1.Open;
UniQuery1.Edit;
UniQuery1.FieldByName('e_name').AsString := UniQuery1.FieldByName('e_name').AsString + 'test';
UniQuery1.Post;
UniQuery1.ApplyUpdates;-
betadevart
- Posts: 18
- Joined: Tue 20 Mar 2012 17:42
Thanks for the quick response!
That's just another thing I forgot to mention. When I use such a statement like "table.field as table_field" NO update statement goes to the server at all (DbMonitor). ApplyUpdates sends no sql. No error messages.
I tried your syntax, without "as", with no success.
When I degrade the stement like that "select id, name from partner" update sql goes through DbMonitor. From the same form save function of course.
Strange: ApplyUpdates does nothing, but I checked UpdatesPending, it is true and turns to false after ApplyUpdates.
Any idea?
CBuilder XE, UniDac 4.0.1, FB 2.5.1 Win32 on Windows 7 64 bit.
(I cannot send example because I don't work in design time, everything is generated by templates and macros inside datamodel dlls.)
That's just another thing I forgot to mention. When I use such a statement like "table.field as table_field" NO update statement goes to the server at all (DbMonitor). ApplyUpdates sends no sql. No error messages.
I tried your syntax, without "as", with no success.
When I degrade the stement like that "select id, name from partner" update sql goes through DbMonitor. From the same form save function of course.
Strange: ApplyUpdates does nothing, but I checked UpdatesPending, it is true and turns to false after ApplyUpdates.
Any idea?
CBuilder XE, UniDac 4.0.1, FB 2.5.1 Win32 on Windows 7 64 bit.
(I cannot send example because I don't work in design time, everything is generated by templates and macros inside datamodel dlls.)
-
betadevart
- Posts: 18
- Joined: Tue 20 Mar 2012 17:42
I also must admint that I do unusual thing with the dataset.
Set SQL first, than call FieldDefs->Update().
Then create some fields manually, and
create fields from FierldDefs manualy as well.
All of this is before Open().
Everithing is because of generated field binds and so.
Does it have anything with your sql generator?
Set SQL first, than call FieldDefs->Update().
Then create some fields manually, and
create fields from FierldDefs manualy as well.
All of this is before Open().
Everithing is because of generated field binds and so.
Does it have anything with your sql generator?
-
betadevart
- Posts: 18
- Joined: Tue 20 Mar 2012 17:42
I wrote a small form example, and I found that our example works, but I need to set KeyFields to "partner_id".
Is there something with my manual field creation/fielddef updates!?
I use this function:
void CreateFieldsFromDefs(TDataSet *ds)
{
if (!ds->FieldDefs->Updated)
ds->FieldDefs->Update();
int count = ds->FieldDefs->Count;
for (int ix=0; ix FieldDefs->Items[ix]->CreateField(ds);
}
Since I regenerate the queries I also do things:
dataset->Fields->Clear();
dataset->FieldDefs->Clear();
But the other thing is if I step back to use simple "select id,nev" my program emits the update sql.
?
Is there something with my manual field creation/fielddef updates!?
I use this function:
void CreateFieldsFromDefs(TDataSet *ds)
{
if (!ds->FieldDefs->Updated)
ds->FieldDefs->Update();
int count = ds->FieldDefs->Count;
for (int ix=0; ix FieldDefs->Items[ix]->CreateField(ds);
}
Since I regenerate the queries I also do things:
dataset->Fields->Clear();
dataset->FieldDefs->Clear();
But the other thing is if I step back to use simple "select id,nev" my program emits the update sql.
?
-
betadevart
- Posts: 18
- Joined: Tue 20 Mar 2012 17:42
A found something!
The very same query skip ApplyUpdates if I insert my unusual manipulations.
void CreateFieldsFromDefs(TDataSet *ds)
{
if (!ds->FieldDefs->Updated)
ds->FieldDefs->Update();
int count = ds->FieldDefs->Count;
for (int ix=0; ix FieldDefs->Items[ix]->CreateField(ds);
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
// These 2 lines make the difference! Commenting them out brings update sql back.
qry->FieldDefs->Update();
CreateFieldsFromDefs(qry);
qry->Active = true;
}
Can you give me some guide about that?
The very same query skip ApplyUpdates if I insert my unusual manipulations.
void CreateFieldsFromDefs(TDataSet *ds)
{
if (!ds->FieldDefs->Updated)
ds->FieldDefs->Update();
int count = ds->FieldDefs->Count;
for (int ix=0; ix FieldDefs->Items[ix]->CreateField(ds);
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
// These 2 lines make the difference! Commenting them out brings update sql back.
qry->FieldDefs->Update();
CreateFieldsFromDefs(qry);
qry->Active = true;
}
Can you give me some guide about that?
-
betadevart
- Posts: 18
- Joined: Tue 20 Mar 2012 17:42
-
betadevart
- Posts: 18
- Joined: Tue 20 Mar 2012 17:42
aliases AND manual fields
My "final" diagnosis:
If (you use column aliases AND (create fields manually OR design-time in advance))
then
ApplyUpdates sends no data to the server.
Probably it misses the changed fields?
Please let me know if there is something to do about it!
If (you use column aliases AND (create fields manually OR design-time in advance))
then
ApplyUpdates sends no data to the server.
Probably it misses the changed fields?
Please let me know if there is something to do about it!
-
betadevart
- Posts: 18
- Joined: Tue 20 Mar 2012 17:42
Thank you.
Just one more question.
Using joins and renaming columns seems very basic requirement for me. Just as creating fields at design-time.
How others are doing their data entry forms?
Whats the workaround?
How do YOU manage this in real-life?
I need to go ahoead and evaluate my architecture together with UniDac, but need some guidance in the meantime.
Just one more question.
Using joins and renaming columns seems very basic requirement for me. Just as creating fields at design-time.
How others are doing their data entry forms?
Whats the workaround?
How do YOU manage this in real-life?
I need to go ahoead and evaluate my architecture together with UniDac, but need some guidance in the meantime.
-
betadevart
- Posts: 18
- Joined: Tue 20 Mar 2012 17:42