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

Corrections, DB optimizations, and some new features in StateUpd.

File:
1 edited

Legend:

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

    r2765 r2770  
    1 /* $Id: db.cpp,v 1.7 2000-02-12 17:55:03 bird Exp $ *
     1/* $Id: db.cpp,v 1.8 2000-02-12 23:54:29 bird Exp $ *
    22 *
    33 * DB - contains all database routines.
     
    178178 * Count the function in a given dll.
    179179 * @returns  Number of functions. -1 on error.
    180  * @param    usDll  Dll refcode.
    181  */
    182 signed long     _System dbCountFunctionInDll(signed long ulDll)
     180 * @param    usDll        Dll refcode.
     181 * @param    fNotAliases  TRUE: don't count aliased functions.
     182 */
     183signed long     _System dbCountFunctionInDll(signed long ulDll, BOOL fNotAliases)
    183184{
    184185    signed long rc;
     
    189190    {
    190191        sprintf(&szQuery[0], "SELECT count(refcode) FROM function WHERE dll = %ld\n", ulDll);
     192        if (fNotAliases)
     193            strcat(&szQuery[0], " AND aliasfn < 0");
    191194        rc   = mysql_query(pmysql, &szQuery[0]);
    192195        pres = mysql_store_result(pmysql);
     
    284287 * @param     usDll           Dll refcode.
    285288 * @param     pszFunction     Function name.
    286  * @param     pszIntFunction  Internal function name.
     289 * @param     pszIntFunction  Internal function name. (required!)
    287290 * @param     ulOrdinal       Ordinal value.
    288291 * @param     fIgnoreOrdinal  Do not update ordinal value.
     
    297300    MYSQL_RES *pres;
    298301
    299     /* when no internal name, the exported name is the internal name too! */
     302    /* when no internal name fail! */
    300303    if (pszIntFunction == NULL || *pszIntFunction == '\0')
    301         pszIntFunction = pszFunction;
     304        return FALSE;
    302305
    303306    /* try find function */
     
    360363}
    361364
     365
    362366#if 1
     367/*
     368 * Stubs used while optimizing sqls.
     369 */
     370int     mysql_query1(MYSQL *mysql, const char *q)
     371{   return mysql_query(mysql, q); }
     372int     mysql_query2(MYSQL *mysql, const char *q)
     373{   return mysql_query(mysql, q); }
     374int     mysql_query3(MYSQL *mysql, const char *q)
     375{   return mysql_query(mysql, q); }
     376int     mysql_query4(MYSQL *mysql, const char *q)
     377{   return mysql_query(mysql, q); }
     378int     mysql_query5(MYSQL *mysql, const char *q)
     379{   return mysql_query(mysql, q); }
     380MYSQL_RES *  mysql_store_result1(MYSQL *mysql)
     381{   return mysql_store_result(mysql); }
     382MYSQL_RES *  mysql_store_result5(MYSQL *mysql)
     383{   return mysql_store_result(mysql); }
     384
     385#else
     386
     387#define mysql_query1            mysql_query
     388#define mysql_query2            mysql_query
     389#define mysql_query3            mysql_query
     390#define mysql_query4            mysql_query
     391#define mysql_query5            mysql_query
     392#define mysql_store_result1     mysql_store_result
     393#define mysql_store_result5     mysql_store_result
     394
     395#endif
     396
     397
     398
    363399/**
    364400 * Find occurences of a function, given by internal name.
     
    383419                pszFunctionName, lDll);
    384420
    385     rc = mysql_query(pmysql, &szQuery[0]);
     421    rc = mysql_query1(pmysql, &szQuery[0]);
    386422    if (rc >= 0)
    387423    {
    388         pres = mysql_store_result(pmysql);
     424        pres = mysql_store_result1(pmysql);
    389425        if (pres != NULL)
    390426        {
     
    404440            if (lDll >= 0 && pFnFindBuf->cFns != 0)
    405441            {
     442                #if 0
    406443                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 aliasfn IN (");
    439                             for (i = 0; i < pFnFindBuf->cFns; i++)
    440                             {
    441                                 if (i != 0) strcat(&szQuery[0], ", ");
    442                                 sprintf(&szQuery[strlen(szQuery)], "%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             }
    471         }
    472         else
    473             rc = -1;
    474     }
    475 
    476     return rc >= 0;
    477 }
    478 #else
    479 int     mysql_query1(MYSQL *mysql, const char *q)
    480 {
    481     return mysql_query(mysql, q);
    482 }
    483 
    484 int     mysql_query2(MYSQL *mysql, const char *q)
    485 {
    486     return mysql_query(mysql, q);
    487 }
    488 
    489 int     mysql_query3(MYSQL *mysql, const char *q)
    490 {
    491     return mysql_query(mysql, q);
    492 }
    493 
    494 int     mysql_query4(MYSQL *mysql, const char *q)
    495 {
    496     return mysql_query(mysql, q);
    497 }
    498 
    499 int     mysql_query5(MYSQL *mysql, const char *q)
    500 {
    501     return mysql_query(mysql, q);
    502 }
    503 
    504 MYSQL_RES *  mysql_store_result1(MYSQL *mysql)
    505 {
    506     return mysql_store_result(mysql);
    507 }
    508 
    509 MYSQL_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  */
    522 BOOL _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 
    560444                /* Make the selected function to DONT TOUCH */
    561445                sprintf(&szQuery[0], "UPDATE function SET aliasfn = (-2) "
     
    587471                        if (rc >= 0)
    588472                        {
    589                             int cFns = pFnFindBuf->cFns;
    590                             for (i = 0; i < cFns; i++)
     473                            /* get the functions aliases to the functions we have allready found. */
     474                            sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function WHERE dll = %ld AND aliasfn IN (", lDll);
     475                            for (i = 0; i < pFnFindBuf->cFns; i++)
    591476                            {
    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]);
     477                                if (i != 0) strcat(&szQuery[0], ", ");
     478                                sprintf(&szQuery[strlen(szQuery)], "%ld", pFnFindBuf->alRefCode[i]);
     479                            }
     480                            strcat(&szQuery[strlen(szQuery)], ")");
     481
     482                            DosSleep(0);
     483                            rc = mysql_query5(pmysql, &szQuery[0]);
     484                            if (rc >= 0)
     485                            {
     486                                pres = mysql_store_result5(pmysql);
     487                                if (pres != NULL)
     488                                {
     489                                    while ((row = mysql_fetch_row(pres)) != NULL)
     490                                    {
     491                                        pFnFindBuf->alRefCode[pFnFindBuf->cFns] = atol(row[0]);
     492                                        pFnFindBuf->alDllRefCode[pFnFindBuf->cFns] = atol(row[1]);
     493                                        if (row[2] != NULL)
     494                                            pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = atol(row[2]);
     495                                        else
     496                                            pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = ALIAS_NULL;
     497
     498                                        /* next */
     499                                        pFnFindBuf->cFns++;
     500                                    }
     501                                    mysql_free_result(pres);
     502                                }
     503                            }
     504                        }
     505                    }
     506                }
     507                #else
     508                int i;
     509                int cFnsThisDll = (int)pFnFindBuf->cFns;
     510
     511                /* get the functions aliases to the functions we have allready found. */
     512                sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function "
     513                                     "WHERE aliasfn = (-1) AND dll <> %ld AND intname = '%s'",
     514                        lDll, pszFunctionName);
     515                rc = mysql_query2(pmysql, &szQuery[0]);
     516                if (rc >= 0)
     517                {
     518                    pres = mysql_store_result(pmysql);
     519                    if (pres != NULL)
     520                    {
     521                        while ((row = mysql_fetch_row(pres)) != NULL)
     522                        {
     523                            pFnFindBuf->alRefCode[pFnFindBuf->cFns] = atol(row[0]);
     524                            pFnFindBuf->alDllRefCode[pFnFindBuf->cFns] = atol(row[1]);
     525                            if (row[2] != NULL)
     526                                pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = atol(row[2]);
     527                            else
     528                                pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = ALIAS_NULL;
     529
     530                            /* next */
     531                            pFnFindBuf->cFns++;
     532                        }
     533                        mysql_free_result(pres);
     534
     535
     536                        /* get the functions aliases to the functions we have allready found. */
     537                        sprintf(&szQuery[0], "SELECT refcode, dll, aliasfn FROM function "
     538                                             "WHERE aliasfn = (-1) AND dll <> %ld AND name = '%s'",
     539                                lDll, pszFunctionName);
     540                        rc = mysql_query3(pmysql, &szQuery[0]);
     541                        if (rc >= 0)
     542                        {
     543                            pres = mysql_store_result(pmysql);
     544                            if (pres != NULL)
     545                            {
     546                                while ((row = mysql_fetch_row(pres)) != NULL)
     547                                {
     548                                    pFnFindBuf->alRefCode[pFnFindBuf->cFns] = atol(row[0]);
     549                                    pFnFindBuf->alDllRefCode[pFnFindBuf->cFns] = atol(row[1]);
     550                                    if (row[2] != NULL)
     551                                        pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = atol(row[2]);
     552                                    else
     553                                        pFnFindBuf->alAliasFn[pFnFindBuf->cFns] = ALIAS_NULL;
     554
     555                                    /* next */
     556                                    pFnFindBuf->cFns++;
     557                                }
     558                                mysql_free_result(pres);
     559
     560                                /* do updates! */
     561                                /* Make the selected function to DONT TOUCH */
     562                                sprintf(&szQuery[0], "UPDATE function SET aliasfn = (-2) "
     563                                                     "WHERE (",
     564                                        lDll, pszFunctionName);
     565                                for (i = 0; i < cFnsThisDll; i++)
     566                                {
     567                                    if (i != 0) strcat(&szQuery[0], " OR");
     568                                    sprintf(&szQuery[strlen(szQuery)], " refcode = %ld", pFnFindBuf->alRefCode[i]);
     569                                }
     570                                strcat(&szQuery[0], ") AND aliasfn <> (-2)");
     571
     572                                rc = mysql_query4(pmysql, &szQuery[0]);
    596573                                if (rc >= 0)
    597574                                {
    598                                     pres = mysql_store_result2(pmysql);
    599                                     if (pres != NULL)
     575                                    /* Update all with equal internal... which is not in this Dll */
     576                                    sprintf(&szQuery[0], "UPDATE function SET aliasfn = (%ld) "
     577                                                         "WHERE aliasfn = (-1) AND dll <> %ld AND intname = '%s'",
     578                                            pFnFindBuf->alRefCode[0], lDll, pszFunctionName, pszFunctionName);
     579                                    rc = mysql_query5(pmysql, &szQuery[0]);
     580                                    if (rc >= 0)
    600581                                    {
    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);
     582                                        /* Update all with equal external name... which is not in this Dll */
     583                                        sprintf(&szQuery[0], "UPDATE function SET aliasfn = (%ld) "
     584                                                             "WHERE aliasfn = (-1) AND dll <> %ld AND name = '%s'",
     585                                                pFnFindBuf->alRefCode[0], lDll, pszFunctionName, pszFunctionName);
     586
     587                                        rc = mysql_query4(pmysql, &szQuery[0]);
    615588                                    }
    616589                                }
     
    619592                    }
    620593                }
     594                #endif
    621595            }
    622596        }
     
    627601    return rc >= 0;
    628602}
    629 
    630 #endif
    631603
    632604
Note: See TracChangeset for help on using the changeset viewer.