Created
August 21, 2018 10:44
-
-
Save neogeomat/00f5f3433645bb172c85416d9df6e554 to your computer and use it in GitHub Desktop.
Upgrade Saex Database Table with Track and Marginal Info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyodbc | |
def upgrade_saex_database_with_track_and_marginal_info(database_loc): | |
conn_old = ( | |
r'DRIVER={Microsoft Access Driver (*.mdb)};' | |
r'DBQ='+database_loc+';' | |
) | |
cnxn_old = pyodbc.connect(conn_old) | |
crsr_old = cnxn_old.cursor() | |
CodedValue = (3, bytearray(b'\x0e\x00\x00\x00\x02\x00\x00\x00None\x00\x14\x00Wall\x00\x19\x00Shared Wall\x00\x1e\x00Fence\x00(\x00Gate\x004\x00Line Kulo & Wall\x006\x00Line Kulo & Fence\x00:\x00Line Kulo & Gate\x00#\x00Shared Fence\x002\x00Line Kulo\x00\n\x00Building Foot Print\x00\x01\x00Foot Trail\x00\x02\x00Road\x00\x03\x00Marginal Imfo\x00')) | |
MarginNameExists = False | |
for cols in crsr_old.columns(table='Segments'): | |
if cols.column_name == 'MarginName': | |
global MarginNameExists | |
MarginNameExists = True | |
print 'MarginName alreasy exists in ' + database_loc | |
if not MarginNameExists: | |
crsr_old.execute("""ALTER TABLE Segments ADD COLUMN MarginName Text(50)""") | |
crsr_old.execute("""UPDATE GDB_CodedDomains SET [CodedValues] = ? """,CodedValue[1]) | |
crsr_old.commit() | |
print "Segment Table updated in " + database_loc | |
import os | |
for root, dirs, files in os.walk(raw_input("Enter Directory path containing MDB")): | |
for file in files: | |
if file.endswith(".mdb"): | |
print(os.path.join(root, file)) | |
try: | |
upgrade_saex_database_with_track_and_marginal_info(os.path.join(root, file)) | |
except: | |
pass | |
#upgrade_saex_database_with_track_and_marginal_info('F:\\BLANK84oldschema_pyodbc_test.mdb') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment