Popular recipes tagged "sql" but not "database"http://code.activestate.com/recipes/tags/sql-database/2015-02-24T22:08:11-08:00ActiveState Code RecipesPublish SQLite data to PDF using named tuples (Python)
2015-02-24T22:08:11-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579027-publish-sqlite-data-to-pdf-using-named-tuples/
<p style="color: grey">
Python
recipe 579027
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdfwriter/">pdfwriter</a>, <a href="/recipes/tags/sql/">sql</a>, <a href="/recipes/tags/sqlite/">sqlite</a>, <a href="/recipes/tags/sqlite3/">sqlite3</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how to publish SQLite data to PDF, using named tuples from the collections module of Python, the sqlite3 library, and the xtopdf library for PDF generation.</p>
Conjunction select using foreign keys (Text)
2011-06-11T02:43:22-07:00Kaushik Ghosehttp://code.activestate.com/recipes/users/4166965/http://code.activestate.com/recipes/577747-conjunction-select-using-foreign-keys/
<p style="color: grey">
Text
recipe 577747
by <a href="/recipes/users/4166965/">Kaushik Ghose</a>
(<a href="/recipes/tags/conjunction/">conjunction</a>, <a href="/recipes/tags/foreign/">foreign</a>, <a href="/recipes/tags/key/">key</a>, <a href="/recipes/tags/select/">select</a>, <a href="/recipes/tags/sql/">sql</a>).
</p>
<p>Say we have a table (notes) containing rows we want to select. Each note has one or more keywords (stored in a table of the same name). We want to select notes that have a conjunction of keywords (AND). notes and keywords are linked through a foreign key table notes_keywords. The following SQL statement allows us to do this</p>
Populate SQL tables from CSV data files (Python)
2011-02-02T21:21:49-08:00James Millshttp://code.activestate.com/recipes/users/4167757/http://code.activestate.com/recipes/577559-populate-sql-tables-from-csv-data-files/
<p style="color: grey">
Python
recipe 577559
by <a href="/recipes/users/4167757/">James Mills</a>
(<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/sql/">sql</a>).
</p>
<p>Just a quick recipe I developed a few years ago that I thought
might be useful to others. Basically it takes as input a
data file with comma separated values (CSV) and translates
this into a series of SQL "INSERT" statements allowing you
to then feed this into MySQL, SQLite, or any other database.</p>
<p>Example Usage:</p>
<p>$ cat cars.csv
Year,Make,Model,Length
1997,Ford,E350,2.34
2000,Mercury,Cougar,2.38</p>
<p>$ sqlite3 cars.db "CREATE TABLE cars (Year, Make, Model, Length)"</p>
<p>$ ./csv2sql.py cars.csv | sqlite3 cars.db </p>
<p>$ sqlite3 cars.db "SELECT * FROM cars"
1997|Ford|E350|2.34
2000|Mercury|Cougar|2.38</p>
<p>Enjoy! Feedback welcome!</p>
<p>cheers
James Mills / prologic</p>
A MSSQL XML importer for MySQL (Python)
2011-03-09T03:46:49-08:00Albert Perrien IIhttp://code.activestate.com/recipes/users/4177266/http://code.activestate.com/recipes/577601-a-mssql-xml-importer-for-mysql/
<p style="color: grey">
Python
recipe 577601
by <a href="/recipes/users/4177266/">Albert Perrien II</a>
(<a href="/recipes/tags/mysql/">mysql</a>, <a href="/recipes/tags/server/">server</a>, <a href="/recipes/tags/sql/">sql</a>, <a href="/recipes/tags/xml/">xml</a>).
</p>
<p>This is a simple function that takes records exported to XML from SQL Server or Access and imports them into MySQL. </p>
Minimalistic PostgreSQL console shell (Python)
2011-11-30T13:43:28-08:00ccpizzahttp://code.activestate.com/recipes/users/4170754/http://code.activestate.com/recipes/577468-minimalistic-postgresql-console-shell/
<p style="color: grey">
Python
recipe 577468
by <a href="/recipes/users/4170754/">ccpizza</a>
(<a href="/recipes/tags/postgres/">postgres</a>, <a href="/recipes/tags/postgresql/">postgresql</a>, <a href="/recipes/tags/sql/">sql</a>).
Revision 17.
</p>
<p>Primitive shell for running PostgreSQL quieries from console. Make sure you set the right connection settings in the script.</p>
<p>All queries are executed in autocommit mode.</p>
<p>Example command line usage:</p>
<pre class="prettyprint"><code>pg.py select * from mytable where oidh=1
</code></pre>
<p>The script recognizes a number of magic keywords:</p>
<pre class="prettyprint"><code>pg.py show databases
pg.py show schemas
pg.py describe <table_name>
</code></pre>
ExecSql.cgi returning JSON for SQL (Python)
2009-11-28T02:00:30-08:00Martchenkohttp://code.activestate.com/recipes/users/4172446/http://code.activestate.com/recipes/576971-execsqlcgi-returning-json-for-sql/
<p style="color: grey">
Python
recipe 576971
by <a href="/recipes/users/4172446/">Martchenko</a>
(<a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/json/">json</a>, <a href="/recipes/tags/sql/">sql</a>).
</p>
<p>CGI script getting JSON for SQL request</p>
Transparently execute SQL queries as prepared statements with Postgresql (Python)
2009-03-23T07:30:07-07:00Michael Palmerhttp://code.activestate.com/recipes/users/1827292/http://code.activestate.com/recipes/576698-transparently-execute-sql-queries-as-prepared-stat/
<p style="color: grey">
Python
recipe 576698
by <a href="/recipes/users/1827292/">Michael Palmer</a>
(<a href="/recipes/tags/postgresql/">postgresql</a>, <a href="/recipes/tags/prepared_statements/">prepared_statements</a>, <a href="/recipes/tags/sql/">sql</a>).
Revision 4.
</p>
<p>This recipe defines a mixin class for DBAPI cursors that gives them an 'executeps' method. This method transparently converts any SQL query into a prepared statement, which gets cached and executed instead of the original query.</p>