pymssql/freetds 来自 sql server 的日期

pymssql/freetds date from sqlserver

我正在尝试通过 pymssql 从 SQLserver 2014 获取日期数据类型作为本机 python 日期。基于 pymssql doc,我需要 0.95+ freetds lib 和 7.3 freetds ver.

# tsql -C
Compile-time settings (established with the "configure" script)
                        Version: freetds v0.95.8
         freetds.conf directory: /etc
 MS db-lib source compatibility: no
    Sybase binary compatibility: no
                  Thread safety: yes
                  iconv library: yes
                    TDS version: 4.2
                          iODBC: no
                       unixodbc: yes
          SSPI "trusted" logins: no
                       Kerberos: no
                        OpenSSL: no
                         GnuTLS: no

我做了以下配置:

#/etc/freetds.conf
[sqlsvr1]
    host = sqlsvr1
    port = 1433
    tds version = 7.3

而且我仍然得到 python 字符串而不是日期。这是来自 TDSDUMPCONFIG。是因为freetds 0.95.8不支持tds 7.3吗? (major/minor 版本似乎已被替换为 7/1)。

config.c:620:IP addr is 172.16.12.26.
config.c:580:   port = '1433'
config.c:580:   tds version = '7.3'
config.c:886:Setting tds version to 7.3 (0x703).
config.c:568:   Reached EOF
config.c:300:Success: [sqlsvr1] defined in /etc/freetds.conf.
config.c:765:Setting 'dump_file' to '/tmp/freetds.log' from $TDSDUMP.
config.c:689:tds_config_login: client_charset is UTF-8.
config.c:213:Final connection parameters:
config.c:214:            server_name = sqlsvr1:1433
config.c:215:       server_host_name = sqlsvr1
config.c:218:                ip_addr = 172.16.12.26
config.c:218:                ip_addr = 172.16.12.26
config.c:218:                ip_addr = 172.16.12.26
config.c:223:          instance_name =
config.c:224:                   port = 1433
config.c:225:          major_version = 7
config.c:226:          minor_version = 1
config.c:227:             block_size = 0
config.c:228:               language = us_english
config.c:229:         server_charset =
config.c:230:        connect_timeout = 0
config.c:231:       client_host_name = rh1.int
config.c:232:         client_charset = UTF-8
config.c:233:              use_utf16 = 0
config.c:234:               app_name = pymssql
config.c:235:              user_name = USER
config.c:238:                library = DB-Library
config.c:239:              bulk_copy = 0
config.c:240:      suppress_language = 0
config.c:241:          encrypt level = 0
config.c:242:          query_timeout = 0
config.c:245:               database =
config.c:246:              dump_file = /tmp/freetds.log
config.c:247:            debug_flags = 0
config.c:248:              text_size = 64512
config.c:249:     emul_little_endian = 0
config.c:250:      server_realm_name =
config.c:251:             server_spn =
config.c:252:                 cafile =
config.c:253:                crlfile =

如果我在配置中将 tds 版本设置为 7.4,那么我会在日志中注意到这个错误:

config.c:580:   tds version = '7.4'
config.c:881:error: no such version: 7.4
config.c:568:   Reached EOF
config.c:213:Final connection parameters:
... ... 
config.c:225:          major_version = 7
config.c:226:          minor_version = 1

环境:Linux/RH 6 + Python3.4.3 + pymssql(2.1.1) 所有 x64

有什么建议吗?

你已经拥有了大部分所需的作品。

但缺少的是您使用的是 pymssql 2.1.1。

已实现对 DATE 和 TIME 数据类型的支持,但针对的是尚未发布的 pymssql 2.2.0。如果你现在需要它,你需要先从 'master' Git 分支自己构建它。