Page 1 of 1

Posted: Thu Sep 26, 2002 1:53 pm
by BackupUser
Restored from previous forum. Originally posted by ojahier.

I dont undertand what goes on with my purebasic debugger...after a part a code well executed (in the beginning the debugger indicate correctly all the line code executed )but after it's begin to loop marking all line code ,lines not really executed ??!
I verificate the identation (il else while wend...), it's seems ok.
I think thats the origin of the problem are perhaps the database access (the external instruction sql generated as freehandle ??!!) but i'm not sure.
What do you think of ?

------------------------------------------
XIncludeFile "convmontant.pb"
XIncludeFile "addMontant.pb"

Gosub Inipgm
Gosub iniDB
Gosub AnalyseDriver

If ReadFile(0, FichierEntree.s)
While Eof(0) = 0
tt$.s = ReadString()
Gosub alimRub

If compte.s=cpt$
Input()
If code_enr.s="01"
Anc_solde.s=Montant.s
Else
If code_enr.s="04"
If cd_AFB.s="01"
Gosub Lect_database
;B_emi_num_chq$="0043570"
If numchq.s=B_emi_num_chq$
Input()
If mt_mvt.s=B_emi_montant.s
;Test si lettrage fait
If B_emi_emet.s "L"
; zone lettrée => B_emi_emet.s='L'
Gosub Lettrage_DB
If DatabaseQuery(Command$)

If cd_BNPP.s="0001"
nb1.l=nb1.l+1
LCH_let_cpt.s=AddString(LCH_let_cpt.s,mt_mvt.s)
Else
If cd_BNPP.s="0002"
nb11.l=nb11.l+1
LCH_let_gui.s=AddString(LCH_let_gui.s,mt_mvt.s)

Else
nb3.l=nb3.l+1
ligne_ano.s="chq débité avec cd ope BNPP non répertorié"+""+cd_BNPP
Gosub Ecr_ano
EndIf
EndIf

Else
Gosub PB_maj
EndIf
Else
;cas d'un chq déjà léttré
nb3.l=nb3.l+1
ligne_ano.s="chq débité déjà lettré (second débit) "+numchq.s+" "+mt_mvt.s
Gosub Ecr_ano
EndIf
Else
; cas d'un chq débité avec un montant du montant émis
;B_sec_code_ano (zone à toper)
Gosub Topage_DB ; zone topée => B_sec_code_ano='A'
If DatabaseQuery(Command$)
nb2.l=nb2.l+1
LCH_non_let.s=AddString(LCH_non_let.s,mt_mvt.s)
ligne_ano.s="mnt débité mnt émis "+numchq.s+" "+mt_mvt.s+" "+B_emi_montant.s
Gosub Ecr_ano
Else
;Gosub PB_maj
EndIf
EndIf
Else
nb3.l=nb3.l+1
LCH_div_D.s=AddString(LCH_div_D.s,mt_mvt.s)
ligne_ano.s="chq débité non émis "+numchq.s
Gosub Ecr_ano

EndIf
Else
If cd_AFB.s="99"
nb4.l=nb4.l+1
LCH_div_C.s=AddString(LCH_div_C.s,mt_mvt.s)
Gosub Lect_database
If numchq.s=B_emi_num_chq$
mt_mvt.s=Mid(convmontant(Montant.s),2,14)
If mt_mvt.s=B_emi_montant
;le chèque est lettré
If B_emi_emet.s="L"
;zone delettrée => B_emi_emet=' '
Gosub Delettrage_DB
If DatabaseQuery(Command$)
PrintN("delettrage")
Else
Gosub PB_maj
EndIf
Else
ligne_ano.s="régul inapropriée car opé déjà lettrée"+numchq.s
Gosub Ecr_ano
EndIf
Else
ligne_ano.s="régul inapropriée car mnt régul mnt chq émis"+numchq.s
Gosub Ecr_ano
EndIf
Else
ligne_ano.s="régul inapropriée chq non trouvé dans base chq"+numchq.s
Gosub Ecr_ano
EndIf
Else
;opération avec cd AFB "01" et "99"
Gosub Lect_database_cd
If sens.s="D"
nb3.l=nb3.l+1
LCH_div_D.s=AddString(LCH_div_D.s,mt_mvt.s)
ligne_ano.s="opération débit atypique"+numchq.s+" "+mt_mvt.s
Gosub Ecr_ano
Else
;crédit
nb4.l=nb4.l+1
LCH_div_C.s=AddString(LCH_div_C.s,mt_mvt.s)
ligne_ano.s="opération crédit atypique"+numchq.s+" "+mt_mvt.s
Gosub Ecr_ano
EndIf
EndIf
EndIf
Else

If code_enr.s="07"
Nouv_solde.s=Montant.s
EndIf





EndIf
EndIf
EndIf


Print(numchq.s)
Print(" ")
PrintN(cd_BNPP.s)


Wend
PrintN (anc_solde.s)
PrintN (Nouv_solde.s)
CloseFile(0)
CloseFile(1)

Else
MessageRequester("CPAM", "impossible d'ouvrir le fichier", #PB_MessageRequester_Ok)
EndIf

End
;---------------------
;Corps du pgm
;---------------------




;---------------------
;sous programme
;---------------------

alimRub:
compte.s=Mid(tt$.s,22,11)
code_enr.s=Mid(tt$.s,1,2)
date_oper.s=Mid(tt$.s,35,6)
Montant.s=Mid(tt$.s,91,14)
cd_AFB.s=Mid(tt$.s,33,2)
numchq.s=Mid(tt$.s,82,7)
cd_BNPP.s=Mid(tt$.s,8,4)
mt_mvt.s=Mid(convmontant(Montant.s),2,14)
Return

Inipgm:
OpenConsole()
ClearConsole()
cd4$="04"
cd1$="01"
cpt$="00016w33w76"
#Fichier=1
Fichier$ = "0108cpam2"
FichierEntree.s = "C:\dgd\CPAM\" + Fichier$ + ".txt"
nb1.l=0
nb11.l=0
nb2.l=0
nb3.l=0
nb4.l=0
LCH_let_cpt.s=""
LCH_let_gui.s=""
LCH_div_D.s=""
LCH_div_C.s=""
LCH_non_let.s=""
Anc_solde.s=""
Nouv_solde.s=""
Montant.s=""
ligne_ano.s=""
sens.s=""

Return

Ecr_ano:

If CreateFile(1, "CPAM_ano.txt")
WriteStringN(ligne_ano.s)

Else
MessageRequester("Denotage CPAM", "Error: can't write the file", 1)
End
EndIf

Return

Lect_ano:

If ReadFile(1, "CPAM_ano.txt")

First$ = Trim(ReadString()) ; trim supprime les espaces avant et après
MessageRequester("PureBasic", "Line read: "+First$, 1)

CloseFile(1)
Else
MessageRequester("Denotage CPAM", "Error: Can't read the file", 0)
EndIf

WriteStringN(Texte$)

Return

;---------------------------------------------------------------------
;Lecture base cheque
;---------------------------------------------------------------------
iniDB :

If InitDatabase() = 0
MessageRequester("Error", "Can't initialize Database (ODBC v3 or better) environment", 0)
End
EndIf

Dim DatabaseType.s(4)
DatabaseType(0) = "Unknown"
DatabaseType(1) = "Numeric"
DatabaseType(2) = "String"
DatabaseType(3) = "Float"

Return

; First, let's see which drivers are attached to the system..
;

AnalyseDriver:

If ExamineDatabaseDrivers()
While NextDatabaseDriver()
PrintN(DatabaseDriverName()+" - "+DatabaseDriverDescription())
Wend
EndIf

Return

Lect_database:

If OpenDatabase(0,"bd1.mdb","m907052","wwww0002")

Command$="select * from extract where B_emi_num_chq="+"'"+numchq.s+"'"+";"

If DatabaseQuery(Command$)


While NextDatabaseRow()
B_emi_num_chq$=GetDatabaseString(2)
B_mont.f=GetDatabaseFloat(6)
B_ms_correct.l=GetDatabaseLong(21)
B_rej_perime.l=GetDatabaseLong(57)
B_emi_benef$=GetDatabaseString(5)
B_emi_emet.s=GetDatabaseString(0)
B_emi_montant.s=Str(B_mont.f)
B_emi_montant.s=Right("00000000000000"+B_emi_montant.s, 14)

Wend
EndIf

Else
MessageRequester("Info", "Operation canceled", 0)
EndIf

Return

Lettrage_DB:

Command$="update extract set B_emi_emet='L' where B_emi_num_chq="+"'"+numchq.s+"'"+";"

Return

Delettrage_DB:

Command$="update extract set B_emi_emet=' ' where B_emi_num_chq="+"'"+numchq.s+"'"+";"

Return


Topage_DB:

Command$="update extract set B_sec_code_ano='A' where ="+"'"+numchq.s+"'"+";"

Return

PB_maj:
MessageRequester("CPAM", "Pb de maj table : arret TRT", #PB_MessageRequester_Ok)
End

Return

;---------------------------------------------------------------------
;Lecture base cd bnpp
;---------------------------------------------------------------------
Lect_database_cd:


If OpenDatabase(0,"bd1.mdb","m907052","wwww0002")
Command$="select * from cdBNPP where Code_BNP="+"'"+cd_BNPP.s+"'"+";"

If DatabaseQuery(Command$)

While NextDatabaseRow()

SENS_DEBIT.s=GetDatabaseString(2)
SENS_CREDIT.s=GetDatabaseString(3)
If SENS_DEBIT.s="débit"
sens.s="D"
Else
If SENS_CREDIT.s="crédit"
sens.s="C"
EndIf
EndIf
If sens.s "D" And sens.s "C"
MessageRequester("Info", "Operation canceled: sens comptable non déterminé", 0)
End
EndIf

Wend
EndIf

Else
MessageRequester("Info", "Operation canceled", 0)
EndIf

Return

----------------------------
source of addmontant :
Structure CharType
Char.b
EndStructure

Procedure.s AddString(arg1.s, arg2.s)
DefType.CharType *p1, *p2, *pend1, *pend2
sum.s = "" : carry.l = 0
arg1 = "0" + arg1 : arg2 = "0" + arg2
a1 = FindString(arg1, ".", 1)
a2 = FindString(arg2, ".", 1)
If a1 Or a2
If a1 : l1 = Len(arg1) - a1 : Else : arg1 + "." : EndIf
If a2 : l2 = Len(arg2) - a2 : Else : arg2 + "." : EndIf
If l1 l2
If l1 > l2
diff = l1 - l2
sum = Right(arg1, diff)
arg1 = Left(arg1, Len(arg1)-diff)
ElseIf l2 > l1
diff = l2 - l1
sum = Right(arg2, diff)
arg2 = Left(arg2, Len(arg2)-diff)
EndIf
EndIf
EndIf
*pend1 = @arg1 : *p1 = *pend1 + Len(arg1) - 1
*pend2 = @arg2 : *p2 = *pend2 + Len(arg2) - 1
Repeat
If *p1\Char = '.'
sum = "." + sum
Else
tmp = *p1\Char - '0' + *p2\Char - '0' + carry
If tmp >= 10
carry = 1
tmp - 10
Else
carry = 0
EndIf
sum = Chr(tmp + '0') + sum
EndIf
If *p1 > *pend1 : *p1 - 1 : EndIf
If *p2 > *pend2 : *p2 - 1 : EndIf
Until *p1 = *pend1 And *p2=*pend2
If carry
sum = Chr(carry + '0') + sum
EndIf
ProcedureReturn sum
EndProcedure

; Example 1
;b1.s = "1.123456789"
;b2.s = "2.111111111"

;sum.s = AddString(b1, b2)
;Debug b1+" + "+b2+" = "+sum

; Example 2
;b1.s = "999999999"
;b2.s = "1"

;sum.s = AddString(b1, b2)
;Debug b1+" + "+b2+" = "+sum

;Example 3
;b1.s = "12345678901234"
;b2.s = "1501"

;sum.s = AddString(b1, b2)
;Debug b1+" + "+b2+" = "+sum


-------------------------------
Commo estan? Bien ? Me alegro!
(registered PureBasic user)

Posted: Thu Sep 26, 2002 2:35 pm
by BackupUser
Restored from previous forum. Originally posted by Paul.

There is no way to test your program becasue you have Includes that you haven't posted (as well as the actual database) but one thing you might want to look at...

When using a database, usually you open it once at the beginning of your program and close it at the end when you are exiting. (no reason to open/close, open/close continuously... it slows everything down too)

By just glancing over your code, I notice that you open the database in a loop, do your query but never close it. You probably return to this loop to do another query at some time and try opening the database again? (when it is already open)

Just a thought :)



also... this line:
Command$="select * from cdBNPP where Code_BNP="+"'"+cd_BNPP.s+"'"+";"

can be done this way:
Command$="select * from cdBNPP where Code_BNP='"+cd_BNPP.s+"';"





----------
Visit the PB Resources Site at http://www.reelmediaproductions.com/pb

Posted: Thu Sep 26, 2002 4:03 pm
by BackupUser
Restored from previous forum. Originally posted by ojahier.

Thanks for Paul :

I test the modification but there is no way by now.

I post the final of the access log ?!!
I've changed the way of reading the database and cut the loop of readnext for get only one access (without loop of fetch). The program do the same thing : after the first access there is a unfinished loop independant of the database reading (as proove it the access.log posted here):
this is almost all the log witout the beginning :

PureBasic123145 fff76cf7:fffa67cf EXIT SQLExecDirect with return code 0 (SQL_SUCCESS)
HSTMT 0x00b607a0
UCHAR * 0x0105f25c [ 52] "select * from extract where B_emi_num_chq='0043570';"
SDWORD 52

PureBasic123145 fff76cf7:fffa67cf ENTER SQLFetch
HSTMT 0x00b607a0

PureBasic123145 fff76cf7:fffa67cf EXIT SQLFetch with return code 0 (SQL_SUCCESS)
HSTMT 0x00b607a0

PureBasic123145 fff76cf7:fffa67cf ENTER SQLGetData
HSTMT 0x00b607a0
UWORD 3
SWORD 1
PTR 0x00f60078
SDWORD 4096
SDWORD * 0x0063fdbc

PureBasic123145 fff76cf7:fffa67cf EXIT SQLGetData with return code 0 (SQL_SUCCESS)
HSTMT 0x00b607a0
UWORD 3
SWORD 1
PTR 0x00f60078 [ 7] "0043570"
SDWORD 4096
SDWORD * 0x0063fdbc (7)

PureBasic123145 fff76cf7:fffa67cf ENTER SQLGetData
HSTMT 0x00b607a0
UWORD 7
SWORD 7
PTR
SDWORD 4
SDWORD * 0x0063fdbc

PureBasic123145 fff76cf7:fffa67cf EXIT SQLGetData with return code 0 (SQL_SUCCESS)
HSTMT 0x00b607a0
UWORD 7
SWORD 7
PTR
SDWORD 4
SDWORD * 0x0063fdbc (4)

PureBasic123145 fff76cf7:fffa67cf ENTER SQLGetData
HSTMT 0x00b607a0
UWORD 22
SWORD -16
PTR 6553024
SDWORD 4
SDWORD * 0x0063fdbc

PureBasic123145 fff76cf7:fffa67cf EXIT SQLGetData with return code 0 (SQL_SUCCESS)
HSTMT 0x00b607a0
UWORD 22
SWORD -16
PTR 6553024
SDWORD 4
SDWORD * 0x0063fdbc (4)

PureBasic123145 fff76cf7:fffa67cf ENTER SQLGetData
HSTMT 0x00b607a0
UWORD 58
SWORD -16
PTR 6553024
SDWORD 4
SDWORD * 0x0063fdbc

PureBasic123145 fff76cf7:fffa67cf EXIT SQLGetData with return code 0 (SQL_SUCCESS)
HSTMT 0x00b607a0
UWORD 58
SWORD -16
PTR 6553024
SDWORD 4
SDWORD * 0x0063fdbc (4)

PureBasic123145 fff76cf7:fffa67cf ENTER SQLGetData
HSTMT 0x00b607a0
UWORD 6
SWORD 1
PTR 0x00f60078
SDWORD 4096
SDWORD * 0x0063fdbc

PureBasic123145 fff76cf7:fffa67cf EXIT SQLGetData with return code 0 (SQL_SUCCESS)
HSTMT 0x00b607a0
UWORD 6
SWORD 1
PTR 0x00f60078 [ 35] "MLE VIALLETON STEPHANIE "
SDWORD 4096
SDWORD * 0x0063fdbc (35)

PureBasic123145 fff76cf7:fffa67cf ENTER SQLGetData
HSTMT 0x00b607a0
UWORD 1
SWORD 1
PTR 0x00f60078
SDWORD 4096
SDWORD * 0x0063fdbc

PureBasic123145 fff76cf7:fffa67cf EXIT SQLGetData with return code 0 (SQL_SUCCESS)
HSTMT 0x00b607a0
UWORD 1
SWORD 1
PTR 0x00f60078 [ 1] "L"
SDWORD 4096
SDWORD * 0x0063fdbc (1)

PureBasic123145 fff76cf7:fffa4e7f ENTER SQLFreeHandle
SQLSMALLINT 3
SQLHANDLE 0x00b607a0

PureBasic123145 fff76cf7:fffa4e7f EXIT SQLFreeHandle with return code 0 (SQL_SUCCESS)
SQLSMALLINT 3
SQLHANDLE 0x00b607a0

PureBasic123145 fff76cf7:fffa4e7f ENTER SQLDisconnect
HDBC 0x00b60194

PureBasic123145 fff76cf7:fffa4e7f EXIT SQLDisconnect with return code 0 (SQL_SUCCESS)
HDBC 0x00b60194

PureBasic123145 fff76cf7:fffa4e7f ENTER SQLFreeHandle
SQLSMALLINT 2
SQLHANDLE 0x00b60194

PureBasic123145 fff76cf7:fffa4e7f EXIT SQLFreeHandle with return code 0 (SQL_SUCCESS)
SQLSMALLINT 2
SQLHANDLE 0x00b60194



-------------------------------
Commo estan? Bien ? Me alegro!
(registered PureBasic user)

Posted: Thu Sep 26, 2002 4:52 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.
Originally posted by ojahier

I dont undertand what goes on with my purebasic debugger...after a part a code well executed (in the beginning the debugger indicate correctly all the line code executed )but after it's begin to loop marking all line code ,lines not really executed ??!
I verificate the identation (il else while wend...), it's seems ok.
I think thats the origin of the problem are perhaps the database access (the external instruction sql generated as freehandle ??!!) but i'm not sure.
What do you think of ?
When you use include files you must be aware that you cant follow the code inside the included file correctly in the bebugger window, i.e. you don't see the lines inside the include file in the debugger window -you see some code section in the main file being executed, but they're not what's really being executed. You can try by having all code in one file to see better what's going on..

Posted: Fri Sep 27, 2002 9:13 am
by BackupUser
Restored from previous forum. Originally posted by ojahier.

Thanks a lot for pupil,
effectivly it's a lot of more easy to extend the Xincludefile for a better view.
Now i saw that after :
a few loop reading correctly the file whithout database access
at the first database access performed, the next file record read is empty !! ?
I see now that the pointer - loc() - of the file, in the case i use two record of 122 bytes, get the result 122 and 244 without read the database and get 122 and then 62 !!! when there is a database access between the two access file.

I understood only now!!

The problem was due of my use of file reading instructions ('cause I use two file out !)

Only rest one problem for closedatabase instruction but... this don't seems to generate any problem ?!

-------------------------------
Commo estan? Bien ? Me alegro!
(registered PureBasic user)