IonicWind Software

IWBasic => Database => Topic started by: Rock Ridge Farm (Larry) on July 10, 2008, 06:56:43 AM

Title: I have broken something
Post by: Rock Ridge Farm (Larry) on July 10, 2008, 06:56:43 AM
This was working and stopped.
I have a database with one table that has 2 fields, ID - autonumber, and server - text.
I add several records to the db.
I run the following code:

POINTER pReturn,pdbx
int dbH,hSq3,id,count
istring svr[255]

   pReturn=dbConnect("Microsoft Access Driver (*.mdb)","test.mdb",";")
   IF pReturn=NULL
      MESSAGEBOX 0,"Could not connect to OSAA database\n\nPlease check the OSAA Database path, and restart OSAA","Open Database error",@MB_ICONSTOP
     
   ENDIF
   hSq3=dbExecSQL(pReturn,"SELECT * FROM zzz ORDER BY ID")
   IF LEN(dbGetErrorCode(hSq3))
MESSAGEBOX 0,dbGetErrorText(hSq3),dbGetErrorCode(hSq3)
   ENDIF
IF DBGETLAST(hSq3)
dbBindVariable(hSq3,1,id)
dbBindVariable(hSq3,2,svr)
ELSE
MESSAGEBOX 0,"Failed to get last server","ERROR"
ENDIF
MESSAGEBOX 0,str$(id),"debug"
MESSAGEBOX 0,svr,"debug"
count=dbCardinality(pReturn,"zzz")
MESSAGEBOX 0,str$(count),"debug"

It always returns 0 for the ID value. The cardnality returns the number of records.
What am I doing wrong?
Title: Re: I have broken something
Post by: LarryMc on July 10, 2008, 09:02:34 AM
attach a copy of your "test.mdb" and I'll see if I can make it work.

I do notice that hSq3 is declared as an int instead of an uint but don't know if that is the problem.

Larry

Title: Re: I have broken something
Post by: Rock Ridge Farm (Larry) on July 10, 2008, 09:15:25 AM
It would be eaiser for you to make a new db and add the one table.
Table zzz has 2 fields as described above.
You can add data when you create the db.
An empty db is still large (~30K).
If you can not - I will email it to you.
Title: Re: I have broken something
Post by: LarryMc on July 10, 2008, 09:38:17 AM
Your problem is with this section:

IF DBGETLAST(hSq3)
    dbBindVariable(hSq3,1,id)
    dbBindVariable(hSq3,2,svr)
ELSE
    MESSAGEBOX 0,"Failed to get last server","ERROR"
ENDIF

You're trying to get the last record of the results before you are binding the variables which means "0" is the correct result for what you are doing.

Change it to this and it should work:
If hSq3
    dbBindVariable(hSq3,1,id)
    dbBindVariable(hSq3,2,svr)
    DBGETLAST(hSq3)
ELSE
    MESSAGEBOX 0,"Failed to get last server","ERROR"
ENDIF

Title: Re: I have broken something
Post by: Rock Ridge Farm (Larry) on July 11, 2008, 08:00:08 AM
That fixed it - owe you a big thanks.
Not sure when I made the change that broke it - must have been when
I was cleaning up the code.
Title: Re: I have broken something
Post by: Allan on July 11, 2008, 07:34:59 PM
Found a FREE application for repairing MDB.

http://www.softales.com/index_software.php?list=61 (http://www.softales.com/index_software.php?list=61)

Might be of interest.