ArticleslgStudy

computer science

Gadfly (database)

Gadfly (database) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Gadfly (database) rather than just read about it. In short: 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.

Key takeaways

  • Gadfly (database) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Gadfly (database) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Gadfly (database) from memory before moving on to harder problems.

Reference excerpt

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). 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 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".

Usage 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 a Gadfly database when accesses are arbitrated by a TCP/IP Gadfly server process.

Creating a new database Unlike 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 "import gadfly" reads in and initializes some rather large data structures used for parsing SQL, and thus may take longer than other module imports. Within the database the user can create tables, populate them, and commit the result when they are happy:

Reconnecting to an existing database Once 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 None for a non-select).

Features In 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 statement At 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:

Make all combinations of rows from the tables (FROM line) Eliminate those combinations not satisfying condition (WHERE line) (if GROUP present) form aggregate groups that match on group-expressions (if HAVING present) eliminate aggregate groups that don't satisfy the aggregate-condition. compute the columns to keep (SELECT line). (if union-clause present) combine (union, difference, intersect) the result with the result of another select statement. if DISTINCT, throw out redundant entries. (if ORDER present) order the result by the columns (ascending or descending as specified, with precedence as listed). 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".

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Gadfly (database)

Start with the simplest possible case. Write down what Gadfly (database) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Gadfly (database) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Gadfly (database) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Gadfly (database)

In research
Gadfly (database) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Gadfly (database) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Gadfly (database) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Free database management systems, Free software programmed in Python, so understanding it makes those chapters shorter.
In everyday life
Look for Gadfly (database) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Gadfly (database)” →

How to study Gadfly (database) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Gadfly (database) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Gadfly (database) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Gadfly (database) in simple terms?

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.

Why does Gadfly (database) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Gadfly (database)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Gadfly (database).

Tags

  • Free database management systems
  • Free software programmed in Python

Keep exploring