Changeset 2759 for trunk/tools/database/db.cpp
- Timestamp:
- Feb 11, 2000, 7:35:55 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/database/db.cpp
r2742 r2759 1 /* $Id: db.cpp,v 1. 4 2000-02-10 22:10:40bird Exp $ */1 /* $Id: db.cpp,v 1.5 2000-02-11 18:35:54 bird Exp $ */ 2 2 /* 3 3 * DB - contains all database routines. … … 29 29 pres2 = mysql_store_result(pmysql);\ 30 30 if (rc < 0 || pres2 == NULL || \ 31 mysql_num_rows(pres2) <= 0) \31 mysql_num_rows(pres2) == 0) \ 32 32 { \ 33 33 if (pszError[1] == '\xFE') \ … … 151 151 } 152 152 153 /** 154 * Gets the refid for the give dll name. 155 * @returns Dll refid. -1 on error. 156 * @param pszDllName Dll name. 157 */ 158 signed short _System dbGetDll(const char *pszDllName) 159 { 160 int rc; 161 char szQuery[256]; 162 MYSQL_RES * pres; 163 164 sprintf(&szQuery[0], "SELECT refcode FROM dll WHERE name = '%s'\n", pszDllName); 165 rc = mysql_query(pmysql, &szQuery[0]); 166 pres = mysql_store_result(pmysql); 167 168 if (rc >= 0 && pres != NULL && mysql_num_rows(pres) == 1) 169 rc = (int)getvalue(0, mysql_fetch_row(pres)); 170 else 171 rc = -1; 172 mysql_free_result(pres); 173 return (short)rc; 174 } 175 176 177 /** 178 * Count the function in a given dll. 179 * @returns Number of functions. -1 on error. 180 * @param usDll Dll refcode. 181 */ 182 signed long _System dbCountFunctionInDll(signed long ulDll) 183 { 184 signed long rc; 185 char szQuery[256]; 186 MYSQL_RES * pres; 187 188 if (ulDll >= 0) 189 { 190 sprintf(&szQuery[0], "SELECT count(refcode) FROM function WHERE dll = %d\n", ulDll); 191 rc = mysql_query(pmysql, &szQuery[0]); 192 pres = mysql_store_result(pmysql); 193 194 if (rc >= 0 && pres != NULL && mysql_num_rows(pres) == 1) 195 rc = (int)getvalue(0, mysql_fetch_row(pres)); 196 else 197 rc = -1; 198 mysql_free_result(pres); 199 } 200 else 201 rc = -1; 202 return rc; 203 } 204 205 153 206 154 207 /** … … 161 214 signed short _System dbCheckInsertDll(const char *pszDll) 162 215 { 163 int rc;164 char szQuery[256];165 MYSQL_RES * pres;216 int rc; 217 char szQuery[256]; 218 MYSQL_RES * pres; 166 219 167 220 /* try find match */ … … 230 283 * @returns Success indicator. TRUE / FALSE. 231 284 * @param usDll Dll refcode. 232 * @param pszFunction Functionname. 285 * @param pszFunction Function name. 286 * @param pszIntFunction Internal function name. 233 287 * @param ulOrdinal Ordinal value. 234 288 * @param fIgnoreOrdinal Do not update ordinal value. 235 289 */ 236 BOOL _System dbInsertUpdateFunction(unsigned short usDll, const char *pszFunction, 290 BOOL _System dbInsertUpdateFunction(unsigned short usDll, 291 const char *pszFunction, const char *pszIntFunction, 237 292 unsigned long ulOrdinal, BOOL fIgnoreOrdinal) 238 293 { … … 242 297 MYSQL_RES *pres; 243 298 299 /* when no internal name, the exported name is the internal name too! */ 300 if (pszIntFunction == NULL || *pszIntFunction == '\0') 301 pszIntFunction = pszFunction; 302 244 303 /* try find function */ 245 sprintf(&szQuery[0], "SELECT refcode FROM function WHERE dll = %d AND name = '%s'", usDll, pszFunction);304 sprintf(&szQuery[0], "SELECT refcode, intname FROM function WHERE dll = %d AND name = '%s'", usDll, pszFunction); 246 305 rc = mysql_query(pmysql, &szQuery[0]); 247 306 pres = mysql_store_result(pmysql); 248 if (rc >= 0 && pres != NULL && mysql_num_rows(pres) >0)307 if (rc >= 0 && pres != NULL && mysql_num_rows(pres) != 0) 249 308 { /* update function (function is found) */ 250 309 MYSQL_ROW parow; … … 261 320 mysql_free_result(pres); 262 321 263 if (!fIgnoreOrdinal) 322 if (strcmp(parow[1], pszIntFunction) != 0) 323 { 324 sprintf(&szQuery[0], "UPDATE function SET intname = '%s' WHERE refcode = %ld", 325 pszIntFunction, lFunction); 326 rc = mysql_query(pmysql, &szQuery[0]); 327 } 328 329 if (rc >= 0 && !fIgnoreOrdinal) 264 330 { 265 331 sprintf(&szQuery[0], "UPDATE function SET ordinal = %ld WHERE refcode = %ld", … … 267 333 rc = mysql_query(pmysql, &szQuery[0]); 268 334 } 335 269 336 } 270 337 else 271 338 { /* insert */ 272 sprintf(&szQuery[0], "INSERT INTO function(dll, name, ordinal) VALUES(%d, '%s', %ld)",273 usDll, pszFunction, ulOrdinal);339 sprintf(&szQuery[0], "INSERT INTO function(dll, name, intname, ordinal) VALUES(%d, '%s', '%s', %ld)", 340 usDll, pszFunction, pszIntFunction, ulOrdinal); 274 341 rc = mysql_query(pmysql, &szQuery[0]); 275 342 } … … 295 362 296 363 /** 297 * Find occurences of a function, given by name.364 * Find occurences of a function, given by internal name. 298 365 * @returns success indicator, TRUE / FALSE. 299 366 * @param pszFunctionName … … 307 374 char szQuery[256]; 308 375 309 sprintf(&szQuery[0], "SELECT refcode, dll FROM function WHERE name = '%s'", pszFunctionName); 376 sprintf(&szQuery[0], "SELECT refcode, dll FROM function WHERE intname = '%s'", 377 pszFunctionName, pszFunctionName); 310 378 311 379 rc = mysql_query(pmysql, &szQuery[0]); … … 416 484 char *pszQuery = &szQuery[0]; 417 485 long lCurrentState; 418 int i, rc;486 int i,k,rc; 419 487 unsigned long ulRc = 0; 420 488 BOOL f = FALSE; 421 489 422 lCurrentState = dbGetFunctionState(pFnDesc->lRefCode); 423 if (lCurrentState == -1) 424 { 425 strcpy(pszError, dbGetLastErrorDesc()); 426 return 1; 427 } 428 429 /* update function table first */ 430 strcpy(pszQuery, "UPDATE function SET "); 431 pszQuery += strlen(pszQuery); 432 if (pFnDesc->lStatus != 99 || lCurrentState == 0) 433 { 434 sprintf(pszQuery, "state = %ld ", pFnDesc->lStatus); 435 f = TRUE; 436 } 437 pszQuery += strlen(pszQuery); 438 439 if (pFnDesc->pszReturnType != NULL) 440 { 490 for (k = 0; k < pFnDesc->cRefCodes; k++) 491 { 492 /* set updated flag */ 493 sprintf(pszQuery, "UPDATE function SET updated = updated + 1 WHERE refcode = %d", 494 pFnDesc->alRefCode[k]); 495 rc = mysql_query(pmysql, &szQuery[0]); 496 497 /* get current status */ 498 lCurrentState = dbGetFunctionState(pFnDesc->alRefCode[k]); 499 if (lCurrentState == -1) 500 { 501 strcpy(pszError, dbGetLastErrorDesc()); 502 return 1; 503 } 504 505 /* update function table first */ 506 strcpy(pszQuery, "UPDATE function SET "); 507 pszQuery += strlen(pszQuery); 508 if (pFnDesc->lStatus != 99 || lCurrentState == 0) 509 { 510 sprintf(pszQuery, "state = %ld ", pFnDesc->lStatus); 511 f = TRUE; 512 } 513 pszQuery += strlen(pszQuery); 514 515 if (pFnDesc->pszReturnType != NULL) 516 { 517 if (f) 518 { 519 strcat(pszQuery, ", "); 520 pszQuery += strlen(pszQuery); 521 } 522 sprintf(pszQuery, "return = '%s' ", pFnDesc->pszReturnType); 523 pszQuery += strlen(pszQuery); 524 f = TRUE; 525 } 526 441 527 if (f) 442 528 { 443 strcat(pszQuery, ", "); 444 pszQuery += strlen(pszQuery); 445 } 446 sprintf(pszQuery, "return = '%s' ", pFnDesc->pszReturnType); 447 pszQuery += strlen(pszQuery); 448 f = TRUE; 449 } 450 451 if (f) 452 { 453 sprintf(pszQuery, "WHERE refcode = %ld", pFnDesc->lRefCode); 529 sprintf(pszQuery, "WHERE refcode = %ld", pFnDesc->alRefCode[k]); 530 rc = mysql_query(pmysql, &szQuery[0]); 531 if (rc < 0) 532 { 533 sprintf(pszError, "Updating functiontable failed with error: %s - (sql=%s) ", 534 dbGetLastErrorDesc(), &szQuery[0]); 535 pszError += strlen(pszError) - 1; 536 ulRc++; 537 } 538 } 539 540 /* parameters */ 541 pszQuery = &szQuery[0]; 542 sprintf(pszQuery, "DELETE FROM parameter WHERE function = %ld", pFnDesc->alRefCode[k]); 454 543 rc = mysql_query(pmysql, &szQuery[0]); 455 544 if (rc < 0) 456 545 { 457 sprintf(pszError, "Updating functiontable failed with error: %s - (sql=%s) ", 546 if (*pszError == ' ') 547 strcpy(pszError++, "\n\t"); 548 sprintf(pszError, "Deleting old parameters failed with error: %s - (sql=%s) ", 458 549 dbGetLastErrorDesc(), &szQuery[0]); 459 550 pszError += strlen(pszError) - 1; 460 551 ulRc++; 461 552 } 462 } 463 464 /* parameters */465 pszQuery = &szQuery[0];466 sprintf(pszQuery, "DELETE FROM parameter WHERE function = %ld", pFnDesc->lRefCode);467 rc = mysql_query(pmysql, &szQuery[0]);468 if (rc < 0)469 {470 if (*pszError == ' ')471 strcpy(pszError++, "\n\t");472 sprintf(pszError, "Deleting old parameters failed with error: %s - (sql=%s) ",473 dbGetLastErrorDesc(), &szQuery[0]);474 pszError += strlen(pszError) - 1;475 ulRc++;476 }477 478 for (i = 0; i < pFnDesc->cParams; i++)479 {480 sprintf(pszQuery, "INSERT INTO parameter(function, sequencenbr, type, name) "481 "VALUES (%ld, %d, '%s', '%s')",482 pFnDesc->lRefCode, i, 483 pFnDesc->apszParamType[i] != NULL ? pFnDesc->apszParamType[i] : "",484 pFnDesc->apszParamName[i] != NULL ? pFnDesc->apszParamName[i] : ""485 486 rc = mysql_query(pmysql, pszQuery);553 554 for (i = 0; i < pFnDesc->cParams; i++) 555 { 556 sprintf(pszQuery, "INSERT INTO parameter(function, sequencenbr, type, name) " 557 "VALUES (%ld, %d, '%s', '%s')", 558 pFnDesc->alRefCode[k], i, 559 pFnDesc->apszParamType[i] != NULL ? pFnDesc->apszParamType[i] : "", 560 pFnDesc->apszParamName[i] != NULL ? pFnDesc->apszParamName[i] : "" 561 ); 562 rc = mysql_query(pmysql, pszQuery); 563 if (rc < 0) 564 { 565 if (*pszError == ' ') 566 strcpy(pszError++, "\n\t"); 567 sprintf(pszError, "Inserting parameter %i failed with error: %s - (sql=%s) ", 568 i, dbGetLastErrorDesc(), &szQuery[0]); 569 pszError += strlen(pszError) - 1; 570 ulRc++; 571 } 572 } 573 574 /* authors */ 575 pszQuery = &szQuery[0]; 576 sprintf(pszQuery, "DELETE FROM fnauthor WHERE function = %ld", pFnDesc->alRefCode[k]); 577 rc = mysql_query(pmysql, &szQuery[0]); 487 578 if (rc < 0) 488 579 { 489 580 if (*pszError == ' ') 490 581 strcpy(pszError++, "\n\t"); 491 sprintf(pszError, " Inserting parameter %ifailed with error: %s - (sql=%s) ",492 i,dbGetLastErrorDesc(), &szQuery[0]);582 sprintf(pszError, "Deleting old authors failed with error: %s - (sql=%s) ", 583 dbGetLastErrorDesc(), &szQuery[0]); 493 584 pszError += strlen(pszError) - 1; 494 585 ulRc++; 495 586 } 496 } 497 498 /* authors */ 499 pszQuery = &szQuery[0]; 500 sprintf(pszQuery, "DELETE FROM fnauthor WHERE function = %ld", pFnDesc->lRefCode); 501 rc = mysql_query(pmysql, &szQuery[0]); 502 if (rc < 0) 503 { 504 if (*pszError == ' ') 505 strcpy(pszError++, "\n\t"); 506 sprintf(pszError, "Deleting old authors failed with error: %s - (sql=%s) ", 507 dbGetLastErrorDesc(), &szQuery[0]); 508 pszError += strlen(pszError) - 1; 509 ulRc++; 510 } 511 512 for (i = 0; i < pFnDesc->cAuthors; i++) 513 { 514 if (pFnDesc->alAuthorRefCode[i] == -1) 515 continue; 516 sprintf(pszQuery, "INSERT INTO fnauthor(author, function) " 517 "VALUES (%ld, %ld)", 518 pFnDesc->alAuthorRefCode[i], pFnDesc->lRefCode); 519 rc = mysql_query(pmysql, pszQuery); 520 if (rc < 0) 521 { 522 if (*pszError == ' ') 523 strcpy(pszError++, "\n\t"); 524 sprintf(pszError, "Inserting parameter %i failed with error: %s - (sql=%s) ", 525 i, dbGetLastErrorDesc(), &szQuery[0]); 526 pszError += strlen(pszError) - 1; 527 ulRc++; 528 } 529 } 530 587 588 for (i = 0; i < pFnDesc->cAuthors; i++) 589 { 590 if (pFnDesc->alAuthorRefCode[i] == -1) 591 continue; 592 sprintf(pszQuery, "INSERT INTO fnauthor(author, function) " 593 "VALUES (%ld, %ld)", 594 pFnDesc->alAuthorRefCode[i], pFnDesc->alRefCode[k]); 595 rc = mysql_query(pmysql, pszQuery); 596 if (rc < 0) 597 { 598 if (*pszError == ' ') 599 strcpy(pszError++, "\n\t"); 600 sprintf(pszError, "Inserting parameter %i failed with error: %s - (sql=%s) ", 601 i, dbGetLastErrorDesc(), &szQuery[0]); 602 pszError += strlen(pszError) - 1; 603 ulRc++; 604 } 605 } 606 } /* for */ 531 607 return ulRc; 532 608 } … … 908 984 rc = mysql_query(pmysql, pszQuery); 909 985 pres = mysql_store_result(pmysql); 910 if (rc < 0 || (pres != NULL && mysql_num_rows(pres) >0))986 if (rc < 0 || (pres != NULL && mysql_num_rows(pres) != 0)) 911 987 { /* some kind of error has occurred */ 912 988 if (pszError[1] == '\xFE') … … 1099 1175 } 1100 1176 } 1177 1178 return fRet; 1179 } 1180 1181 1182 /** 1183 * Display all functions for, the given dll, that is not updated. 1184 * @returns TRUE / FALSE. 1185 * @param lDll Dll reference number. 1186 * @param dbFetchCall Callback function which will be called once for each 1187 * field for all the functions not updated. 1188 * pvUser is NULL, pszValue field value, pszFieldName the field name. 1189 */ 1190 BOOL _System dbGetNotUpdatedFunction(signed long lDll, DBCALLBACKFETCH dbFetchCallBack) 1191 { 1192 BOOL fRet = FALSE; 1193 void *pres; 1194 char szQuery[128]; 1195 1196 /* not updated names */ 1197 sprintf(&szQuery[0], "SELECT name, intname FROM function WHERE dll = %d AND updated = 0", 1198 lDll); 1199 pres = dbExecuteQuery(szQuery); 1200 if (pres != NULL) 1201 { 1202 BOOL f; 1203 do 1204 { 1205 f = dbFetch(pres, dbFetchCallBack, NULL); 1206 } while (f); 1207 dbFreeResult(pres); 1208 fRet = TRUE; 1209 } 1210 1211 /* warn about updated > 1 too */ 1212 sprintf(&szQuery[0], "SELECT updated, name, intname FROM function WHERE dll = %d AND updated > 1", 1213 lDll); 1214 pres = dbExecuteQuery(szQuery); 1215 if (pres != NULL) 1216 { 1217 BOOL f; 1218 do 1219 { 1220 f = dbFetch(pres, dbFetchCallBack, NULL); 1221 } while (f); 1222 dbFreeResult(pres); 1223 fRet = TRUE; 1224 } 1225 1226 sprintf(&szQuery[0], "UPDATE function SET updated = 0", 1227 lDll); 1228 mysql_query(pmysql, &szQuery[0]); 1101 1229 1102 1230 return fRet;
Note:
See TracChangeset
for help on using the changeset viewer.