Most viewed recipes tagged "database"http://code.activestate.com/recipes/tags/database/views/2013-09-29T19:25:23-07:00ActiveState Code RecipesMicrosoft Access Database Connectivity (DSN-Less) (PHP) 2006-08-29T03:08:29-07:00Erick Guanlaohttp://code.activestate.com/recipes/users/670494/http://code.activestate.com/recipes/163447-microsoft-access-database-connectivity-dsn-less/ <p style="color: grey"> PHP recipe 163447 by <a href="/recipes/users/670494/">Erick Guanlao</a> (<a href="/recipes/tags/database/">database</a>). Revision 4. </p> <p>An example of connecting to a Microsoft Access database, executing an SQL query, and displaying the results in HTML using PHP and COM (Windows only).</p> <p>NOTE: This works with PHP 4.x. I have been unsuccessful with getting this to work with PHP 5.1.6 and Apache 2.0.59 on Windowx XP Professional.</p> Use generators for fetching large db record sets (Python) 2010-02-10T10:47:53-08:00Christopher Prinoshttp://code.activestate.com/recipes/users/481494/http://code.activestate.com/recipes/137270-use-generators-for-fetching-large-db-record-sets/ <p style="color: grey"> Python recipe 137270 by <a href="/recipes/users/481494/">Christopher Prinos</a> (<a href="/recipes/tags/database/">database</a>). Revision 5. </p> <p>When using the python DB API, it's tempting to always use a cursor's fetchall() method so that you can easily iterate through a result set. For very large result sets though, this could be expensive in terms of memory (and time to wait for the entire result set to come back). You can use fetchmany() instead, but then have to manage looping through the intemediate result sets. Here's a generator that simplifies that for you.</p> DBF reader and writer (Python) 2009-04-29T07:28:14-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/362715-dbf-reader-and-writer/ <p style="color: grey"> Python recipe 362715 by <a href="/recipes/users/178123/">Raymond Hettinger</a> (<a href="/recipes/tags/database/">database</a>). Revision 7. </p> <p>Reader iterates over records in Dbase or Xbase files. Writer creates dbf files from Python sequences.</p> Read tabular data from Excel spreadsheets the fast and easy way (Python) 2005-12-14T20:36:30-08:00Nicolas Lehuenhttp://code.activestate.com/recipes/users/1599156/http://code.activestate.com/recipes/440661-read-tabular-data-from-excel-spreadsheets-the-fast/ <p style="color: grey"> Python recipe 440661 by <a href="/recipes/users/1599156/">Nicolas Lehuen</a> (<a href="/recipes/tags/database/">database</a>). Revision 3. </p> <p>Sometimes you get an Excel spreadsheet (say, from the marketing departement) and you want to read tabular data from it (i.e. a line with column headers and lines of data). There are many ways to do this (including ODBC + mxODBC), but the easiest way I've found is this one : provide a file name and a sheet name, and read the data !</p> Microsoft Access Database Connectivity (PHP) 2002-04-28T10:39:45-07:00Daniel Hendrickshttp://code.activestate.com/recipes/users/386772/http://code.activestate.com/recipes/123709-microsoft-access-database-connectivity/ <p style="color: grey"> PHP recipe 123709 by <a href="/recipes/users/386772/">Daniel Hendricks</a> (<a href="/recipes/tags/database/">database</a>). </p> <p>This is an example of how you can pull data from a Microsoft Access database through ADO.</p> Python Database Interface for MS SQL Server (Python) 2010-06-04T14:31:44-07:00Jorge Besadahttp://code.activestate.com/recipes/users/100038/http://code.activestate.com/recipes/144183-python-database-interface-for-ms-sql-server/ <p style="color: grey"> Python recipe 144183 by <a href="/recipes/users/100038/">Jorge Besada</a> (<a href="/recipes/tags/database/">database</a>). Revision 11. </p> <p>This DBI implements the Cursor and Connection objects. It is functional: you can create connections, cursors, do fetchone, fetchall, get rowcount, etc. It uses osql or sqlcmd instead of ODBC or ADO. There is a good sized section with examples to get you started. </p> PHP MySQL Search Class (PHP) 2003-10-28T19:57:45-08:00Stephen Bartholomewhttp://code.activestate.com/recipes/users/350445/http://code.activestate.com/recipes/125901-php-mysql-search-class/ <p style="color: grey"> PHP recipe 125901 by <a href="/recipes/users/350445/">Stephen Bartholomew</a> (<a href="/recipes/tags/database/">database</a>). Revision 10. </p> <p>This class can perform a full text search over multiple columns of a MySQL database table, matching entries containing all search terms parsed to it.</p> Storing binary data in SQLite (Python) 2003-12-13T20:37:16-08:00John Barhamhttp://code.activestate.com/recipes/users/305009/http://code.activestate.com/recipes/252531-storing-binary-data-in-sqlite/ <p style="color: grey"> Python recipe 252531 by <a href="/recipes/users/305009/">John Barham</a> (<a href="/recipes/tags/database/">database</a>). </p> <p>This script demonstrates how to store binary data (aka BLOB or BINARY fields) in SQLite using the PySQLite extension.</p> Extraction and manipulation class for Microsoft Access (Python) 2008-03-01T07:15:52-08:00Grant Paton-Simpsonhttp://code.activestate.com/recipes/users/4074475/http://code.activestate.com/recipes/528868-extraction-and-manipulation-class-for-microsoft-ac/ <p style="color: grey"> Python recipe 528868 by <a href="/recipes/users/4074475/">Grant Paton-Simpson</a> (<a href="/recipes/tags/database/">database</a>). Revision 2. </p> <p>Class for extracting and manipulating data from Microsoft Access - identifying tables, getting recordsets, iterating through the results, counting rows, getting field names, getting index information, deleting indexes, and adding and deleting relationships.</p> Class for writing content to Excel and formatting it (Python) 2007-09-07T03:08:02-07:00Grant Paton-Simpsonhttp://code.activestate.com/recipes/users/4074475/http://code.activestate.com/recipes/528870-class-for-writing-content-to-excel-and-formatting-/ <p style="color: grey"> Python recipe 528870 by <a href="/recipes/users/4074475/">Grant Paton-Simpson</a> (<a href="/recipes/tags/database/">database</a>). Revision 4. </p> <p>Class for creating Excel spreadsheets - esp writing data and formatting them. NB OpenOffice Calc will be easily able to open the outputs too.</p> Create SQL tables from CSV files (Python) 2010-02-24T13:47:36-08:00Matt Keranenhttp://code.activestate.com/recipes/users/38288/http://code.activestate.com/recipes/498130-create-sql-tables-from-csv-files/ <p style="color: grey"> Python recipe 498130 by <a href="/recipes/users/38288/">Matt Keranen</a> (<a href="/recipes/tags/database/">database</a>). </p> <p>Script generates CREATE TABLE statements based on the width of data present in comma delimited (csv) test files. Setting the correct datatypes (other than VARCHAR), is still a manual adventure.</p> <h5>TODOs:</h5> <ul> <li>Eliminate '#N/A', '@NA' from data</li> <li>Remove commas from numeric data</li> <li>Check for duplicate column names</li> <li>Create BCP format file or INSERT statements?</li> </ul> MultiThread support for SQLite access. (Python) 2010-07-20T14:29:35-07:00Louis RIVIEREhttp://code.activestate.com/recipes/users/4035877/http://code.activestate.com/recipes/526618-multithread-support-for-sqlite-access/ <p style="color: grey"> Python recipe 526618 by <a href="/recipes/users/4035877/">Louis RIVIERE</a> (<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/sqlite/">sqlite</a>, <a href="/recipes/tags/threads/">threads</a>). Revision 4. </p> <p>Workaround for the SQLite limitation that prevents multiple threads from sharing a Connection object.</p> Export Oracle Database to CSV using cx_Oracle (Python) 2010-07-11T19:49:42-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577304-export-oracle-database-to-csv-using-cx_oracle/ <p style="color: grey"> Python recipe 577304 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/database/">database</a>). </p> <p>Creates a CSV file for each table in the target Oracle database.</p> Generate SQL for insertation into table from dictionary object (Python) 2005-11-26T18:28:53-08:00Carson Reynoldshttp://code.activestate.com/recipes/users/2680336/http://code.activestate.com/recipes/457661-generate-sql-for-insertation-into-table-from-dicti/ <p style="color: grey"> Python recipe 457661 by <a href="/recipes/users/2680336/">Carson Reynolds</a> (<a href="/recipes/tags/database/">database</a>). Revision 2. </p> <p>This recipe shows you how you might generate SQL code to insert the key-value pairs in a dictionary. The parameter table corresponds to an existing SQL table and dictionary keys correspond to the table's SQL column names. The SQL generated can then be inserted into a database (in this case MySQL) in the manner shown in exampleOfUse().</p> A higher level struct module (Python) 2006-10-26T14:47:57-07:00Brian McErleanhttp://code.activestate.com/recipes/users/111980/http://code.activestate.com/recipes/498149-a-higher-level-struct-module/ <p style="color: grey"> Python recipe 498149 by <a href="/recipes/users/111980/">Brian McErlean</a> (<a href="/recipes/tags/database/">database</a>). Revision 4. </p> <p>This recipe provides a higher level wrapper around the struct module. It provides a more convenient syntax for defining and using structs, and adds additional features such as: - Allows embedding structures within other structures - Allows defining arrays of items (or other structures) - Class based syntax, allowing access and updates by field name, not position - Extension of structures by inheritance</p> Reverse engineer MS Access/Jet databases (Python) 2004-09-16T19:24:51-07:00Matt Keranenhttp://code.activestate.com/recipes/users/38288/http://code.activestate.com/recipes/52267-reverse-engineer-ms-accessjet-databases/ <p style="color: grey"> Python recipe 52267 by <a href="/recipes/users/38288/">Matt Keranen</a> (<a href="/recipes/tags/database/">database</a>). Revision 5. </p> <p>Reads the structure of a Jet (Microsoft Access .MDB) database file, and creates the SQL DDL necessary to recreate the structure.</p> <p>Originally written to aid in migrating Jet databases to larger RDBMS systems, through E/R design tools, when the supplied "import" routines missed objects like indexes and FKs.</p> <p>A first experiment in Python, that became an often used tool.</p> PyDbLite, a small in-memory database engine (Python) 2011-07-18T19:36:04-07:00Pierre Quentelhttp://code.activestate.com/recipes/users/1552957/http://code.activestate.com/recipes/496770-pydblite-a-small-in-memory-database-engine/ <p style="color: grey"> Python recipe 496770 by <a href="/recipes/users/1552957/">Pierre Quentel</a> (<a href="/recipes/tags/database/">database</a>). Revision 4. </p> <p>A small, fast, in-memory database management program</p> <p>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 :</p> <pre class="prettyprint"><code>cursor.execute("SELECT name FROM table WHERE age=30") rows = cursor.fetchall() </code></pre> <p>is :</p> <pre class="prettyprint"><code>rows = table(age=30) </code></pre> <p>The module stores data in a cPickled file. Records are indexed by a unique record identifier, that can be used for direct access. Since operations are processed in memory they are extremely fast, nearly as fast as SQLite in the few tests I made, and MUCH faster than other pure-Python modules such as Gadfly or KirbyBase. An index can be created on a field to even speed up selections</p> <p>Concurrency control is supported by a version number set for each record</p> <p>Complete documentation is <a href="http://www.pydblite.net">here</a></p> Using Berkeley DB Database (Python) 2003-03-12T01:25:46-08:00Farhad Fouladihttp://code.activestate.com/recipes/users/492016/http://code.activestate.com/recipes/189060-using-berkeley-db-database/ <p style="color: grey"> Python recipe 189060 by <a href="/recipes/users/492016/">Farhad Fouladi</a> (<a href="/recipes/tags/database/">database</a>). </p> <p>Berkeley DB is an open source database. Its most important advantages are its simplicity to use and its performance.</p> <p>This is an introductory example, that shows how to create a database, add new elements in it (as Key/Value pairs) and finally how to print all content of the database. The example is divided in two independent part.</p> Using the MySQLdb interface (Python) 2002-05-12T22:36:47-07:00Mark Nenadovhttp://code.activestate.com/recipes/users/114221/http://code.activestate.com/recipes/65235-using-the-mysqldb-interface/ <p style="color: grey"> Python recipe 65235 by <a href="/recipes/users/114221/">Mark Nenadov</a> (<a href="/recipes/tags/database/">database</a>). Revision 5. </p> <p>A simple example showing how to use the MySQLdb interface to function with your MySQL database.</p> A Phone Book GUI Built in wxPython Connected To Database Using Data Grid View (Python) 2013-09-29T19:25:23-07:00toufic zaarourhttp://code.activestate.com/recipes/users/4187866/http://code.activestate.com/recipes/578676-a-phone-book-gui-built-in-wxpython-connected-to-da/ <p style="color: grey"> Python recipe 578676 by <a href="/recipes/users/4187866/">toufic zaarour</a> (<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/datagridview/">datagridview</a>, <a href="/recipes/tags/graphical/">graphical</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/interface/">interface</a>). </p> <p>this GUI as simple as it is explains some basic but important graphical database interfacing; "Add", "Edit","Delete","Search" and few others along with a data grid view. in order to work create an sqlite3 database as follows:</p> <p>data table : Phone, column 1 : ID, column 2 : name, column 3 : surname, column 4 : telephone.</p> <p>save the sqlite3 file as file.db in a folder called Data and place it in the same directory as your python script.</p> <p>if you want to create the sqlite3 database graphically use my previous post : <a href="http://code.activestate.com/recipes/578665-a-wxpython-gui-to-create-sqlite3-databases/" rel="nofollow">http://code.activestate.com/recipes/578665-a-wxpython-gui-to-create-sqlite3-databases/</a></p> <p>Also there is more: I did not use auto-number for 'id' because I also wanted to include in the code a renumbering script.</p> <p>I am pleased to receive all the suggestions and improvements on this site or to my e-mail directly if this is convenient to you.</p> <p>note: if you don't like the database table name, and columns name create your own but make sure to change them in the code as well! in the end life is great! remember that!</p>