python 操作达 梦数据库

python 达梦数据库操作流程
  1. 连接数据库 dm.connect( ... )
  2. 获取游标 dm_conn.cursor()
  3. 编写SQL语句 sql_str
  4. 执行SQL语句 dm_cursor.execute()
  5. 获取结果列表 dt_breakpoint = dm_cursor.fetchall()
  6. 关闭游标 dm_cursor.close()
  7. 关闭数据库连接 dm_conn.close()

代码示例

import pandas as pd
import numpy as np
import datetime
import dmPython as dm

user_name = "dameng"
passwd = "admin"
server_name = "LOCALHOST"
server_port = 5236

def query_ustpf_time_breakpoint( wf_no ):    
    dm_conn = dm.connect( user=user_name, password=passwd, server=server_name, port=server_port )
    dm_cursor = dm_conn.cursor()
    sql_str = "select MAIN_LF_4H_PROC_TIME from WF_ST_PF_PARA where WINDPLANT_NO=%d;" % ( wf_no )
    print( "func(query_ustpf_time_breakpoint):", sql_str )
    try:
        dm_cursor.execute( sql_str )
    except Exception as e:
        print( ‘func(query_ustpf_time_breakpoint) -- dm_cursor.execute(...) Error: ‘, e )
    dt_breakpoint = dm_cursor.fetchall()
    dm_cursor.close()
    dm_conn.close()
    if len( dt_breakpoint ) > 0:
        return dt_breakpoint[0][0]
    else:
        return None

备注

预先安装达梦数据库python语言支持包dmPython。

python 操作达 梦数据库

上一篇:STRAIGHT_JOIN优化坑爹SQL


下一篇:Ubuntu14.04下MySQL的安装与卸载