1. Ben Antwi
  2. Valentina Reports ADK
  3. Tuesday, April 12 2022, 04:18 PM
  4.  Subscribe via email
Valentina is a great reporting tool but I'm still finding it difficult to search a record from sqlite database with python. Please I need help
Comment
There are no comments made yet.
Sergey Pashkov Accepted Answer
Hello Ben,

Does this report work in Valentina Studio and problem only with python?
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Reports ADK
  3. # 1
Ben Antwi Accepted Answer
In Valentina Studio it works fine with just producing a record using a parameter for that row.
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Reports ADK
  3. # 2
Ben Antwi Accepted Answer
I want to run the sql query example below to enable the user to type in any item_ID the user want , so that sql statement will return the exact record of the item_Id typed by the user.


SELECT item_Id, FROM permanent_staff WHERE staff_no=? ''',([Search_Id])
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Reports ADK
  3. # 3
Ben Antwi Accepted Answer
I want to run the sql query example below to enable the user to type in any item_ID the user want , so that sql statement will return the exact record of the item_Id typed by the user.


SELECT item_Id, FROM items WHERE item_Id=? ''',([Search_Id])

Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Reports ADK
  3. # 4
Ben Antwi Accepted Answer
@ Sergey Pashkov Please do you understand my logic?
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Reports ADK
  3. # 5
Sergey Pashkov Accepted Answer
So you defined a parameter and used it in a query that you created in the Valentina Studio.

We have added a method to set report’s parameters in python:
report.setParameterValue( ‘param1’, ‘value1’)
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Reports ADK
  3. # 6
Ben Antwi Accepted Answer
This is original table I have below in the image
Attachments (1)
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Reports ADK
  3. # 7
Ben Antwi Accepted Answer
I have set parameter in patameter Tab as pitem_id and Default Value =4.

This is the query in the Valentina Studio:


SELECT item_id, item_name, item_type from items WHERE item_id=$P(pitem_id)
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Reports ADK
  3. # 8
Ben Antwi Accepted Answer
The result from the test Tab is as the image below
Attachments (1)
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Reports ADK
  3. # 9
Ben Antwi Accepted Answer
I don't want to change my parameter and Default Value all the time when I want to retrieve a record from the table. Please is there a way to set the parameter and Default Value one time to get all records when an input field requires a record ?
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Reports ADK
  3. # 10
Sergey Pashkov Accepted Answer
In Python?
You use setParameterValue to set an actual value:

report = project.report(...
report.setParameterValue( 'pitem_id','4' )
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Reports ADK
  3. # 11
Ben Antwi Accepted Answer
I want to use a search field like the image below to search in my application , so is it possible to use

report.setParameterValue( 'pitem_id','4' )
?
Attachments (1)
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Reports ADK
  3. # 12
Sergey Pashkov Accepted Answer
Yes, that's correct.
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Reports ADK
  3. # 13
Ben Antwi Accepted Answer
what if I want to get say last record in my table , please what Default Value should I use?
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Reports ADK
  3. # 14
Ben Antwi Accepted Answer
Assuming I don't know the length of item_id column and I want to get the last item_id in the items table, Please what parameter should I set?
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Reports ADK
  3. # 15
Sergey Pashkov Accepted Answer
For example, you can execute sql query with max function to get the last ID if they are sequential
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Reports ADK
  3. # 16
Ben Antwi Accepted Answer
Ok, that's great!
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Reports ADK
  3. # 17
Ben Antwi Accepted Answer
Sorry I'm still confused, If a specific parameter Value for example

report.setParameterValue( 'pitem_id','4' )
is set. Meaning after I package the app as .exe I can only search for the record with parameter value of '4'. But I would like to search for any other record. So is there a say a variable that could hold all the parameter values one time?
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Reports ADK
  3. # 18
Sergey Pashkov Accepted Answer
Store the necessary value in a variable and pass it

report.setParameterValue( 'pitem_id', paramValue )
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Reports ADK
  3. # 19
Ben Antwi Accepted Answer
Ok , so can I set the parameter name and parameter value in Valentina Studio Pro as in the image below right?





and pass same parameter Value variable name in python as follows?


report.setParameterValue( 'pitem_id', paramValue )
Attachments (1)
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Reports ADK
  3. # 20


There are no replies made for this post yet.
However, you are not allowed to reply to this post.