词条 | Gadfly (database) |
释义 |
| name = Gadfly | logo = | screenshot = | caption = | collapsible = | developer = Aaron Robert Watters | released = {{Start date and age|1994}} | latest release version = 1.0 | latest release date = {{Start date and age|2005|01|05}} | latest preview version = | latest preview date = | operating system = Cross-platform | programming language = Python | genre = Relational Database Management System | license = Python License | website = {{URL|gadfly.sourceforge.net}} }}{{Portal|Free and open-source software|Python programming}}Gadfly is a relational database management system written in Python. Gadfly is a collection of Python modules that provides relational database functionality entirely implemented in Python. It supports a subset of the standard RDBMS Structured Query Language (SQL).[1][2] Gadfly runs wherever Python runs and supports client/server on any platform that supports the standard Python socket interface. The file formats used by Gadfly for storage are cross-platform—a gadfly database directory can be moved from Windows 95 to Linux using a binary copying mechanism and gadfly will read and run the database. It supports persistent databases consisting of a collection of structured tables with indices, and a large subset of SQL for accessing and modifying those tables. It supports a log-based recovery protocol which allows committed operations of a database to be recovered even if the database was not shut down{{clarify|committing changes?|date=May 2012}} in a proper manner (i.e., in the event of a CPU or software crash, [but not in the event of a disk crash]). It also supports a TCP/IP Client/Server mode where remote clients can access a Gadfly database over a TCP/IP network (such as the Internet) subject to configurable security mechanisms. Since Gadfly depends intimately on the kwParsing package it is distributed as part of the kwParsing package, under the same copyright. Gadfly allows Python programs to store, retrieve and query tabular data without having to rely on any external database engine or package. It provides an in-memory relational database style engine for Python programs, complete with a notion of a "committed, recoverable transaction" and "aborts".{{citation needed|date=September 2009}} Usage{{howto|section|date=March 2012}}The main "gadfly" module attempts to faithfully adhere to Greg Stein's Python Database API, as discussed and certified by the Python DB-SIG. Concurrent database updates are not supported. The "databases" are currently designed to be written/modified by one process in isolation. Multiple processes can access{{clarify|read only?|date=May 2012}} a Gadfly database when accesses are arbitrated by a TCP/IP Gadfly server process. Creating a new databaseUnlike most Python/database-engine interfaces Gadfly databases must be created using Python. To accomplish this programmers use: with no arguments. Then they startup a database using the startup method: Here "mydirectory" must be a directory which exists and which can be written to in order to store the database files. The startup creates some files in "mydirectory". This has the effect of clobbering any existing Gadfly database called "mydatabase" in the directory "mydirectory". Gadfly will not allow a start up the same connection twice, however. The first " Within the database the user can create tables, populate them, and commit the result when they are happy: Reconnecting to an existing databaseOnce a database exists it can be reconnected to: This will read in the database tables with the most recently committed values. The initialized database is then queried and updated: If the user does not want to commit updates then the do not execute a commit on the connection object (which writes out the tables). To restore the old values from the existing database they use: Updates are only stored upon a connection.commit(). [Actually, if autocheckpoint is disabled, updates are only stored to table files on checkpoint—see the documentation on the recovery mechanism.] to "pretty print" the result of any evaluation (which might be FeaturesIn this version all tables are read into memory upon "connecting" to the database and "touched" tables are written out upon checkpoint. Each table is represented as a separate file in the destination directory, and there is a "data definition" file as well (a list of data definition declarations). During active use a log file appears in the active directory as well, and if the process crashes this log file is used to recover committed operations. The SELECT statementAt this point Gadfly supports quite a lot of the SQL semantics requested in the ODBC 2.0 specification. SQL statements supported include the SELECT: This statement is quite powerful. It reads as follows:
The actual implementation in gadfly is much better than the intuitive reading, particularly at steps 1 and 2 (which are combined via optimizing transformations and hash join algorithms). Conditions may include equalities, and inequalities of expressions. Conditions may also be combined using AND, OR, NOT. Expressions include column names, constants, and standard arithmetic operations over them. Embedded queries supported include subquery expressions, expr IN (subselect), quantified comparisons, and the EXISTS (subselect) predicate. Aggregate tests and computations can only be applied after the GROUPing and before the columns are selected (steps 3,4,5). Aggregate operations include COUNT(*), COUNT(expression), AVG(expression), SUM(expression), MAX(expression), MIN(expression), and the non-standard MEDIAN(expression). These may be applied to DISTINCT values (throwing out redundancies, as in COUNT(DISTINCT drinker). if no GROUPing is present the aggregate computations apply to the entire result after step 2. There is much more to know about the SELECT statement. The test suite test/test_gadfly.py gives numerous examples of SELECT statements. Table creation and "data types"Create tables using the CREATE TABLE statement: Data types currently "supported" are integer, float, and varchar. They are ignored by the implementation, anything that is hashable and marshallable can currently go in any column (but that is likely to change). For example: At present tuples, complexes, or anything else can be put into a column specified as "VARCHAR". Other supported statements Gadfly also supports the searched DELETE and UPDATE; INSERT VALUES and INSERT subselect; CREATE/DROP INDEX, and DROP TABLE. These have the informal syntax: Multiple statements may be executed in one cursor.execute(S) by separating the statements with semicolons in S, for example S might have the string value: SQL is case insensitive. Dynamic valuesExpressions also include the special expression '?' (the ODBC-style dynamic expression) as in: Dynamic values allow the cursor to use the same parsed expression many times for a similar operation. Above the insertstat is parsed and bound to the database only once. Using dynamic attributes should speed up accesses. Thus the above should run much faster than the equivalent: Dynamic attributes can appear in other statements containing expressions (such as SELECTs, UPDATEs and DELETEs too). For SELECT, UPDATE, and DELETE the dynamic expression substitutions must consist of a single tuple, as in: Since the dynamic substitution eliminates the need for parsing and binding (expensive operations!) the above should run faster than the equivalent: If several similar queries are repeated multiple times, each query "template string" is associated with a unique cursor object so that each template must be parsed and bound only once. Some relatively complex queries from the test suite run 2 to 3 times faster after they have been parsed and bound, even without the kjbuckets builtin. With kjbuckets the same ran 5 to 10 times faster. Multiple batch inserts and dynamic valuesFor the special case of INSERT VALUES a list of substitution tuples allows the query engine to perform the inserts in optimized batch mode. Thus the fastest way to perform the three inserts given earlier is: It would be even faster if the cursor had previously executed the stat with different data (since then no parsing or binding would occur). IntrospectionBy default a gadfly database automatically includes "introspective" tables which allow a gadfly query to "query the shape of the database"—for example to view table names and names of rows in tables: Here DUAL is a standard one row/one column test table (from the Oracle tradition) and the other tables provide information about the database schema: Interactive testingAfter installation, the created database can be interactively tested from the same directory using the interactive interpreter: ArchitectureThe SQL grammar is described in grammar.py, the binding of the grammar constructs to semantic objects is performed in bindings.py, the semantic objects and their execution strategies is defined in semantics.py. The semantics use a lot of classical and non-classical logic (cylindric logic) as well as optimization heuristics to define a relatively efficient and correct implementation of SQL. The most basic data structures of the implementation are given in either kjbuckets0.py or the faster kjbucketsmodule.c, which implement the same data type signatures in Python and in a C extension to Python respectively. The database.py module is a simple wrapper that provides a standard DBAPI interface to the system. The test suite test/test_gadfly.py attempts to provide a regression test and a demonstration of the system. The SQL parser also requires the kwParsing parser generation package, which consists of a number of additional python modules. ToolsWith gfplus a gadfly database can be interactively manipulated with SQL commands. The tool works similar to Oracle's SQL*Plus. ConcurrencyBecause it lacks true concurrency control and file-system based indexing it is not appropriate for very large multiprocess transaction-based systems. Two applications may access the same database concurrently. However, changes made by one application may not be seen by the other application until after it restarts. This may be because each application loads the database in-memory at startup only. References1. ^{{cite web|url=http://www.informit.com/articles/article.aspx?p=24698&seqNum=8|publisher=InformIT|title=Gadfly—Zope's Integrated Demo Relational Database|accessdate=February 19, 2011}} 2. ^{{cite web|url=http://gadfly.sourceforge.net/gadfly.html|publisher=SourceForge|title=Gadfly|accessdate=February 19, 2011}} External links
2 : Free database management systems|Free software programmed in Python |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。