IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 2, 2026, 3:48:37 PM (3 months ago)
Author:
eugene
Message:

plug a leak in p_psDBRunQueryPrepared; add function to free prepared queries (for general cleanup); init the MYSQL_TIME structure (or time types break); fractional part in query is in microseconds, not nanoseconds; do not delete all rows if a limit is provided; fix tap test to take database info from args; fix tap tests to work in Ubuntu 22.04 / MySQL 8.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-pstamp-20260421/psLib/src/db/psDB.c

    r42826 r43004  
    713713
    714714    // Create SQL statement string
    715     psString query = psDBGenerateDeleteRowSQL(tableName, where,limit);
     715    psString query = psDBGenerateDeleteRowSQL(tableName, where, limit);
    716716    if (!query) {
    717717        psError(PS_ERR_UNEXPECTED_NULL, false, "Query generation failed.");
     
    871871}
    872872
     873bool psDBFreeQueryPrepared (void) {
     874
     875    // initalize the prepared query cache
     876    if (!preparedQuery) {
     877      return true;
     878    }
     879
     880    // start lock on query cache
     881    if (psMemGetThreadSafety()) {
     882        pthread_mutex_lock(&preparedQueryMutex);
     883    }
     884
     885    psFree (preparedQuery);
     886    preparedQuery = NULL;
     887
     888    pthread_mutex_unlock(&preparedQueryMutex);
     889
     890    return true;
     891}
     892
    873893long p_psDBRunQueryPrepared(psDB *dbh,
    874894                            const psArray *rowSet,
     
    918938        // add this statement to the cache
    919939        psHashAdd(preparedQuery, query, stmt);
     940        psFree (stmt);
    920941    } else {
    921942        psTrace("psLib.db", PS_LOG_INFO, "found statment in query cache");
     
    16081629                    // have to be free'd
    16091630                    MYSQL_TIME *myTime = psAlloc(sizeof(MYSQL_TIME));
     1631                    memset(myTime, 0, sizeof(MYSQL_TIME));
     1632                   
    16101633                    myTime->year    = (unsigned int)tmTime->tm_year + 1900;
    16111634                    myTime->month   = (unsigned int)tmTime->tm_mon + 1;
     
    16191642                    // in 5.0 and 5.6, my_bool is char
    16201643                    myTime->neg     = (bool)false;
    1621                     // currently unused by mysql
    1622                     myTime->second_part  = (unsigned long)time->nsec;
     1644
     1645                    // MySQL expects fractional seconds in microseconds, not nanoseconds
     1646                    myTime->second_part = (unsigned long)(time->nsec / 1000);
     1647
     1648                    // XXX remove: currently unused by mysql
     1649                    // myTime->second_part  = (unsigned long)time->nsec;
     1650
    16231651                    psFree(tmTime);
    16241652
    16251653                    bind[i].buffer  = myTime;
    16261654                    bind[i].buffer_length = sizeof(MYSQL_TIME);
    1627                     bind[i].length  = &bind[i].buffer_length;
     1655                    // XXX bind[i].length  = &bind[i].buffer_length;
     1656                    bind[i].length  = 0;
    16281657                    bind[i].is_null = NULL;
    16291658                } else {
     
    21292158    char            *limitString;
    21302159
    2131     // delete all rows if where is NULL
    2132     if (!where) {
     2160    // delete all rows if WHERE is NULL and no limit is given (limit == 0)
     2161    if (!where && !limit) {
    21332162        psStringAppend(&query, "TRUNCATE TABLE %s", tableName);
    21342163        return query;
    21352164    }
    21362165
    2137     // Generate where SQL substring
    2138     whereSQL = psDBGenerateWhereSQL(where, tableName);
    2139     if (!whereSQL) {
     2166    psStringAppend(&query, "DELETE FROM %s", tableName);
     2167
     2168    if (where) {
     2169      // Generate where SQL substring
     2170      whereSQL = psDBGenerateWhereSQL(where, tableName);
     2171      if (!whereSQL) {
    21402172        psError(PS_ERR_UNEXPECTED_NULL, false, _("SQL substring generation failed."));
    21412173        return NULL;
    2142     }
    2143 
    2144     psStringAppend(&query, "DELETE FROM %s %s", tableName, whereSQL);
     2174      }
     2175      psStringAppend(&query, " %s", whereSQL);
     2176      psFree(whereSQL);
     2177    }
    21452178
    21462179    // Complete delete SQL command string
     
    21512184        psFree(limitString);
    21522185    }
    2153     psFree(whereSQL);
    21542186
    21552187    return query;
     
    29452977
    29462978#endif // HAVE_PSDB
     2979
Note: See TracChangeset for help on using the changeset viewer.