Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CursorAdapter & Fox Tables (Update)
Message
De
21/04/2010 16:54:28
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01461271
Message ID:
01461407
Vues:
197
>I summarize the status of my situation and the problem i find in using CurosrAdapter class to access fox tables.
>I have a table, included in a dbc database; this table has 128 fields and for all fields i have a default value to avoid null values..
>I create a class, Test4.prg, that i attach to this message.
>If in this class i select all fields of my table i have no problem in modify or delete records, but when i insert a new record i have an error message that let me to select if revert data; if i revert data, and obviously lost new data inserted, and retry a new insert operation, it runs correctly and i can insert the new record and other new records.....Since aftre the error message and the revert operation i can do anything in this table...
>I have tested if the problem was in number of records, but it wasn't. I have seen that the problem are 3 fields (two date fields and one datetime field), but in the table i have already date fields and these don't show problems when insertinf a new record.
>If i reduce the number of fields in the cursor i obtain, and in this reduced cursor i insert the fields that create problem, i have no problem and i can insert new record without error. If i add new date field in the table and select all the fields i have the error, if i add a character fields i have not the error....
>Ok, i can try to work with limited number of fields.....but i 'd like to understand where is the problem before start a new application with this class and this method to access data in fox tables....
>I thank to all i have already attempt to hep me with this problem...and i hope something can give me a suggest to overtake this problem...
>

Would you try this:
Public oApp
oApp = Createobject('MyApp')

loTest = Createobject('clifor')
loTest.CursorFill(.T.)
Browse
Tableupdate(2,.T.,'Anag')

Procedure e2n
  Lparameters tuValue
  If Empty(m.tuValue) Or (Vartype(m.tuValue) = 'C' And Trim(m.tuValue) == '{}')
    Return .Null.
  Else
    Return m.tuValue
  Endif
Endproc

Define Class myApp As Custom
  DataMode = "VFP"
  DataConnectionString = 'Provider=VFPOLEDB;Data Source=C:\Programmi\ApprodoGlobe\Aziende\Acut'
Enddefine

Define Class clifor As cabase Of 'cabase.prg'
  BatchUpdateCount = 1

  Alias = "Anag"
  KeyFieldList = "CODE"
  Tables = "Test4"
  Name = "CliFor"

  SelectCmd = "select CODE, RAS1, INDI, LOCA, CAP, PROV, STAT, PCON, CFIS, PIVA, TEL1, TEL2, CELL, TFAX, "+;
    "MAIL, ABI, CAB, CTCO, CPAG, NSPE, ZONA, DIKM, DIHO, CTVE, CTRI, CIVA, LETT, DLET, PROT, DPRO, CAGE, DIVI, "+;
    "TRAS, VETT, CDES, PORT, SETT, CATE, LIST, PLIS, SCO1, SCO2, PAGE, MES1, MES2, SDAY, ALARM, LBLO, LMOV, TFATT, "+;
    "TRAT, INTE, DAT1, DAT2, FIDO, CONF, COMM, ASS, RICO, RICS, RICA, RICM, FIL2, FIL3, FIL4, FIL5, FIL6, PPR, CEE, "+;
    "FOL, CIN, CBIC, CCP, CIFA, CINT, COR, IBAN, IWEB, LFA, NAL, NAP,NOP, NTE, PPG, PR1, PR2, PR3, RCP, GCRI, SOSP, NLIN, NOFT, EAN, ACTI, CEVE, "+;
    "CORA,DEAL, PROM, SCAT, TEL3, TIPO, CCLA, EVID, UEID, FOLDER, IMP, LDA, NAT, STI, ARS, PWD, TIPP,UML, UPD, USR"+;
    ", SITU, LNAS, SES, RSR, REGI, CLAS, RIV, CCAP, CODC, DNAS from test4"
  *!*		",DNAS, DAT5, LUP, DAAZ"

  CursorSchema = "CODE C(6), RAS1 C(40), INDI C(40), LOCA C(40), CAP I, "+;
    "PROV C(2), STAT C(3), PCON C(40), CFIS C(16), PIVA Y, TEL1 C(15), TEL2 C(15), "+;
    "CELL C(15), TFAX C(15), MAIL C(50), ABI I, CAB I, CTCO C(15), CPAG C(3), NSPE N(2, 0), "+;
    "ZONA C(3), DIKM I, DIHO N(5, 1), CTVE I, CTRI I, CIVA C(3), LETT C(10), DLET D, PROT C(10), "+;
    "DPRO D, CAGE C(3), DIVI C(3), TRAS C(3), VETT C(3), CDES C(6), PORT C(3), SETT C(3), "+;
    "CATE C(3), LIST C(3), PLIS C(3), SCO1 N(5, 1), SCO2 N(5, 1), PAGE N(5, 1), MES1 N(3, 0), "+;
    "MES2 N(3, 0), SDAY N(3, 0), ALARM C(40), LBLO L, LMOV L, TFATT C(3), TRAT C(1), INTE C(1), "+;
    "DAT1 D, DAT2 D, FIDO I, CONF M, COMM M, ASS M, RICO N(3, 0), RICS N(3, 0), RICA N(3, 0), "+;
    "RICM N(4, 0), FIL2 Y, FIL3 C(10), FIL4 C(10), FIL5 C(3), FIL6 C(2), PPR N(3, 0), CEE C(2), "+;
    "FOL C(40), CIN C(1), CBIC C(34), CCP C(15), CIFA C(6), CINT C(6), COR Y, IBAN C(34), "+;
    "IWEB C(50), LFA L, NAL Y, NAP Y, NOP Y, NTE Y, PPG Y, PR1 C(40), PR2 C(40), "+;
    "PR3 C(40), RCP C(30), GCRI N(4, 0), SOSP L, NLIN N(2, 0), NOFT L, EAN C(7), ACTI C(3),CEVE C(3), CORA C(6), DEAL C(3), PROM C(3), SCAT C(3), TEL3 C(15), TIPO C(1), CCLA C(2),EVID I, UEID I, FOLDER C(40), IMP L, LDA L, NAT L, STI L"+;
    ", ARS L, PWD C(15), TIPP N(2, 0), UML C(50), UPD L, USR C(20)"+;
    ", SITU C(2), LNAS C(40), "+;
    "SES C(1), RSR C(30), REGI C(3), CLAS C(1), RIV C(20), CCAP C(10), CODC C(10), DNAS D"
  *!*		"DNAS D, DAT5 D, LUP T , DAAZ D"

  UpdatableFieldList = "CODE, RAS1, INDI, LOCA, CAP, PROV, STAT, PCON, CFIS, PIVA, TEL1, TEL2, CELL, TFAX, "+;
    "MAIL, ABI, CAB, CTCO, CPAG, NSPE, ZONA, DIKM, DIHO, CTVE, CTRI, CIVA, LETT, DLET, PROT, DPRO, CAGE, DIVI, "+;
    "TRAS, VETT, CDES, PORT, SETT, CATE, LIST, PLIS, SCO1, SCO2, PAGE, MES1, MES2, SDAY, ALARM, LBLO, LMOV, TFATT, "+;
    "TRAT, INTE, DAT1, DAT2, FIDO, CONF, COMM, ASS, RICO, RICS, RICA, RICM, FIL2, FIL3, FIL4, FIL5, FIL6, PPR, CEE, "+;
    "FOL, CIN, CBIC, CCP, CIFA, CINT, COR, IBAN, IWEB, LFA, NAL, NAP"+;
    ",NOP, NTE, PPG, PR1, PR2, PR3, RCP, GCRI, SOSP, NLIN, NOFT, EAN, ACTI, CEVE, CORA,DEAL, PROM, SCAT, TEL3, TIPO, CCLA"+;
    ", EVID, UEID, FOLDER, IMP, LDA, NAT, STI, ARS, PWD, TIPP,UML, UPD, USR, SITU, LNAS, SES, RSR, REGI, CLAS, RIV, CCAP, CODC, DNAS"
  *!*		",DNAS, DAT5, LUP, DAAZ"

  UpdateNameList = "CODE test4.code, RAS1 test4.ras1, INDI test4.indi, LOCA test4.loca, CAP test4.CAP, PROV test4.PROV, "+;
    "STAT test4.STAT, PCON test4.PCON, CFIS test4.CFIS, PIVA test4.PIVA, TEL1 test4.TEL1, TEL2 test4.TEL2, CELL test4.CELL, "+;
    "TFAX test4.TFAX, MAIL test4.MAIL, ABI test4.ABI, CAB test4.CAB, CTCO test4.CTCO, CPAG test4.CPAG, NSPE test4.NSPE, "+;
    "ZONA test4.ZONA, DIKM test4.DIKM, DIHO test4.DIHO, CTVE test4.CTVE, CTRI test4.CTRI, CIVA test4.CIVA, LETT test4.LETT, "+;
    "DLET test4.DLET, PROT test4.PROT, DPRO test4.DPRO, CAGE test4.CAGE, DIVI test4.DIVI, TRAS test4.TRAS, VETT test4.VETT, "+;
    "CDES test4.CDES, PORT test4.PORT, SETT test4.SETT, CATE test4.CATE, LIST test4.LIST, PLIS test4.PLIS, SCO1 test4.SCO1, "+;
    "SCO2 test4.SCO2, PAGE test4.PAGE, MES1 test4.MES1, MES2 test4.MES2, SDAY test4.SDAY, ALARM test4.ALARM, LBLO test4.LBLO, "+;
    "LMOV test4.LMOV, TFATT test4.TFATT, TRAT test4.TRAT, INTE test4.INTE, DAT1 test4.DAT1, DAT2 test4.DAT2, FIDO test4.FIDO, "+;
    "CONF test4.CONF, COMM test4.COMM, ASS test4.ASS, RICO test4.RICO, RICS test4.RICS, RICA test4.RICA, RICM test4.RICM, "+;
    "FIL2 test4.FIL2, FIL3 test4.FIL3, FIL4 test4.FIL4, FIL5 test4.FIL5, FIL6 test4.FIL6, PPR test4.PPR, CEE test4.CEE, "+;
    "FOL test4.FOL, CIN test4.CIN, CBIC test4.CBIC, CCP test4.CCP, CIFA test4.CIFA, CINT test4.CINT, COR test4.COR, "+;
    "IBAN test4.IBAN, IWEB test4.IWEB, LFA test4.LFA, NAL test4.NAL, NAP test4.NAP, NOP test4.NOP, NTE test4.NTE, "+;
    "PPG test4.PPG, PR1 test4.PR1, PR2 test4.PR2, PR3 test4.PR3, RCP test4.RCP, GCRI "+;
    "test4.GCRI, SOSP test4.SOSP, NLIN "+;
    "test4.NLIN, NOFT test4.NOFT, EAN test4.EAN, ACTI test4.ACTI, CEVE test4.CEVE, CORA test4.CORA,DEAL test4.DEAL, PROM test4.PROM, SCAT test4.SCAT, TEL3 test4.TEL3, TIPO test4.TIPO, CCLA test4.CCLA"+;
    ", EVID test4.EVID, "+;
    "UEID test4.UEID, FOLDER test4.FOLDER, IMP test4.IMP, LDA test4.LDA, NAT test4.NAT, STI test4.STI"+;
    ",ARS test4.ARS, PWD test4.PWD, TIPP test4.TIPP, UML test4.UML, UPD test4.UPD, USR test4.USR"+;
    ",SITU test4.SITU, LNAS test4.LNAS, SES test4.SES, RSR test4.RSR, REGI test4.REGI, CLAS test4.CLAS, "+;
    "RIV test4.RIV, CCAP test4.CCAP, CODC test4.CODC, DNAS test4.DNAS"
  *!*		", DNAS test4.DNAS, DAT5 test4.DAT5 , LUP test4.LUP , DAAZ test4.DAAZ"

  ConversionFunc = "DLET E2N,DPRO E2N,DAT1 E2N,DAT2 E2N,DNAS E2N"

Enddefine
* CaBase.Prg:
Define Class CaBase As CursorAdapter
  Tag = oApp.DataConnectionString
  DataSourceType = "ADO"
  Flags = 0
  CompareMemo = .F.
  FetchMemo = .T.
  FetchAsNeeded = .T.
  FetchSize = 10
  BatchUpdateCount = 100
  WhereType = 1
  AllowSimultaneousFetch = .T.
  MapVarchar = .T.
  MapBinary = .T.
  UseCursorSchema = .T.
  BufferModeOverride = 5
  FilterExpr = ''
  FilterExprMerge = ''
  Handle = 0
  lAutoOpen = .T.
  Order = ''

  Procedure AutoOpen
    If This.lAutoOpen
      If Not Pemstatus(This, '__VFPSetup', 5)
        This.AddProperty('__VFPSetup', 1)
        This.Init()
      Endif
    Endif
  Endproc

  Procedure Init(tcAlias,tcParamBlock,tcOrder)
    Local lnPcount
    lnPcount = Pcount()
    This.Tag = ''
    Local llReturn
    Do Case
      Case Not Pemstatus(This, '__VFPSetup', 5)
        This.AddProperty('__VFPSetup', 0)
      Case This.__VFPSetup = 1
        This.__VFPSetup = 2
      Case This.__VFPSetup = 2
        This.__VFPSetup = 0
        Return
    Endcase

    If !Empty(m.tcAlias)
      This.Alias = m.tcAlias
    Endif
    This.Order = Evl(m.tcOrder,'')

    Set Multilocks On
    llReturn = DoDefault()

    Store This.DataSourceType To ;
      this.InsertCmdDataSourceType, ;
      this.UpdateCmdDataSourceType, ;
      this.DeleteCmdDataSourceType

    ***<DataSource>
        Local loConnDataSource
        loConnDataSource = Createobject('ADODB.Connection')
        ***<DataSource>
        loConnDataSource.ConnectionString = oApp.DataConnectionString
        ***</DataSource>
        loConnDataSource.Open()
        If oApp.DataMode = 'VFP'
        	loConnDataSource.Execute('set null off')
        endif

        This.Datasource = Createobject('ADODB.RecordSet')
        This.Datasource.CursorLocation   = 3  && adUseClient
        This.Datasource.LockType         = 3  && adLockOptimistic
        This.Datasource.ActiveConnection = loConnDataSource
        *** End of Select connection code: DO NOT REMOVE

        loCommand = Createobject('ADODB.Command')
        loCommand.ActiveConnection = loConnDataSource
        This.AddProperty('oCommand',loCommand)
        This.UpdateCmdDataSource=loCommand
        This.InsertCmdDataSource=loCommand
        This.DeleteCmdDataSource=loCommand
    ***</DataSource>
    If !Empty(m.tcParamBlock)
      If Occurs('<p>', m.tcParamBlock) > 0
        SetCAParameters(This, m.tcParamBlock)
        This.CursorFill(.T., .F., 0, loCommand)
        This.lAutoOpen = .F.
      Else
        This.FilterExpr = m.tcParamBlock
      Endif
    Endif

    If This.__VFPSetup = 1
      This.__VFPSetup = 2
    Endif
    Return llReturn
  Endproc

  Procedure BeforeCursorFill
    Lparameters lUseCursorSchema, lNoDataOnLoad, cSelectCmd
    If !Empty(This.FilterExprMerge)
      cSelectCmd = m.cSelectCmd +" where "+Textmerge(This.FilterExprMerge)
    Else
      If !Empty(This.FilterExpr)
        cSelectCmd = m.cSelectCmd +" where "+This.FilterExpr
      Endif
    Endif
  Endproc

  Procedure AfterCursorFill
    Lparameters lUseCursorSchema, NoDataOnLoad, cSelectCmd, lResult
    CursorSetProp("Buffering",5,This.Alias)
  Endproc

  Procedure BeforeCursorRefresh
    Lparameters cSelectCmd
    Tablerevert(.T., This.Alias)
  Endproc

  Procedure AfterCursorRefresh
    Lparameters cSelectCmd, lResult
  ENDPROC
  
  Procedure PrefixOwner(tcSQL, tcPrefix, tcOwner)
	Local lnOccurance,ix, lcRest
	lnOccurance = Occurs( Upper(m.tcPrefix), Upper(m.tcSQL) )
	For ix = 1 To m.lnOccurance
		lcRest = Substr(m.tcSQL,Atc(m.tcPrefix, m.tcSQL, m.ix)+Len(m.tcPrefix))
		If Left(Ltrim(m.lcRest,1,Chr(32),Chr(13),Chr(10)),1) <> '('
			lcRest = Textmerge('[<<TRIM(m.tcOwner)>>].')+Ltrim(m.lcRest,1,Chr(32),Chr(13),Chr(10))
			tcSQL = Left(m.tcSQL,Atc(m.tcPrefix, m.tcSQL, m.ix)+Len(m.tcPrefix)) + ' ' + m.lcRest
		Endif
	Endfor
	Return m.tcSQL
ENDPROC
Enddefine
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform