Page 1 of 1

PostPosted: Sun Jun 01, 2003 12:29 pm
by mgreen
The following is a program fragment that is intended to copy a HanDBase database to a Pilot-DB database. I'm using the latest versions of each from their respective websites and Pocket Toolbox 7.5.3. The data appears to be copied successfully, but the field names (past the first one) are not set up correctly. I have other similar programs and databases with more (and different) fields that exhibit the same problem.

main() {
int i,n;
pointer p,q;
string sDB = "ICD9 Codes";
string sHDB = "ICD9-Codes";
p = Array("is,2,2");
p[0][0] = 1; p[0][1] = "ICD9";
p[1][0] = 1; p[1][1] = "ICD9Desc";
if (DBcreate(sDB,1,2,p)) {
alert("Can't create"); exit(); }
q = Array("s,2");
if (DBopen(sHDB)) {
alert("Can't open 1"); exit(); }
n = DBinfo(2,0);
for (i=0;i<n;i++) {
if (DBopen(sHDB)) {
alert("Can't open 2"); exit(); }
if (DBgetrec(i,q)) {
alert("Can't getrec"); exit(); }
if (DBopen(sDB)) {
alert("Can't open 3"); exit(); }
if (DBsetrec(-1,q)) {
alert("Can't setrec"); exit(); }
alert("All done ...");

Michael Green

PostPosted: Sun Jun 01, 2003 2:44 pm
by jstadolnik
There are 3 bugs in your code...

1) You are creating a Pilot-DB database rather than a HanDBase one. The second argument of DBcreate() should be a zero to produce a HanDBase database.

2) PocketC multi-demensional arrays are not like true C arrays. As such, you need to pass a pointer to the first data element. For the fourth argument of DBcreate(), use "&p[0][0]" rather than just "p".

3) The database name that you use with DBcreate() and DBopen() differ. This will cause DBopen() to fail.

Also, DBcreate() will fail if database by the name already exist (you have a Pilot-DB database by that name on your device if you ran your demo program.

Ony one line of code needs to change...

Code: Select all
if (DBcreate(sHDB,0,2,&p[0][0])) { //name, type, and pointer changed


The PToolboxLib guy.

PostPosted: Sun Jun 01, 2003 6:00 pm
by mgreen
Thanks for your prompt reply. The change you suggested worked perfectly. For your information, I wanted to copy a HanDBase file to a Pilot-DB file with a slightly different name, hence #1 and #3. When you next update the documentation, you might clarify #2.

Michael Green