Chapter 5. Tips and tricks

Table of Contents

How to display the data
How to execute a query
How to create a table
How to create a calculated value field
How to use the last inserted value as a default for the next row that will be inserted
How to define macros
How to format numbers
How to print rows in alternating colours
How to set the focus in a form
How to react on pressed keys
How to load a file content into a field using a filedialog
How to add or modify data, copy data between 2 datasources etc.
How to load a subform

How to display the data

Example 5.1. Show data

horst@horstnotebook:~> python
Python 2.2.2 (#1, Mar 17 2003, 15:17:58)
[GCC 3.3 20030226 (prerelease) (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from hk_classes import *
>>> dr=hk_drivermanager()
>>> con=dr.new_connection("mysql")
>>> con.set_password("secret")
>>> con.connect()
1
>>> db=con.new_database("exampledb")
>>> table=db.new_table("authors")
>>> i=0
>>> table.enable()
SQL : SELECT  *  FROM  `authors`
1
>>> table.goto_first()
1
>>> while i< table.max_rows():
    ...    table.show_currentrow()
    ...    table.goto_next()
    ...    i=i+1
['1', 'Goethe,Johann Wolfgang', '1749', '1832', 'FALSE']
1
['2', 'Schiller, Friedrich von', '1759', '1805', 'TRUE']
1
['3', 'Lessing, Gotthold Ephraim', '1729', '1781', 'TRUE']
1
['4', 'Kleist', '1400', '0', 'FALSE']