[python-win32] python win32com.client; reverse engineer sql server timestamp

Anrik Drenth drentha at gmail.com
Mon Dec 17 20:20:03 EST 2018


I'm looking for the mapping table / logic that will render sql server
timestamp values as win32com.client does.

I'm currently  importing a text file into Access. The text file contains a
column with a timestamp value which has been extracted from sql server.
The values for the (Access String 50) column look something like "
0x000000000189CF01".

Using VBA I want to convert these to the exact same value that win32com
creates.

In python (sample code below) the timestamp value is stored as an 8 byte,
bytearray.  Which then gets interpreted by Access.

Below is a sample of how the sql server timestamp value is stored in Access:

*SQL Server (Timestamp) | Access (Text 50)* 0x000000000189CF01  |  003F49
0x000000000189D001  |  003F69 0x0000000001B54DFF  |  003F6D
0x0000000001F74701   | 003F4E 0x000000000189C003   | 003F70
So it tries to do a mapping, sometimes 1 to 1, sometimes not as page 5 of
the below link demonstrates
https://scripts.sil.org/cms/scripts/render_download.php?format=file&media_id=UnicodeWord&filename=unicodeissuesinword97-2000.pdf

I'd appreciate it if anyone has logic or a link to the mapping tables.

*Sample Python code *

MSAccessconnect = 'Driver={Microsoft Access Driver (*.mdb)};Dbq=test.mdb;'
SQLServerconnect = '[ODBC;Driver=SQL
Server;SERVER=server1;Database=test;UID=%s;PWD=%s]' %('user', 'pass')

strsql = "SELECT * FROM %s.%s;" % (SQLServerconnect, "sqltesttable")
print strsql

from win32com.client import Dispatch
oConn = Dispatch('ADODB.Connection')
oConn.ConnectionString = MSAccessconnect
oConn.Open()

oRS = Dispatch('ADODB.RecordSet')
oRS.ActiveConnection = oConn
oRS.Open(strsql)

while not oRS.EOF:
   print oRS.Fields.Item("Stamp").Value

The text displayed is ▒▒▒
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20181218/4646e680/attachment.html>


More information about the python-win32 mailing list