Ignore:
Timestamp:
Jul 21, 2000, 11:09:45 PM (25 years ago)
Author:
bird
Message:

Corrections and handling of the updated field in function and file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/database/db.cpp

    r3848 r3882  
    1 /* $Id: db.cpp,v 1.15 2000-07-18 17:56:50 bird Exp $ *
     1/* $Id: db.cpp,v 1.16 2000-07-21 21:09:44 bird Exp $ *
    22 *
    33 * DB - contains all database routines.
     
    158158 * @param     pszDllName  Dll name.
    159159 */
    160 signed short _System dbGetDll(const char *pszDllName)
     160signed long _System dbGetDll(const char *pszDllName)
    161161{
    162162    int         rc;
     
    173173        rc = -1;
    174174    mysql_free_result(pres);
    175     return (short)rc;
     175    return (signed long)rc;
    176176}
    177177
     
    180180 * Count the function in a given dll.
    181181 * @returns  Number of functions. -1 on error.
    182  * @param    usDll        Dll refcode.
     182 * @param    lDll         Dll refcode.
    183183 * @param    fNotAliases  TRUE: don't count aliased functions.
    184184 */
    185 signed long     _System dbCountFunctionInDll(signed long ulDll, BOOL fNotAliases)
     185signed long     _System dbCountFunctionInDll(signed long lDll, BOOL fNotAliases)
    186186{
    187187    signed long rc;
     
    189189    MYSQL_RES * pres;
    190190
    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);
    194194        if (fNotAliases)
    195195            strcat(&szQuery[0], " AND aliasfn < 0");
     
    217217 *            (In the mysql-world everything is case insensitive!)
    218218 */
    219 signed short _System dbCheckInsertDll(const char *pszDll)
     219signed long _System dbCheckInsertDll(const char *pszDll, char fchType)
    220220{
    221221    int         rc;
     
    233233        mysql_free_result(pres);
    234234
    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);
    236236        rc = mysql_query(pmysql, &szQuery[0]);
     237        if (rc < 0)
     238            return -1;
    237239
    238240        /* select row to get refcode */
     
    248250    mysql_free_result(pres);
    249251
    250     return (short)rc;
     252    return (long)rc;
    251253}
    252254
     
    280282    mysql_free_result(pres);
    281283
    282     return (short)rc;
     284    return (unsigned short)rc;
    283285}
    284286
     
    286288/**
    287289 * 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 */
     299BOOL _System dbInsertUpdateFunction(signed long lDll,
    296300                                    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];
    302307    MYSQL_RES *pres;
    303308
     
    307312
    308313    /* 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);
    311316    pres = mysql_store_result(pmysql);
    312317    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         */
    314321        MYSQL_ROW parow;
    315322        if (mysql_num_rows(pres) > 1)
    316323        {
    317324            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);
    319326            return FALSE;
    320327        }
    321328
    322329        parow = mysql_fetch_row(pres);
    323         if (parow != NULL)
    324             lFunction = getvalue(0, parow);
     330        lFunction = getvalue(0, parow);
    325331        mysql_free_result(pres);
    326332
     333        strcpy(pszQuery, "UPDATE function SET updated = updated + 1");
     334        pszQuery += strlen(pszQuery);
    327335        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]);
    341343    }
    342344    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);
    346351        rc = mysql_query(pmysql, &szQuery[0]);
    347352    }
     
    355360 * Inserts or updates (existing) file information.
    356361 * @returns     Success indicator (TRUE / FALSE).
    357  * @param       usDll           Dll reference code.
     362 * @param       lDll           Dll reference code.
    358363 * @param       pszFilename     Filename.
    359364 * @param       pszDescription  Pointer to file description.
     
    364369 * @remark
    365370 */
    366 BOOL            _System dbInsertUpdateFile(unsigned short usDll,
     371BOOL            _System dbInsertUpdateFile(signed long lDll,
    367372                                           const char *pszFilename,
    368373                                           const char *pszDescription,
     
    377382
    378383    /* parameter assertions */
    379     assert(usDll != 0);
     384    assert(lDll != 0);
    380385    assert(pszFilename != NULL);
    381386    assert(*pszFilename != '\0');
    382387
    383388    /* 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);
    385390    rc = mysql_query(pmysql, &szQuery[0]);
    386391    pres = mysql_store_result(pmysql);
     
    391396        {
    392397            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);
    394399            return FALSE;
    395400        }
     
    446451    {   /* insert */
    447452        sprintf(&szQuery[0], "INSERT INTO file(dll, name, description, lastauthor, lastdatetime, revision) VALUES(%d, '%s', %ld, ",
    448                 usDll, pszFilename, lLastAuthor);
     453                lDll, pszFilename, lLastAuthor);
    449454        if (pszDescription != NULL && *pszDescription != '\0')
    450455            sqlstrcat(&szQuery[0], NULL, pszDescription);
     
    986991        }
    987992
    988         /* Equiv */
     993        /* Time */
    989994        if (pFnDesc->pszTime != NULL)
    990995        {
     
    19171922
    19181923
     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 */
     1932BOOL             _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 */
     1953BOOL             _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 */
     1979BOOL             _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 */
     2030BOOL             _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
    19192074/**
    19202075 * Appends a set of strings to a query. The main string (pszStr) is enclosed in "'"s.
     
    19292084static char *sqlstrcat(char *pszQuery, const char *pszBefore, const char *pszStr, const char *pszAfter)
    19302085{
    1931     char *          pszLineStart = pszQuery;   
     2086    char *          pszLineStart = pszQuery;
    19322087    register char   ch;
    19332088
     
    19822137                *pszQuery++ = 'n';
    19832138                break;
    1984            
     2139
    19852140            case '\t':
    19862141                *pszQuery++ = '\\';
Note: See TracChangeset for help on using the changeset viewer.