barcodefontsoft.com

pythonhtp1_17.fm Page 609 Wednesday, December 19, 2001 2:46 PM in Microsoft Office Embed QR Code 2d barcode in Microsoft Office pythonhtp1_17.fm Page 609 Wednesday, December 19, 2001 2:46 PM

pythonhtp1_17.fm Page 609 Wednesday, December 19, 2001 2:46 PM generate, create qr-code none on microsoft office projects data matrix 17 . Database Applicatio n Programming Interface (DB-API). A pattern that co Microsoft Office qr bidimensional barcode ntains a percent character (%) searches for strings that have zero or more characters at the percent character s position in the pattern. An underscore ( _ ) in the pattern string indicates a single character at that position in the pattern. The results of a query can be arranged in ascending or descending order using the optional ORDER BY clause.

The simplest form of an ORDER BY clause is SELECT * FROM tableName ORDER BY field ASC SELECT * FROM tableName ORDER BY field DESC where ASC specifies ascending order (lowest to highest), DESC specifies descending order (highest to lowest) and field specifies the field on which the sort is based. Multiple fields can be used for ordering purposes with an ORDER BY clause of the form ORDER BY field1 sortingOrder, field2 sortingOrder, where sortingOrder is either ASC or DESC. Note that the sortingOrder does not have to be identical for each field.

The WHERE and ORDER BY clauses can be combined in one query. A join merges records from two or more tables by testing for matching values in a field that is common to both tables. The simplest format of a join is SELECT fieldName1, fieldName2, FROM table1 INNER JOIN table2 ON table1.

fieldName = table2.fieldName A fully qualified name specifies the fields from each table that should be compared to join the tables. The tableName.

syntax is required if the fields have the same name in both tables. The same syntax can be used in a query to distinguish fields in different tables that happen to have the same name. Fully qualified names that start with the database name can be used to perform crossdatabase queries.

The INSERT statement inserts a new record in a table. The simplest form of this statement is INSERT INTO tableName ( fieldName1, , fieldNameN ) VALUES ( value1, , valueN ) where tableName is the table in which to insert the record. The tableName is followed by a comma-separated list of field names in parentheses.

(This list is not required if the INSERT INTO operation specifies a value for every column of the table in the correct order.) The list of field names is followed by the SQL keyword VALUES and a comma-separated list of values in parentheses. The values specified here should match the field names specified after the table name in order and type (i.

e., if fieldName1 is supposed to be the FirstName field, then value1 should be a string in single quotes representing the first name). An UPDATE statement modifies data in a table.

The simplest form for an UPDATE statement is UPDATE tableName SET fieldName1 = value1, , fieldNameN = valueN WHERE criteria where tableName is the table in which to update a record (or records). The tableName is followed by keyword SET and a comma-separated list of field name/value pairs in the format fieldName = value. The WHERE clause specifies the criteria used to determine which record(s) to update.

. pythonhtp1_17.fm Page 610 Wednesday, December 19, 2001 2:46 PM Database Applicatio QR for None n Programming Interface (DB-API). 17 . An SQL DELETE sta Microsoft Office QRCode tement removes data from a table. The simplest form for a DELETE statement is DELETE FROM tableName WHERE criteria where tableName is the table from which to delete a record (or records). The WHERE clause specifies the criteria used to determine which record(s) to delete.

Modules have been written that can interface with most popular databases, hiding database details from the programmer. These modules follow the Python Database Application Programming Interface (DB-API), a document that specifies common object and method names for manipulating any database. The DB-API describes a Connection object that programs create to connect to a database.

A program can use a Connection object to create a Cursor object, which the program uses to execute queries against the database. The major benefit of the DB-API is that a program does not need to know much about the database to which the program connects. Therefore, the programmer can change the database a program uses without changing vast amounts of Python code.

However, changing the DB often requires changes in the SQL code. Module MySQLdb contains classes and functions for manipulating MySQL databases in Python. Function MySQLdb.

connect creates the connection. The function receives the name of the database as the value of keyword argument db. If MySQLdb.

connect fails, the function raises an OperationalError exception. The Cursor method execute takes as an argument a query string to execute against the database. A Cursor object internally stores the results of a database query.

The Cursor method fetchall returns a tuple of records that matched the query. Each record is represented as a tuple that contains the values of that records field. The Cursor method close closes the Cursor object.

The Connection method close closes the Connection object. A PanedWidget is a subdivided frame that allows the user to change the size of the subdivisions. The PanedWidget constructor s orient argument takes the value "horizontal" or "vertical".

If the value is "horizontal", the panes are placed left to right in the frame; if the value is "vertical", the panes are placed top to bottom in the frame. Metadata are data that describe other data. The Cursor attribute description contains a tuple of tuples that provides information about the fields of the data obtained by function execute.

The cursor and connection are closed. The PanedWidget method pane takes the name of a pane and returns a reference to that pane. The PanedWidget method setnaturalsize sets the size of each pane to be large enough to view the largest label in the pane.

.
Copyright © barcodefontsoft.com . All rights reserved.