How to execute a query
Prev | Chapter 5. Tips and tricks | Next

## How to execute a query

Result queries (SELECT statement) return data when they are executed.

Example 5.2. Execute a "SELECT" query

    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 *
    d>>> dr=hk_drivermanager()
    >>> con=dr.new_connection("mysql")
    >>> con.set_password("secret")
    >>> con.connect()
    1
    >>> db=con.new_database("exampledb")
    >>> query=db.new_resultquery()
    >>> query.set_sql("SELECT * FROM authors")
    1
    >>> query.enable()
    SQL : SELECT  *  FROM  authors
    1

Many queries, such as data definition queries, don't return data. They only report whether execution of the query was successful or whether it failed.

Example 5.3. Execute an action query

    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 *
    d>>> dr=hk_drivermanager()
    >>> con=dr.new_connection("mysql")
    >>> con.set_password("secret")
    >>> con.connect()
    1
    >>> db=con.new_database("exampledb")
    >>> query=db.new_actionquery()
    >>> query.set_sql("CREATE TABLE `another new table`
    ( `id` BIGINT(1) NOT NULL AUTO_INCREMENT , `name` BIGINT, PRIMARY KEY ( `id` ) )")
    >>> query.execute()
    CREATE TABLE `another new table` ( `id` BIGINT(1) NOT NULL AUTO_INCREMENT ,
     `name` BIGINT, PRIMARY KEY ( `id` ) )
    1

Prev | Up | Next
Chapter 5. Tips and tricks | Home | How to create a table