Changeset 2761 for trunk/tools/database/db.cpp
- Timestamp:
- Feb 12, 2000, 12:54:25 AM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/database/db.cpp
r2759 r2761 1 /* $Id: db.cpp,v 1. 5 2000-02-11 18:35:54 bird Exp $ */2 /*1 /* $Id: db.cpp,v 1.6 2000-02-11 23:54:25 bird Exp $ * 2 * 3 3 * DB - contains all database routines. 4 4 * … … 80 80 static unsigned long CheckAuthorError(char * &pszError, const char *pszFieldName, const char *pszFieldValue, const char *pszQuery); 81 81 static unsigned long logDbError(char * &pszError, const char *pszQuery); 82 #if def NOTDLL82 #ifndef DLL 83 83 extern "C" void dbHandler(int sig); 84 84 #endif … … 103 103 { 104 104 BOOL fRet = FALSE; 105 #if def NOTDLL105 #ifndef DLL 106 106 static fHandler = FALSE; 107 107 /* signal handler */ … … 188 188 if (ulDll >= 0) 189 189 { 190 sprintf(&szQuery[0], "SELECT count(refcode) FROM function WHERE dll = % d\n", ulDll);190 sprintf(&szQuery[0], "SELECT count(refcode) FROM function WHERE dll = %ld\n", ulDll); 191 191 rc = mysql_query(pmysql, &szQuery[0]); 192 192 pres = mysql_store_result(pmysql); … … 360 360 } 361 361 362 362 #if 0 363 363 /** 364 364 * Find occurences of a function, given by internal name. … … 366 366 * @param pszFunctionName 367 367 * @param pFnFindBuf 368 */ 369 BOOL _System dbFindFunction(const char *pszFunctionName, PFNFINDBUF pFnFindBuf) 368 * @param lDll 369 */ 370 BOOL _System dbFindFunction(const char *pszFunctionName, PFNFINDBUF pFnFindBuf, signed long lDll) 370 371 { 371 372 MYSQL_RES *pres; … … 374 375 char szQuery[256]; 375 376 376 sprintf(&szQuery[0], "SELECT refcode, dll FROM function WHERE intname = '%s'", 377 pszFunctionName, pszFunctionName); 377 if (lDll < 0) 378 sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function WHERE intname = '%s'", 379 pszFunctionName); 380 else 381 sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function " 382 "WHERE intname = '%s' AND dll = %ld", 383 pszFunctionName, lDll); 378 384 379 385 rc = mysql_query(pmysql, &szQuery[0]); … … 388 394 pFnFindBuf->alRefCode[pFnFindBuf->cFns] = atol(row[0]); 389 395 pFnFindBuf->alDllRefCode[pFnFindBuf->cFns] = atol(row[1]); 396 pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = atol(row[2]); 390 397 391 398 /* next */ … … 393 400 } 394 401 mysql_free_result(pres); 402 403 /* alias check and fix */ 404 if (lDll >= 0 && pFnFindBuf->cFns != 0) 405 { 406 int i; 407 408 /* Make the selected function to DONT TOUCH */ 409 sprintf(&szQuery[0], "UPDATE function SET aliasfn = (-2) " 410 "WHERE (", 411 lDll, pszFunctionName); 412 for (i = 0; i < pFnFindBuf->cFns; i++) 413 { 414 if (i != 0) strcat(&szQuery[0], " OR"); 415 sprintf(&szQuery[strlen(szQuery)], " refcode = %ld", pFnFindBuf->alRefCode[i]); 416 } 417 strcat(&szQuery[0], ") AND aliasfn <> (-2)"); 418 419 rc = mysql_query(pmysql, &szQuery[0]); 420 if (rc >= 0) 421 { 422 /* Update all with equal internal... which is not in this Dll */ 423 sprintf(&szQuery[0], "UPDATE function SET aliasfn = (%ld) " 424 "WHERE aliasfn = (-1) AND dll <> %ld AND intname = '%s'", 425 pFnFindBuf->alRefCode[0], lDll, pszFunctionName, pszFunctionName); 426 rc = mysql_query(pmysql, &szQuery[0]); 427 if (rc >= 0) 428 { 429 /* Update all with equal external name... which is not in this Dll */ 430 sprintf(&szQuery[0], "UPDATE function SET aliasfn = (%ld) " 431 "WHERE aliasfn = (-1) AND dll <> %ld AND name = '%s'", 432 pFnFindBuf->alRefCode[0], lDll, pszFunctionName, pszFunctionName); 433 434 rc = mysql_query(pmysql, &szQuery[0]); 435 if (rc >= 0) 436 { 437 /* get the functions aliases to the functions we have allready found. */ 438 strcpy(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function WHERE ("); 439 for (i = 0; i < pFnFindBuf->cFns; i++) 440 { 441 if (i != 0) strcat(&szQuery[0], "OR "); 442 sprintf(&szQuery[strlen(szQuery)], "aliasfn = %ld ", pFnFindBuf->alRefCode[i]); 443 } 444 sprintf(&szQuery[strlen(szQuery)], ") AND dll <> %ld", lDll); 445 446 rc = mysql_query(pmysql, &szQuery[0]); 447 if (rc >= 0) 448 { 449 pres = mysql_store_result(pmysql); 450 if (pres != NULL) 451 { 452 while ((row = mysql_fetch_row(pres)) != NULL) 453 { 454 pFnFindBuf->alRefCode[pFnFindBuf->cFns] = atol(row[0]); 455 pFnFindBuf->alDllRefCode[pFnFindBuf->cFns] = atol(row[1]); 456 if (row[2] != NULL) 457 pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = atol(row[2]); 458 else 459 pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = ALIAS_NULL; 460 461 /* next */ 462 pFnFindBuf->cFns++; 463 } 464 mysql_free_result(pres); 465 } 466 } 467 } 468 } 469 } 470 } 395 471 } 396 472 else … … 400 476 return rc >= 0; 401 477 } 478 #else 479 int mysql_query1(MYSQL *mysql, const char *q) 480 { 481 return mysql_query(mysql, q); 482 } 483 484 int mysql_query2(MYSQL *mysql, const char *q) 485 { 486 return mysql_query(mysql, q); 487 } 488 489 int mysql_query3(MYSQL *mysql, const char *q) 490 { 491 return mysql_query(mysql, q); 492 } 493 494 int mysql_query4(MYSQL *mysql, const char *q) 495 { 496 return mysql_query(mysql, q); 497 } 498 499 int mysql_query5(MYSQL *mysql, const char *q) 500 { 501 return mysql_query(mysql, q); 502 } 503 504 MYSQL_RES * mysql_store_result1(MYSQL *mysql) 505 { 506 return mysql_store_result(mysql); 507 } 508 509 MYSQL_RES * mysql_store_result2(MYSQL *mysql) 510 { 511 return mysql_store_result(mysql); 512 } 513 514 515 /** 516 * Find occurences of a function, given by internal name. 517 * @returns success indicator, TRUE / FALSE. 518 * @param pszFunctionName 519 * @param pFnFindBuf 520 * @param lDll 521 */ 522 BOOL _System dbFindFunction(const char *pszFunctionName, PFNFINDBUF pFnFindBuf, signed long lDll) 523 { 524 MYSQL_RES *pres; 525 MYSQL_ROW row; 526 int rc; 527 char szQuery[256]; 528 529 if (lDll < 0) 530 sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function WHERE intname = '%s'", 531 pszFunctionName); 532 else 533 sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function " 534 "WHERE intname = '%s' AND dll = %ld", 535 pszFunctionName, lDll); 536 537 rc = mysql_query1(pmysql, &szQuery[0]); 538 if (rc >= 0) 539 { 540 pres = mysql_store_result1(pmysql); 541 if (pres != NULL) 542 { 543 pFnFindBuf->cFns = 0; 544 while ((row = mysql_fetch_row(pres)) != NULL) 545 { 546 pFnFindBuf->alRefCode[pFnFindBuf->cFns] = atol(row[0]); 547 pFnFindBuf->alDllRefCode[pFnFindBuf->cFns] = atol(row[1]); 548 pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = atol(row[2]); 549 550 /* next */ 551 pFnFindBuf->cFns++; 552 } 553 mysql_free_result(pres); 554 555 /* alias check and fix */ 556 if (lDll >= 0 && pFnFindBuf->cFns != 0) 557 { 558 int i; 559 560 /* Make the selected function to DONT TOUCH */ 561 sprintf(&szQuery[0], "UPDATE function SET aliasfn = (-2) " 562 "WHERE (", 563 lDll, pszFunctionName); 564 for (i = 0; i < pFnFindBuf->cFns; i++) 565 { 566 if (i != 0) strcat(&szQuery[0], " OR"); 567 sprintf(&szQuery[strlen(szQuery)], " refcode = %ld", pFnFindBuf->alRefCode[i]); 568 } 569 strcat(&szQuery[0], ") AND aliasfn <> (-2)"); 570 571 rc = mysql_query2(pmysql, &szQuery[0]); 572 if (rc >= 0) 573 { 574 /* Update all with equal internal... which is not in this Dll */ 575 sprintf(&szQuery[0], "UPDATE function SET aliasfn = (%ld) " 576 "WHERE aliasfn = (-1) AND dll <> %ld AND intname = '%s'", 577 pFnFindBuf->alRefCode[0], lDll, pszFunctionName, pszFunctionName); 578 rc = mysql_query3(pmysql, &szQuery[0]); 579 if (rc >= 0) 580 { 581 /* Update all with equal external name... which is not in this Dll */ 582 sprintf(&szQuery[0], "UPDATE function SET aliasfn = (%ld) " 583 "WHERE aliasfn = (-1) AND dll <> %ld AND name = '%s'", 584 pFnFindBuf->alRefCode[0], lDll, pszFunctionName, pszFunctionName); 585 586 rc = mysql_query4(pmysql, &szQuery[0]); 587 if (rc >= 0) 588 { 589 int cFns = pFnFindBuf->cFns; 590 for (i = 0; i < cFns; i++) 591 { 592 /* get the functions aliases to the functions we have allready found. */ 593 sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function WHERE aliasfn = %ld AND dll <> %ld", 594 pFnFindBuf->alRefCode[i], lDll); 595 rc = mysql_query5(pmysql, &szQuery[0]); 596 if (rc >= 0) 597 { 598 pres = mysql_store_result2(pmysql); 599 if (pres != NULL) 600 { 601 while ((row = mysql_fetch_row(pres)) != NULL) 602 { 603 pFnFindBuf->alRefCode[pFnFindBuf->cFns] = atol(row[0]); 604 pFnFindBuf->alDllRefCode[pFnFindBuf->cFns] = atol(row[1]); 605 if (row[2] != NULL) 606 pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = atol(row[2]); 607 else 608 pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = ALIAS_NULL; 609 610 /* next */ 611 if (pFnFindBuf->alDllRefCode[pFnFindBuf->cFns] != lDll) 612 pFnFindBuf->cFns++; 613 } 614 mysql_free_result(pres); 615 } 616 } 617 } 618 } 619 } 620 } 621 } 622 } 623 else 624 rc = -1; 625 } 626 627 return rc >= 0; 628 } 629 630 #endif 402 631 403 632 … … 475 704 * Updates function information. 476 705 * @returns number of errors. 477 * @param pFnDesc 478 * @param pszError 706 * @param pFnDesc Function description struct. 707 * @param lDll Dll which we are working at. 708 * @param pszError Buffer for error messages 479 709 * @result on error(s) pszError will hold information about the error(s). 480 710 */ 481 unsigned long _System dbUpdateFunction(PFNDESC pFnDesc, char *pszError)711 unsigned long _System dbUpdateFunction(PFNDESC pFnDesc, signed long lDll, char *pszError) 482 712 { 483 713 char szQuery[256]; … … 491 721 { 492 722 /* set updated flag */ 493 sprintf(pszQuery, "UPDATE function SET updated = updated + 1 WHERE refcode = % d",723 sprintf(pszQuery, "UPDATE function SET updated = updated + 1 WHERE refcode = %ld", 494 724 pFnDesc->alRefCode[k]); 495 725 rc = mysql_query(pmysql, &szQuery[0]); … … 515 745 if (pFnDesc->pszReturnType != NULL) 516 746 { 517 if (f) 518 { 519 strcat(pszQuery, ", "); 520 pszQuery += strlen(pszQuery); 521 } 522 sprintf(pszQuery, "return = '%s' ", pFnDesc->pszReturnType); 747 if (f) strcat(pszQuery, ", "); 748 sprintf(pszQuery + strlen(pszQuery), "return = '%s' ", pFnDesc->pszReturnType); 523 749 pszQuery += strlen(pszQuery); 524 750 f = TRUE; … … 527 753 if (f) 528 754 { 529 sprintf(pszQuery , "WHERE refcode = %ld", pFnDesc->alRefCode[k]);755 sprintf(pszQuery + strlen(pszQuery), "WHERE refcode = %ld", pFnDesc->alRefCode[k]); 530 756 rc = mysql_query(pmysql, &szQuery[0]); 531 757 if (rc < 0) … … 605 831 } 606 832 } /* for */ 833 834 lDll = lDll; 607 835 return ulRc; 608 836 } … … 1195 1423 1196 1424 /* not updated names */ 1197 sprintf(&szQuery[0], "SELECT name, intname FROM function WHERE dll = % d AND updated = 0",1425 sprintf(&szQuery[0], "SELECT name, intname FROM function WHERE dll = %ld AND updated = 0", 1198 1426 lDll); 1199 1427 pres = dbExecuteQuery(szQuery); … … 1210 1438 1211 1439 /* warn about updated > 1 too */ 1212 sprintf(&szQuery[0], "SELECT updated, name, intname FROM function WHERE dll = % d AND updated > 1",1440 sprintf(&szQuery[0], "SELECT updated, name, intname FROM function WHERE dll = %ld AND updated > 1", 1213 1441 lDll); 1214 1442 pres = dbExecuteQuery(szQuery); … … 1224 1452 } 1225 1453 1226 sprintf(&szQuery[0], "UPDATE function SET updated = 0", 1227 lDll); 1454 strcpy(&szQuery[0], "UPDATE function SET updated = 0"); 1228 1455 mysql_query(pmysql, &szQuery[0]); 1229 1456 … … 1232 1459 1233 1460 1234 #if def NOTDLL1461 #ifndef DLL 1235 1462 /** 1236 1463 * Signal handler.
Note:
See TracChangeset
for help on using the changeset viewer.