Python pymssql and dblib Examples
Revision as of 19:19, 30 April 2008 by PeterHarding (talk | contribs) (New page: <pre> import pymssql con = pymssql.connect(host='192.168.13.122',user='sa',password='',database='tempdb') cur = con.cursor() query="create table pymssql (no int, fno float, comment va...)
import pymssql con = pymssql.connect(host='192.168.13.122',user='sa',password='',database='tempdb') cur = con.cursor() query="create table pymssql (no int, fno float, comment varchar(50));" cur.execute(query) print "create table: %d" % cur.rowcount for x in range(10): query="insert into pymssql (no,fno,comment) values (%d,%d.%d,'%dth comment');" % (x+1,x+1,x+1,x+1) ret=cur.execute(query) print "insert table: %d" % cur.rowcount for x in range(10): query="update pymssql set comment='%dth hahaha.' where no = %d" % (x+1,x+1) ret=cur.execute(query) print "update table: %d" % cur.rowcount query="EXEC sp_tables; select * from pymssql;" for x in range(10): cur.execute(query) while 1: print cur.fetchall() if 0 == cur.nextset(): break query="drop table pymssql;" cur.execute(query) print "drop table: %d" % cur.rowcount con.commit() con.close()