Ignore:
Timestamp:
Feb 12, 2000, 12:54:25 AM (26 years ago)
Author:
bird
Message:

Preformance and corrections.

File:
1 edited

Legend:

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

    r2759 r2761  
    1 /* $Id: db.cpp,v 1.5 2000-02-11 18:35:54 bird Exp $ */
    2 /*
     1/* $Id: db.cpp,v 1.6 2000-02-11 23:54:25 bird Exp $ *
     2 *
    33 * DB - contains all database routines.
    44 *
     
    8080static unsigned long CheckAuthorError(char * &pszError, const char *pszFieldName, const char *pszFieldValue, const char *pszQuery);
    8181static unsigned long logDbError(char * &pszError, const char *pszQuery);
    82 #ifdef NOTDLL
     82#ifndef DLL
    8383    extern "C" void      dbHandler(int sig);
    8484#endif
     
    103103{
    104104    BOOL fRet = FALSE;
    105     #ifdef NOTDLL
     105    #ifndef DLL
    106106        static fHandler = FALSE;
    107107        /* signal handler */
     
    188188    if (ulDll >= 0)
    189189    {
    190         sprintf(&szQuery[0], "SELECT count(refcode) FROM function WHERE dll = %d\n", ulDll);
     190        sprintf(&szQuery[0], "SELECT count(refcode) FROM function WHERE dll = %ld\n", ulDll);
    191191        rc   = mysql_query(pmysql, &szQuery[0]);
    192192        pres = mysql_store_result(pmysql);
     
    360360}
    361361
    362 
     362#if 0
    363363/**
    364364 * Find occurences of a function, given by internal name.
     
    366366 * @param     pszFunctionName
    367367 * @param     pFnFindBuf
    368  */
    369 BOOL _System dbFindFunction(const char *pszFunctionName, PFNFINDBUF pFnFindBuf)
     368 * @param     lDll
     369 */
     370BOOL _System dbFindFunction(const char *pszFunctionName, PFNFINDBUF pFnFindBuf, signed long lDll)
    370371{
    371372    MYSQL_RES   *pres;
     
    374375    char         szQuery[256];
    375376
    376     sprintf(&szQuery[0], "SELECT refcode, dll FROM function WHERE intname = '%s'",
    377             pszFunctionName, pszFunctionName);
     377    if (lDll < 0)
     378        sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function WHERE intname = '%s'",
     379                pszFunctionName);
     380    else
     381        sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function "
     382                "WHERE intname = '%s' AND dll = %ld",
     383                pszFunctionName, lDll);
    378384
    379385    rc = mysql_query(pmysql, &szQuery[0]);
     
    388394                pFnFindBuf->alRefCode[pFnFindBuf->cFns] = atol(row[0]);
    389395                pFnFindBuf->alDllRefCode[pFnFindBuf->cFns] = atol(row[1]);
     396                pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = atol(row[2]);
    390397
    391398                /* next */
     
    393400            }
    394401            mysql_free_result(pres);
     402
     403            /* alias check and fix */
     404            if (lDll >= 0 && pFnFindBuf->cFns != 0)
     405            {
     406                int i;
     407
     408                /* Make the selected function to DONT TOUCH */
     409                sprintf(&szQuery[0], "UPDATE function SET aliasfn = (-2) "
     410                                     "WHERE (",
     411                        lDll, pszFunctionName);
     412                for (i = 0; i < pFnFindBuf->cFns; i++)
     413                {
     414                    if (i != 0) strcat(&szQuery[0], " OR");
     415                    sprintf(&szQuery[strlen(szQuery)], " refcode = %ld", pFnFindBuf->alRefCode[i]);
     416                }
     417                strcat(&szQuery[0], ") AND aliasfn <> (-2)");
     418
     419                rc = mysql_query(pmysql, &szQuery[0]);
     420                if (rc >= 0)
     421                {
     422                    /* Update all with equal internal... which is not in this Dll */
     423                    sprintf(&szQuery[0], "UPDATE function SET aliasfn = (%ld) "
     424                                         "WHERE aliasfn = (-1) AND dll <> %ld AND intname = '%s'",
     425                            pFnFindBuf->alRefCode[0], lDll, pszFunctionName, pszFunctionName);
     426                    rc = mysql_query(pmysql, &szQuery[0]);
     427                    if (rc >= 0)
     428                    {
     429                        /* Update all with equal external name... which is not in this Dll */
     430                        sprintf(&szQuery[0], "UPDATE function SET aliasfn = (%ld) "
     431                                             "WHERE aliasfn = (-1) AND dll <> %ld AND name = '%s'",
     432                                pFnFindBuf->alRefCode[0], lDll, pszFunctionName, pszFunctionName);
     433
     434                        rc = mysql_query(pmysql, &szQuery[0]);
     435                        if (rc >= 0)
     436                        {
     437                            /* get the functions aliases to the functions we have allready found. */
     438                            strcpy(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function WHERE (");
     439                            for (i = 0; i < pFnFindBuf->cFns; i++)
     440                            {
     441                                if (i != 0) strcat(&szQuery[0], "OR ");
     442                                sprintf(&szQuery[strlen(szQuery)], "aliasfn = %ld ", pFnFindBuf->alRefCode[i]);
     443                            }
     444                            sprintf(&szQuery[strlen(szQuery)], ") AND dll <> %ld", lDll);
     445
     446                            rc = mysql_query(pmysql, &szQuery[0]);
     447                            if (rc >= 0)
     448                            {
     449                                pres = mysql_store_result(pmysql);
     450                                if (pres != NULL)
     451                                {
     452                                    while ((row = mysql_fetch_row(pres)) != NULL)
     453                                    {
     454                                        pFnFindBuf->alRefCode[pFnFindBuf->cFns] = atol(row[0]);
     455                                        pFnFindBuf->alDllRefCode[pFnFindBuf->cFns] = atol(row[1]);
     456                                        if (row[2] != NULL)
     457                                            pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = atol(row[2]);
     458                                        else
     459                                            pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = ALIAS_NULL;
     460
     461                                        /* next */
     462                                        pFnFindBuf->cFns++;
     463                                    }
     464                                    mysql_free_result(pres);
     465                                }
     466                            }
     467                        }
     468                    }
     469                }
     470            }
    395471        }
    396472        else
     
    400476    return rc >= 0;
    401477}
     478#else
     479int     mysql_query1(MYSQL *mysql, const char *q)
     480{
     481    return mysql_query(mysql, q);
     482}
     483
     484int     mysql_query2(MYSQL *mysql, const char *q)
     485{
     486    return mysql_query(mysql, q);
     487}
     488
     489int     mysql_query3(MYSQL *mysql, const char *q)
     490{
     491    return mysql_query(mysql, q);
     492}
     493
     494int     mysql_query4(MYSQL *mysql, const char *q)
     495{
     496    return mysql_query(mysql, q);
     497}
     498
     499int     mysql_query5(MYSQL *mysql, const char *q)
     500{
     501    return mysql_query(mysql, q);
     502}
     503
     504MYSQL_RES *  mysql_store_result1(MYSQL *mysql)
     505{
     506    return mysql_store_result(mysql);
     507}
     508
     509MYSQL_RES *  mysql_store_result2(MYSQL *mysql)
     510{
     511    return mysql_store_result(mysql);
     512}
     513
     514
     515/**
     516 * Find occurences of a function, given by internal name.
     517 * @returns   success indicator, TRUE / FALSE.
     518 * @param     pszFunctionName
     519 * @param     pFnFindBuf
     520 * @param     lDll
     521 */
     522BOOL _System dbFindFunction(const char *pszFunctionName, PFNFINDBUF pFnFindBuf, signed long lDll)
     523{
     524    MYSQL_RES   *pres;
     525    MYSQL_ROW    row;
     526    int          rc;
     527    char         szQuery[256];
     528
     529    if (lDll < 0)
     530        sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function WHERE intname = '%s'",
     531                pszFunctionName);
     532    else
     533        sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function "
     534                "WHERE intname = '%s' AND dll = %ld",
     535                pszFunctionName, lDll);
     536
     537    rc = mysql_query1(pmysql, &szQuery[0]);
     538    if (rc >= 0)
     539    {
     540        pres = mysql_store_result1(pmysql);
     541        if (pres != NULL)
     542        {
     543            pFnFindBuf->cFns = 0;
     544            while ((row = mysql_fetch_row(pres)) != NULL)
     545            {
     546                pFnFindBuf->alRefCode[pFnFindBuf->cFns] = atol(row[0]);
     547                pFnFindBuf->alDllRefCode[pFnFindBuf->cFns] = atol(row[1]);
     548                pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = atol(row[2]);
     549
     550                /* next */
     551                pFnFindBuf->cFns++;
     552            }
     553            mysql_free_result(pres);
     554
     555            /* alias check and fix */
     556            if (lDll >= 0 && pFnFindBuf->cFns != 0)
     557            {
     558                int i;
     559
     560                /* Make the selected function to DONT TOUCH */
     561                sprintf(&szQuery[0], "UPDATE function SET aliasfn = (-2) "
     562                                     "WHERE (",
     563                        lDll, pszFunctionName);
     564                for (i = 0; i < pFnFindBuf->cFns; i++)
     565                {
     566                    if (i != 0) strcat(&szQuery[0], " OR");
     567                    sprintf(&szQuery[strlen(szQuery)], " refcode = %ld", pFnFindBuf->alRefCode[i]);
     568                }
     569                strcat(&szQuery[0], ") AND aliasfn <> (-2)");
     570
     571                rc = mysql_query2(pmysql, &szQuery[0]);
     572                if (rc >= 0)
     573                {
     574                    /* Update all with equal internal... which is not in this Dll */
     575                    sprintf(&szQuery[0], "UPDATE function SET aliasfn = (%ld) "
     576                                         "WHERE aliasfn = (-1) AND dll <> %ld AND intname = '%s'",
     577                            pFnFindBuf->alRefCode[0], lDll, pszFunctionName, pszFunctionName);
     578                    rc = mysql_query3(pmysql, &szQuery[0]);
     579                    if (rc >= 0)
     580                    {
     581                        /* Update all with equal external name... which is not in this Dll */
     582                        sprintf(&szQuery[0], "UPDATE function SET aliasfn = (%ld) "
     583                                             "WHERE aliasfn = (-1) AND dll <> %ld AND name = '%s'",
     584                                pFnFindBuf->alRefCode[0], lDll, pszFunctionName, pszFunctionName);
     585
     586                        rc = mysql_query4(pmysql, &szQuery[0]);
     587                        if (rc >= 0)
     588                        {
     589                            int cFns = pFnFindBuf->cFns;
     590                            for (i = 0; i < cFns; i++)
     591                            {
     592                                /* get the functions aliases to the functions we have allready found. */
     593                                sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function WHERE aliasfn = %ld AND dll <> %ld",
     594                                        pFnFindBuf->alRefCode[i], lDll);
     595                                rc = mysql_query5(pmysql, &szQuery[0]);
     596                                if (rc >= 0)
     597                                {
     598                                    pres = mysql_store_result2(pmysql);
     599                                    if (pres != NULL)
     600                                    {
     601                                        while ((row = mysql_fetch_row(pres)) != NULL)
     602                                        {
     603                                            pFnFindBuf->alRefCode[pFnFindBuf->cFns] = atol(row[0]);
     604                                            pFnFindBuf->alDllRefCode[pFnFindBuf->cFns] = atol(row[1]);
     605                                            if (row[2] != NULL)
     606                                                pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = atol(row[2]);
     607                                            else
     608                                                pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = ALIAS_NULL;
     609
     610                                            /* next */
     611                                            if (pFnFindBuf->alDllRefCode[pFnFindBuf->cFns] != lDll)
     612                                                pFnFindBuf->cFns++;
     613                                        }
     614                                        mysql_free_result(pres);
     615                                    }
     616                                }
     617                            }
     618                        }
     619                    }
     620                }
     621            }
     622        }
     623        else
     624            rc = -1;
     625    }
     626
     627    return rc >= 0;
     628}
     629
     630#endif
    402631
    403632
     
    475704 * Updates function information.
    476705 * @returns   number of errors.
    477  * @param     pFnDesc
    478  * @param     pszError
     706 * @param     pFnDesc   Function description struct.
     707 * @param     lDll      Dll which we are working at.
     708 * @param     pszError  Buffer for error messages
    479709 * @result    on error(s) pszError will hold information about the error(s).
    480710 */
    481 unsigned long _System dbUpdateFunction(PFNDESC pFnDesc, char *pszError)
     711unsigned long _System dbUpdateFunction(PFNDESC pFnDesc, signed long lDll, char *pszError)
    482712{
    483713    char  szQuery[256];
     
    491721    {
    492722        /* set updated flag */
    493         sprintf(pszQuery, "UPDATE function SET updated = updated + 1 WHERE refcode = %d",
     723        sprintf(pszQuery, "UPDATE function SET updated = updated + 1 WHERE refcode = %ld",
    494724                pFnDesc->alRefCode[k]);
    495725        rc = mysql_query(pmysql, &szQuery[0]);
     
    515745        if (pFnDesc->pszReturnType != NULL)
    516746        {
    517             if (f)
    518             {
    519                 strcat(pszQuery, ", ");
    520                 pszQuery += strlen(pszQuery);
    521             }
    522             sprintf(pszQuery, "return = '%s' ", pFnDesc->pszReturnType);
     747            if (f)  strcat(pszQuery, ", ");
     748            sprintf(pszQuery + strlen(pszQuery),  "return = '%s' ", pFnDesc->pszReturnType);
    523749            pszQuery += strlen(pszQuery);
    524750            f = TRUE;
     
    527753        if (f)
    528754        {
    529             sprintf(pszQuery, "WHERE refcode = %ld", pFnDesc->alRefCode[k]);
     755            sprintf(pszQuery + strlen(pszQuery), "WHERE refcode = %ld", pFnDesc->alRefCode[k]);
    530756            rc = mysql_query(pmysql, &szQuery[0]);
    531757            if (rc < 0)
     
    605831        }
    606832    } /* for */
     833
     834    lDll = lDll;
    607835    return ulRc;
    608836}
     
    11951423
    11961424    /* not updated names */
    1197     sprintf(&szQuery[0], "SELECT name, intname FROM function WHERE dll = %d AND updated = 0",
     1425    sprintf(&szQuery[0], "SELECT name, intname FROM function WHERE dll = %ld AND updated = 0",
    11981426            lDll);
    11991427    pres = dbExecuteQuery(szQuery);
     
    12101438
    12111439    /* warn about updated > 1 too */
    1212     sprintf(&szQuery[0], "SELECT updated, name, intname FROM function WHERE dll = %d AND updated > 1",
     1440    sprintf(&szQuery[0], "SELECT updated, name, intname FROM function WHERE dll = %ld AND updated > 1",
    12131441            lDll);
    12141442    pres = dbExecuteQuery(szQuery);
     
    12241452    }
    12251453
    1226     sprintf(&szQuery[0], "UPDATE function SET updated = 0",
    1227             lDll);
     1454    strcpy(&szQuery[0], "UPDATE function SET updated = 0");
    12281455    mysql_query(pmysql, &szQuery[0]);
    12291456
     
    12321459
    12331460
    1234 #ifdef NOTDLL
     1461#ifndef DLL
    12351462/**
    12361463 * Signal handler.
Note: See TracChangeset for help on using the changeset viewer.