FAQ
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 ParameterDirectionEnum


class DBConnect:
def __init__(self):
self.Cnn = win32com.client.Dispatch(r'ADODB.Connection')
self.ConnStr = r'File Name=C:\Graal.dsn'
self.Cnn.Open (self.ConnStr)
locale.setlocale(locale.LC_ALL , "it")

def GetHeaders(self):
dati=[]
Cmd =win32com.client.Dispatch(r'ADODB.Command')
Cmd.ActiveConnection = self.Cnn
Cmd.CommandText = 'Intestazioni'
Cmd.CommandType = adCmdTable
Cmd.CommandTimeout = 15
Rst = win32com.client.Dispatch(r'ADODB.Recordset')
Rst.Open (Cmd)

dati.append(Rst.Fields.Item('DataRiferimento').Value.Format("%d.%m.%Y"))
Rst.Close()
self.Cnn.Close()
return dati

def GetReturn(self, Ndg36):
dati=[]
if not str(Ndg).isdigit():
raise NoDataError('Il codice cliente inserito non e numerico')
Cmd =win32com.client.Dispatch(r'ADODB.Command')
Cmd.ActiveConnection = self.Cnn
Cmd.CommandText = 'Incassi_CercaPerNdg'
Cmd.CommandType = adCmdStoredProc
Cmd.CommandTimeout = 15

Prm = win32com.client.Dispatch(r'ADODB.Parameter')
Prm = Cmd.CreateParameter('@Ndg',adInteger, adParamInput,8,Ndg)
Cmd.Parameters.Append (Prm)
Rst = win32com.client.Dispatch(r'ADODB.Recordset')
Rst.Open (Cmd)
while not Rst.EOF:
for i in range(Rst.Fields.__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.Fields.Item(i).Value[0])<<32)) /1e4
dati.append(locale.format('%.2f',temp, 1))
else:
pass
Rst.MoveNext()
Rst.Close
self.Cnn.Close
return dati

def GetData(self,Ndg36):
dati=[]
if not str(Ndg).isdigit():
raise NoDataError('Il codice cliente inserito non e numerico')
Cmd =win32com.client.Dispatch(r'ADODB.Command')
Cmd.ActiveConnection = self.Cnn
Cmd.CommandText = 'Anagrafe_CercaPerNdg'
Cmd.CommandType = adCmdStoredProc
Cmd.CommandTimeout = 15

Prm = win32com.client.Dispatch(r'ADODB.Parameter')
Prm = Cmd.CreateParameter('@Ndg',adInteger, adParamInput,8,Ndg)
Cmd.Parameters.Append (Prm)
Rst = win32com.client.Dispatch(r'ADODB.Recordset')
Rst.Open (Cmd)
if not Rst.EOF:
for i in range(Rst.Fields.__len__()):
if Rst.Fields.Item(i).Value == None:
dati.append(None)
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.Fields.Item(i).Value[0])<<32)) /1e4
dati.append(locale.format('%.2f',temp, 1))
elif Rst.Fields.Item(i).Type = 2 or
Rst.Fields.Item(i).Type = 3:
a= (Rst.Fields.Item(i).Value)
dati.append(a.encode('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(Error):
def __init__(self, message):
self.message = message

def __str__(self):
return `self.message`

if __name__ == '__main__':
prova = DBConnect()
try:
a = prova.GetData()
b = prova.GetHeaders()
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: python-list-admin at python.org
[mailto:python-list-admin at python.org]Per conto di JZ
Inviato: lunedi 15 settembre 2003 13.14
A: python-list at python.org
Oggetto: Re: caching the sql queries


On Mon, 15 Sep 2003 12:55:15 +0200, "Luca Calderano"
wrote:
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)
The Only way is using Com
What do you mean?

Search Discussions

  • Gerhard Häring at Sep 15, 2003 at 11:40 am

    Luca Calderano wrote:
    I MEAN YOU CAN ACCESS ADO TROUGHT COM
    AS EXPLAINED HERE: [...]
    No need to shout. This is all fine and dandy, but perhaps you should
    look at the link the OP posted ;-)

    Considering you have database experience as well, I'd be interested in
    hearing your opinion about something like this. I personally find it
    awful :-D

    -- Gerhard
  • Bob Gailer at Sep 15, 2003 at 2:45 pm

    At 05:27 AM 9/15/2003, Luca Calderano wrote:
    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 ParameterDirectionEnum


    class DBConnect:
    def __init__(self):
    self.Cnn = win32com.client.Dispatch(r'ADODB.Connection')
    self.ConnStr = r'File Name=C:\Graal.dsn'
    I want to learn form your excellent example.

    What is the function of r'File Name=C:\Graal.dsn' in this context?

    Can I use this approach to connect to MS SQL Server? and if so how? what
    would the connection string be?

    [snip]

    Bob Gailer
    bgailer at alum.rpi.edu
    303 442 2625
    -------------- next part --------------

    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedSep 15, '03 at 11:27a
activeSep 15, '03 at 2:45p
posts3
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase