Difference between revisions of "Python - ODBC"
Jump to navigation
Jump to search
PeterHarding (talk | contribs) |
PeterHarding (talk | contribs) |
||
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=References= | =References= | ||
==Useful== | |||
* http://www.etsimo.uniovi.es/python/windows/win32/odbc.html | |||
==Still to Categorize== | |||
* http://www.petersblog.org/node/847 | * http://www.petersblog.org/node/847 | ||
Line 10: | Line 16: | ||
* http://www.iodbc.org/index.php?page=languages/python/odbc-pythonHOWTO | * http://www.iodbc.org/index.php?page=languages/python/odbc-pythonHOWTO | ||
* http://pyodbc.sourceforge.net/ | * http://pyodbc.sourceforge.net/ | ||
* http://pypi.python.org/pypi/adodbapi/2.0 | |||
* http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/414879 | |||
* http://hex-dump.blogspot.com/2005/05/creating-odbc-data-source-using-python.html | |||
* http://www.easysoft.com/products/data_access/ | |||
* http://www.etsimo.uniovi.es/python/windows/win32/odbc.html | |||
* http://www.freetds.org/ | |||
* http://jtds.sourceforge.net/ | |||
=SQL Clients= | |||
* http://squirrel-sql.sourceforge.net/ | |||
* http://www.ibm.com/developerworks/db2/library/techarticle/dm-0312bhogal/index.html | |||
==Installing SquirrelSQL== | |||
<pre> | |||
$ java -jar !$ | |||
java -jar squirrel-sql-2.6.5a-install.jar | |||
</pre> | |||
... and follow your nose ... | |||
=Examples= | |||
<pre> | |||
import ctypes | |||
ODBC_ADD_DSN = 1 # Add data source | |||
ODBC_CONFIG_DSN = 2 # Configure (edit) data source | |||
ODBC_REMOVE_DSN = 3 # Remove data source | |||
ODBC_ADD_SYS_DSN = 4 # add a system DSN | |||
ODBC_CONFIG_SYS_DSN = 5 # Configure a system DSN | |||
ODBC_REMOVE_SYS_DSN = 6 # remove a system DSN | |||
def create_sys_dsn(driver, **kw): | |||
"""Create a system DSN | |||
Parameters: | |||
driver - ODBC driver name | |||
kw - Driver attributes | |||
Returns: | |||
0 - DSN not created | |||
1 - DSN created | |||
""" | |||
nul = chr(0) | |||
attributes = [] | |||
for attr in kw.keys(): | |||
attributes.append("%s=%s" % (attr, kw[attr])) | |||
return ctypes.windll.ODBCCP32.SQLConfigDataSource(0, ODBC_ADD_SYS_DSN, driver, nul.join(attributes)) | |||
if __name__ == "__main__": | |||
print create_sys_dsn("SQL Server",SERVER="(local)", DESCRIPTION="SQL Server DSN", DSN="SQL SERVER DSN", Database="mydatabase", Trusted_Connection="Yes") | |||
print create_sys_dsn("mySQL",SERVER="local", DESCRIPTION="mySQL Server Test1", DSN="mySQL DSN", DATABASE="mySQLDb", UID="username", PASSWORD="password", PORT="3306", OPTION="3") | |||
</pre> | |||
[[Category:Python]] | [[Category:Python]] | ||
[[Category:Database]] | [[Category:Database]] |
Latest revision as of 10:05, 30 April 2008
References
Useful
Still to Categorize
- http://www.petersblog.org/node/847
- http://www.petersblog.org/node/844
- http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303667
- http://mail.python.org/pipermail/python-list/2005-June/325341.html
- http://www.marknenadov.com/howto_odbcpy
- http://www.easysoft.com/developer/languages/python/mxodbc.html
- http://www.iodbc.org/
- http://www.iodbc.org/index.php?page=languages/python/odbc-pythonHOWTO
- http://pyodbc.sourceforge.net/
- http://pypi.python.org/pypi/adodbapi/2.0
- http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/414879
- http://www.easysoft.com/products/data_access/
- http://www.etsimo.uniovi.es/python/windows/win32/odbc.html
SQL Clients
- http://squirrel-sql.sourceforge.net/
- http://www.ibm.com/developerworks/db2/library/techarticle/dm-0312bhogal/index.html
Installing SquirrelSQL
$ java -jar !$ java -jar squirrel-sql-2.6.5a-install.jar
... and follow your nose ...
Examples
import ctypes ODBC_ADD_DSN = 1 # Add data source ODBC_CONFIG_DSN = 2 # Configure (edit) data source ODBC_REMOVE_DSN = 3 # Remove data source ODBC_ADD_SYS_DSN = 4 # add a system DSN ODBC_CONFIG_SYS_DSN = 5 # Configure a system DSN ODBC_REMOVE_SYS_DSN = 6 # remove a system DSN def create_sys_dsn(driver, **kw): """Create a system DSN Parameters: driver - ODBC driver name kw - Driver attributes Returns: 0 - DSN not created 1 - DSN created """ nul = chr(0) attributes = [] for attr in kw.keys(): attributes.append("%s=%s" % (attr, kw[attr])) return ctypes.windll.ODBCCP32.SQLConfigDataSource(0, ODBC_ADD_SYS_DSN, driver, nul.join(attributes)) if __name__ == "__main__": print create_sys_dsn("SQL Server",SERVER="(local)", DESCRIPTION="SQL Server DSN", DSN="SQL SERVER DSN", Database="mydatabase", Trusted_Connection="Yes") print create_sys_dsn("mySQL",SERVER="local", DESCRIPTION="mySQL Server Test1", DSN="mySQL DSN", DATABASE="mySQLDb", UID="username", PASSWORD="password", PORT="3306", OPTION="3")