Lazarus

Programming => Databases => Topic started by: Nicole on August 16, 2022, 09:11:09 pm

Title: IBExpress - best practise to change to "active"?
Post by: Nicole on August 16, 2022, 09:11:09 pm
I am new to IBExpress and portate old cold into it (coming from FireDAC, which did some tricks automatically).
So I am not sure about the basics of IBExpress.

This I have at the moment and it works at design-time:
ibdatbase
ibconnection
tbtransaction
ibdatasource
ibdataset

=> DBGrid

Above this DBGrid are Buttons, which generate SQL select-Codes for my database.
Their results I want to see at runtime.

What I want to do at the shortest way:
1) change the SQL code
2) display the updated DBGrid

my questions
a) Where is the best place to change the SQL-request?
b) What has to be set to "active" or "connect" either for the first request or for an update of the SQL?
c) How can I avoid, that the password is requested every time?

Thanks.
Title: Re: IBExpress - best practise to change to "active"?
Post by: HeavyUser on August 17, 2022, 01:00:33 am
I am new to IBExpress and portate old cold into it (coming from FireDAC, which did some tricks automatically).
So I am not sure about the basics of IBExpress.

This I have at the moment and it works at design-time:
ibdatbase
ibconnection
tbtransaction
ibdatasource
ibdataset

=> DBGrid

Above this DBGrid are Buttons, which generate SQL select-Codes for my database.
Their results I want to see at runtime.

What I want to do at the shortest way:
1) change the SQL code
2) display the updated DBGrid

my questions
a) Where is the best place to change the SQL-request?
The dataset is the only place where you can change the sql.
b) What has to be set to "active" or "connect" either for the first request or for an update of the SQL?
You set the datasets active := false change the sql and then set it to true again.
c) How can I avoid, that the password is requested every time?
on ibdatabase there is a property named loginPrompt set it to false.
Title: Re: IBExpress - best practise to change to "active"?
Post by: Nicole on August 17, 2022, 09:49:27 am
Thank you for your answer.
Unfortunately it does not work for me.

At design-time the dataset asks for the keyword on setting it to active.
After I key it in another time, it works fine.

At runtime, I do not see this login-request, but the error message:

[Window Title]
Fehler

[Content]
Projekt project_Tiger hat Exception-Klasse »External: ACCESS VIOLATION« ausgelöst mit der Meldung:
Access violation reading from address $00000000000000C0.

 In Datei 'frame_waren_.pas' in Zeile 37:
DataModule1.IBDataSet_Waren.Active:=true;

[Ok]
Title: Re: IBExpress - best practise to change to "active"?
Post by: HeavyUser on August 17, 2022, 10:04:15 am
Thank you for your answer.
Unfortunately it does not work for me.

At design-time the dataset asks for the keyword on setting it to active.
After I key it in another time, it works fine.

At runtime, I do not see this login-request, but the error message:

[Window Title]
Fehler

[Content]
Projekt project_Tiger hat Exception-Klasse »External: ACCESS VIOLATION« ausgelöst mit der Meldung:
Access violation reading from address $00000000000000C0.

 In Datei 'frame_waren_.pas' in Zeile 37:
DataModule1.IBDataSet_Waren.Active:=true;

[Ok]
attach a sample application that  demonstrates the problem to take a closer look.
Title: Re: IBExpress - best practise to change to "active"?
Post by: Nicole on August 17, 2022, 10:09:46 am
How shall this work?
The environment of the db is in a VM of more than 100 GB and the data inside are confidential.
Title: Re: IBExpress - best practise to change to "active"?
Post by: PascalDragon on August 17, 2022, 01:37:02 pm
How shall this work?
The environment of the db is in a VM of more than 100 GB and the data inside are confidential.

You simply need to try to provide a small, self contained example that shows the same behaviour. Without such it's nearly always hard to tell what goes wrong, because some small setting might be different that you didn't mention or didn't even notice.
Title: Re: IBExpress - best practise to change to "active"?
Post by: Nicole on August 17, 2022, 01:42:00 pm
Again:
How shall this work? - You need a driver for a Firebird db and this driver is installed in the operating system of my Virtual machine.
Title: Re: IBExpress - best practise to change to "active"?
Post by: rvk on August 17, 2022, 01:42:34 pm
In Datei 'frame_waren_.pas' in Zeile 37:
DataModule1.IBDataSet_Waren.Active:=true;
Look at the order the forms are created (in project options>forms).

The form with this code (probably in formcreate) is in front of the DataModule1.
You need to move DataModule1 to the top so it's created first.
Title: Re: IBExpress - best practise to change to "active"?
Post by: Nicole on August 17, 2022, 01:54:32 pm
Thank you for the reply. I checked it, the series is
- dbmodul
- form1
- frame1 => for the db which does not work
Title: Re: IBExpress - best practise to change to "active"?
Post by: rvk on August 17, 2022, 02:06:47 pm
Thank you for the reply. I checked it, the series is
- dbmodul
- form1
- frame1 => for the db which does not work
And how is frame1 created?
Where is it used?

What function is line 37 of In Datei frame_waren_.pas and where is this function called?

And is there a special reason for using a frame? Are you reusing that frame somewhere else too?
Title: Re: IBExpress - best practise to change to "active"?
Post by: rvk on August 17, 2022, 02:10:29 pm
BTW. If frame1 is really a frame then it shouldn't be in the auto-create section of Forms in Project options.

A Frame isn't a Form which is to be autocreated. It is to be used by a component TFrame.

So, is that really a frame of just a poor named Form?
Title: Re: IBExpress - best practise to change to "active"?
Post by: Nicole on August 17, 2022, 03:57:44 pm
This hint with the frames was a clou!
These frames are created at runtime and I checked the wrong list in my project inspector.
Your question made me aware of that.

This is corrected thing:
Now my DBModul is REALLY created at the first place and I am one error-message step further.
It reads:

Code: Text  [Select][+][-]
  1. [Debuggerausnahmen-Nachricht]
  2.  
  3.  
  4. [Break]
  5. Projekt project_Tiger hat Exception-Klasse »EIBInterBaseError« ausgelöst mit der Meldung:
  6. Engine Code: 335544472
  7. Your user name and password are not defined. Ask your database administrator to set up a Firebird login
  8.  
  9.  In Datei 'IBDatabase.pas' in Zeile 1082
  10.  
  11.  
  12. [Diesen Ausnahmetyp übergehen]
  13.  
  14. [Continue]

Which means to me in other words:
"Key in user name and password somewhere."
But where exactly? (pls see the list of what I have in my first posting)
Title: Re: IBExpress - best practise to change to "active"?
Post by: rvk on August 17, 2022, 04:13:27 pm
Usually for TIBDatabase you set LoginPrompt to false (so it doesn't prompt you with a login dialog each time).
But in that case you also need to provide the login details in code.

You can add this to your IBDataSet_Waren.Params property
Code: [Select]
user_name=SYSDBA
password=masterkey

Or you can do it in code in the FormCreate or DataModuleCreate
Code: Pascal  [Select][+][-]
  1. IBDataSet_Waren.Params.Values['user_name'] := Username_read_from_config_file;
  2. IBDataSet_Waren.Params.Values['password'] := Password_read_from_config_file;

The first one is the easiest but then the username and password would always need to be the same.
Title: Re: IBExpress - best practise to change to "active"?
Post by: Nicole on August 17, 2022, 06:19:40 pm
This looks good, but it does not work yet.

I found in dataset a
database.params.strings

There was already a line
user_name=SYSDBA


I added
password=masterkey

Never the less at design-time I am asked to key in the pw, if I check "active".
If I do, the thing works.
At runtime there is an error-message instead of a request.

So either the password is on the wrong place or it is not found at all.
Title: Re: IBExpress - best practise to change to "active"?
Post by: rvk on August 17, 2022, 06:34:48 pm
Don't forget to set the LoginPromot to false.

Also, don't leave the TIBDatabase connected at design time.
Always set active to false before running your program.
Otherwise you can't set anything before the connection is made.

It's best to set the TIBDatabase to active in your code.
(So you can set the filelocation to some alternative before the connection is made)
Title: [solved] Re: IBExpress - best practise to change to "active"?
Post by: Nicole on August 17, 2022, 07:01:45 pm
Thanks, I am two steps further:

If I set login-prompt to TRUE in the dataset.database, it works at design-time to check "active"
("false" in all other components)
So design-time is solved.

At runtime it works to login without prompt, if the setting is to FALSE in the dataset as well (yes, ok, this time it is logic).

and hint of the Compiler:

Code: Text  [Select][+][-]
  1. Have you included ibexpress in your program uses list?
  2.  


==> done & restarted

next error-messages:

Code: Text  [Select][+][-]
  1. ....
  2. Transaction is not active
  3.  


Is there a way to make start the transaction automatically if it is needed?
If not, when and where shall I start the transaction?
What is the syntax?

Do I have to close then transaction again?
And: Does it make sense to have an own transaction for every dataset?


Title: Re: IBExpress - best practise to change to "active"?
Post by: rvk on August 17, 2022, 07:09:27 pm
Yes, I would always use a transaction per action.
Sometimes this is for one TIBQuery. Other times it's one transaction per several TIBQueries.
It depends on what you use it for.

You can set the AllowAutoStart of a transaction to true.
But you really need to know what transactions do and when you need to commit them (or roll them back).

If you don't care about transaction you can just use the defaulttransaction for every query but don't forget to commit when needed.
Title: Re: IBExpress - best practise to change to "active"?
Post by: Nicole on August 17, 2022, 07:31:46 pm
Many, many years ago I messed around with transactions of Interbase.
Then I had FireDAC and it just worked without it.
I hardly can remember this old code. Did not save it neither.

Back to the transactions:
I cannot find a property "AllowAutostart" in my TIBtransaction.
Title: Re: IBExpress - best practise to change to "active"?
Post by: rvk on August 17, 2022, 08:03:00 pm
I cannot find a property "AllowAutostart" in my TIBtransaction.
I'm probably thinking of IBX for Delphi.

In IBX for Lazarus there is a TIBQuery.AllowAutoActivateTransaction which you can set to true.
And if you set the default Action of the transaction to TACommit you almost have the same as in FireDAC.

Many, many years ago I messed around with transactions of Interbase.
Then I had FireDAC and it just worked without it.
I hardly can remember this old code. Did not save it neither.
FireDAC also uses transaction (behind the scenes) but you have much less control over it.
TinyPortal © 2005-2018