Changeset 2759 for trunk/tools/database
- Timestamp:
- Feb 11, 2000, 7:35:55 PM (26 years ago)
- Location:
- trunk/tools/database
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/database/APIImport.cpp
r830 r2759 1 /* $Id: APIImport.cpp,v 1. 1 1999-09-05 02:53:04bird Exp $ */1 /* $Id: APIImport.cpp,v 1.2 2000-02-11 18:35:53 bird Exp $ */ 2 2 /* 3 3 * 4 4 * APIImport - imports a DLL or Dll-.def with functions into the Odin32 database. 5 5 * 6 * Copyright (c) 1999 knut st. osmundsen6 * Copyright (c) 1999-2000 knut st. osmundsen 7 7 * 8 8 */ … … 34 34 static void openLog(void); 35 35 static void closeLog(void); 36 static long processFile(const char *pszFilename, const POPTIONS pOptions); 36 static long processFile(const char *pszFilename, const POPTIONS pOptions, long &cFunctions); 37 static void demangle(const char *pszMangledName, char *pszDemangled); 37 38 38 39 … … 54 55 char *pszUser = "root"; 55 56 char *pszPasswd = ""; 57 long cFunctions = 0; 58 56 59 57 60 /************************************************************************** … … 127 130 if (dbConnect(pszHost, pszUser, pszPasswd, pszDatabase)) 128 131 { 129 l = processFile(argv[argi], &options );132 l = processFile(argv[argi], &options, cFunctions); 130 133 lRc = ((lRc & 0xffff0000UL) | (l & 0xffff0000UL)) | ((lRc & 0x0000ffffUL) + l & 0x0000ffffUL); 131 134 dbDisconnect(); … … 141 144 argi++; 142 145 } 146 147 /* write function count */ 148 if (phLog != NULL) 149 fprintf(phLog, "\n %d functions were imported!\n\n", cFunctions); 143 150 144 151 /* close the log */ … … 225 232 * @param pszFilename Pointer to the filename of the file which is to be processed. 226 233 * @param pOptions Pointer to the options-struct. 227 */ 228 static long processFile(const char *pszFilename, const POPTIONS pOptions) 234 * @param cFunctions Function count which is to be updated when functions are imported. 235 */ 236 static long processFile(const char *pszFilename, const POPTIONS pOptions, long &cFunctions) 229 237 { 230 238 kFileFormatBase *pFile; … … 275 283 if (!pFile->isDef() || export.ulOrdinal < ORD_START_INTERNAL_FUNCTIONS) 276 284 { 277 if (export.achName[0] != '\0') 278 { /* name */ 279 int iName = strncmp(&export.achName[0], "_OS2", 4) != 0 ? 0 : 4; 280 fprintf(phLog, "%s: %08ld %s\n", pszFilename, export.ulOrdinal, &export.achName[iName]); 281 fOk = dbInsertUpdateFunction(sDll, &export.achName[iName], export.ulOrdinal, 282 pOptions->fIgnoreOrdinals && export.ulOrdinal != 0xffffffffUL); 283 } 285 char szIntName[64]; 286 char szName[64]; 287 288 demangle(export.achIntName, &szIntName[0]); 289 if (export.achName == '\0') 290 sprintf(&szName[0], "Ordinal%04ld", export.ulOrdinal); 284 291 else 285 { /* ordinal only */ 286 char szFn[50]; 287 288 sprintf(&szFn[0], "Ordinal%04ld", export.ulOrdinal); 289 fprintf(phLog, "%s: %08ld %s\n", pszFilename, export.ulOrdinal, &szFn[0]); 290 if (export.ulOrdinal != 0xffffffffUL) 291 fOk = dbInsertUpdateFunction(sDll, &szFn[0], export.ulOrdinal, pOptions->fIgnoreOrdinals); 292 else 293 fprintf(phLog, "%s: error - invalid ordinal value!\n", pszFilename); 294 } 292 strcpy(&szName[0], &export.achName[0]); 293 294 fprintf(phLog, "%s: %08ld %-30s %s\n", 295 pszFilename, export.ulOrdinal, &szName[0], &szIntName[0]); 296 297 fOk = dbInsertUpdateFunction(sDll, 298 &szName[0], 299 &szIntName[0], 300 export.ulOrdinal, 301 pOptions->fIgnoreOrdinals && export.ulOrdinal != 0xffffffffUL); 302 if (fOk) 303 cFunctions++; 295 304 } 296 305 … … 330 339 } 331 340 341 342 /** 343 * Demangles stdcall functions. 344 * @param pszMangledName Mangled name 345 * @param pszDemangled Pointer to buffer which will hold the demangled name upon return. 346 */ 347 static void demangle(const char *pszMangledName, char *pszDemangled) 348 { 349 int iEnd; 350 /* check for @ */ 351 iEnd = strlen(pszMangledName); 352 if (iEnd-- > 3 && *pszMangledName == '_') 353 { 354 while ((pszMangledName[iEnd] >= '0' && pszMangledName[iEnd] <= '9') && iEnd > 0) 355 iEnd--; 356 if (pszMangledName[iEnd] == '@') 357 { 358 *pszDemangled = '\0'; 359 strncat(pszDemangled, pszMangledName+1, iEnd - 1); 360 return; 361 } 362 } 363 364 /* not stdcall */ 365 strcpy(pszDemangled, pszMangledName); 366 } 367 -
trunk/tools/database/APIImport.h
r830 r2759 1 /* $Id: APIImport.h,v 1. 1 1999-09-05 02:53:04bird Exp $ */1 /* $Id: APIImport.h,v 1.2 2000-02-11 18:35:53 bird Exp $ */ 2 2 /* 3 3 * APIImportPE - imports a DLL with functions into the Odin32 database. Header. … … 13 13 ******************************************************************************/ 14 14 #define MAJOR_VER 0 15 #define MINOR_VER 415 #define MINOR_VER 5 16 16 17 17 /****************************************************************************** -
trunk/tools/database/CreateTables.sql
r830 r2759 1 -- $Id: CreateTables.sql,v 1. 1 1999-09-05 02:53:04 bird Exp $1 -- $Id: CreateTables.sql,v 1.2 2000-02-11 18:35:54 bird Exp $ 2 2 -- 3 3 -- Create all tables. … … 30 30 dll TINYINT NOT NULL, 31 31 name VARCHAR(64) NOT NULL, 32 intname VARCHAR(64) NOT NULL, 32 33 state TINYINT NOT NULL DEFAULT 0, 33 34 ordinal INTEGER NOT NULL, 34 35 apigroup SMALLINT, 35 36 return VARCHAR(64), 37 updated TINYINT NOT NULL DEFAULT 0, 36 38 UNIQUE i1(refcode), 37 UNIQUE i2(name,dll) 39 UNIQUE i2(name,dll), 40 UNIQUE i3(intname, refcode) 38 41 ); 39 42 -
trunk/tools/database/Makefile
r2747 r2759 1 # $Id: Makefile,v 1. 5 2000-02-10 22:45:19bird Exp $1 # $Id: Makefile,v 1.6 2000-02-11 18:35:55 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+ $(CINCLUDES) -DNO_CLIENT_LONG_LONG -Wall+ppt-ppc-inl-cnv-gnr-vft-16 CXXFLAGS = $(CXXFLAGS) -Ge+ -Gx- -Tx+ $(CINCLUDES) -DNO_CLIENT_LONG_LONG -Wall+ppt-ppc-inl-cnv-gnr-vft-15 CFLAGS = $(CFLAGS) -Ge+ -Tx+ -Tm- $(CINCLUDES) -DNO_CLIENT_LONG_LONG -Wall+ppt-ppc-inl-cnv-gnr-vft- 16 CXXFLAGS = $(CXXFLAGS) -Ge+ -Gx- -Tx+ -Tm- $(CINCLUDES) -DNO_CLIENT_LONG_LONG -Wall+ppt-ppc-inl-cnv-gnr-vft- 17 17 LDFLAGS = $(LDFLAGS) -Ge+ -Fe$@ /B"/MAP:full" $(RTLLIB) os2386.lib 18 18 !else -
trunk/tools/database/StateUpd.cpp
r2748 r2759 1 /* $Id: StateUpd.cpp,v 1. 7 2000-02-10 23:37:52bird Exp $1 /* $Id: StateUpd.cpp,v 1.8 2000-02-11 18:35:54 bird Exp $ 2 2 * 3 3 * StateUpd - Scans source files for API functions and imports data on them. … … 44 44 static unsigned long analyseFnDcl2(PFNDESC pFnDesc, char **papszLines, int i, int &iRet, const char *pszFilename, POPTIONS pOptions); 45 45 static BOOL isFunction(char **papszLines, int i, POPTIONS pOptions); 46 static long _System dbNotUpdatedCallBack(const char *pszValue, const char *pszFieldName, void *pvUser); 46 47 static char *skipInsignificantChars(char **papszLines, int &i, char *psz); 47 48 static char *readFileIntoMemory(const char *pszFilename); … … 66 67 BOOL fFatal = FALSE; 67 68 unsigned long ulRc = 0; 68 OPTIONS options = {TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE}; 69 char szDLLName[64]; 70 OPTIONS options = {TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, &szDLLName[0], -1}; 69 71 unsigned long ulRc2; 70 72 char *pszErrorDesc = NULL; … … 73 75 char *pszUser = "root"; 74 76 char *pszPasswd = ""; 75 77 ULONG ul1, ul2; 76 78 DosError(0x3); 79 80 /* get dll name from directory */ 81 ul1 = ul2 = 0; 82 DosQueryCurrentDisk(&ul1, &ul2); 83 ul2 = sizeof(szDLLName); 84 DosQueryCurrentDir(ul1, &szDLLName[0], &ul2); 85 if (ul2 != 0) 86 { 87 if (szDLLName[ul2-1] == '\\' || szDLLName[ul2-1] == '/') 88 szDLLName[--ul2] = '\0'; 89 ul1 = ul2; 90 while (ul1 != 0 && szDLLName[ul1-1] != '\\' && szDLLName[ul1-1] != '/') 91 ul1--; 92 if (ul1 != 0) 93 options.pszDLLName = &szDLLName[ul1]; 94 } 95 else 96 szDLLName[0] = '\0'; 97 77 98 78 99 /************************************************************************** … … 87 108 * -COMCTL32<[+]|-> Removes 'COMCTL32'-prefix from function name. 88 109 * -VERSION<[+]|-> Removes 'VERSION'-prefix from function name. 110 * -Dll:<dllname> Name of the dll being processed. 89 111 * -d:<dbname> Database name 90 112 * -p:<passwd> Password … … 101 123 case 'd': 102 124 case 'D': 103 if ( argv[argi][2] == ':')104 pszDatabase = &argv[argi][3];125 if (strnicmp(argv[argi], "dll:", 4) == 0 ) 126 options.pszDLLName = &argv[argi][5]; 105 127 else 106 fprintf(stderr, "warning: option '-d:' requires database name.\n"); 128 { 129 if (argv[argi][2] == ':') 130 pszDatabase = &argv[argi][3]; 131 else 132 fprintf(stderr, "warning: option '-d:' requires database name.\n"); 133 } 107 134 break; 108 135 … … 217 244 if (!options.fIntegrityOnly) 218 245 { 246 /* find dll */ 247 options.lDllRefcode = dbGetDll(options.pszDLLName); 248 fprintf(phLog, "DLL: refcode=%d, name=%s\n", options.lDllRefcode, options.pszDLLName); 249 219 250 /* processing */ 220 251 if (argv[argi] == NULL || *argv[argi] == '\0') … … 253 284 } 254 285 286 /* write status to log */ 287 fprintf(phLog, "-------------------------------------------------\n"); 288 fprintf(phLog, "-------- Functions which was not updated --------\n"); 289 dbGetNotUpdatedFunction(options.lDllRefcode, dbNotUpdatedCallBack); 290 fprintf(phLog, "-------------------------------------------------\n"); 291 fprintf(phLog, "-------------------------------------------------\n\n"); 292 ul1 = dbCountFunctionInDll(options.lDllRefcode); 293 fprintf(phLog,"Number of function in this DLL: %4ld\n", ul1); 294 fprintf(phLog,"Number of successfully processed APIs: %4ld\n", (long)(0x0000FFFF & ulRc)); 295 fprintf(phLog,"Number of signals: %4ld\n", (long)(ulRc >> 16)); 296 255 297 /* close the logs */ 256 298 closeLogs(); … … 260 302 261 303 /* warn if error during processing. */ 304 fprintf(stdout,"Number of function in this DLL: %4ld\n", ul1); 262 305 fprintf(stdout,"Number of successfully processed APIs: %4ld\n", (long)(0x0000FFFF & ulRc)); 263 306 fprintf(stdout,"Number of signals: %4ld\n", (long)(ulRc >> 16)); … … 568 611 569 612 /* 3.*/ 570 fprintf(phLog, "Name: '%s' (refcode=%ld)\n", FnDesc.pszName, FnDesc.lRefCode); 613 fprintf(phLog, "Name: '%s' (refcodes=", FnDesc.pszName); 614 for (j = 0; j < FnDesc.cRefCodes; j++) 615 fprintf(phLog, j > 0 ? ", %ld" : "%ld", FnDesc.alRefCode[j]); 616 fprintf(phLog, ")\n"); 571 617 fprintf(phLog, " Returns: '%s'\n", FnDesc.pszReturnType != NULL ? FnDesc.pszReturnType : "<missing>"); 572 618 fprintf(phLog, " cParams: %2d\n", FnDesc.cParams); … … 640 686 } 641 687 642 if (FnFindBuf.cFns == 0) 643 { 688 pFnDesc->cRefCodes = 0; 689 if (FnFindBuf.cFns != 0) 690 { 691 if (pOptions->lDllRefcode < 0) 692 { 693 if (FnFindBuf.cFns > 1) 694 { 695 fprintf(phSignal, "%s: unknown dll and more than two occurences of this function!\n", pszFilename); 696 return 0x00010000; 697 } 698 pOptions->lDllRefcode = FnFindBuf.alDllRefCode[0]; 699 fprintf(phLog, "DllRef = %d\n", pOptions->lDllRefcode); 700 } 701 702 for (lFn = 0; lFn < FnFindBuf.cFns; lFn++) 703 { 704 if (FnFindBuf.alDllRefCode[lFn] == pOptions->lDllRefcode) 705 pFnDesc->alRefCode[pFnDesc->cRefCodes++] = FnFindBuf.alRefCode[lFn]; 706 } 707 708 if (pFnDesc->cRefCodes == 0) 709 fprintf(phLog, "%s was not an API in this dll(%d)!\n", pFnDesc->pszName, pOptions->lDllRefcode); 710 } 711 else 644 712 fprintf(phLog, "%s was not an API\n", pFnDesc->pszName); 645 return 0; 646 } 647 else if (FnFindBuf.cFns > 1) 648 { /* 3b.*/ 649 while (lFn < (int)FnFindBuf.cFns && FnFindBuf.alDllRefCode[lFn] != lPrevFnDll) 650 lFn++; 651 if (lPrevFnDll == -1L && lFn >= (int)FnFindBuf.cFns) 652 { 653 fprintf(phSignal, "%s, %s: error - more than one function by the name '%s'\n", 654 pszFilename, pFnDesc->pszName, pFnDesc->pszName); 655 return 0x00010000; 656 } 657 } 658 pFnDesc->lRefCode = FnFindBuf.alRefCode[lFn]; 659 lPrevFnDll = FnFindBuf.alDllRefCode[lFn]; 660 713 714 ulRc = pFnDesc->cRefCodes; 661 715 return ulRc; 662 716 } … … 681 735 * 1. find the '(' 682 736 * 2. find the word ahead of the '(', this is the function name. 737 * 2a. class test. 683 738 * 3. find the closing ')' 684 739 * 4. copy the parameters, which is between the two '()' … … 687 742 688 743 int iFn, iP1, iP2, j; 689 char * pszFn, *psz P1, *pszP2;744 char * pszFn, *pszFnEnd, *pszP1, *pszP2; 690 745 char * psz, *pszEnd; 691 746 int cArgs; … … 729 784 return 0x00010000; 730 785 } 786 pszFnEnd = pszFn; 731 787 pszFn = findStartOfWord(pszFn, papszLines[i]); 788 789 /* 2a. */ 790 psz = pszFn; 791 while (psz >= papszLines[i] && *psz == ' ') 792 psz--; 793 if (psz > papszLines[i] && *psz == ':') 794 { 795 while (psz >= papszLines[i] && *psz == ' ') 796 psz--; 797 if (psz > papszLines[i] && *psz == ':') 798 { 799 while (psz >= papszLines[i] && *psz == ' ') 800 psz--; 801 if (psz > papszLines[i]) 802 pszFn = findStartOfWord(psz, papszLines[i]); 803 else 804 fprintf(phLog, "%.*s: class name is not at same line as the ::\n", pszFnEnd - psz-1, psz+1); 805 } 806 else 807 { 808 fprintf(phLog, "%.*s: invalid class '::'\n", pszFnEnd - psz, psz); 809 return 0; 810 } 811 } 732 812 733 813 /* 3. */ … … 792 872 else 793 873 { 874 /* return type - not implemented TODO/FIXME! */ 875 *pszEnd = '\0'; 876 copy(pszEnd, papszLines[i], i, pszFn-1, iFn, papszLines); 877 pFnDesc->pszReturnType = *pszEnd == '\0' ? NULL : pszEnd; 878 pszEnd = strlen(pszEnd) + pszEnd + 1; 879 794 880 /* function name */ 795 881 *pszEnd = '\0'; 796 strncat(pszEnd, pszFn, findEndOfWord(pszFn) - pszFn); 882 if (pFnDesc->pszReturnType != NULL 883 && stristr(pFnDesc->pszReturnType, "cdecl") != NULL) 884 { /* cdecl function is prefixed with an '_' */ 885 strcpy(pszEnd, "_"); 886 strncat(pszEnd+1, pszFn, pszFnEnd - pszFn+1); 887 } 888 else 889 strncat(pszEnd, pszFn, pszFnEnd - pszFn+1); 890 797 891 pFnDesc->pszName = pszEnd; 798 799 /* return type - not implemented TODO/FIXME! */800 pFnDesc->pszReturnType = NULL;801 892 802 893 /* arguments */ … … 1227 1318 1228 1319 1320 1321 /** 1322 * Callback function for the dbGetNotUpdatedFunction routine. 1323 * 1324 */ 1325 static long _System dbNotUpdatedCallBack(const char *pszValue, const char *pszFieldName, void *pvUser) 1326 { 1327 if (stricmp(pszFieldName, "name") == 0) 1328 fprintf(phLog, "%s ", pszValue); 1329 else if (stricmp(pszFieldName, "updated") == 0) 1330 fprintf(phLog, "update=%s ", pszValue); 1331 else if (stricmp(pszFieldName, "intname") == 0) 1332 fprintf(phLog, "(%s)\n", pszValue); 1333 1334 pvUser = pvUser; 1335 return 0; 1336 } 1337 1338 1229 1339 /** 1230 1340 * Skips insignificant chars (spaces, new-lines and comments) -
trunk/tools/database/StateUpd.h
r830 r2759 1 /* $Id: StateUpd.h,v 1. 1 1999-09-05 02:53:05bird Exp $ */1 /* $Id: StateUpd.h,v 1.2 2000-02-11 18:35:54 bird Exp $ */ 2 2 /* 3 3 * StateUpd - Scans source files for API functions and imports data on them. … … 10 10 11 11 #define MAJOR_VER 0 12 #define MINOR_VER 412 #define MINOR_VER 5 13 13 14 14 #pragma pack() … … 16 16 typedef struct _options 17 17 { 18 BOOL fIntegrityBefore; /* ib */ 19 BOOL fIntegrityAfter; /* ie */ 20 BOOL fIntegrityOnly; /* io */ 21 BOOL fRecursive; /* s */ 22 BOOL fOld; /* Old */ 23 BOOL fOS2; /* Ignore OS2 prefixes */ 24 BOOL fCOMCTL32; /* Ignore COMCTL32 prefixes */ 25 BOOL fVERSION; /* Ignore VERSION prefixes */ 18 BOOL fIntegrityBefore; /* ib */ 19 BOOL fIntegrityAfter; /* ie */ 20 BOOL fIntegrityOnly; /* io */ 21 BOOL fRecursive; /* s */ 22 BOOL fOld; /* Old */ 23 BOOL fOS2; /* Ignore OS2 prefixes */ 24 BOOL fCOMCTL32; /* Ignore COMCTL32 prefixes */ 25 BOOL fVERSION; /* Ignore VERSION prefixes */ 26 char * pszDLLName; /* Name of the dll being processed */ 27 signed long lDllRefcode; /* Database reference code of the dll */ 26 28 } OPTIONS, *POPTIONS; 27 29 -
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; -
trunk/tools/database/db.h
r1993 r2759 1 /* $Id: db.h,v 1. 2 1999-12-06 18:11:50bird Exp $ */1 /* $Id: db.h,v 1.3 2000-02-11 18:35:54 bird Exp $ */ 2 2 /* 3 3 * DB - contains all database routines … … 15 15 #endif 16 16 17 18 /******************************************************************************* 19 * Defined Constants * 20 *******************************************************************************/ 21 #define NBR_FUNCTIONS 20 22 #define NBR_AUTHORS 20 23 17 24 /******************************************************************************* 18 25 * Structures and Typedefs * … … 27 34 char *pszName; 28 35 char *pszReturnType; 29 long lRefCode; 36 long cRefCodes; 37 long alRefCode[NBR_FUNCTIONS]; 30 38 31 39 /* parameters */ … … 36 44 /* authors */ 37 45 int cAuthors; 38 char *apszAuthor[ 20];39 long alAuthorRefCode[ 20];46 char *apszAuthor[NBR_AUTHORS]; 47 long alAuthorRefCode[NBR_AUTHORS]; 40 48 41 49 /* status */ … … 48 56 { 49 57 unsigned long cFns; 50 signed long alRefCode[ 10];51 signed long alDllRefCode[ 10];58 signed long alRefCode[NBR_FUNCTIONS]; 59 signed long alDllRefCode[NBR_FUNCTIONS]; 52 60 } FNFINDBUF, *PFNFINDBUF; 53 61 … … 59 67 char * _System dbGetLastErrorDesc(void); 60 68 61 BOOL _System dbConnect(const char *pszHost, const char *pszUser, const char *pszPassword, const char *pszDatabase); 69 BOOL _System dbConnect(const char *pszHost, 70 const char *pszUser, 71 const char *pszPassword, 72 const char *pszDatabase); 62 73 BOOL _System dbDisconnect(); 74 signed short _System dbGetDll(const char *pszDllName); 75 signed long _System dbCountFunctionInDll(signed long ulDll); 76 63 77 signed short _System dbCheckInsertDll(const char *pszDll); 64 unsigned short _System dbGet(const char *pszTable, const char *pszGetColumn, 65 const char *pszMatch1, const char *pszMatchValue1); 66 BOOL _System dbInsertUpdateFunction(unsigned short usDll, const char *pszFunction, 67 unsigned long ulOrdinal, BOOL fIgnoreOrdinal); 68 BOOL _System dbFindFunction(const char *pszFunctionName, PFNFINDBUF pFnFindBuf); 78 unsigned short _System dbGet(const char *pszTable, 79 const char *pszGetColumn, 80 const char *pszMatch1, 81 const char *pszMatchValue1); 82 BOOL _System dbInsertUpdateFunction(unsigned short usDll, 83 const char *pszFunction, 84 const char *pszIntFunction, 85 unsigned long ulOrdinal, 86 BOOL fIgnoreOrdinal); 87 BOOL _System dbFindFunction(const char *pszFunctionName, 88 PFNFINDBUF pFnFindBuf); 69 89 signed long _System dbFindAuthor(const char *pszAuthor); 70 90 signed long _System dbGetFunctionState(signed long lRefCode); 71 unsigned long _System dbUpdateFunction(PFNDESC pFnDesc, char *pszError); 91 unsigned long _System dbUpdateFunction(PFNDESC pFnDesc, 92 char *pszError); 72 93 unsigned long _System dbCreateHistory(char *pszError); 73 94 unsigned long _System dbCheckIntegrity(char *pszError); … … 77 98 signed long _System dbQueryResultRows(void *pres); 78 99 BOOL _System dbFreeResult(void *pres); 79 BOOL _System dbFetch(void *pres, DBCALLBACKFETCH dbFetchCallBack, void *pvUser); 100 BOOL _System dbFetch(void *pres, 101 DBCALLBACKFETCH dbFetchCallBack, 102 void *pvUser); 80 103 signed long _System dbDateToDaysAfterChrist(const char *pszDate); 81 BOOL _System dbDaysAfterChristToDate(signed long ulDays, char *pszDate); 104 BOOL _System dbDaysAfterChristToDate(signed long ulDays, 105 char *pszDate); 106 /* StateUpd stuff */ 107 BOOL _System dbGetNotUpdatedFunction(signed long lDll, 108 DBCALLBACKFETCH dbFetchCallBack); 82 109 83 110 #ifdef __cplusplus
Note:
See TracChangeset
for help on using the changeset viewer.