1 """
2 A Grammar feeding from an odbc connection.
3 """
4
5
6
7
8
9
10
11 import pyodbc
12
13 from gavo import base
14 from gavo.grammars.common import Grammar, RowIterator
15
16
26
27
29 """A grammar that feeds from a remote database.
30
31 This works as a sort of poor man's foreign data wrapper: you pull
32 data from a remote database now and then, mogrifying it into whatever
33 format you want locally.
34
35 This expects files containing pyodbc connection strings as sources,
36 so you'll normally just have one source. Having the credentials
37 externally helps keeping RDs using this safe for public version control.
38
39 An example for an ODBC connection string::
40
41 DRIVER={SQL Server};SERVER=localhost;DATABASE=testdb;UID=me;PWD=pass
42
43 See also http://www.connectionstrings.com/
44
45 This will only work if pyodbc (debian: python-pyodbc) is installed.
46 Additionally, you will have to install the odbc driver corresponding
47 to your source database (e.g., odbc-postgresql).
48 """
49 name_ = "odbcGrammar"
50
51 _query = base.UnicodeAttribute("query",
52 description="The query to run on the remote server. The keys of"
53 " the grammar will be the names of the result columns.",
54 copyable=True)
55
56 rowIterator = ODBCIterator
57