Both on Windows 10 64bit and Lazarus 64bit, or Raspberry Pi 3 and Lazarus doesn't work.
Database server is PostgreSQL 9.4.10 on Raspberry Pi 3
Steps to reproduce:
I have following text in my SQLQuery1.SQL
Code: [Select]
select * from test where abc = :param
All below is at design time. I am using object inspector;
-Click Params (new windows pops: Editing SQLQuery1.Params[0])
-Click 0 - param to set parameter "param" (Object Inspector changes into TParam properties)
-Click Value and type something.
1- When I hit Enter Value reverts back to "(Null)"
2- When I try to set a Parameter Value Type it simply reverts back to "Null"
Additional information:
It is not just Object Inspector that cannot assign a parameter value, parameters are not assigned using code, too.
For attached project, I have log_statement = 'all' in my postgresql.conf to understand better what's going on.
I think, that you are not required to install PostgreSQL.
IMO problem may be reproducible with any TCustomSQLQuery (descendant) component with any TSQLConnection descendant on any platform (not only RPi).
May be this help:
TCustomSQLQuery.Params is declared of type TParams (collection of TParam), but object created at runtime is always of type TSQLDBParams (is descendant from TParams i.e.=class(TParams)) and item in this collection is of type TSQLDBParam
Btw. you can reproduce it without PostgreSQL:
- Open attached project1 (in bug31965_param.zip)- Click in Object inspector on "SQLQuery1: TSQLQuery" "FieldDefs: TSQLDBFieldDefs" changes to "<unknow collection>: TSQLDBFieldDefs" ?- Then click on "Params" property and on "0-param"- Try change Value to any numeric value. You will see, that (Null) is set back ... (Also when you save form, form is damaged, because there is: Params = < item DataType = ftInteger Name = 'param' ParamType = ptInput Value = <--- end> )
In r56036 is resolved only problem with:
"FieldDefs: TSQLDBFieldDefs" changes to "&LtPos;unknow collection>: TSQLDBFieldDefs"
There are still problems with "0-param".Value:
- When I change value of Value or any other property (like Size, Precision, Name etc.) in Object inspector then in toolbox (and main menu) is not enabled Save (Ctrl+S) button ... seems like change is not catched
- When I change value of Type property (under Value property) to Unassigned or Null and save form , form becomes corrupted as I wrote above (you cannot open it later)
In Lazarus 1.6.4 (FPC 3.0.2) it does not work, but behaves differently. When I try to change Value error dialog is shown "Could not convert variant of type (Null) ..." and only option is press Esc to cancel change. Later when I save form, form is NOT corrupted (Value property is not present in LFM file of course).
When I change value of any other property Save is also not enabled.
In Lazarus 1.4.4 (FPC 2.6.4) when I click "0-param" there is no Value property in object inspector at all!
When I change value of any other property Save is also not enabled.
So conclusion: none of above mentioned versions works correctly, but none cause LFM corruption. It is hard to fix this bug in trunk? (I do not know what is root of problem, streaming NULL variant values or ?)
I believe it is easy if you know how to do it. :)
I don't know it but I will debug it at some point.
BTW, nobody maintains the DB stuff very actively. Many bug reports are open since 8+ years.
If somebody provides well tested patches, I can apply.
I fixed the TVariantPropertyEditor in r56146. I had applied its initial implementation by Michal Gawrycki a year and a half ago. Didn't even remember.
Please test.
Now the LFM does not corrupt any more but I am still puzzled of what is going on.
In your example app I can add Params in the property editor and set their values. After I save the project I can see they are stored in LFM file. Good.
However when I open the project again it only shows the one Param that was there already. The others are ignored. Is the one saved also somewhere else?
Changes in FieldDefs are stored OK. It is also shown in the component treeview. Why params are not there? Uhhh...
Yes, I can confirm that LFM is okay.
Only small cosmetic problem is with "Save" (as I wrote when I change something in "param" Save button is not enabled ... I must go to owner component and there do any change)
There is IMO no problem, when you add params and save LFM and restore, that newly added params are mising ... it is like TSQLQuery works ... Params are built based on SQL text in SQL property ... so sql statement is parsed and params are put in TParams collection.
So from my POV root problem is fixed ... may be this is candidate for merging in 1.8.x branch
So from my POV root problem is fixed ... may be this is candidate for merging in 1.8.x branch
Yes, the 2 revisions are already merged. This was a major bug anyway, and partly a regression.
I try to figure out the remaining Save-button issue. I guess it is common with many Collection properties.
I just checked with Lazarus 1.8.0.RC5 SVN 56257 and problem is still present.
- Open new project
- Put a TSQLQuery on the form.
- Write following in SQL property: "select * from abc where id = :id"
- Go to params property and click "0 - id"
From this point on all of the following failed for me:
1- Directly type something in Value (it stays as Null)
2- Change DataType to ftString and write something in Value (it stays as Null)
3- Change Value.Type to String (it is not changing to string)
Basically, I could not set a value for a parameter at design time.