Search
Code Directory
 ASP
 ASP.NET
 C/C++
 CFML
 CGI/PERL
 Delphi
 Development
 Flash
 HTML
 Java
 JavaScript
 Pascal
 PHP
 Python
 SQL
 Tools
 Visual Basic & VB.NET
 XML
New Code
C# QR Code Generator 4.0.2.2
Salesforce WordPress Customer Portal 3.2.0
Single Leg MLM 1.2.1
OzGIS 14.6
Quick Maps For Dynamics CRM 3.1
Job Board Software 4.2
PHP Real Estate Script 1.3.2
IP2Location Geolocation Database April.2019
dbForge Data Generator for Oracle 2.1
VisualNEO Web 2018.12.15
SentiMask SDK Trial 1.0.0
OrgChart JS 4.6.4
dotConnect for BigCommerce 1.8
FedEx Smart Shipping For Magento 1.0.0
Database Workbench Pro 5.6.2.311
Top Code
Cuckoo Search (CS) Algorithm 1.0
MATLAB Support Package for Arduino (aka ArduinoIO Package) 1.0
Modbus RS232 ASCII Communication Functions 1.0
Job Board Software 4.2
Hyperion Tools 1.0
Emulator_8051 _8051
bit plane slicing 1.0
CardCheck COM DLL for Credit Card Processing 1.1
Efficient K-Means Clustering using JIT 1.0
webmoney - Webmoney payment gateway 5.x-1.2
Azizi search engine script PHP 4.1.10
Power System Stability and Control 1.0
NDRZilla NDR viewer
Image Cut (Image Splitter) 1.504
Comag Channel List Editor 1.0
Top Rated
VisualNEO Web 2018.12.15
Paste phpSoftPro 1.4.1
Deals and Discounts Website Script 1.0.2
ADO.NET Provider for ExactTarget 1.0
Solid File System OS edition 5.1
Classified Ad Lister 1.0
Aglowsoft SQL Query Tools 8.2
Invoice Manager by PHPJabbers 3.0
ICPennyBid Penny Auction Script 4.0
PHP Review Script 1.0
ATN Resume Finder 2.0
ATN Site Builder 3.0
Availability Booking Calendar PHP 1.0
PHP GZ Blog Script 1.1
ATN Jobs Software 4.0
Generator expressions for database requests 
File ID: 65993






Generator expressions for database requests 
Download Generator expressions for database requests http://code.activestate.com/recipes/577988-funny-text-generator/?in=lang-pythonReport Error Link
License: Freeware
Downloads: 3
User Rating:1 Stars  (1 rating)
Submit Rating:
Generator expressions for database requests  Description
Description: This recipe is a follow-up to #440653, which was easy to implement but very slow because the iteration required to read all the rows of a table

As suggested by Matteo Dell'Amico in a comment, it would be much better if we could write something like

query(r.name for r in plane_tbl if r.country == "France")

where the generator expression is first translated into an SQL select, so that the iteration on the instance of query only reads the rows selected by the SQL statement

The present recipe is an attempt to achieve this. The first problem is to get the source code of the generator expression. I use information from the stack frame to get the file name and the line number, then the tokenize module to read the elements of the generator expression in the source code

Then, to build the SQL statement, the source code must be parsed : this is done using the compiler package and "visitors" that walk the AST tree returned by compiler.parse and do operations on the nodes, depending on their type

Finally, once the SQL statement is built, the iteration on the query instance can start : for the first one, the SQL statement is executed ; then the iteration yields the selected rows one by one.

The items can be :
- objects, with attribute names matching those in the generator expression, except that qualified names (table.name) are converted to table_name
- dictionaries : the keys are the same as the attribute names above
- lists

For instance :
- iterating on query(name for r in plane_tbl) returns objects with an attribute name
- iterating on query(r.name for r in plane_tbl) returns objects with an attribute r_name

This is because of iteration on tables which have the same field names

query((r.name,c.name) for r in plane_tbl for c in country_tbl if r.speed > 500 )

The type of the items is set by query.return_type = object, dict or list

License: Freeware

Related: Database

O/S:Windows

Downloads: 3



More Similar Code

A small, fast, in-memory database management program

The database object supports the iterator protocol, so that requests can be expressed with list comprehensions or generator expressions instead of SQL. The equivalent of :

cursor.execute("SELECT name FROM table WHERE age=30")
rows = cursor.fetchall()


is :

rows = table(age=30)


The module stores data in a...



The JET Code Generator is a DataBase code generation system based on industry standard XSLT. If you've ever felt that you're writing the same data access code over and over again, this tool is for you!!

The process represented by the...



EMS Data Generator 2005 for PostgreSQL is a powerful utility for generating test data to several PostgreSQL database tables at once. The wizard application allows you to define tables and fields for generating data, set value ranges, generate char...



EMS Data Generator 2005 for SQL Server is a powerful utility for generating test data to several Microsoft SQL database tables at once. The wizard application allows you to define tables and fields for generating data, set value ranges, generate...



EMS Data Generator 2005 for InterBase/Firebird is a powerful utility for generating test data to several InterBase/FireBird database tables at once. The wizard application allows you to define tables and fields for generating data, set value...



DB form generator, for database-content edition. Based on an existing database structure or an XML-based definition, the tool generates a highly customizable set of tools for editing the database tables (PHP/www and Python/GTK interfaces)



PHP code generator that can quickly and easilly create code for database operations (create-read-update-delete), with flexible code-generation options, based on table data gathered from a DB.



FrameWeb is a website and db administration generator: design the database for a site and generate automatically the administration for the content and the layout.
The target is a web developer that is tired of making cut&paste for...



Multi functional code generator.The Codejay program can be your Web Assistant. / Create web administration for database driven web sites. / Create web reports. / Choose among ASP, PHP, COLDFUSION, ASP.NET as your / programming language without...



Report generator for database end-user. This first version will be helpful for IS developers.

User Review for Generator expressions for database requests
- required fields
     

Please enter text on the image