I MEAN YOU CAN ACCESS ADO TROUGHT COM
AS EXPLAINED HERE:
import win32com.client
import locale
from os import sys
adCmdStoredProc = 4 # Evaluates CommandText as a stored procedure
name.
adCmdTable = 2 # Evaluates CommandText as a table name.
adInteger = 3 # A 4-byte signed integer.
adParamInput = 0x1 # from enum ParameterDirect ionEnum
class DBConnect:
def __init__(self):
self.Cnn = win32com.client .Dispatch(r'ADO DB.Connection')
self.ConnStr = r'File Name=C:\Graal.d sn'
self.Cnn.Open (self.ConnStr)
locale.setlocal e(locale.LC_ALL , "it")
def GetHeaders(self ):
dati=[]
Cmd =win32com.clien t.Dispatch(r'AD ODB.Command')
Cmd.ActiveConne ction = self.Cnn
Cmd.CommandText = 'Intestazioni'
Cmd.CommandType = adCmdTable
Cmd.CommandTime out = 15
Rst = win32com.client .Dispatch(r'ADO DB.Recordset')
Rst.Open (Cmd)
dati.append(Rst .Fields.Item('D ataRiferimento' ).Value.Format( "%d.%m.%Y") )
Rst.Close()
self.Cnn.Close( )
return dati
def GetReturn(self, Ndg=1036):
dati=[]
if not str(Ndg).isdigi t():
raise NoDataError('Il codice cliente inserito non e numerico')
Cmd =win32com.clien t.Dispatch(r'AD ODB.Command')
Cmd.ActiveConne ction = self.Cnn
Cmd.CommandText = 'Incassi_CercaP erNdg'
Cmd.CommandType = adCmdStoredProc
Cmd.CommandTime out = 15
Prm = win32com.client .Dispatch(r'ADO DB.Parameter')
Prm = Cmd.CreateParam eter('@Ndg',adI nteger, adParamInput,8, Ndg)
Cmd.Parameters. Append (Prm)
Rst = win32com.client .Dispatch(r'ADO DB.Recordset')
Rst.Open (Cmd)
while not Rst.EOF:
for i in range(Rst.Field s.__len__()):
if Rst.Fields.Item (i).Type == 135:
dati.append(Rst .Fields.Item(i) .Value.Format(" %d/%m/%Y"))
elif Rst.Fields.Item (i).Type == 6:
temp =
float((long(Rst .Fields.Item(i) .Value[1])&0xFFFFFFFFL ) |
(long(Rst.Field s.Item(i).Value[0])<<32)) /1e4
dati.append(loc ale.format('%.2 f',temp, 1))
else:
pass
Rst.MoveNext()
Rst.Close
self.Cnn.Close
return dati
def GetData(self,Nd g=1036):
dati=[]
if not str(Ndg).isdigi t():
raise NoDataError('Il codice cliente inserito non e numerico')
Cmd =win32com.clien t.Dispatch(r'AD ODB.Command')
Cmd.ActiveConne ction = self.Cnn
Cmd.CommandText = 'Anagrafe_Cerca PerNdg'
Cmd.CommandType = adCmdStoredProc
Cmd.CommandTime out = 15
Prm = win32com.client .Dispatch(r'ADO DB.Parameter')
Prm = Cmd.CreateParam eter('@Ndg',adI nteger, adParamInput,8, Ndg)
Cmd.Parameters. Append (Prm)
Rst = win32com.client .Dispatch(r'ADO DB.Recordset')
Rst.Open (Cmd)
if not Rst.EOF:
for i in range(Rst.Field s.__len__()):
if Rst.Fields.Item (i).Value == None:
dati.append(Non e)
elif Rst.Fields.Item (i).Type == 135:
dati.append(Rst .Fields.Item(i) .Value.Format(" %d/%m/%Y"))
elif Rst.Fields.Item (i).Type == 6:
temp =
float((long(Rst .Fields.Item(i) .Value[1])&0xFFFFFFFFL ) |
(long(Rst.Field s.Item(i).Value[0])<<32)) /1e4
dati.append(loc ale.format('%.2 f',temp, 1))
elif Rst.Fields.Item (i).Type ==202 or
Rst.Fields.Item (i).Type ==203:
a= (Rst.Fields.Ite m(i).Value)
dati.append(a.e ncode('latin-1','ignore'))
else:
dati.append(Rst .Fields.Item(i) .Value)
else:
Rst.Close
self.Cnn.Close
raise NoDataError('Il codice cliente inserito non e corretto')
Rst.Close
self.Cnn.Close
return dati
class Error(Exception ):
pass
class NoDataError(Err or):
def __init__(self, message):
self.message = message
def __str__(self):
return `self.message`
if __name__ == '__main__':
prova = DBConnect()
try:
a = prova.GetData()
b = prova.GetHeader s()
prova = DBConnect()
c = prova.GetReturn ()
print b ,c
print '-'*20
for v in a:
if v:
print v
else:
print ''
except NoDataError,e :
print e
S.G.A S.p.A.
Nucleo Sistemi Informativi
Luca Calderano
-----Messaggio originale-----
Da: [email protected] g
[mailto:[email protected] g]Per conto di JZ
Inviato: lunedi 15 settembre 2003 13.14
A: [email protected]
Oggetto: Re: caching the sql queries
On Mon, 15 Sep 2003 12:55:15 +0200, "Luca Calderano"
<calderano@sgas pa.it> wrote:
[color=blue][color=green]
>>Is there any equivalent of caching sql queries for Python like ADOdb
>>for PHP? (For those who did not hear about ADODb and its feature :
>>http://phplens.com/adodb/caching.of.recordsets.html)[/color]
>
>The Only way is using Com[/color]
What do you mean?
--
JZ
--
AS EXPLAINED HERE:
import win32com.client
import locale
from os import sys
adCmdStoredProc = 4 # Evaluates CommandText as a stored procedure
name.
adCmdTable = 2 # Evaluates CommandText as a table name.
adInteger = 3 # A 4-byte signed integer.
adParamInput = 0x1 # from enum ParameterDirect ionEnum
class DBConnect:
def __init__(self):
self.Cnn = win32com.client .Dispatch(r'ADO DB.Connection')
self.ConnStr = r'File Name=C:\Graal.d sn'
self.Cnn.Open (self.ConnStr)
locale.setlocal e(locale.LC_ALL , "it")
def GetHeaders(self ):
dati=[]
Cmd =win32com.clien t.Dispatch(r'AD ODB.Command')
Cmd.ActiveConne ction = self.Cnn
Cmd.CommandText = 'Intestazioni'
Cmd.CommandType = adCmdTable
Cmd.CommandTime out = 15
Rst = win32com.client .Dispatch(r'ADO DB.Recordset')
Rst.Open (Cmd)
dati.append(Rst .Fields.Item('D ataRiferimento' ).Value.Format( "%d.%m.%Y") )
Rst.Close()
self.Cnn.Close( )
return dati
def GetReturn(self, Ndg=1036):
dati=[]
if not str(Ndg).isdigi t():
raise NoDataError('Il codice cliente inserito non e numerico')
Cmd =win32com.clien t.Dispatch(r'AD ODB.Command')
Cmd.ActiveConne ction = self.Cnn
Cmd.CommandText = 'Incassi_CercaP erNdg'
Cmd.CommandType = adCmdStoredProc
Cmd.CommandTime out = 15
Prm = win32com.client .Dispatch(r'ADO DB.Parameter')
Prm = Cmd.CreateParam eter('@Ndg',adI nteger, adParamInput,8, Ndg)
Cmd.Parameters. Append (Prm)
Rst = win32com.client .Dispatch(r'ADO DB.Recordset')
Rst.Open (Cmd)
while not Rst.EOF:
for i in range(Rst.Field s.__len__()):
if Rst.Fields.Item (i).Type == 135:
dati.append(Rst .Fields.Item(i) .Value.Format(" %d/%m/%Y"))
elif Rst.Fields.Item (i).Type == 6:
temp =
float((long(Rst .Fields.Item(i) .Value[1])&0xFFFFFFFFL ) |
(long(Rst.Field s.Item(i).Value[0])<<32)) /1e4
dati.append(loc ale.format('%.2 f',temp, 1))
else:
pass
Rst.MoveNext()
Rst.Close
self.Cnn.Close
return dati
def GetData(self,Nd g=1036):
dati=[]
if not str(Ndg).isdigi t():
raise NoDataError('Il codice cliente inserito non e numerico')
Cmd =win32com.clien t.Dispatch(r'AD ODB.Command')
Cmd.ActiveConne ction = self.Cnn
Cmd.CommandText = 'Anagrafe_Cerca PerNdg'
Cmd.CommandType = adCmdStoredProc
Cmd.CommandTime out = 15
Prm = win32com.client .Dispatch(r'ADO DB.Parameter')
Prm = Cmd.CreateParam eter('@Ndg',adI nteger, adParamInput,8, Ndg)
Cmd.Parameters. Append (Prm)
Rst = win32com.client .Dispatch(r'ADO DB.Recordset')
Rst.Open (Cmd)
if not Rst.EOF:
for i in range(Rst.Field s.__len__()):
if Rst.Fields.Item (i).Value == None:
dati.append(Non e)
elif Rst.Fields.Item (i).Type == 135:
dati.append(Rst .Fields.Item(i) .Value.Format(" %d/%m/%Y"))
elif Rst.Fields.Item (i).Type == 6:
temp =
float((long(Rst .Fields.Item(i) .Value[1])&0xFFFFFFFFL ) |
(long(Rst.Field s.Item(i).Value[0])<<32)) /1e4
dati.append(loc ale.format('%.2 f',temp, 1))
elif Rst.Fields.Item (i).Type ==202 or
Rst.Fields.Item (i).Type ==203:
a= (Rst.Fields.Ite m(i).Value)
dati.append(a.e ncode('latin-1','ignore'))
else:
dati.append(Rst .Fields.Item(i) .Value)
else:
Rst.Close
self.Cnn.Close
raise NoDataError('Il codice cliente inserito non e corretto')
Rst.Close
self.Cnn.Close
return dati
class Error(Exception ):
pass
class NoDataError(Err or):
def __init__(self, message):
self.message = message
def __str__(self):
return `self.message`
if __name__ == '__main__':
prova = DBConnect()
try:
a = prova.GetData()
b = prova.GetHeader s()
prova = DBConnect()
c = prova.GetReturn ()
print b ,c
print '-'*20
for v in a:
if v:
print v
else:
print ''
except NoDataError,e :
print e
S.G.A S.p.A.
Nucleo Sistemi Informativi
Luca Calderano
-----Messaggio originale-----
Da: [email protected] g
[mailto:[email protected] g]Per conto di JZ
Inviato: lunedi 15 settembre 2003 13.14
A: [email protected]
Oggetto: Re: caching the sql queries
On Mon, 15 Sep 2003 12:55:15 +0200, "Luca Calderano"
<calderano@sgas pa.it> wrote:
[color=blue][color=green]
>>Is there any equivalent of caching sql queries for Python like ADOdb
>>for PHP? (For those who did not hear about ADODb and its feature :
>>http://phplens.com/adodb/caching.of.recordsets.html)[/color]
>
>The Only way is using Com[/color]
What do you mean?
--
JZ
--