Changeset 2773 for trunk/tools/database
- Timestamp:
- Feb 14, 2000, 2:49:14 PM (26 years ago)
- Location:
- trunk/tools/database
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/database/APIImport.cpp
r2770 r2773 1 /* $Id: APIImport.cpp,v 1. 3 2000-02-12 23:54:28bird Exp $ */1 /* $Id: APIImport.cpp,v 1.4 2000-02-14 13:49:12 bird Exp $ */ 2 2 /* 3 3 * … … 290 290 sprintf(&szName[0], "Ordinal%04ld", export.ulOrdinal); 291 291 else 292 strcpy(&szName[0], &export.achName[0]);292 demangle(&szName[0], &export.achName[0]); 293 293 294 294 /* internal name */ -
trunk/tools/database/CreateTables.sql
r2770 r2773 1 -- $Id: CreateTables.sql,v 1. 4 2000-02-12 23:54:29bird Exp $1 -- $Id: CreateTables.sql,v 1.5 2000-02-14 13:49:12 bird Exp $ 2 2 -- 3 3 -- Create all tables. … … 30 30 dll TINYINT NOT NULL, 31 31 aliasfn INTEGER NOT NULL DEFAULT -1, 32 name VARCHAR( 64) NOT NULL,33 intname VARCHAR( 64) NOT NULL,32 name VARCHAR(74) NOT NULL, 33 intname VARCHAR(74) NOT NULL, 34 34 state TINYINT NOT NULL DEFAULT 0, 35 35 ordinal INTEGER NOT NULL, -
trunk/tools/database/Makefile
r2770 r2773 1 # $Id: Makefile,v 1. 8 2000-02-12 23:54:29bird Exp $1 # $Id: Makefile,v 1.9 2000-02-14 13:49:14 bird Exp $ 2 2 3 3 # … … 13 13 CINCLUDES= -I$(PDWIN32_INCLUDE) -I$(PDWIN32_INCLUDE)\win -Igd -Imysql -I..\common 14 14 !ifdef DEBUG 15 CFLAGS = $(CFLAGS) -Ge+ -Tx+ -Tm- $(CINCLUDES) -DNO_CLIENT_LONG_LONG -Wall+ppt-ppc-inl-cnv-gnr-vft- -Gh+ 16 CXXFLAGS = $(CXXFLAGS) -Ge+ -Gx- -Tx+ -Tm- $(CINCLUDES) -DNO_CLIENT_LONG_LONG -Wall+ppt-ppc-inl-cnv-gnr-vft- -Gh+ 15 CFLAGS = $(CFLAGS) -Ge+ -Tx+ -Tm- $(CINCLUDES) -DNO_CLIENT_LONG_LONG -Wall+ppt-ppc-inl-cnv-gnr-vft- -Gh+ -DDEBUG_ALLOC 16 CXXFLAGS = $(CXXFLAGS) -Ge+ -Gx- -Tx+ -Tm- $(CINCLUDES) -DNO_CLIENT_LONG_LONG -Wall+ppt-ppc-inl-cnv-gnr-vft- -Gh+ -DDEBUG_ALLOC 17 17 LDFLAGS = $(LDFLAGS) -Ge+ -Fe$@ /B"/MAP:full" $(RTLLIB) os2386.lib cppopa3.obj 18 18 !else -
trunk/tools/database/StateUpd.cpp
r2770 r2773 1 /* $Id: StateUpd.cpp,v 1.1 1 2000-02-12 23:54:29bird Exp $1 /* $Id: StateUpd.cpp,v 1.12 2000-02-14 13:49:13 bird Exp $ 2 2 * 3 3 * StateUpd - Scans source files for API functions and imports data on them. … … 608 608 { 609 609 unsigned long ulRcTmp; 610 char szErrorDesc[2113]; /* due to some limitation in the latest EMX release size is 2112 and not 4096 as initially implemented. */ 610 //char szErrorDesc[2113]; /* due to some limitation in the latest EMX release size is 2112 and not 4096 as initially implemented. */ 611 char *pszErrorDesc = (char*)malloc(20480); 611 612 612 613 /* 2.*/ … … 632 633 633 634 /* 4.*/ 634 ulRcTmp = dbUpdateFunction(&FnDesc, pOptions->lDllRefcode, &szErrorDesc[0]);635 ulRcTmp = dbUpdateFunction(&FnDesc, pOptions->lDllRefcode, pszErrorDesc); 635 636 if (ulRcTmp != 0) 636 637 { 637 fprintf(phSignal, "%s,%s: %s\n", pszFilename, FnDesc.pszName, &szErrorDesc[0]);638 fprintf(phSignal, "%s,%s: %s\n", pszFilename, FnDesc.pszName, pszErrorDesc); 638 639 ulRc += ulRcTmp << 16; 639 640 } 641 free(pszErrorDesc); 640 642 } 641 643 … … 914 916 *pszEnd = '\0'; 915 917 copy(pszEnd, pszReturn, iReturn, pszFn-1, iFn, papszLines); 916 if (strlen(pszEnd) > 1 024)918 if (strlen(pszEnd) > 128) 917 919 { 918 920 fprintf(phSignal,"Fatal error! return statement is too larget. len=%d", strlen(pszEnd)); … … 950 952 { 951 953 if ((psz = strchr(apszArgs[j], ')')) == NULL) 952 { 953 pFnDesc->apszParamName[j] = findStartOfWord(apszArgs[j] + strlen(apszArgs[j]) - 1, 954 { /* Common argument */ 955 if (apszArgs[j][strlen(apszArgs[j]-1)] != '*') 956 { /* Normal case, Type [moretype] Name.*/ 957 pFnDesc->apszParamName[j] = findStartOfWord(apszArgs[j] + strlen(apszArgs[j]) - 1, 954 958 apszArgs[j]); 955 pFnDesc->apszParamName[j][-1] = '\0'; 959 pFnDesc->apszParamName[j][-1] = '\0'; 960 } 961 else 962 { /* No argument name only type - make a dummy one: 'arg[1..n]' */ 963 sprintf(pszEnd, "arg%i", j); 964 pFnDesc->apszParamName[j] = pszEnd; 965 pszEnd = strlen(pszEnd) + pszEnd + 1; 966 *pszEnd = '\0'; 967 } 956 968 pFnDesc->apszParamType[j] = trim(apszArgs[j]); 957 969 } 958 970 else 959 { 971 { /* Function pointer argument... */ 960 972 char *pszP2 = psz; 961 973 psz = findStartOfWord(psz-1, apszArgs[j]); … … 1643 1655 1644 1656 1657 /** 1658 * Trims a string, ie. removing spaces (and tabs) from both ends of the string. 1659 * @returns Pointer to first not space or tab char in the string. 1660 * @param psz Pointer to the string which is to be trimmed. 1661 * @status completely implmented. 1662 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 1663 */ 1645 1664 static char *trim(char *psz) 1646 1665 { … … 1661 1680 * ensuring space after '*', ensuring no space before ',' and ')'. 1662 1681 */ 1663 1664 1682 static void copy(char *psz, char *pszFrom, int iFrom, char *pszTo, int iTo, char **papszLines) 1665 1683 { … … 1718 1736 1719 1737 #else 1738 /** 1739 * Copies a set of lines to a buffer (psz) removing precompiler lines and all comments. 1740 * @param psz 1741 * @param jFrom Starting position, index into line iFrom. 1742 * @param iFrom Starting position, index into papszLines. 1743 * @param jTo Ending position, index into line iFrom. 1744 * @param iTo Ending position, index into papszLines. 1745 * @param papszLines Array of lines. 1746 * @status completely implemented. 1747 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 1748 */ 1720 1749 static void copy(char *psz, int jFrom, int iFrom, int jTo, int iTo, char **papszLines) 1721 1750 { … … 1781 1810 * @param ch Char to capitalize. 1782 1811 */ 1812 #if 0 1783 1813 inline char upcase(char ch) 1784 1814 { 1785 1815 return ch >= 'a' && ch <= 'z' ? (char)(ch - ('a' - 'A')) : ch; 1786 1816 } 1817 #else 1818 #define upcase(ch) ((ch) >= 'a' && (ch) <= 'z' ? (char)((ch) - ('a' - 'A')) : (ch)) 1819 #endif 1787 1820 1788 1821 -
trunk/tools/database/db.cpp
r2770 r2773 1 /* $Id: db.cpp,v 1. 8 2000-02-12 23:54:29bird Exp $ *1 /* $Id: db.cpp,v 1.9 2000-02-14 13:49:13 bird Exp $ * 2 2 * 3 3 * DB - contains all database routines. … … 364 364 365 365 366 #if 1366 #if 0 367 367 /* 368 368 * Stubs used while optimizing sqls. … … 378 378 int mysql_query5(MYSQL *mysql, const char *q) 379 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); } 380 int mysql_query6(MYSQL *mysql, const char *q) 381 { return mysql_query(mysql, q); } 384 382 385 383 #else … … 390 388 #define mysql_query4 mysql_query 391 389 #define mysql_query5 mysql_query 392 #define mysql_store_result1 mysql_store_result 393 #define mysql_store_result5 mysql_store_result 390 #define mysql_query6 mysql_query 394 391 395 392 #endif … … 403 400 * @param pFnFindBuf 404 401 * @param lDll 402 * @sketch 1) Get functions for this dll(if given). 403 * 2) Get functions which aliases the functions found in (1). 404 * 3) Get new aliases by intname 405 * 4) Get new aliases by name 406 * 5) Update all functions from (1) to have aliasfn -2 (DONTMIND) 407 * 6) Update all functions from (3) and (4) to alias the first function from 1. 405 408 */ 406 409 BOOL _System dbFindFunction(const char *pszFunctionName, PFNFINDBUF pFnFindBuf, signed long lDll) … … 411 414 char szQuery[256]; 412 415 416 /* 417 * 1) Get functions for this dll(if given). 418 */ 413 419 if (lDll < 0) 414 sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function WHERE intname = '%s'",420 sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn, name FROM function WHERE intname = '%s'", 415 421 pszFunctionName); 416 422 else 417 sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function "423 sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn, name FROM function " 418 424 "WHERE intname = '%s' AND dll = %ld", 419 425 pszFunctionName, lDll); … … 422 428 if (rc >= 0) 423 429 { 424 pres = mysql_store_result 1(pmysql);430 pres = mysql_store_result(pmysql); 425 431 if (pres != NULL) 426 432 { 433 char szFnName[NBR_FUNCTIONS][80]; 434 427 435 pFnFindBuf->cFns = 0; 428 436 while ((row = mysql_fetch_row(pres)) != NULL) … … 431 439 pFnFindBuf->alDllRefCode[pFnFindBuf->cFns] = atol(row[1]); 432 440 pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = atol(row[2]); 441 strcpy(szFnName[pFnFindBuf->cFns], row[3]); 433 442 434 443 /* next */ … … 440 449 if (lDll >= 0 && pFnFindBuf->cFns != 0) 441 450 { 442 #if 0 443 int i; 444 /* Make the selected function to DONT TOUCH */ 445 sprintf(&szQuery[0], "UPDATE function SET aliasfn = (-2) " 446 "WHERE (", 447 lDll, pszFunctionName); 448 for (i = 0; i < pFnFindBuf->cFns; i++) 451 int cFnsThisDll, cFnsAliasesAndThisDll, i; 452 453 /* 454 * 2) Get functions which aliases the functions found in (1). 455 */ 456 cFnsThisDll = (int)pFnFindBuf->cFns; 457 strcpy(&szQuery[0], "SELECT refcode, dll, aliasfn, name FROM function WHERE aliasfn IN ("); 458 for (i = 0; i < cFnsThisDll; i++) 449 459 { 450 if (i != 0) strcat(&szQuery[0], " OR");451 sprintf(&szQuery[strlen(szQuery)], " refcode = %ld", pFnFindBuf->alRefCode[i]);460 if (i > 0) strcat(&szQuery[0], " OR "); 461 sprintf(&szQuery[strlen(szQuery)], "(%ld)", pFnFindBuf->alRefCode[i]); 452 462 } 453 strcat(&szQuery[0], ") AND aliasfn <> (-2)"); 454 455 rc = mysql_query2(pmysql, &szQuery[0]); 456 if (rc >= 0) 457 { 458 /* Update all with equal internal... which is not in this Dll */ 459 sprintf(&szQuery[0], "UPDATE function SET aliasfn = (%ld) " 460 "WHERE aliasfn = (-1) AND dll <> %ld AND intname = '%s'", 461 pFnFindBuf->alRefCode[0], lDll, pszFunctionName, pszFunctionName); 462 rc = mysql_query3(pmysql, &szQuery[0]); 463 if (rc >= 0) 464 { 465 /* Update all with equal external name... which is not in this Dll */ 466 sprintf(&szQuery[0], "UPDATE function SET aliasfn = (%ld) " 467 "WHERE aliasfn = (-1) AND dll <> %ld AND name = '%s'", 468 pFnFindBuf->alRefCode[0], lDll, pszFunctionName, pszFunctionName); 469 470 rc = mysql_query4(pmysql, &szQuery[0]); 471 if (rc >= 0) 472 { 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++) 476 { 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); 463 strcat(&szQuery[0], ")"); 464 515 465 rc = mysql_query2(pmysql, &szQuery[0]); 516 466 if (rc >= 0) … … 523 473 pFnFindBuf->alRefCode[pFnFindBuf->cFns] = atol(row[0]); 524 474 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; 475 pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = atol(row[2]); 476 strcpy(szFnName[pFnFindBuf->cFns], row[3]); 529 477 530 478 /* next */ … … 533 481 mysql_free_result(pres); 534 482 535 536 /* get the functions aliases to the functions we have allready found. */ 483 /* 484 * 3) Get new aliases by intname 485 */ 486 cFnsAliasesAndThisDll = (int)pFnFindBuf->cFns; 537 487 sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function " 538 "WHERE aliasfn = (-1) AND dll <> %ld AND name = '%s'",488 "WHERE aliasfn = (-1) AND dll <> %ld AND (intname = '%s'", 539 489 lDll, pszFunctionName); 490 for (i = 0; i < cFnsAliasesAndThisDll; i++) 491 sprintf(&szQuery[strlen(&szQuery[0])], " OR intname = '%s'", szFnName[i]); 492 strcat(&szQuery[0], ")"); 493 540 494 rc = mysql_query3(pmysql, &szQuery[0]); 541 495 if (rc >= 0) … … 558 512 mysql_free_result(pres); 559 513 560 /* do updates! */ 561 /* Make the selected function to DONT TOUCH */ 562 sprintf(&szQuery[0], "UPDATE function SET aliasfn = (-2) " 563 "WHERE (", 514 515 /* 516 * 4) Get new aliases by name 517 */ 518 sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function " 519 "WHERE aliasfn = (-1) AND dll <> %ld AND (name = '%s'", 564 520 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)"); 521 for (i = 0; i < cFnsAliasesAndThisDll; i++) 522 sprintf(&szQuery[strlen(&szQuery[0])], " OR name = '%s'", szFnName[i]); 523 strcat(&szQuery[0], ")"); 571 524 572 525 rc = mysql_query4(pmysql, &szQuery[0]); 573 526 if (rc >= 0) 574 527 { 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) 528 pres = mysql_store_result(pmysql); 529 if (pres != NULL) 581 530 { 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]); 531 while ((row = mysql_fetch_row(pres)) != NULL) 532 { 533 pFnFindBuf->alRefCode[pFnFindBuf->cFns] = atol(row[0]); 534 pFnFindBuf->alDllRefCode[pFnFindBuf->cFns] = atol(row[1]); 535 if (row[2] != NULL) 536 pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = atol(row[2]); 537 else 538 pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = ALIAS_NULL; 539 540 /* next */ 541 pFnFindBuf->cFns++; 542 } 543 mysql_free_result(pres); 544 545 /* 546 * 5) Update all functions from (1) to have aliasfn -2 (DONTMIND) 547 */ 548 sprintf(&szQuery[0], "UPDATE function SET aliasfn = (-2) " 549 "WHERE (", 550 lDll, pszFunctionName); 551 for (i = 0; i < cFnsThisDll; i++) 552 { 553 if (i != 0) strcat(&szQuery[0], " OR"); 554 sprintf(&szQuery[strlen(szQuery)], " refcode = %ld", pFnFindBuf->alRefCode[i]); 555 } 556 strcat(&szQuery[0], ") AND aliasfn <> (-2)"); 557 558 rc = mysql_query5(pmysql, &szQuery[0]); 559 if (rc >= 0 && cFnsAliasesAndThisDll < pFnFindBuf->cFns) 560 { 561 /* 562 * 6) Update all functions from (3) and (4) to alias the first function from 1. 563 */ 564 sprintf(&szQuery[0], "UPDATE function SET aliasfn = (%ld) " 565 "WHERE aliasfn = (-1) AND refcode IN (", 566 pFnFindBuf->alRefCode[0]); 567 for (i = cFnsAliasesAndThisDll; i < pFnFindBuf->cFns; i++) 568 sprintf(&szQuery[strlen(&szQuery[0])], 569 i > 0 ? ", %ld" : "%ld", pFnFindBuf->alRefCode[i]); 570 strcat(&szQuery[0], ")"); 571 rc = mysql_query6(pmysql, &szQuery[0]); 572 } /* query 5 */ 588 573 } 589 } 574 } /* query 4 */ 590 575 } 591 } 576 } /* query 3 */ 592 577 } 593 } 594 #endif 578 } /* query 2 */ 595 579 } 596 } 580 } /* query 1 */ 597 581 else 598 582 rc = -1; … … 672 656 } 673 657 658 #if 1 659 /* 660 * Stubs used while optimizing sqls. 661 */ 662 int mysql_queryu1(MYSQL *mysql, const char *q) 663 { return mysql_query(mysql, q); } 664 int mysql_queryu2(MYSQL *mysql, const char *q) 665 { return mysql_query(mysql, q); } 666 int mysql_queryu3(MYSQL *mysql, const char *q) 667 { return mysql_query(mysql, q); } 668 int mysql_queryu4(MYSQL *mysql, const char *q) 669 { return mysql_query(mysql, q); } 670 int mysql_queryu5(MYSQL *mysql, const char *q) 671 { return mysql_query(mysql, q); } 672 int mysql_queryu6(MYSQL *mysql, const char *q) 673 { return mysql_query(mysql, q); } 674 int mysql_queryu7(MYSQL *mysql, const char *q) 675 { return mysql_query(mysql, q); } 676 int mysql_queryu8(MYSQL *mysql, const char *q) 677 { return mysql_query(mysql, q); } 678 #else 679 #define mysql_queryu1 mysql_query 680 #define mysql_queryu2 mysql_query 681 #define mysql_queryu3 mysql_query 682 #define mysql_queryu4 mysql_query 683 #define mysql_queryu5 mysql_query 684 #define mysql_queryu6 mysql_query 685 #define mysql_queryu7 mysql_query 686 #define mysql_queryu8 mysql_query 687 #endif 674 688 675 689 /** … … 683 697 unsigned long _System dbUpdateFunction(PFNDESC pFnDesc, signed long lDll, char *pszError) 684 698 { 685 char szQuery[256]; 686 char *pszQuery = &szQuery[0]; 687 long lCurrentState; 688 int i,k,rc; 689 unsigned long ulRc = 0; 699 MYSQL_RES * pres; 700 MYSQL_ROW row; 701 char szQuery[512]; 702 char * pszQuery = &szQuery[0]; 703 long lCurrentState; 704 int i,k,rc; 705 unsigned long ulRc = 0; 690 706 691 707 for (k = 0; k < pFnDesc->cRefCodes; k++) … … 693 709 BOOL f = FALSE; 694 710 695 /* set updated flag */ 711 /* 712 * Set updated flag 713 */ 696 714 sprintf(pszQuery, "UPDATE function SET updated = updated + 1 WHERE refcode = %ld", 697 715 pFnDesc->alRefCode[k]); 698 rc = mysql_query(pmysql, &szQuery[0]); 699 700 /* get current status */ 716 rc = mysql_queryu1(pmysql, &szQuery[0]); 717 718 719 /* 720 * Get current status 721 */ 701 722 lCurrentState = dbGetFunctionState(pFnDesc->alRefCode[k]); 702 723 if (lCurrentState == -1) … … 706 727 } 707 728 708 /* update function table first */ 729 730 /* 731 * Update function table first 732 */ 709 733 strcpy(pszQuery, "UPDATE function SET "); 710 734 pszQuery += strlen(pszQuery); … … 727 751 { 728 752 sprintf(pszQuery + strlen(pszQuery), "WHERE refcode = %ld", pFnDesc->alRefCode[k]); 729 rc = mysql_query (pmysql, &szQuery[0]);753 rc = mysql_queryu2(pmysql, &szQuery[0]); 730 754 if (rc < 0) 731 755 { … … 737 761 } 738 762 739 /* parameters */ 763 764 /* 765 * Parameters 766 */ 740 767 pszQuery = &szQuery[0]; 741 sprintf(pszQuery, "DELETE FROM parameter WHERE function = %ld", pFnDesc->alRefCode[k]); 742 rc = mysql_query(pmysql, &szQuery[0]); 743 if (rc < 0) 768 sprintf(pszQuery, "SELECT count(*) FROM parameter WHERE function = %ld", pFnDesc->alRefCode[k]); 769 rc = mysql_queryu3(pmysql, pszQuery); 770 if (rc >= 0) 771 { 772 pres = mysql_store_result(pmysql); 773 if (pres != NULL) 774 row = mysql_fetch_row(pres); 775 if (pres != NULL && row != NULL && mysql_num_rows(pres) == 1) 776 { 777 if (atol(row[0]) == pFnDesc->cParams) 778 { /* update parameters */ 779 for (i = 0; i < pFnDesc->cParams; i++) 780 { 781 sprintf(pszQuery, "UPDATE parameter SET type = '%s', name = '%s' " 782 "WHERE function = (%ld) AND sequencenbr == (%ld)", 783 pFnDesc->apszParamType[i] != NULL ? pFnDesc->apszParamType[i] : "", 784 pFnDesc->apszParamName[i] != NULL ? pFnDesc->apszParamName[i] : "", 785 pFnDesc->alRefCode[k], i 786 ); 787 rc = mysql_queryu4(pmysql, pszQuery); 788 if (rc < 0) 789 { 790 if (*pszError == ' ') 791 strcpy(pszError++, "\n\t"); 792 sprintf(pszError, "Updateing parameter %i failed with error: %s - (sql=%s) ", 793 i, dbGetLastErrorDesc(), pszQuery); 794 pszError += strlen(pszError) - 1; 795 ulRc++; 796 } 797 } 798 } 799 else 800 { 801 if (atol(row[0]) != 0) 802 { /* delete old parameters */ 803 sprintf(pszQuery, "DELETE FROM parameter WHERE function = %ld", pFnDesc->alRefCode[k]); 804 rc = mysql_queryu5(pmysql, pszQuery); 805 if (rc < 0) 806 { 807 if (*pszError == ' ') 808 strcpy(pszError++, "\n\t"); 809 sprintf(pszError, "Deleting old parameters failed with error: %s - (sql=%s) ", 810 dbGetLastErrorDesc(), pszQuery); 811 pszError += strlen(pszError) - 1; 812 ulRc++; 813 } 814 } 815 816 /* insert parameters */ 817 for (i = 0; i < pFnDesc->cParams; i++) 818 { 819 sprintf(pszQuery, "INSERT INTO parameter(function, sequencenbr, type, name) " 820 "VALUES (%ld, %d, '%s', '%s')", 821 pFnDesc->alRefCode[k], i, 822 pFnDesc->apszParamType[i] != NULL ? pFnDesc->apszParamType[i] : "", 823 pFnDesc->apszParamName[i] != NULL ? pFnDesc->apszParamName[i] : "" 824 ); 825 rc = mysql_queryu6(pmysql, pszQuery); 826 if (rc < 0) 827 { 828 if (*pszError == ' ') 829 strcpy(pszError++, "\n\t"); 830 sprintf(pszError, "Inserting parameter %i failed with error: %s - (sql=%s) ", 831 i, dbGetLastErrorDesc(), pszQuery); 832 pszError += strlen(pszError) - 1; 833 ulRc++; 834 } 835 } 836 } 837 } 838 else 839 { 840 if (*pszError == ' ') 841 strcpy(pszError++, "\n\t"); 842 sprintf(pszError, "failed to store result or to fetch a row , error: %s - (sql=%s) ", 843 dbGetLastErrorDesc(), pszQuery); 844 pszError += strlen(pszError) - 1; 845 ulRc++; 846 } 847 } 848 else 744 849 { 745 850 if (*pszError == ' ') 746 851 strcpy(pszError++, "\n\t"); 747 sprintf(pszError, " Deleting old parameters failed witherror: %s - (sql=%s) ",748 dbGetLastErrorDesc(), &szQuery[0]);852 sprintf(pszError, "Failed querying number of parameters, error: %s - (sql=%s) ", 853 dbGetLastErrorDesc(), pszQuery); 749 854 pszError += strlen(pszError) - 1; 750 855 ulRc++; 751 856 } 752 857 753 for (i = 0; i < pFnDesc->cParams; i++) 754 { 755 sprintf(pszQuery, "INSERT INTO parameter(function, sequencenbr, type, name) " 756 "VALUES (%ld, %d, '%s', '%s')", 757 pFnDesc->alRefCode[k], i, 758 pFnDesc->apszParamType[i] != NULL ? pFnDesc->apszParamType[i] : "", 759 pFnDesc->apszParamName[i] != NULL ? pFnDesc->apszParamName[i] : "" 760 ); 761 rc = mysql_query(pmysql, pszQuery); 858 859 /* 860 * Authors 861 */ 862 sprintf(pszQuery, "DELETE FROM fnauthor WHERE function = %ld", pFnDesc->alRefCode[k]); 863 rc = mysql_queryu7(pmysql, pszQuery); 864 if (rc < 0) 865 { 866 if (*pszError == ' ') 867 strcpy(pszError++, "\n\t"); 868 sprintf(pszError, "Deleting old authors failed with error: %s - (sql=%s) ", 869 dbGetLastErrorDesc(), pszQuery); 870 pszError += strlen(pszError) - 1; 871 ulRc++; 872 } 873 874 for (i = 0; i < pFnDesc->cAuthors; i++) 875 { 876 if (pFnDesc->alAuthorRefCode[i] == -1) 877 continue; 878 sprintf(pszQuery, "INSERT INTO fnauthor(author, function) " 879 "VALUES (%ld, %ld)", 880 pFnDesc->alAuthorRefCode[i], pFnDesc->alRefCode[k]); 881 rc = mysql_queryu8(pmysql, pszQuery); 762 882 if (rc < 0) 763 883 { … … 765 885 strcpy(pszError++, "\n\t"); 766 886 sprintf(pszError, "Inserting parameter %i failed with error: %s - (sql=%s) ", 767 i, dbGetLastErrorDesc(), &szQuery[0]); 768 pszError += strlen(pszError) - 1; 769 ulRc++; 770 } 771 } 772 773 /* authors */ 774 pszQuery = &szQuery[0]; 775 sprintf(pszQuery, "DELETE FROM fnauthor WHERE function = %ld", pFnDesc->alRefCode[k]); 776 rc = mysql_query(pmysql, &szQuery[0]); 777 if (rc < 0) 778 { 779 if (*pszError == ' ') 780 strcpy(pszError++, "\n\t"); 781 sprintf(pszError, "Deleting old authors failed with error: %s - (sql=%s) ", 782 dbGetLastErrorDesc(), &szQuery[0]); 783 pszError += strlen(pszError) - 1; 784 ulRc++; 785 } 786 787 for (i = 0; i < pFnDesc->cAuthors; i++) 788 { 789 if (pFnDesc->alAuthorRefCode[i] == -1) 790 continue; 791 sprintf(pszQuery, "INSERT INTO fnauthor(author, function) " 792 "VALUES (%ld, %ld)", 793 pFnDesc->alAuthorRefCode[i], pFnDesc->alRefCode[k]); 794 rc = mysql_query(pmysql, pszQuery); 795 if (rc < 0) 796 { 797 if (*pszError == ' ') 798 strcpy(pszError++, "\n\t"); 799 sprintf(pszError, "Inserting parameter %i failed with error: %s - (sql=%s) ", 800 i, dbGetLastErrorDesc(), &szQuery[0]); 887 i, dbGetLastErrorDesc(), pszQuery); 801 888 pszError += strlen(pszError) - 1; 802 889 ulRc++;
Note:
See TracChangeset
for help on using the changeset viewer.