Recent

Author Topic: TSQLQuery lookup field?  (Read 17844 times)

panoss

  • Full Member
  • ***
  • Posts: 162
  • You only live twice
TSQLQuery lookup field?
« on: November 24, 2014, 07:33:44 pm »
I 'm trying to make a lookup field in a TSQLQuery.
Right click->Edit fields->Create new fields->LookUp.
I choose the 'Dataset' from the drop down list and a message appears:
"Access violation.

Press OK to ignore and risk data corruption.
Press Cancel to kill the program."

If I press cancel, Lazarus gets killed.

If I press Ok, 'LookUp keys' combo and 'Result field' combo are disabled.
In 'keyfields' combo, I can type the field name, but there's no list of fields.
Windows 10 64bit, Lazarus Version 2.2.0    FPC 3.2.2.

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: TSQLQuery lookup field?
« Reply #1 on: November 25, 2014, 08:49:38 am »
The lookupfiels will not work in TSQLQuery as you expect. Is there a reason to create this lookupfield?
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: TSQLQuery lookup field?
« Reply #2 on: November 25, 2014, 08:58:42 am »
Of course you can use select query to show everything but also you can create new field lookup-type. It works excellent.
see: http://lazarus-ccr.sourceforge.net/docs/lcl/dbctrls/tdblookupcombobox.html

I guess that the problem is an active SqlQuery, try to set query active tru or false and then try again

p.s. http://wiki.freepascal.org/dblookupcombobox
       http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-How-to-use-DBCombobox-td4024465.html
« Last Edit: November 25, 2014, 09:09:36 am by exdatis »

panoss

  • Full Member
  • ***
  • Posts: 162
  • You only live twice
Re: TSQLQuery lookup field?
« Reply #3 on: November 25, 2014, 09:07:27 am »
The lookupfiels will not work in TSQLQuery as you expect. Is there a reason to create this lookupfield?
I have a grid which takes data from the table OrderDetails.
The table has a field, productID.

Another table, Products, has the fields ProductD and Name.

I want in the grid to show the product Name, not the productID that is shown now.

So I thought of a lookup field, like in ms Access.
Windows 10 64bit, Lazarus Version 2.2.0    FPC 3.2.2.

panoss

  • Full Member
  • ***
  • Posts: 162
  • You only live twice
Re: TSQLQuery lookup field?
« Reply #4 on: November 25, 2014, 09:10:25 am »
Of course you can use select query to show everything but also you can create new field lookup-type. It works excellent.
see: http://lazarus-ccr.sourceforge.net/docs/lcl/dbctrls/tdblookupcombobox.html

I guess that the problem is an active SqlQuery, try to set query active tru or false and then try again
How do I create a lookup field?
I 'm using SQLite.
Windows 10 64bit, Lazarus Version 2.2.0    FPC 3.2.2.

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: TSQLQuery lookup field?
« Reply #5 on: November 25, 2014, 09:16:23 am »
See :
/usr/share/lazarus/1.2.6/examples/database {* this is path on Debian 7.7 *}
there is an example: dblookup and sqlitetutorial(find it in lazarus folder).

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: TSQLQuery lookup field?
« Reply #6 on: November 25, 2014, 09:29:37 am »

So I thought of a lookup field, like in ms Access.

Use fields editor to create new field(query->fields)
(M$access is not similar)
« Last Edit: November 25, 2014, 09:31:44 am by exdatis »

panoss

  • Full Member
  • ***
  • Posts: 162
  • You only live twice
Re: TSQLQuery lookup field?
« Reply #7 on: November 25, 2014, 09:35:52 am »

So I thought of a lookup field, like in ms Access.

Use fields editor to create new field(query->fields)
(M$access is not similar)
You mean a new field in the TSQLQuery?
Windows 10 64bit, Lazarus Version 2.2.0    FPC 3.2.2.

panoss

  • Full Member
  • ***
  • Posts: 162
  • You only live twice
Re: TSQLQuery lookup field?
« Reply #8 on: November 25, 2014, 09:45:08 am »
See :
/usr/share/lazarus/1.2.6/examples/database {* this is path on Debian 7.7 *}
there is an example: dblookup and sqlitetutorial(find it in lazarus folder).
There are no lookup fields in these examples. (or maybe there are but I can't understand them. Also, in the dblookup they use DBase database)
« Last Edit: November 25, 2014, 10:01:03 am by panoss »
Windows 10 64bit, Lazarus Version 2.2.0    FPC 3.2.2.

talorigomat

  • Jr. Member
  • **
  • Posts: 96
Re: TSQLQuery lookup field?
« Reply #9 on: November 25, 2014, 10:56:47 am »
Hi Panoss

I also had the access violation error when I tried to set up a lookup field.  After I recieved this error I restarted Lazarus and opened the project again.  Before trying to set up the Lookup field set all the relevant TSQLQuery(s) to active so that the TSQLQuery that you want to set up the lookup filed is showing some data.  Then proceed as before.
Lazarus 1.8.0Rc4, Windows 10

panoss

  • Full Member
  • ***
  • Posts: 162
  • You only live twice
Re: TSQLQuery lookup field?
« Reply #10 on: November 25, 2014, 11:14:58 am »
Before trying to set up the Lookup field set all the relevant TSQLQuery(s) to active
I tried this and returns me error: 'no such table: Products'.
(the table, of course, exists)
The Connection and the Transaction (the respective ones to my TSQLQuery) are active.
« Last Edit: November 25, 2014, 11:16:45 am by panoss »
Windows 10 64bit, Lazarus Version 2.2.0    FPC 3.2.2.

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: TSQLQuery lookup field?
« Reply #11 on: November 25, 2014, 11:16:37 am »
OnHold field is created as new field, calculated, boolean, the same way as create lookup field

panoss

  • Full Member
  • ***
  • Posts: 162
  • You only live twice
Re: TSQLQuery lookup field?
« Reply #12 on: November 25, 2014, 11:20:03 am »
exdatis read my first post.
Windows 10 64bit, Lazarus Version 2.2.0    FPC 3.2.2.

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: TSQLQuery lookup field?
« Reply #13 on: November 25, 2014, 11:26:25 am »

I tried this and returns me error: 'no such table: Products'.
(the table, of course, exists)
The Connection and the Transaction (the respective ones to my TSQLQuery) are active.

I can't understand? Do you have TSQLQuery which use table Products and TDataSet which use query Products?

panoss

  • Full Member
  • ***
  • Posts: 162
  • You only live twice
Re: TSQLQuery lookup field?
« Reply #14 on: November 25, 2014, 11:28:35 am »
I guess I'm doing something wrong.
I must tell you how each component connects to the others.
I use 4 components:
Code: [Select]
TSQLite3Connection
name: Connection
DatabaseName: data
Transaction: Transaction

TSQLTransaction
name: Transaction
Database: Connection

TSQLQuery
name: qryProducts
Database: Connection
Transaction: Transaction
SQL: Select * FROM Products

TDataSource
name:DataSource
DataSet: qryProducts
Windows 10 64bit, Lazarus Version 2.2.0    FPC 3.2.2.

 

TinyPortal © 2005-2018