You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.8 KiB
77 lines
2.8 KiB
13 years ago
|
This directory contains some translated sql examples from TQt 3.x.
|
||
13 years ago
|
|
||
|
runform1.py, form1.ui:
|
||
|
|
||
13 years ago
|
A simple designer generated TQDataTable. Run "pyuic form1.ui -o form1.py".
|
||
13 years ago
|
|
||
|
runform2.py, form2.ui:
|
||
|
|
||
13 years ago
|
A simple designer generated TQDataBrowser. Run "pyuic form2.ui -o form2.py".
|
||
13 years ago
|
|
||
|
sqlcustom1.py:
|
||
|
|
||
13 years ago
|
TQSqlForm based form with a simple custom editor forcing all input to
|
||
13 years ago
|
be uppercase
|
||
|
|
||
|
sqltable4.py:
|
||
|
|
||
13 years ago
|
Custom TQDataTable with reimplemented paintField method, combined with
|
||
|
a TQComboBox based custom field editor (StatusPicker), gathering its
|
||
13 years ago
|
items from a different table (status) and a calculated column (monsalary).
|
||
13 years ago
|
Note, that TQSqlEditorFactory based field editors are somewhat restricted,
|
||
12 years ago
|
because TQt's TQ_PROPERTY feature isn't supported, yet. I've circumvented
|
||
13 years ago
|
this limitation by choosing the status table ids corresponding to the
|
||
13 years ago
|
index in the TQComboBox.
|
||
13 years ago
|
|
||
|
sqlsubclass5.py:
|
||
|
|
||
|
Similar to the former, and even more deviated from its qt ancestor,
|
||
|
because the sense escaped me. This could be related to the different
|
||
|
database layout needed for MySQL (Trolltech used PostgreSQL sequences,
|
||
|
while we're using the simpler, but less powerful auto_increment here).
|
||
|
If you enter and invalid date (e.g. day: 0) in the Paid column, it is
|
||
|
shown as "not yet", but produces some qt warnings.
|
||
|
|
||
|
runsqlex.py, sqlex.ui, sqlex.ui.h, connect.ui, connect.ui.h:
|
||
|
|
||
13 years ago
|
This one is a most advanced example, showing the use of a TQSqlCursor
|
||
|
driven by TQSqlQuery and iterating through database tables and fields.
|
||
13 years ago
|
Definitely worth a look.
|
||
|
|
||
12 years ago
|
Unfortunately you will have to make sure that these prerequisites are met
|
||
13 years ago
|
before trying the examples:
|
||
|
|
||
|
- Install MySQL or PostgreSQL and any development packages
|
||
|
|
||
|
- Create a database user with sufficient rights
|
||
|
|
||
|
- Create the testdb database
|
||
|
- For MySQL, run: mysql -u user -p password < testdb_mysql.sql
|
||
|
- For PostgreSQL, run: psql -U user template1 -f testdb_pg.sql
|
||
|
|
||
13 years ago
|
- Build TQt with the mysql and/or psql modules activated.
|
||
13 years ago
|
|
||
|
Now you should be ready for the fun part. You can run dbconnect.py from
|
||
|
a command line and try to connect to the database. If all went well,
|
||
|
'ok' should be printed after pressing OK. If you don't want to enter all
|
||
|
your data over and over again, create a file named local_dbpar.py here,
|
||
|
with the following keys (with your own data, of course):
|
||
|
|
||
|
DB_HOSTNAMES = ["localhost"]
|
||
|
DB_DATABASES = ["testdb"]
|
||
|
DB_USERNAME = "name"
|
||
|
DB_PASSWORD = "pass"
|
||
|
|
||
|
The dbconnect.py script is generated from dbconnect.ui, which was created
|
||
|
with qt's designer. You can find it also in Boudewijn Rempt's book
|
||
13 years ago
|
"GUI Programming with Python, using the TQt Toolkit". Although you won't find
|
||
13 years ago
|
the SQL widgets discussed there, for the simple reason of the book being
|
||
|
written before they appeared, it is a valuable source for anybody new in
|
||
|
this area.
|
||
|
|
||
13 years ago
|
Please direct any comments, patches and questions to <pytde@mats.gmd.de>.
|
||
13 years ago
|
|
||
|
Good luck
|
||
|
|
||
|
Hans-Peter Jansen <hpj@urpla.net>
|