Skip to content

Instantly share code, notes, and snippets.

@miltonlab
Last active April 14, 2018 11:10
Show Gist options
  • Save miltonlab/ea778dc00baf3bca8dfce81e18a11c68 to your computer and use it in GitHub Desktop.
Save miltonlab/ea778dc00baf3bca8dfce81e18a11c68 to your computer and use it in GitHub Desktop.
Set record read from Access to insert into SQLServer
import decimal
from decimal import Decimal
import datetime
#Read from Microsoft Access
#rows = cursor_access.execute("SELECT * FROM Predios")
#One record example:
row = (98, '11', '04', '57', '01', '01', '004', '005', '000', '00', '000', '1104570101004005', 'EDIFICADO', 'TNTE MAXIMILIANO RODRIGUEZ', 'UNIPROPIEDAD', 'Residencial', 'C:\\FOTOS\\570101\\004\\005.jpg', 'MODESTO BURNEO', 'S/N', 'JACINTA REYES', 'LOJA, SAN SEBASTIAN', 'Natural', None, datetime.datetime(1973, 1, 26, 0, 0), 44, 'Femenino', False, 'CARMEN PAULINA', 'ILLESCAS BURNEO', 'Cédula', '1102962741', '-', '-', 'Casado', 'MANUEL AGUSTIN', 'TOLEDO CUEVA', 'Cédula', '-', '-', '-', 'BURNEO CAMPOVERDE JULIO MARIANA', '-', None, None, None, None, None, None, None, 'Cédula', None, None, None, False, True, 'Loja', 'Celica', '3', datetime.datetime(2011, 10, 7, 0, 0), '254', datetime.datetime(2011, 10, 31, 0, 0), False, 0, 0, 'Compra - venta', True, 'Calle', 'Adoquín de cemento', True, True, True, True, False, True, True, True, False, True, False, False, False, False, False, False, False, False, False, False, 'No tiene', 'A Nivel', 'Intermedio', Decimal('0.00'), Decimal('0'), 'Regular', 'Seco', 'GRANDA SÁNCHEZ MARCO GEOVANY', Decimal('0.00'), 'BUSTAMANTE JARAMILLO ÁLVARO FRANCISCO', Decimal('0.00'), 'INFA', Decimal('0.00'), 'CALLE MODESTO BURNEO', Decimal('0.00'), None, Decimal('0.00'), None, Decimal('0.00'), Decimal('0.0000'), Decimal('0.0000'))
def replace(field):
mapeo = {None: 'NULL', False: 'F', True: 'T'}
if type(field) == decimal.Decimal:
return float(field)
elif type(field) == datetime.datetime:
return "{0}-{1}-{2}".format(field.year, field.month, field.day)
elif mapeo.get(field):
return mapeo.get(field)
else:
return field
row2 = tuple(map(replace, row))
# Insert into SQLServer
#cursor_mssql.execute("INSERT INTO Predios VALUES " + str(row2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment