Revision 126
Added by Aaron Marcuse-Kubitza about 13 years ago
scripts/lib/sql.py | ||
---|---|---|
97 | 97 |
if match: raise NullValueException(match.group(1), e) |
98 | 98 |
raise # no specific exception raised |
99 | 99 |
|
100 |
def pkey(db, table): # Assumed to be first column in table |
|
100 |
def pkey(db, cache, table): # Assumed to be first column in table
|
|
101 | 101 |
check_name(table) |
102 |
return col(run_query(db, 'SELECT * FROM '+table+' LIMIT 0'), 0) |
|
102 |
if table not in cache: |
|
103 |
cache[table] = col(run_query(db, 'SELECT * FROM '+table+' LIMIT 0'), 0) |
|
104 |
return cache[table] |
|
103 | 105 |
|
104 | 106 |
def get(db, table, row, pkey, create=False, row_ct_ref=None): |
105 | 107 |
try: return value(select(db, table, [pkey], row, 1)) |
scripts/lib/db_xml.py | ||
---|---|---|
32 | 32 |
elif child_name == name: return child |
33 | 33 |
return None |
34 | 34 |
|
35 |
def get(db, node, pkeys=None, parent_id=None): |
|
36 |
if pkeys == None: pkeys = {} |
|
37 |
def pkey(table): return sql.pkey(db, pkeys, table) |
|
38 |
|
|
39 |
|
|
35 | 40 |
def put(db, node, store_ids=False, row_ct_ref=None, pkeys=None, parent_id=None): |
36 | 41 |
# store_ids enables searching the tree for missing fields |
37 | 42 |
if pkeys == None: pkeys = {} |
38 |
def pkey(table): |
|
39 |
if table not in pkeys: pkeys[table] = sql.pkey(db, table) |
|
40 |
return pkeys[table] |
|
43 |
def pkey(table): return sql.pkey(db, pkeys, table) |
|
41 | 44 |
|
42 | 45 |
table = name_of(node) |
43 | 46 |
pkey_ = pkey(table) |
scripts/map | ||
---|---|---|
69 | 69 |
if map_path != None: |
70 | 70 |
doc1 = xml.dom.minidom.getDOMImplementation().createDocument(None, |
71 | 71 |
dest, None) |
72 |
if in_is_xml: raise SystemExit('XML-XML mapping not supported yet') |
|
73 |
elif in_is_db: |
|
72 |
if in_is_db: |
|
73 |
assert in_is_xml |
|
74 |
|
|
74 | 75 |
import psycopg2 |
75 |
|
|
76 | 76 |
import db_xml |
77 | 77 |
|
78 |
try: src_root = xpath.parse(src_root) |
|
79 |
except SyntaxException, ex: raise SystemExit(str(ex)) |
|
80 |
|
|
78 | 81 |
in_db = psycopg2.connect(**in_db_config) |
79 | 82 |
for in_, out in mappings: |
80 | 83 |
value = metadata_value(in_) |
81 | 84 |
if value == None: |
82 | 85 |
raise SystemExit('DB-XML mapping not supported yet') |
83 | 86 |
in_db.close() |
87 |
elif in_is_xml: raise SystemExit('XML-XML mapping not supported yet') |
|
84 | 88 |
else: # input is CSV |
85 | 89 |
metadata = [] |
86 | 90 |
map_ = {} |
... | ... | |
105 | 109 |
if out_db_config != None: # output is database |
106 | 110 |
import psycopg2 |
107 | 111 |
from psycopg2.extensions import ISOLATION_LEVEL_SERIALIZABLE |
108 |
|
|
109 | 112 |
import db_xml |
110 | 113 |
|
111 | 114 |
db = psycopg2.connect(**out_db_config) |
Also available in: Unified diff
map: Started adding database get by XPath functionality