Exemplo n.º 1
0
                 and m.cd_punto = r.dbi_cd_punto
                 and r.ordine_reverse = 1
                 and m.fl_completa = 'S'
                 and m.dt_mese_competenza >= to_date(eadat, 'yyyymmdd') --, TO_DATE('01032012', 'DDMMYYYY'))
                 AND sb.Utc_begin <= dt_Utc
                 AND sb.Utc_End > Dt_Utc
                 AND se.Utc_begin <= (dt_utc + (15 / (24 * 60)))
                 AND se.Utc_End > (dt_Utc + (15 / (24 * 60)))
                 )
                 group by pod, tipo, Start_Date, Start_Ts, Start_Offset, End_Date, End_Ts, End_Offset, Misura, Filler, Um, Spazio, ordine, utc
                 order by ordine, utc
'''
#inizializzazione e apertura file di log
date=datetime.datetime.now()
htmlMode=''
log = LogManager('E_curve', Constants.getDebugMode(),date,htmlMode)
#creazione oggetto di connessione Oracle
conn = ConnectionManager('E_curve',log)
#inizializzazione e apertura file CSV
mycsv = CsvManager('curve',';',False)
#nome programma
log.testata("creazione csv Curve" )

cursor = conn.conn.cursor()
cur_s1 = conn.conn.cursor()
cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYYMMDD HH24:MI:SS'")
#cursor.execute("ALTER SESSION SET NLS_NUMERIC_CHARACTERS = ',.'")
#
#select principale
cur_s1.execute(stat_finale)
Exemplo n.º 2
0
            vrefer,
            vertrag,
            TO_CHAR(v.d_valido_dal,'yyyymmdd'),
            TO_CHAR(v.d_valido_al,'yyyymmdd'),
            p.cd_prodotto,
            v.ctar1,
            v.acdan
        ORDER BY
            vrefer desc,
            acdan desc,
            TO_CHAR(v.d_valido_al,'yyyymmdd')
'''
#inizializzazione e apertura file di log
date=datetime.datetime.now()
htmlMode=''
log = LogManager('E_everh', Constants.getDebugMode(),date,htmlMode)
#creazione oggetto di connessione Oracle
conn = ConnectionManager('E_Everh',log)
#inizializzazione e apertura file CSV
mycsv = CsvManager('everh',';',False)
#nome programma
log.testata("creazione csv EVERH" )

cursor = conn.conn.cursor()
cur_s1 = conn.conn.cursor()
cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYYMMDD HH24:MI:SS'")
#
#sap_conn=pysap.Rfc_connection(conn_file='sapconn.ini',conn_name='INT2')
#sap_conn.open()
#
campi_temksv = ['mandt', 'firma', 'object','oldkey','newkey']
Exemplo n.º 3
0
'''
Created on 15/gen/2013

@author: Stefano Tizianel
'''
import datetime
import pysap
from it_eutile_utils_properties.Constants import Constants
from it_eutile_utils_database.ConnectionManager import ConnectionManager
from it_eutile_utils_log.LogManager import LogManager
from it_eutile_utils_csvmanager.CsvManager import CsvManager
#
#inizializzazione e apertura file di log
date=datetime.datetime.now()
htmlMode=''
log = LogManager('E_te422', Constants.getDebugMode(),date,htmlMode)
#creazione oggetto di connessione Oracle
conn = ConnectionManager('E_Temksv',log)
#inizializzazione e apertura file CSV
mycsv = CsvManager('everh',';',False)
#nome programma
log.testata("aggiornamento Z_TE422" )

cursor = conn.conn.cursor()
cur_s1 = conn.conn.cursor()
cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYYMMDD HH24:MI:SS'")
#
sap_conn=pysap.Rfc_connection(conn_file='sapconn.ini',conn_name='IAQ')
sap_conn.open()
#
campi_temksv = ['mandt', 'termschl', 'portion']
Exemplo n.º 4
0
'''
Created on 15/gen/2013

@author: Stefano Tizianel
'''
import datetime
import pysap
from it_eutile_utils_properties.Constants import Constants
from it_eutile_utils_database.ConnectionManager import ConnectionManager
from it_eutile_utils_log.LogManager import LogManager
from it_eutile_utils_csvmanager.CsvManager import CsvManager
#
#inizializzazione e apertura file di log
date=datetime.datetime.now()
htmlMode=''
log = LogManager('temksv', Constants.getDebugMode(),date,htmlMode)
#creazione oggetto di connessione Oracle
conn = ConnectionManager('E_Temksv',log)
#inizializzazione e apertura file CSV
mycsv = CsvManager('E_Temksv',';',False)
#nome programma
log.testata("aggiornamento Temksv - ACCOUNT" )

cursor = conn.conn.cursor()
cur_s1 = conn.conn.cursor()
cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYYMMDD HH24:MI:SS'")
#
sap_conn=pysap.Rfc_connection(conn_file='sapconn.ini',conn_name='SDI_VPN')
sap_conn.open()
#
campi_temksv = ['mandt', 'firma', 'object','oldkey','newkey']
Exemplo n.º 5
0
        ("select legacy, tipo, operand, prog                        from facts_f_dema a      where a.legacy = :key", "select legacy, tipo, ab, bis, lmenge                                                     from facts_v_dema a       where a.legacy = :key and a.prog = :prog"),
        ("select legacy, tipo, operand, ' ', timbasis, timtyp, prog from facts_f_tqua a      where a.legacy = :key", "select legacy, tipo, ab, bis, menge,    tarifart, kondigr                                from facts_v_tqua a       where a.legacy = :key and a.prog = :prog"),
        ("select legacy, tipo, operand, prog                        from facts_f_qprice a    where a.legacy = :key", "select legacy, tipo, ab, bis, preis,    prsbtr,   waers,    tarifart, kondgir            from facts_v_qprice a     where a.legacy = :key and a.prog = :prog"),
        ("select legacy, tipo, operand, prog                        from facts_f_factor a    where a.legacy = :key", "select legacy, tipo, ab, bis, factor,   tarifart, kondigr                                from facts_v_factor a     where a.legacy = :key and a.prog = :prog"),
        ("select legacy, tipo, operand, prog                        from facts_f_flag   a    where a.legacy = :key", "select legacy, tipo, ab, bis, boolkz,   tarifart, kondigr                                from facts_v_flag a       where a.legacy = :key and a.prog = :prog"),
        ("select legacy, tipo, operand, prog                        from emg_facts_integer a where a.legacy = :key", "select legacy, tipo, ab, bis, integer4, tarifart, kondigr                                from emg_value_integer a  where a.legacy = :key and a.prog = :prog"),
        ("select legacy, tipo, operand, prog                        from facts_f_rate_type a where a.legacy = :key", "select legacy, tipo, ab, bis, tarifart, kondigr                                          from facts_v_rate_type a  where a.legacy = :key and a.prog = :prog"),
        ("select legacy, tipo, operand, prog                        from facts_f_lpri   a    where a.legacy = :key", "select legacy, tipo, ab, bis, preis, tarifart, kondgir                                  from facts_v_lprice a     where a.legacy = :key and a.prog = :prog"),
        ("select legacy, tipo, operand, prog                        from facts_f_tpri   a    where a.legacy = :key", "select legacy, tipo, ab, bis, preis,    prsbtr,   waers,    tarifart, kondgir            from facts_v_tprice a     where a.legacy = :key and a.prog = :prog"),
        ("select legacy, tipo, operand, prog                        from facts_f_udef   a    where a.legacy = :key", "select legacy, tipo, ab, bis, udefval1, udefval2, udefval3, udefval4, tarifart, kondgir  from facts_v_udef a       where a.legacy = :key and a.prog = :prog")]
date=datetime.datetime.now()
htmlMode=''
#-----------------------------------------------------------------
#  
#inizializzazione e apertura file di log
log = LogManager('E_adrstreet_geolab', Constants.getDebugMode(),date,htmlMode)
#                
#inizializzazione e apertura file emigall
mycsv = CsvManager('adrstreet_geolab','\t',False)
            
#creazione oggetto di connessione Oracle
conn = ConnectionManager('adrstreet_geolab',log)

#nome programma
log.testata(" creazione file strade da geolab")

#cursori
cur_s1 = conn.conn.cursor()
cur_s2 = conn.conn.cursor()
cur_s3 = conn.conn.cursor()
#select principale
Exemplo n.º 6
0
from it_eutile_utils_database.ConnectionManager import ConnectionManager
from it_eutile_utils_log.LogManager import LogManager
from it_eutile_utils_csvmanager.CsvManager import CsvManager
#
stat_finale = '''
select t.cd_intestatario, t.s_fattura_def, t.s_boll_post
  from dbi_user.rpl_anu_t_documenti t,
  sapsr3.but000@sap_iap z --partner z
 where t.s_boll_post is not null
 and lpad(t.cd_intestatario,10,'0') = lpad(z.partner,10,'0')
      
'''
#inizializzazione e apertura file di log
date=datetime.datetime.now()
htmlMode=''
log = LogManager('E_bollettini', Constants.getDebugMode(),date,htmlMode)
#creazione oggetto di connessione Oracle
conn = ConnectionManager('E_interazioni',log)
#inizializzazione e apertura file CSV
mycsv = CsvManager('Bollettini',';',False)
#nome programma
log.testata("creazione csv Bollettini" )

cursor = conn.conn.cursor()
cur_s1 = conn.conn.cursor()
cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYYMMDD HH24:MI:SS'")
#cursor.execute("ALTER SESSION SET NLS_NUMERIC_CHARACTERS = ',.'")
#
#select principale
cur_s1.execute(stat_finale)
Exemplo n.º 7
0
       v.indprov,
       decode(v.indnazi, 'ITALIA', 'IT', 'SAN MARINO', 'SM', 'IT'),
       t.anmte,
       acdfi,
       apiva
  from dbi_user.ifc_sap_anagrclienti   t,
       dbi_user.ifc_sap_anagrindirizzi b,
       v_indirizzi                     v
 where b.indcli = t.acdan
   and atipoentita = 'PROSPECT'
   and b.indprog = v.indprog
'''
#inizializzazione e apertura file di log
date=datetime.datetime.now()
htmlMode=''
log = LogManager('E_Prospects', Constants.getDebugMode(),date,htmlMode)
#creazione oggetto di connessione Oracle
conn = ConnectionManager('E_Prospects',log)
#inizializzazione e apertura file CSV
mycsv = CsvManager('prospects',';',False)
#nome programma
log.testata("creazione csv Prospects" )

cursor = conn.conn.cursor()
cur_s1 = conn.conn.cursor()
cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYYMMDD HH24:MI:SS'")
#

#select principale
cur_s1.execute(stat_finale)
Exemplo n.º 8
0
  left outer join sapsr3.temksv@sap_iaq z3
    on (z3.oldkey = b.cd_entita_fatt || '-' || B.CUSTOMER_TRX_ID and z3.object = 'PAYMENT'), 
       sapsr3.fkkvkp@sap_iaq p, 
       sapsr3.temksv@sap_iaq z, 
       sapsr3.temksv@sap_iaq z2
 where a.customer_trx_id = b.customer_trx_id
   and b.cd_entita_fatt = z.oldkey
   and z.object = 'ACCOUNT'
   and z2.oldkey = b.cd_entita_fatt || '-' || B.CUSTOMER_TRX_ID
   and z2.object = 'DOCUMENT'
   and z.newkey = p.vkont
'''
#inizializzazione e apertura file di log
date=datetime.datetime.now()
htmlMode=''
log = LogManager('E_FactorPartite', Constants.getDebugMode(),date,htmlMode)
#creazione oggetto di connessione Oracle
conn = ConnectionManager('E_FactorPartite',log)
#inizializzazione e apertura file CSV
mycsv = CsvManager('factorPartite',';',False)
#nome programma
log.testata("creazione csv Partite Factor" )

cursor = conn.conn.cursor()
cur_s1 = conn.conn.cursor()
cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYYMMDD HH24:MI:SS'")
#

#select principale
cur_s1.execute(stat_finale)
Exemplo n.º 9
0
from it_eutile_utils_database.ConnectionManager import ConnectionManager
from it_eutile_utils_log.LogManager import LogManager
#-----------------------------------------------------------------
mainSelect="select * from gas_facts_key"
lfacts=[("select legacy, tipo, operand, prog                       from emg_facts_quant a    where a.legacy = :key", "select legacy, tipo, ab, bis, menge, tarifart, kondigr                                   from emg_value_quant a    where a.legacy = :key and a.prog = :prog"),
        ("select legacy, tipo, operand, prog                         from gas_facts_f_qprice a    where a.legacy = :key", "select legacy, tipo, ab, bis, preis,    prsbtr,   waers,    tarifart, kondgir            from gas_facts_v_qprice a     where a.legacy = :key and a.prog = :prog"),
        ("select legacy, tipo, operand, prog                        from gas_facts_f_factor a    where a.legacy = :key group by legacy, tipo, operand, prog", "select legacy, tipo, ab, bis, to_number(factor),   tarifart, kondigr  from gas_facts_v_factor a     where a.legacy = :key and a.prog = :prog"),
        ("select legacy, tipo, operand, prog                        from emg_facts_integer a where a.legacy = :key group by legacy, tipo, operand, prog", "select legacy, tipo, ab, bis, integer4, tarifart, kondigr    from emg_value_integer a  where a.legacy = :key and a.prog = :prog"),
        ("select legacy, tipo, operand, prog                        from gas_facts_f_rate_type a where a.legacy = :key group by legacy, tipo, operand, prog", "select legacy, tipo, ab, bis, tarifart, kondigr     from gas_facts_v_rate_type a  where a.legacy = :key  and a.prog = :prog"),
        ("select legacy, tipo, operand, prog                         from gas_facts_f_udef   a    where a.legacy = :key group by legacy, tipo, operand, prog", "select legacy, tipo, ab, bis, udefval1, udefval2, udefval3, udefval4, tarifart, kondgir  from gas_facts_v_udef a       where a.legacy = :key and a.prog = :prog")]
date=datetime.datetime.now()
htmlMode=''
#-----------------------------------------------------------------
#  
#inizializzazione e apertura file di log
log = LogManager('factsgen', Constants.getDebugMode(),date,htmlMode)
#                
#inizializzazione e apertura file emigall
mycsv = CsvManager('factsgenGas','\t',False)
            
#creazione oggetto di connessione Oracle
conn = ConnectionManager('factsgen',log)

#nome programma
log.testata(" creazione csv Emigall " + 'factsgen')

#cursori
cur_s1 = conn.conn.cursor()
cur_s2 = conn.conn.cursor()
cur_s3 = conn.conn.cursor()
#select principale
Exemplo n.º 10
0
    dbi_user.IFC_SAP_CRM_INT_CONTATTI,
    sapsr3.but000@sap_caq b, --partner
    sapsr3.isu_pod@sap_caq c, --ext_ui
    sapsr3.crmm_babr_h@sap_caq d --zzvkona
WHERE
    lpad(Partner_Contatto,10,'0') = lpad(b.partner,10,'0')
AND pod = c.ext_ui
AND d.zzvkona = ca
AND Categoria_3 NOT IN ('TBD',
                        'N.A.')
AND Categoria_3 IS NOT NULL      
'''
#inizializzazione e apertura file di log
date=datetime.datetime.now()
htmlMode=''
log = LogManager('E_interazioni', Constants.getDebugMode(),date,htmlMode)
#creazione oggetto di connessione Oracle
conn = ConnectionManager('E_interazioni',log)
#inizializzazione e apertura file CSV
mycsv = CsvManager('interazioni',';',False)
#nome programma
log.testata("creazione csv Interazioni" )

cursor = conn.conn.cursor()
cur_s1 = conn.conn.cursor()
cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYYMMDD HH24:MI:SS'")
#cursor.execute("ALTER SESSION SET NLS_NUMERIC_CHARACTERS = ',.'")
#
#select principale
cur_s1.execute(stat_finale)
Exemplo n.º 11
0
'''
Created on 15/gen/2013

@author: Stefano Tizianel
'''
import datetime
import pysap
from it_eutile_utils_properties.Constants import Constants
from it_eutile_utils_database.ConnectionManager import ConnectionManager
from it_eutile_utils_log.LogManager import LogManager
from it_eutile_utils_csvmanager.CsvManager import CsvManager
#
#inizializzazione e apertura file di log
date=datetime.datetime.now()
htmlMode=''
log = LogManager('temksv', Constants.getDebugMode(),date,htmlMode)
#creazione oggetto di connessione Oracle
conn = ConnectionManager('E_Temksv',log)
#inizializzazione e apertura file CSV
mycsv = CsvManager('everh',';',False)
#nome programma
log.testata("aggiornamento Temksv" )

cursor = conn.conn.cursor()
cur_s1 = conn.conn.cursor()
cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYYMMDD HH24:MI:SS'")
#
sap_conn=pysap.Rfc_connection(conn_file='sapconn.ini',conn_name='INT2')
sap_conn.open()
#
campi_temksv = ['mandt', 'firma', 'object','oldkey','newkey']
Exemplo n.º 12
0
    Stato_Offerta ,
    testa.Motivo_Sosp_Rif ,
    Flag_Switch_Voltura ,
    Nome_Intest ,
    Cognome_Intest ,
    Codice_Fiscale ,
    Ragione_Sociale ,
    Partita_IVA ,
    Associazione_Consorzio ,
    Campagna ,
    Ufficio
'''
#inizializzazione e apertura file di log
date=datetime.datetime.now()
htmlMode=''
log = LogManager('E_Offerte_Testata', Constants.getDebugMode(),date,htmlMode)
#creazione oggetto di connessione Oracle
conn = ConnectionManager('E_Offerte_testata',log)
#inizializzazione e apertura file CSV
mycsv = CsvManager('offerte_testate',';',False)
#nome programma
#log.testata("creazione csv SR" )

cursor = conn.conn.cursor()
cur_s1 = conn.conn.cursor()
cur_s1.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYYMMDD'")
cur_s1.execute("ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYYMMDDHH24MISS'")
#cur_s1.execute("ALTER SESSION SET NLS_TIME_FORMAT = 'HHMMSS'")
cur_s1.execute("SELECT * FROM v$nls_parameters WHERE REGEXP_LIKE(parameter, 'NLS_(DATE|TIME).*')")
for rec_s1 in cur_s1:
                    print("PARAMETER: " + rec_s1[0] + " VALUE: " + rec_s1[1])
Exemplo n.º 13
0
def runSingleExtractor(self,w_gruppo=1):
    mainMasterSelect = "SELECT k.legacy,a.tipo,a.prog,k.legacy||'\t'||k.tipo||'\t'||k.anlage||'\t'||k.bis,a.intestazione,a.dettaglio FROM (select '01F_DEMA' tipo,a.prog prog ,a.legacy||'\t'||a.tipo||'\t'||a.operand intestazione ,b.legacy||'\t'||b.tipo||'\t'||b.ab||'\t'||b.bis||'\t'||b.lmenge dettaglio,a.legacy  from facts_f_dema a,facts_v_dema b where a.legacy = b.legacy and a.prog = b.prog and b.bis >'20080401' group by '01F_DEMA' ,a.prog ,a.legacy||'\t'||a.tipo||'\t'||a.operand ,b.legacy||'\t'||b.tipo||'\t'||b.ab||'\t'||b.bis||'\t'||b.lmenge,a.legacy UNION ALL select '02F_TQUA',A.PROG PROG, A.legacy||'\t'||A.tipo||'\t'||A.operand||'\t'||' '||'\t'||A.timbasis||'\t'||A.timtyp intestazione , B.legacy||'\t'||B.tipo||'\t'||B.ab||'\t'||B.bis||'\t'||B.menge||'\t'||B.tarifart||'\t'||B.kondigr dettaglio,a.legacy from facts_f_tqua a, facts_v_tqua B where a.legacy = B.legacy and a.prog = B.prog and B.bis >'20080401' group by '02F_TQUA',A.PROG , A.legacy||'\t'||A.tipo||'\t'||A.operand||'\t'||' '||'\t'||A.timbasis||'\t'||A.timtyp , B.legacy||'\t'||B.tipo||'\t'||B.ab||'\t'||B.bis||'\t'||B.menge||'\t'||B.tarifart||'\t'||B.kondigr,a.legacy  UNION ALL select '03F_QPRICE' tipo ,a.prog prog ,a.legacy||'\t'||a.tipo||'\t'||a.operand intestazione ,b.legacy||'\t'||b.tipo||'\t'||b.ab||'\t'||b.bis||'\t'||b.preis||'\t'||b.prsbtr||'\t'||b.waers||'\t'||b.tarifart||'\t'||b.kondgir dettaglio,a.legacy from facts_f_qprice a, facts_v_qprice b where a.operand !='ESQP_01_FT' and a.legacy = b.legacy and a.prog = b.prog and b.prog !='126' and b.bis >'20080401' group by '03F_QPRICE',a.prog,a.legacy||'\t'||a.tipo||'\t'||a.operand,b.legacy||'\t'||b.tipo||'\t'||b.ab||'\t'||b.bis||'\t'||b.preis||'\t'||b.prsbtr||'\t'||b.waers||'\t'||b.tarifart||'\t'||b.kondgir,a.legacy UNION ALL select '04F_FACTOR' tipo,a.prog prog, A.legacy||'\t'||A.tipo||'\t'||A.operand intestazione ,B.legacy||'\t'||B.tipo||'\t'||B.ab||'\t'||B.bis||'\t'||B.factor||'\t'||B.tarifart||'\t'||B.kondigr dettaglio,a.legacy from facts_f_factor a,facts_v_factor B "

    mainMasterSelect += " where a.legacy = b.legacy and a.prog = b.prog and b.bis >'20080401' AND b.BIS>=b.AB GROUP BY '04F_FACTOR' ,a.prog , A.legacy||'\t'||A.tipo||'\t'||A.operand,B.legacy||'\t'||B.tipo||'\t'||B.ab||'\t'||B.bis||'\t'||B.factor||'\t'||B.tarifart||'\t'||B.kondigr,a.legacy UNION ALL select '05F_FLAG' tipo,a.prog prog ,a.legacy||'\t'||a.tipo||'\t'||a.operand intestazione ,b.legacy||'\t'||b.tipo||'\t'||b.ab||'\t'||b.bis||'\t'||b.boolkz||'\t'||b.tarifart||'\t'||b.kondigr dettaglio,a.legacy from facts_f_flag   a,facts_v_flag b where a.legacy = b.legacy and b.prog = a.prog and b.bis >'20080401' group by '05F_FLAG' ,a.prog ,a.legacy||'\t'||a.tipo||'\t'||a.operand,b.legacy||'\t'||b.tipo||'\t'||b.ab||'\t'||b.bis||'\t'||b.boolkz||'\t'||b.tarifart||'\t'||b.kondigr,a.legacy UNION ALL select '06F_RATE' tipo,a.prog prog ,A.legacy||'\t'||A.tipo||'\t'||a.operand  intestazione ,b.legacy||'\t'||b.tipo||'\t'||b.ab||'\t'||b.bis||'\t'||b.tarifart||'\t'||b.kondigr dettaglio,a.legacy from facts_f_rate a, facts_v_rate b where a.legacy = b.legacy and a.prog = b.prog and b.bis >'20080401' group by '06F_RATE' ,a.prog ,A.legacy||'\t'||A.tipo||'\t'||a.operand,b.legacy||'\t'||b.tipo||'\t'||b.ab||'\t'||b.bis||'\t'||b.tarifart||'\t'||b.kondigr,a.legacy UNION ALL select '07F_LPRI' tipo,a.prog prog ,a.legacy||'\t'||a.tipo||'\t'||a.operand intestazione ,b.legacy||'\t'||b.tipo||'\t'||b.ab||'\t'||b.bis||'\t'||b.preis||'\t'||b.tarifart||'\t'||b.kondgir dettaglio,a.legacy from facts_f_lpri a,facts_v_lprice b   where a.legacy = b.legacy and a.prog = b.prog and b.bis >'20080401' GROUP BY '07F_LPRI' ,a.prog,a.legacy||'\t'||a.tipo||'\t'||a.operand,b.legacy||'\t'||b.tipo||'\t'||b.ab||'\t'||b.bis||'\t'||b.preis||'\t'||b.tarifart||'\t'||b.kondgir,a.legacy UNION ALL select '08F_TPRI' tipo,a.prog prog ,A.legacy||'\t'||a.tipo||'\t'||a.operand  intestazione ,b.legacy||'\t'||b.tipo||'\t'||b.ab||'\t'||b.bis||'\t'||b.preis||'\t'||b.prsbtr||'\t'||b.waers||'\t'||b.tarifart||'\t'||b.kondgir dettaglio,a.legacy "
    mainMasterSelect +=  " from facts_f_tpri   a, facts_v_tprice b   where a.legacy = b.legacy and a.prog = b.prog and b.bis >'20080401' GROUP BY '08F_TPRI' ,a.prog,A.legacy||'\t'||a.tipo||'\t'||a.operand,b.legacy||'\t'||b.tipo||'\t'||b.ab||'\t'||b.bis||'\t'||b.preis||'\t'||b.prsbtr||'\t'||b.waers||'\t'||b.tarifart, b.kondgir,a.legacy UNION ALL select '09F_UDEF' tipo,a.prog prog ,a.legacy||'\t'||a.tipo||'\t'||a.operand intestazione ,b.legacy||'\t'||b.tipo||'\t'||b.ab||'\t'||b.bis||'\t'||b.udefval1||'\t'||b.udefval2||'\t'||b.udefval3||'\t'||b.udefval4||'\t'||b.tarifart||'\t'||b.kondgir dettaglio,a.legacy from facts_f_udef   a,facts_v_udef b  where a.legacy = b.legacy and a.prog = b.prog and b.bis >'20080401' GROUP BY '09F_UDEF' ,a.prog,a.legacy||'\t'||a.tipo||'\t'||a.operand,b.legacy||'\t'||b.tipo||'\t'||b.ab||'\t'||b.bis||'\t'||b.udefval1||'\t'||b.udefval2||'\t'||b.udefval3||'\t'||b.udefval4||'\t'||b.tarifart||'\t'||b.kondgir,a.legacy " 
    mainMasterSelect +=  " ) a,facts_key k where k.gruppo = :gruppo and a.legacy = k.legacy ORDER BY k.legacy,a.TIPO,a.PROG"

    date=datetime.datetime.now()
    htmlMode=''
    log = LogManager('factsgen_optz_'+w_gruppo, Constants.getDebugMode(),date,htmlMode)
    #                
    #inizializzazione e apertura file emigall
    mycsv = CsvManager('factsgen_optz_'+w_gruppo,'\t',False)
                
    #creazione oggetto di connessione Oracle
    conn = ConnectionManager('factsgen_optz_'+w_gruppo,log)
    
    #nome programma
    log.testata(" creazione csv Emigall " + 'factsgen_optz_'+w_gruppo)
    
    #cursori
    cur_s1 = conn.conn.cursor()
    cur_s2 = conn.conn.cursor()
    #select principale
    cur_s1.execute(mainMasterSelect, gruppo=w_gruppo)
    log.writeInfo("----- Fine Esecuzione Query Gruppo " + w_gruppo + " -----")
    #loop sul resultset
    linesToWrite = []
    yy=1
    ctrEnde=0
    ctrTota=0
    with open(mycsv.csvFileName.replace('$s',str(yy)), 'wb') as f:
        csv.register_dialect('emigall', delimiter='\t',quotechar="", quoting=csv.QUOTE_NONE)
        dialect = csv.get_dialect('emigall')
        writer = csv.writer(f,dialect)
        w_prog_prec = ''
        w_type_prec = '' 
        w_key_prec = ''           
        for record_s1 in cur_s1:
    #        print record_s1
            w_key = record_s1[0]
            w_prog = record_s1[2]
            w_type = record_s1[1]
            if (w_key!=w_key_prec and w_key_prec!=''):
                ultima = (w_key, '&ENDE')
                linesToWrite.append(ultima)
                ctrEnde+=1
            if (w_key!=w_key_prec):
                linesToWrite.append(record_s1[3].split('\t'))
                ctrTota+=1
            if (w_key!=w_key_prec or w_prog!=w_prog_prec or w_type!=w_type_prec):
                linesToWrite.append(record_s1[4].split('\t')) #niente ultimo campo W_PROG
                ctrTota+=1
            linesToWrite.append(record_s1[5].split('\t'))
            ctrTota+=1
            w_type_prec = w_type
            w_prog_prec = w_prog
            w_key_prec = w_key
    
           
            if (ctrEnde % 1000 == 0):
                writer.writerows(linesToWrite)
                linesToWrite = []
        ultima = (w_key_prec, '&ENDE')
        linesToWrite.append(ultima)
        ctrEnde+=1
        writer.writerows(linesToWrite)
        linesToWrite=[]
                        
    #chiusura componenti
    cur_s1.close()
    cur_s2.close()
    print "Sono state scritte ",ctrEnde," strutture e per un totale di ",ctrTota," righe."
    conn.closeConnection()
    log.close()