1. Ben Antwi
  2. Valentina Reports ADK
  3. Вторник, Апрель 12 2022, 04:18 PM
  4.  Подписаться через 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
Комментарий
There are no comments made yet.
Sergey Pashkov Ответ принят
So if I want to generate a particular record for a specific actor_id how I do that?

There are two ways:
1) Using parameters

The query in Valentina Studio is defined like that:
SELECT * FROM actor WHERE actor_id = $(pActorID)

Then, in Python code, we supply the actual value:

report.setParameterValue( 'pActorID', some_variable )


2) In the latest version - changing the source query:

project.report( 'Report_1', 'sqlite://....', 'SELECT * FROM actor WHERE actor_id={}'.format( some_variable ) )


As you can see you can set any query you want.

some_variable - is an ID that is passed somehow to the script.
Комментарий
There are no comments made yet.
Ben Antwi Ответ принят
And also after installing Valentina Pro 12 I cannot locate the example folder for python.
Комментарий
There are no comments made yet.
Ben Antwi Ответ принят
Hi Sergey Pashkov ,
Sorry for the late reply. So if I want to generate a particular record for a specific actor_id how I do that?
Комментарий
There are no comments made yet.
Sergey Pashkov Ответ принят
Hello Ben,

Do you have any further questions? Sorry, we didn't have an Internet connection for a while.

The latest version of VPython ADK contains a change for report generation - an ability to set any source query for a report:
project.report( 'Report_1', 'sqlite://....', 'SELECT * FROM actor ORDER BY actor_id DESC LIMIT 1' )


In the example, the report is generated for the latest record, without specifying an actual ID.
Комментарий
There are no comments made yet.
Sergey Pashkov Ответ принят
No need to change the default value in Valentina Studio , just set value in python.
Комментарий
There are no comments made yet.
Ben Antwi Ответ принят
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 )
Вложения
Комментарий
There are no comments made yet.
Sergey Pashkov Ответ принят
Store the necessary value in a variable and pass it

report.setParameterValue( 'pitem_id', paramValue )
Комментарий
There are no comments made yet.
Ben Antwi Ответ принят
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?
Комментарий
There are no comments made yet.
Ben Antwi Ответ принят
Ok, that's great!
Комментарий
There are no comments made yet.
Sergey Pashkov Ответ принят
For example, you can execute sql query with max function to get the last ID if they are sequential
Комментарий
There are no comments made yet.
Ben Antwi Ответ принят
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?
Комментарий
There are no comments made yet.
Ben Antwi Ответ принят
what if I want to get say last record in my table , please what Default Value should I use?
Комментарий
There are no comments made yet.
Sergey Pashkov Ответ принят
Yes, that's correct.
Комментарий
There are no comments made yet.
Ben Antwi Ответ принят
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' )
?
Вложения
Комментарий
There are no comments made yet.
Sergey Pashkov Ответ принят
In Python?
You use setParameterValue to set an actual value:

report = project.report(...
report.setParameterValue( 'pitem_id','4' )
Комментарий
There are no comments made yet.
Ben Antwi Ответ принят
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 ?
Комментарий
There are no comments made yet.
Ben Antwi Ответ принят
The result from the test Tab is as the image below
Вложения
Комментарий
There are no comments made yet.
Ben Antwi Ответ принят
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)
Комментарий
There are no comments made yet.
Ben Antwi Ответ принят
This is original table I have below in the image
Вложения
Комментарий
There are no comments made yet.
Sergey Pashkov Ответ принят
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’)
Комментарий
There are no comments made yet.
  • Страница :
  • 1
  • 2


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

Categories

Announcements & News
  1. 0 subcategories
Valentina Studio
  1. 2 subcategories
Valentina Server
  1. 4 subcategories
Valentina Database ADK
  1. 0 subcategories
Valentina Reports ADK
  1. 0 subcategories
Other Discussions
  1. 2 subcategories
BETA Testing
  1. 0 subcategories
Education & Research
  1. 0 subcategories