Changeset 2759 for trunk/tools/database


Ignore:
Timestamp:
Feb 11, 2000, 7:35:55 PM (26 years ago)
Author:
bird
Message:

Odin32 DB.

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:04 bird Exp $ */
     1/* $Id: APIImport.cpp,v 1.2 2000-02-11 18:35:53 bird Exp $ */
    22/*
    33 *
    44 * APIImport - imports a DLL or Dll-.def with functions into the Odin32 database.
    55 *
    6  * Copyright (c) 1999 knut st. osmundsen
     6 * Copyright (c) 1999-2000 knut st. osmundsen
    77 *
    88 */
     
    3434static void openLog(void);
    3535static void closeLog(void);
    36 static long processFile(const char *pszFilename, const POPTIONS pOptions);
     36static long processFile(const char *pszFilename, const POPTIONS pOptions, long &cFunctions);
     37static void demangle(const char *pszMangledName, char *pszDemangled);
    3738
    3839
     
    5455    char   *pszUser     = "root";
    5556    char   *pszPasswd   = "";
     57    long    cFunctions  = 0;
     58
    5659
    5760    /**************************************************************************
     
    127130            if (dbConnect(pszHost, pszUser, pszPasswd, pszDatabase))
    128131            {
    129                 l = processFile(argv[argi], &options);
     132                l = processFile(argv[argi], &options, cFunctions);
    130133                lRc = ((lRc & 0xffff0000UL) | (l & 0xffff0000UL)) | ((lRc & 0x0000ffffUL) + l & 0x0000ffffUL);
    131134                dbDisconnect();
     
    141144        argi++;
    142145    }
     146
     147    /* write function count */
     148    if (phLog != NULL)
     149        fprintf(phLog, "\n %d functions were imported!\n\n", cFunctions);
    143150
    144151    /* close the log */
     
    225232 * @param     pszFilename  Pointer to the filename of the file which is to be processed.
    226233 * @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 */
     236static long processFile(const char *pszFilename, const POPTIONS pOptions, long &cFunctions)
    229237{
    230238    kFileFormatBase  *pFile;
     
    275283                        if (!pFile->isDef() || export.ulOrdinal < ORD_START_INTERNAL_FUNCTIONS)
    276284                        {
    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);
    284291                            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++;
    295304                        }
    296305
     
    330339}
    331340
     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 */
     347static 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:04 bird Exp $ */
     1/* $Id: APIImport.h,v 1.2 2000-02-11 18:35:53 bird Exp $ */
    22/*
    33 * APIImportPE - imports a DLL with functions into the Odin32 database. Header.
     
    1313******************************************************************************/
    1414#define MAJOR_VER 0
    15 #define MINOR_VER 4
     15#define MINOR_VER 5
    1616
    1717/******************************************************************************
  • 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 $
    22--
    33-- Create all tables.
     
    3030    dll     TINYINT NOT NULL,
    3131    name    VARCHAR(64) NOT NULL,
     32    intname VARCHAR(64) NOT NULL,
    3233    state   TINYINT NOT NULL DEFAULT 0,
    3334    ordinal INTEGER NOT NULL,
    3435    apigroup SMALLINT,
    3536    return VARCHAR(64),
     37    updated TINYINT NOT NULL DEFAULT 0,
    3638    UNIQUE i1(refcode),
    37     UNIQUE i2(name,dll)
     39    UNIQUE i2(name,dll),
     40    UNIQUE i3(intname, refcode)
    3841);
    3942
  • trunk/tools/database/Makefile

    r2747 r2759  
    1 # $Id: Makefile,v 1.5 2000-02-10 22:45:19 bird Exp $
     1# $Id: Makefile,v 1.6 2000-02-11 18:35:55 bird Exp $
    22
    33#
     
    1313CINCLUDES= -I$(PDWIN32_INCLUDE) -I$(PDWIN32_INCLUDE)\win -Igd -Imysql -I..\common
    1414!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-
     15CFLAGS   = $(CFLAGS)   -Ge+ -Tx+ -Tm- $(CINCLUDES)      -DNO_CLIENT_LONG_LONG -Wall+ppt-ppc-inl-cnv-gnr-vft-
     16CXXFLAGS = $(CXXFLAGS) -Ge+ -Gx- -Tx+ -Tm- $(CINCLUDES) -DNO_CLIENT_LONG_LONG -Wall+ppt-ppc-inl-cnv-gnr-vft-
    1717LDFLAGS  = $(LDFLAGS)  -Ge+ -Fe$@ /B"/MAP:full" $(RTLLIB) os2386.lib
    1818!else
  • trunk/tools/database/StateUpd.cpp

    r2748 r2759  
    1 /* $Id: StateUpd.cpp,v 1.7 2000-02-10 23:37:52 bird Exp $
     1/* $Id: StateUpd.cpp,v 1.8 2000-02-11 18:35:54 bird Exp $
    22 *
    33 * StateUpd - Scans source files for API functions and imports data on them.
     
    4444static unsigned long analyseFnDcl2(PFNDESC pFnDesc, char **papszLines, int i, int &iRet, const char *pszFilename, POPTIONS pOptions);
    4545static BOOL  isFunction(char **papszLines, int i, POPTIONS pOptions);
     46static long _System dbNotUpdatedCallBack(const char *pszValue, const char *pszFieldName, void *pvUser);
    4647static char *skipInsignificantChars(char **papszLines, int &i, char *psz);
    4748static char *readFileIntoMemory(const char *pszFilename);
     
    6667    BOOL           fFatal = FALSE;
    6768    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};
    6971    unsigned long  ulRc2;
    7072    char          *pszErrorDesc = NULL;
     
    7375    char          *pszUser     = "root";
    7476    char          *pszPasswd   = "";
    75 
     77    ULONG          ul1, ul2;
    7678    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
    7798
    7899    /**************************************************************************
     
    87108    *           -COMCTL32<[+]|-> Removes 'COMCTL32'-prefix from function name.
    88109    *           -VERSION<[+]|->  Removes 'VERSION'-prefix from function name.
     110    *           -Dll:<dllname>   Name of the dll being processed.
    89111    *           -d:<dbname>      Database name
    90112    *           -p:<passwd>      Password
     
    101123                case 'd':
    102124                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];
    105127                    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                    }
    107134                    break;
    108135
     
    217244        if (!options.fIntegrityOnly)
    218245        {
     246            /* find dll */
     247            options.lDllRefcode = dbGetDll(options.pszDLLName);
     248            fprintf(phLog, "DLL: refcode=%d, name=%s\n", options.lDllRefcode, options.pszDLLName);
     249
    219250            /* processing */
    220251            if (argv[argi] == NULL || *argv[argi] == '\0')
     
    253284        }
    254285
     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
    255297        /* close the logs */
    256298        closeLogs();
     
    260302
    261303        /* warn if error during processing. */
     304        fprintf(stdout,"Number of function in this DLL:        %4ld\n", ul1);
    262305        fprintf(stdout,"Number of successfully processed APIs: %4ld\n", (long)(0x0000FFFF & ulRc));
    263306        fprintf(stdout,"Number of signals:                     %4ld\n", (long)(ulRc >> 16));
     
    568611
    569612        /* 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");
    571617        fprintf(phLog, "  Returns: '%s'\n", FnDesc.pszReturnType != NULL ? FnDesc.pszReturnType : "<missing>");
    572618        fprintf(phLog, "  cParams: %2d\n", FnDesc.cParams);
     
    640686    }
    641687
    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
    644712        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;
    661715    return ulRc;
    662716}
     
    681735     * 1. find the '('
    682736     * 2. find the word ahead of the '(', this is the function name.
     737     * 2a. class test.
    683738     * 3. find the closing ')'
    684739     * 4. copy the parameters, which is between the two '()'
     
    687742
    688743    int     iFn, iP1, iP2, j;
    689     char *  pszFn, *pszP1, *pszP2;
     744    char *  pszFn, *pszFnEnd, *pszP1, *pszP2;
    690745    char *  psz, *pszEnd;
    691746    int     cArgs;
     
    729784        return 0x00010000;
    730785    }
     786    pszFnEnd = pszFn;
    731787    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    }
    732812
    733813    /* 3. */
     
    792872    else
    793873    {
     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
    794880        /* function name */
    795881        *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
    797891        pFnDesc->pszName = pszEnd;
    798 
    799         /* return type - not implemented TODO/FIXME! */
    800         pFnDesc->pszReturnType = NULL;
    801892
    802893        /* arguments */
     
    12271318
    12281319
     1320
     1321/**
     1322 * Callback function for the dbGetNotUpdatedFunction routine.
     1323 *
     1324 */
     1325static 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
    12291339/**
    12301340 * 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:05 bird Exp $ */
     1/* $Id: StateUpd.h,v 1.2 2000-02-11 18:35:54 bird Exp $ */
    22/*
    33 * StateUpd - Scans source files for API functions and imports data on them.
     
    1010
    1111#define MAJOR_VER   0
    12 #define MINOR_VER   4
     12#define MINOR_VER   5
    1313
    1414#pragma pack()
     
    1616typedef struct _options
    1717{
    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 */
    2628} OPTIONS, *POPTIONS;
    2729
  • trunk/tools/database/db.cpp

    r2742 r2759  
    1 /* $Id: db.cpp,v 1.4 2000-02-10 22:10:40 bird Exp $ */
     1/* $Id: db.cpp,v 1.5 2000-02-11 18:35:54 bird Exp $ */
    22/*
    33 * DB - contains all database routines.
     
    2929    pres2 = mysql_store_result(pmysql);\
    3030    if (rc < 0 || pres2 == NULL ||     \
    31         mysql_num_rows(pres2) <= 0)    \
     31        mysql_num_rows(pres2) == 0)    \
    3232    {                                  \
    3333        if (pszError[1] == '\xFE')     \
     
    151151}
    152152
     153/**
     154 * Gets the refid for the give dll name.
     155 * @returns   Dll refid. -1 on error.
     156 * @param     pszDllName  Dll name.
     157 */
     158signed 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 */
     182signed 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
    153206
    154207/**
     
    161214signed short _System dbCheckInsertDll(const char *pszDll)
    162215{
    163     int  rc;
    164     char szQuery[256];
    165     MYSQL_RES *pres;
     216    int         rc;
     217    char        szQuery[256];
     218    MYSQL_RES * pres;
    166219
    167220    /* try find match */
     
    230283 * @returns   Success indicator. TRUE / FALSE.
    231284 * @param     usDll           Dll refcode.
    232  * @param     pszFunction     Functionname.
     285 * @param     pszFunction     Function name.
     286 * @param     pszIntFunction  Internal function name.
    233287 * @param     ulOrdinal       Ordinal value.
    234288 * @param     fIgnoreOrdinal  Do not update ordinal value.
    235289 */
    236 BOOL _System dbInsertUpdateFunction(unsigned short usDll, const char *pszFunction,
     290BOOL _System dbInsertUpdateFunction(unsigned short usDll,
     291                                    const char *pszFunction, const char *pszIntFunction,
    237292                                    unsigned long ulOrdinal, BOOL fIgnoreOrdinal)
    238293{
     
    242297    MYSQL_RES *pres;
    243298
     299    /* when no internal name, the exported name is the internal name too! */
     300    if (pszIntFunction == NULL || *pszIntFunction == '\0')
     301        pszIntFunction = pszFunction;
     302
    244303    /* 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);
    246305    rc = mysql_query(pmysql, &szQuery[0]);
    247306    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)
    249308    {   /* update function (function is found) */
    250309        MYSQL_ROW parow;
     
    261320        mysql_free_result(pres);
    262321
    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)
    264330        {
    265331            sprintf(&szQuery[0], "UPDATE function SET ordinal = %ld WHERE refcode = %ld",
     
    267333            rc = mysql_query(pmysql, &szQuery[0]);
    268334        }
     335
    269336    }
    270337    else
    271338    {   /* 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);
    274341        rc = mysql_query(pmysql, &szQuery[0]);
    275342    }
     
    295362
    296363/**
    297  * Find occurences of a function, given by name.
     364 * Find occurences of a function, given by internal name.
    298365 * @returns   success indicator, TRUE / FALSE.
    299366 * @param     pszFunctionName
     
    307374    char         szQuery[256];
    308375
    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);
    310378
    311379    rc = mysql_query(pmysql, &szQuery[0]);
     
    416484    char *pszQuery = &szQuery[0];
    417485    long  lCurrentState;
    418     int   i,rc;
     486    int   i,k,rc;
    419487    unsigned long ulRc = 0;
    420488    BOOL          f = FALSE;
    421489
    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
    441527        if (f)
    442528        {
    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]);
    454543        rc = mysql_query(pmysql, &szQuery[0]);
    455544        if (rc < 0)
    456545        {
    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) ",
    458549                    dbGetLastErrorDesc(), &szQuery[0]);
    459550            pszError += strlen(pszError) - 1;
    460551            ulRc++;
    461552        }
    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]);
    487578        if (rc < 0)
    488579        {
    489580            if (*pszError == ' ')
    490581                strcpy(pszError++, "\n\t");
    491             sprintf(pszError, "Inserting parameter %i failed 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]);
    493584            pszError += strlen(pszError) - 1;
    494585            ulRc++;
    495586        }
    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 */
    531607    return ulRc;
    532608}
     
    908984    rc = mysql_query(pmysql, pszQuery);
    909985    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))
    911987    {   /* some kind of error has occurred */
    912988        if (pszError[1] == '\xFE')
     
    10991175        }
    11001176    }
     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 */
     1190BOOL _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]);
    11011229
    11021230    return fRet;
  • trunk/tools/database/db.h

    r1993 r2759  
    1 /* $Id: db.h,v 1.2 1999-12-06 18:11:50 bird Exp $ */
     1/* $Id: db.h,v 1.3 2000-02-11 18:35:54 bird Exp $ */
    22/*
    33 * DB - contains all database routines
     
    1515#endif
    1616
     17
     18/*******************************************************************************
     19*   Defined Constants                                                          *
     20*******************************************************************************/
     21#define NBR_FUNCTIONS   20
     22#define NBR_AUTHORS     20
     23
    1724/*******************************************************************************
    1825*   Structures and Typedefs                                                    *
     
    2734        char *pszName;
    2835        char *pszReturnType;
    29         long  lRefCode;
     36        long  cRefCodes;
     37        long  alRefCode[NBR_FUNCTIONS];
    3038
    3139        /* parameters */
     
    3644        /* authors */
    3745        int   cAuthors;
    38         char *apszAuthor[20];
    39         long  alAuthorRefCode[20];
     46        char *apszAuthor[NBR_AUTHORS];
     47        long  alAuthorRefCode[NBR_AUTHORS];
    4048
    4149        /* status */
     
    4856    {
    4957        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];
    5260    } FNFINDBUF, *PFNFINDBUF;
    5361
     
    5967    char *          _System dbGetLastErrorDesc(void);
    6068
    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);
    6273    BOOL            _System dbDisconnect();
     74    signed short    _System dbGetDll(const char *pszDllName);
     75    signed long     _System dbCountFunctionInDll(signed long ulDll);
     76
    6377    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);
    6989    signed long     _System dbFindAuthor(const char *pszAuthor);
    7090    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);
    7293    unsigned long   _System dbCreateHistory(char *pszError);
    7394    unsigned long   _System dbCheckIntegrity(char *pszError);
     
    7798    signed long     _System dbQueryResultRows(void *pres);
    7899    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);
    80103    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);
    82109
    83110#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.