RE: Declaring MS SQL variables as parameters: sample script

"Charles Bearden" <[email protected]> Thu, 5 Aug 2004 14:21:25 -0500
Newsgroups gmane.comp.python.sybase
Message-ID <[email protected]>
Here's the script that generated the traceback I gave in the previous
message:
---------------------------------------------------------------------
import sys, os
if not os.environ.get('SYBASE'):
  os.environ['SYBASE'] = '/usr/local/freetds'
if not os.environ.get('ODBCINI'):
  os.environ['ODBCINI'] = '/usr/local/etc/odbc.ini'
import Sybase
from pyPgSQL import PgSQL

s = 'DBServer'
u = 'DOMAIN\jrandomuser'
p = 'securepwd'
d = 'DBName'

c_pg = PgSQL.connect(database=d)
cu_pg = c_pg.cursor()
c_sy = Sybase.connect(s, u, p, d)
cu_sy = c_sy.cursor()

cu_pg.execute('select pmid, xmldata from pmxml limit 10')
while True:
  r = cu_pg.fetchone()
  if not r: break
  dct = { '@pmid' : r[0] , '@xmldata' : r[1] }
  cu_sy.execute('delete from fooflap')
  s = '''
    INSERT INTO testTable
    (PMID, XmlData)
    VALUES
    (@pmid, @xmldata)
  '''
  cu_sy.execute('declare @pmid nvarchar(10), @xmldata ntext')
  cu_sy.execute(s, dct)


c_pg.close()
c_sy.close()
---------------------------------------------------------------------

Thanks,
Chuck