Changeset 2770 for trunk/tools/database/db.cpp
- Timestamp:
- Feb 13, 2000, 12:54:30 AM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/database/db.cpp
r2765 r2770 1 /* $Id: db.cpp,v 1. 7 2000-02-12 17:55:03bird Exp $ *1 /* $Id: db.cpp,v 1.8 2000-02-12 23:54:29 bird Exp $ * 2 2 * 3 3 * DB - contains all database routines. … … 178 178 * Count the function in a given dll. 179 179 * @returns Number of functions. -1 on error. 180 * @param usDll Dll refcode. 181 */ 182 signed long _System dbCountFunctionInDll(signed long ulDll) 180 * @param usDll Dll refcode. 181 * @param fNotAliases TRUE: don't count aliased functions. 182 */ 183 signed long _System dbCountFunctionInDll(signed long ulDll, BOOL fNotAliases) 183 184 { 184 185 signed long rc; … … 189 190 { 190 191 sprintf(&szQuery[0], "SELECT count(refcode) FROM function WHERE dll = %ld\n", ulDll); 192 if (fNotAliases) 193 strcat(&szQuery[0], " AND aliasfn < 0"); 191 194 rc = mysql_query(pmysql, &szQuery[0]); 192 195 pres = mysql_store_result(pmysql); … … 284 287 * @param usDll Dll refcode. 285 288 * @param pszFunction Function name. 286 * @param pszIntFunction Internal function name. 289 * @param pszIntFunction Internal function name. (required!) 287 290 * @param ulOrdinal Ordinal value. 288 291 * @param fIgnoreOrdinal Do not update ordinal value. … … 297 300 MYSQL_RES *pres; 298 301 299 /* when no internal name , the exported name is the internal name too! */302 /* when no internal name fail! */ 300 303 if (pszIntFunction == NULL || *pszIntFunction == '\0') 301 pszIntFunction = pszFunction;304 return FALSE; 302 305 303 306 /* try find function */ … … 360 363 } 361 364 365 362 366 #if 1 367 /* 368 * Stubs used while optimizing sqls. 369 */ 370 int mysql_query1(MYSQL *mysql, const char *q) 371 { return mysql_query(mysql, q); } 372 int mysql_query2(MYSQL *mysql, const char *q) 373 { return mysql_query(mysql, q); } 374 int mysql_query3(MYSQL *mysql, const char *q) 375 { return mysql_query(mysql, q); } 376 int mysql_query4(MYSQL *mysql, const char *q) 377 { return mysql_query(mysql, q); } 378 int mysql_query5(MYSQL *mysql, const char *q) 379 { return mysql_query(mysql, q); } 380 MYSQL_RES * mysql_store_result1(MYSQL *mysql) 381 { return mysql_store_result(mysql); } 382 MYSQL_RES * mysql_store_result5(MYSQL *mysql) 383 { return mysql_store_result(mysql); } 384 385 #else 386 387 #define mysql_query1 mysql_query 388 #define mysql_query2 mysql_query 389 #define mysql_query3 mysql_query 390 #define mysql_query4 mysql_query 391 #define mysql_query5 mysql_query 392 #define mysql_store_result1 mysql_store_result 393 #define mysql_store_result5 mysql_store_result 394 395 #endif 396 397 398 363 399 /** 364 400 * Find occurences of a function, given by internal name. … … 383 419 pszFunctionName, lDll); 384 420 385 rc = mysql_query (pmysql, &szQuery[0]);421 rc = mysql_query1(pmysql, &szQuery[0]); 386 422 if (rc >= 0) 387 423 { 388 pres = mysql_store_result (pmysql);424 pres = mysql_store_result1(pmysql); 389 425 if (pres != NULL) 390 426 { … … 404 440 if (lDll >= 0 && pFnFindBuf->cFns != 0) 405 441 { 442 #if 0 406 443 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 aliasfn IN (");439 for (i = 0; i < pFnFindBuf->cFns; i++)440 {441 if (i != 0) strcat(&szQuery[0], ", ");442 sprintf(&szQuery[strlen(szQuery)], "%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 else459 pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = ALIAS_NULL;460 461 /* next */462 pFnFindBuf->cFns++;463 }464 mysql_free_result(pres);465 }466 }467 }468 }469 }470 }471 }472 else473 rc = -1;474 }475 476 return rc >= 0;477 }478 #else479 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 pszFunctionName519 * @param pFnFindBuf520 * @param lDll521 */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 else533 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 444 /* Make the selected function to DONT TOUCH */ 561 445 sprintf(&szQuery[0], "UPDATE function SET aliasfn = (-2) " … … 587 471 if (rc >= 0) 588 472 { 589 int cFns = pFnFindBuf->cFns; 590 for (i = 0; i < cFns; i++) 473 /* get the functions aliases to the functions we have allready found. */ 474 sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function WHERE dll = %ld AND aliasfn IN (", lDll); 475 for (i = 0; i < pFnFindBuf->cFns; i++) 591 476 { 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]); 477 if (i != 0) strcat(&szQuery[0], ", "); 478 sprintf(&szQuery[strlen(szQuery)], "%ld", pFnFindBuf->alRefCode[i]); 479 } 480 strcat(&szQuery[strlen(szQuery)], ")"); 481 482 DosSleep(0); 483 rc = mysql_query5(pmysql, &szQuery[0]); 484 if (rc >= 0) 485 { 486 pres = mysql_store_result5(pmysql); 487 if (pres != NULL) 488 { 489 while ((row = mysql_fetch_row(pres)) != NULL) 490 { 491 pFnFindBuf->alRefCode[pFnFindBuf->cFns] = atol(row[0]); 492 pFnFindBuf->alDllRefCode[pFnFindBuf->cFns] = atol(row[1]); 493 if (row[2] != NULL) 494 pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = atol(row[2]); 495 else 496 pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = ALIAS_NULL; 497 498 /* next */ 499 pFnFindBuf->cFns++; 500 } 501 mysql_free_result(pres); 502 } 503 } 504 } 505 } 506 } 507 #else 508 int i; 509 int cFnsThisDll = (int)pFnFindBuf->cFns; 510 511 /* get the functions aliases to the functions we have allready found. */ 512 sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function " 513 "WHERE aliasfn = (-1) AND dll <> %ld AND intname = '%s'", 514 lDll, pszFunctionName); 515 rc = mysql_query2(pmysql, &szQuery[0]); 516 if (rc >= 0) 517 { 518 pres = mysql_store_result(pmysql); 519 if (pres != NULL) 520 { 521 while ((row = mysql_fetch_row(pres)) != NULL) 522 { 523 pFnFindBuf->alRefCode[pFnFindBuf->cFns] = atol(row[0]); 524 pFnFindBuf->alDllRefCode[pFnFindBuf->cFns] = atol(row[1]); 525 if (row[2] != NULL) 526 pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = atol(row[2]); 527 else 528 pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = ALIAS_NULL; 529 530 /* next */ 531 pFnFindBuf->cFns++; 532 } 533 mysql_free_result(pres); 534 535 536 /* get the functions aliases to the functions we have allready found. */ 537 sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function " 538 "WHERE aliasfn = (-1) AND dll <> %ld AND name = '%s'", 539 lDll, pszFunctionName); 540 rc = mysql_query3(pmysql, &szQuery[0]); 541 if (rc >= 0) 542 { 543 pres = mysql_store_result(pmysql); 544 if (pres != NULL) 545 { 546 while ((row = mysql_fetch_row(pres)) != NULL) 547 { 548 pFnFindBuf->alRefCode[pFnFindBuf->cFns] = atol(row[0]); 549 pFnFindBuf->alDllRefCode[pFnFindBuf->cFns] = atol(row[1]); 550 if (row[2] != NULL) 551 pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = atol(row[2]); 552 else 553 pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = ALIAS_NULL; 554 555 /* next */ 556 pFnFindBuf->cFns++; 557 } 558 mysql_free_result(pres); 559 560 /* do updates! */ 561 /* Make the selected function to DONT TOUCH */ 562 sprintf(&szQuery[0], "UPDATE function SET aliasfn = (-2) " 563 "WHERE (", 564 lDll, pszFunctionName); 565 for (i = 0; i < cFnsThisDll; i++) 566 { 567 if (i != 0) strcat(&szQuery[0], " OR"); 568 sprintf(&szQuery[strlen(szQuery)], " refcode = %ld", pFnFindBuf->alRefCode[i]); 569 } 570 strcat(&szQuery[0], ") AND aliasfn <> (-2)"); 571 572 rc = mysql_query4(pmysql, &szQuery[0]); 596 573 if (rc >= 0) 597 574 { 598 pres = mysql_store_result2(pmysql); 599 if (pres != NULL) 575 /* Update all with equal internal... which is not in this Dll */ 576 sprintf(&szQuery[0], "UPDATE function SET aliasfn = (%ld) " 577 "WHERE aliasfn = (-1) AND dll <> %ld AND intname = '%s'", 578 pFnFindBuf->alRefCode[0], lDll, pszFunctionName, pszFunctionName); 579 rc = mysql_query5(pmysql, &szQuery[0]); 580 if (rc >= 0) 600 581 { 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); 582 /* Update all with equal external name... which is not in this Dll */ 583 sprintf(&szQuery[0], "UPDATE function SET aliasfn = (%ld) " 584 "WHERE aliasfn = (-1) AND dll <> %ld AND name = '%s'", 585 pFnFindBuf->alRefCode[0], lDll, pszFunctionName, pszFunctionName); 586 587 rc = mysql_query4(pmysql, &szQuery[0]); 615 588 } 616 589 } … … 619 592 } 620 593 } 594 #endif 621 595 } 622 596 } … … 627 601 return rc >= 0; 628 602 } 629 630 #endif631 603 632 604
Note:
See TracChangeset
for help on using the changeset viewer.