Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Mario Orlandi

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Result Object Methods

// Assuming that we have set result to being a result object we can use the following methods:

len(result)
     this will show the number rows returned (which would be 3 in the example above).

result.names()
    a list of all the column headings, returning a list containing emp_id, first, last and salary

result.tuples()
    returns a list of tuples in our example:

    [(43, 'Bob', 'Roberts', 50000),
     (101, 'Cheeta', 'leCat', 100000),
     (99, 'Jane', 'Junglewoman', 100001)]

result.dictionaries()
    will return a list of dictionaries, with one dictionary for each row:

    [{'emp_id': 42, 'first': 'Bob','last': 'Roberts', 'salary': 50000},
     {'emp_id': 101, 'first: 'Cheeta', 'last': 'leCat', 'salary': 100000},
     {'emp_id': 99, 'first': 'Jane', 'last': 'Junglewoman', 'salary': 100001}]

result.data_dictionary()
    returns a dictionary describing the structure of the results table. 

The dictionary has the key name, type, null and width. 
Name and type are self explanatory, null is true if that field may contain a null value and width is the width in characters of the field. 
Note that null and width may not be set by some Database Adapters.

result.asRDB()
    displays the result in a similar way to a relational database. 

The DTML below displays the result below:
    <pre>
      <dtml-var "list_all_employees().asRDB()">
    </pre>

    ... displays ...

    emp_id first last salary
    42 Bob Roberts 50000
    101 Cheeta leCat 100000
    99 Jane Junglewoman 100001

result[0][1]
    return row 0, column 1 of the result, bob in this example. 

Be careful using this method as changes in the schema will cause unexpected results. 

Db Connection

// eGenix mxODBC Database Connection: connection string sample
DSN=LocalServer;
DATABASE=GammaMedidata;
UID=sa;
PWD=******;


// eGenix mxODBC Database Connection: connection string sample
DRIVER=SQL Server;
SERVER=(local);
UID=sa;
PWD=****;
DATABASE=wam


// MySQL connection string sample
dbcobraf@www2.cobraf.com cobraf 'password'
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS