Changeset 3882 for trunk/tools/database/db.cpp
- Timestamp:
- Jul 21, 2000, 11:09:45 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/database/db.cpp
r3848 r3882 1 /* $Id: db.cpp,v 1.1 5 2000-07-18 17:56:50bird Exp $ *1 /* $Id: db.cpp,v 1.16 2000-07-21 21:09:44 bird Exp $ * 2 2 * 3 3 * DB - contains all database routines. … … 158 158 * @param pszDllName Dll name. 159 159 */ 160 signed short_System dbGetDll(const char *pszDllName)160 signed long _System dbGetDll(const char *pszDllName) 161 161 { 162 162 int rc; … … 173 173 rc = -1; 174 174 mysql_free_result(pres); 175 return (s hort)rc;175 return (signed long)rc; 176 176 } 177 177 … … 180 180 * Count the function in a given dll. 181 181 * @returns Number of functions. -1 on error. 182 * @param usDllDll refcode.182 * @param lDll Dll refcode. 183 183 * @param fNotAliases TRUE: don't count aliased functions. 184 184 */ 185 signed long _System dbCountFunctionInDll(signed long ulDll, BOOL fNotAliases)185 signed long _System dbCountFunctionInDll(signed long lDll, BOOL fNotAliases) 186 186 { 187 187 signed long rc; … … 189 189 MYSQL_RES * pres; 190 190 191 if ( ulDll >= 0)192 { 193 sprintf(&szQuery[0], "SELECT count(refcode) FROM function WHERE dll = %ld\n", ulDll);191 if (lDll >= 0) 192 { 193 sprintf(&szQuery[0], "SELECT count(refcode) FROM function WHERE dll = %ld\n", lDll); 194 194 if (fNotAliases) 195 195 strcat(&szQuery[0], " AND aliasfn < 0"); … … 217 217 * (In the mysql-world everything is case insensitive!) 218 218 */ 219 signed short _System dbCheckInsertDll(const char *pszDll)219 signed long _System dbCheckInsertDll(const char *pszDll, char fchType) 220 220 { 221 221 int rc; … … 233 233 mysql_free_result(pres); 234 234 235 sprintf(&szQuery[0], "INSERT INTO dll(name ) VALUES('%s')\n", pszDll);235 sprintf(&szQuery[0], "INSERT INTO dll(name, type) VALUES('%s', '%c')\n", pszDll, fchType); 236 236 rc = mysql_query(pmysql, &szQuery[0]); 237 if (rc < 0) 238 return -1; 237 239 238 240 /* select row to get refcode */ … … 248 250 mysql_free_result(pres); 249 251 250 return ( short)rc;252 return (long)rc; 251 253 } 252 254 … … 280 282 mysql_free_result(pres); 281 283 282 return ( short)rc;284 return (unsigned short)rc; 283 285 } 284 286 … … 286 288 /** 287 289 * Updates or inserts a function name into the database. 288 * @returns Success indicator. TRUE / FALSE. 289 * @param usDll Dll refcode. 290 * @param pszFunction Function name. 291 * @param pszIntFunction Internal function name. (required!) 292 * @param ulOrdinal Ordinal value. 293 * @param fIgnoreOrdinal Do not update ordinal value. 294 */ 295 BOOL _System dbInsertUpdateFunction(unsigned short usDll, 290 * The update flags is always updated. 291 * @returns Success indicator. TRUE / FALSE. 292 * @param lDll Dll refcode. 293 * @param pszFunction Function name. 294 * @param pszIntFunction Internal function name. (required!) 295 * @param ulOrdinal Ordinal value. 296 * @param fIgnoreOrdinal Do not update ordinal value. 297 * @param fchType Function type flag. One of the FUNCTION_* defines. 298 */ 299 BOOL _System dbInsertUpdateFunction(signed long lDll, 296 300 const char *pszFunction, const char *pszIntFunction, 297 unsigned long ulOrdinal, BOOL fIgnoreOrdinal) 298 { 299 int rc; 300 long lFunction = -1; 301 char szQuery[512]; 301 unsigned long ulOrdinal, BOOL fIgnoreOrdinal, char fchType) 302 { 303 int rc; 304 long lFunction = -1; 305 char szQuery[512]; 306 char * pszQuery = &szQuery[0]; 302 307 MYSQL_RES *pres; 303 308 … … 307 312 308 313 /* try find function */ 309 sprintf( &szQuery[0], "SELECT refcode, intname FROM function WHERE dll = %d AND name = '%s'", usDll, pszFunction);310 rc = mysql_query(pmysql, &szQuery[0]);314 sprintf(pszQuery, "SELECT refcode, intname FROM function WHERE dll = %d AND name = '%s'", lDll, pszFunction); 315 rc = mysql_query(pmysql, pszQuery); 311 316 pres = mysql_store_result(pmysql); 312 317 if (rc >= 0 && pres != NULL && mysql_num_rows(pres) != 0) 313 { /* update function (function is found) */ 318 { /* 319 * Found the function. So now we'll update it. 320 */ 314 321 MYSQL_ROW parow; 315 322 if (mysql_num_rows(pres) > 1) 316 323 { 317 324 fprintf(stderr, "internal database integrity error(%s): More function by the same name for the same dll. " 318 " usDll = %d, pszFunction = %s\n", __FUNCTION__, usDll, pszFunction);325 "lDll = %d, pszFunction = %s\n", __FUNCTION__, lDll, pszFunction); 319 326 return FALSE; 320 327 } 321 328 322 329 parow = mysql_fetch_row(pres); 323 if (parow != NULL) 324 lFunction = getvalue(0, parow); 330 lFunction = getvalue(0, parow); 325 331 mysql_free_result(pres); 326 332 333 strcpy(pszQuery, "UPDATE function SET updated = updated + 1"); 334 pszQuery += strlen(pszQuery); 327 335 if (strcmp(parow[1], pszIntFunction) != 0) 328 { 329 sprintf(&szQuery[0], "UPDATE function SET intname = '%s' WHERE refcode = %ld", 330 pszIntFunction, lFunction); 331 rc = mysql_query(pmysql, &szQuery[0]); 332 } 333 334 if (rc >= 0 && !fIgnoreOrdinal) 335 { 336 sprintf(&szQuery[0], "UPDATE function SET ordinal = %ld WHERE refcode = %ld", 337 ulOrdinal, lFunction); 338 rc = mysql_query(pmysql, &szQuery[0]); 339 } 340 336 pszQuery += sprintf(pszQuery, ", intname = '%s'", pszIntFunction); 337 338 if (!fIgnoreOrdinal) 339 pszQuery += sprintf(pszQuery, ", ordinal = %ld", ulOrdinal); 340 341 sprintf(pszQuery, ", type = '%c' WHERE refcode = %ld", fchType, lFunction); 342 rc = mysql_query(pmysql, &szQuery[0]); 341 343 } 342 344 else 343 { /* insert */ 344 sprintf(&szQuery[0], "INSERT INTO function(dll, name, intname, ordinal) VALUES(%d, '%s', '%s', %ld)", 345 usDll, pszFunction, pszIntFunction, ulOrdinal); 345 { /* 346 * The function was not found. (or maybe an error occured?) 347 * Insert it. 348 */ 349 sprintf(&szQuery[0], "INSERT INTO function(dll, name, intname, ordinal, updated, type) VALUES(%d, '%s', '%s', %ld, 1, '%c')", 350 lDll, pszFunction, pszIntFunction, ulOrdinal, fchType); 346 351 rc = mysql_query(pmysql, &szQuery[0]); 347 352 } … … 355 360 * Inserts or updates (existing) file information. 356 361 * @returns Success indicator (TRUE / FALSE). 357 * @param usDll Dll reference code.362 * @param lDll Dll reference code. 358 363 * @param pszFilename Filename. 359 364 * @param pszDescription Pointer to file description. … … 364 369 * @remark 365 370 */ 366 BOOL _System dbInsertUpdateFile( unsigned short usDll,371 BOOL _System dbInsertUpdateFile(signed long lDll, 367 372 const char *pszFilename, 368 373 const char *pszDescription, … … 377 382 378 383 /* parameter assertions */ 379 assert( usDll != 0);384 assert(lDll != 0); 380 385 assert(pszFilename != NULL); 381 386 assert(*pszFilename != '\0'); 382 387 383 388 /* try find file */ 384 sprintf(&szQuery[0], "SELECT refcode, name FROM file WHERE dll = %d AND name = '%s'", usDll, pszFilename);389 sprintf(&szQuery[0], "SELECT refcode, name FROM file WHERE dll = %d AND name = '%s'", lDll, pszFilename); 385 390 rc = mysql_query(pmysql, &szQuery[0]); 386 391 pres = mysql_store_result(pmysql); … … 391 396 { 392 397 fprintf(stderr, "internal database integrity error(%s): More files by the same name in the same dll. " 393 " usDll = %d, pszFilename = %s\n", __FUNCTION__, usDll, pszFilename);398 "lDll = %d, pszFilename = %s\n", __FUNCTION__, lDll, pszFilename); 394 399 return FALSE; 395 400 } … … 446 451 { /* insert */ 447 452 sprintf(&szQuery[0], "INSERT INTO file(dll, name, description, lastauthor, lastdatetime, revision) VALUES(%d, '%s', %ld, ", 448 usDll, pszFilename, lLastAuthor);453 lDll, pszFilename, lLastAuthor); 449 454 if (pszDescription != NULL && *pszDescription != '\0') 450 455 sqlstrcat(&szQuery[0], NULL, pszDescription); … … 986 991 } 987 992 988 /* Equiv*/993 /* Time */ 989 994 if (pFnDesc->pszTime != NULL) 990 995 { … … 1917 1922 1918 1923 1924 1925 /** 1926 * Clear the update flags for all file in a dll/module. 1927 * @returns Success indicator. (TRUE / FALSE) 1928 * @param lDll Dll refcode. 1929 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 1930 * @remark Intended for use by APIImport. 1931 */ 1932 BOOL _System dbClearUpdateFlagFile(signed long lDll) 1933 { 1934 int rc; 1935 char szQuery[128]; 1936 1937 sprintf(&szQuery[0], 1938 "UPDATE file SET updated = 0 WHERE dll = (%ld)", 1939 lDll); 1940 rc = mysql_query(pmysql, &szQuery[0]); 1941 return rc == 0; 1942 } 1943 1944 1945 /** 1946 * Clear update flag 1947 * @returns Success indicator. 1948 * @param lDll Dll refcode. 1949 * @param fAll All dll. If false only APIs and Internal APIs are cleared 1950 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 1951 * @remark Intended for use by APIImport. 1952 */ 1953 BOOL _System dbClearUpdateFlagFunction(signed long lDll, BOOL fAll) 1954 { 1955 int rc; 1956 char szQuery[128]; 1957 1958 sprintf(&szQuery[0], 1959 "UPDATE function SET updated = 0 WHERE dll = (%ld)", 1960 lDll); 1961 if (!fAll) 1962 strcat(&szQuery[0], " AND type IN ('A', 'I')"); 1963 rc = mysql_query(pmysql, &szQuery[0]); 1964 return rc == 0; 1965 } 1966 1967 1968 1969 /** 1970 * Deletes all the files in a dll/module which was not found/updated. 1971 * @returns Success indicator. 1972 * @param lDll Dll refcode. 1973 * @sketch Select all files which is to be deleted. 1974 * Set all references to each file in function to -1. 1975 * Delete all files which is to be deleted. 1976 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 1977 * @remark Use with GRATE CARE! 1978 */ 1979 BOOL _System dbDeleteNotUpdatedFiles(signed long lDll) 1980 { 1981 MYSQL_RES * pres; 1982 int rc; 1983 BOOL fRc = TRUE; 1984 char szQuery[128]; 1985 1986 sprintf(&szQuery[0], 1987 "SELECT refcode FROM file WHERE dll = (%ld) AND updated = 0", 1988 lDll); 1989 rc = mysql_query(pmysql, &szQuery[0]); 1990 pres = mysql_store_result(pmysql); 1991 if (pres != NULL && mysql_num_rows(pres)) 1992 { 1993 MYSQL_ROW row; 1994 while ((row = mysql_fetch_row(pres)) != NULL) 1995 { 1996 sprintf(&szQuery[0], 1997 "UPDATE function SET file = -1 WHERE file = %s", 1998 row[0]); 1999 rc = mysql_query(pmysql, &szQuery[0]); 2000 if (rc) fRc = FALSE; 2001 } 2002 } 2003 2004 sprintf(&szQuery[0], 2005 "DELETE FROM file WHERE dll = %ld AND updated = 0", 2006 lDll); 2007 rc = mysql_query(pmysql, &szQuery[0]); 2008 if (rc) fRc = FALSE; 2009 2010 return fRc; 2011 } 2012 2013 2014 /** 2015 * Deletes all the functions which haven't been updated. 2016 * All rows in other tables which references the functions are 2017 * also delete. 2018 * 2019 * @returns Success indicator. (TRUE / FALSE) 2020 * @param lDll The refcode of the dll owning the functions. 2021 * @param fAll All function. If FALSE then only APIs and Internal APIs. 2022 * @sketch Select all functions which has updated = 0 and dll = lDll. 2023 * Delete the referenced to the functions in: 2024 * parameters 2025 * fnauthor 2026 * Delete all function which has updated = 0 and dll = lDll 2027 * 2028 * @remark Use with GREATE CARE! 2029 */ 2030 BOOL _System dbDeleteNotUpdatedFunctions(signed long lDll, BOOL fAll) 2031 { 2032 MYSQL_RES * pres; 2033 int rc; 2034 BOOL fRc = TRUE; 2035 char szQuery[128]; 2036 2037 sprintf(&szQuery[0], 2038 "SELECT refcode FROM function WHERE dll = %ld AND updated = 0", 2039 lDll); 2040 if (!fAll) 2041 strcat(&szQuery[0], " AND type IN ('A', 'I')"); 2042 rc = mysql_query(pmysql, &szQuery[0]); 2043 pres = mysql_store_result(pmysql); 2044 if (pres != NULL && mysql_num_rows(pres)) 2045 { 2046 MYSQL_ROW row; 2047 while ((row = mysql_fetch_row(pres)) != NULL) 2048 { 2049 /* delete parameters */ 2050 sprintf(&szQuery[0], "DELETE FROM parameter WHERE function %s", row[0]); 2051 rc = mysql_query(pmysql, &szQuery[0]); 2052 if (rc) fRc = FALSE; 2053 2054 /* author relations */ 2055 sprintf(&szQuery[0], "DELETE FROM fnauthor WHERE function %s", row[0]); 2056 rc = mysql_query(pmysql, &szQuery[0]); 2057 if (rc) fRc = FALSE; 2058 } 2059 } 2060 2061 sprintf(&szQuery[0], 2062 "DELETE FROM function WHERE dll = %ld AND updated = 0", 2063 lDll); 2064 if (!fAll) 2065 strcat(&szQuery[0], " AND type IN ('A', 'I')"); 2066 rc = mysql_query(pmysql, &szQuery[0]); 2067 if (rc) fRc = FALSE; 2068 2069 return fRc; 2070 } 2071 2072 2073 1919 2074 /** 1920 2075 * Appends a set of strings to a query. The main string (pszStr) is enclosed in "'"s. … … 1929 2084 static char *sqlstrcat(char *pszQuery, const char *pszBefore, const char *pszStr, const char *pszAfter) 1930 2085 { 1931 char * pszLineStart = pszQuery; 2086 char * pszLineStart = pszQuery; 1932 2087 register char ch; 1933 2088 … … 1982 2137 *pszQuery++ = 'n'; 1983 2138 break; 1984 2139 1985 2140 case '\t': 1986 2141 *pszQuery++ = '\\';
Note:
See TracChangeset
for help on using the changeset viewer.