this is a simple example of adbapi use pymssql module to connect to MSSQL server.
from twisted.internet import reactor
from twisted.enterprise import adbapi
def getSites():
return dbpool.runQuery("select * from m_site")
def printResult(l):
for item in l:
print item
dbpool = adbapi.ConnectionPool("pymssql", user="sa", password="bedjo", host="192.168.31.31", database="bedjo")
getSites().addCallback(printResult)
reactor.callLater(4, reactor.stop)
reactor.run()
Thats all ... cheers
Wednesday, April 05, 2006
pymssql - example script
This is a simple script to test a connection of pymssql.
It's easy, but I always forgot. It seems that I'm getting old. lol.
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymssql
>>> con = pymssql.connect(user="sa", password="bedjo", host="192.168.31.31", database="bedjo");
>>> cur = con.cursor();
>>> cur.execute("select * from m_site");
>>> print cur.rowcount;
>>> print cur.fetchall();
>>> cur.execute("insert into log_message values ('succes') ");
>>> con.commit();
>>> con.close();
Thats all, the simple things to do.
It's easy, but I always forgot. It seems that I'm getting old. lol.
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymssql
>>> con = pymssql.connect(user="sa", password="bedjo", host="192.168.31.31", database="bedjo");
>>> cur = con.cursor();
>>> cur.execute("select * from m_site");
>>> print cur.rowcount;
>>> print cur.fetchall();
>>> cur.execute("insert into log_message values ('succes') ");
>>> con.commit();
>>> con.close();
Thats all, the simple things to do.
Subscribe to:
Posts (Atom)