IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 3197


Ignore:
Timestamp:
Feb 11, 2005, 1:35:23 PM (21 years ago)
Author:
jhoblitt
Message:

change psDBInsertRows() to use psDBPackRow()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/archive/psdb/psDB.c

    r3196 r3197  
    88 *  @author Joshua Hoblitt
    99 *
    10  *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2005-02-11 23:19:25 $
     10 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2005-02-11 23:35:23 $
    1212 *
    1313 *  Copyright 2005 Joshua Hoblitt, University of Hawaii
     
    581581    MYSQL_BIND      *bind;              // field values to insert
    582582    psU32           paramCount;         // number of placeholders in query
    583     psHash          *mysqlFieldType;    // type lookup table
    584     mysqlType       *mType;             // type tmp variable
    585     char            *key;               // hash tmp variable
    586     psMetadataItem  *item;              // field in row
    587     psListIterator  *cursor;            // row iterator
    588     psU32           i;                  // field index
    589583    psU64           j;                  // row index
    590     bool            isNull = true;      // used in a MYSQL_BIND to indicate NULL
    591584
    592585    // we are assuming that all rows in the set have an identical with reguard
     
    624617    bind = psAlloc(sizeof(MYSQL_BIND) * paramCount);
    625618
    626     mysqlFieldType = psDBGetPSToMySQLTable();
    627 
    628619    // loop over rows
    629620    for (j = 0; j < rowSet->n; j++) {
    630         // extract the psList, from the psMetadata, in the current psArray element
    631         cursor = psListIteratorAlloc(((psMetadata *)rowSet->data[j])->list, 0);
     621        row = rowSet->data[j];
    632622
    633623        // reset bind for each row
    634624        memset(bind, 0, sizeof(MYSQL_BIND) * paramCount);
    635625
    636         // loop over fields
    637         i = 0;
    638         while ((item = psListGetNext(cursor))) {
    639             // lookup pType -> mysql type
    640             key = psDBIntToString((psU64)item->pType);
    641             mType = psHashLookup(mysqlFieldType, key);
    642             psFree(key);
    643 
    644             // input data length is determined by the MYSQL_TYPE_* unless it's a string
    645             bind[i].buffer  = (char *)item->data.V;
    646             bind[i].buffer_type = mType->type;
    647             bind[i].is_unsigned = mType->isUnsigned;
    648 
    649             // convert NaNs to NULL
    650             bind[i].is_null = psDBIsPTypeNaN(item->pType, item->data.V)
    651                             ? (my_bool *)&isNull
    652                             : NULL;
    653 
    654             if (item->pType == PS_TYPE_PTR) {
    655                 if (item->type == PS_META_STR) {
    656                     if (*(char *)item->data.V == '\0') {
    657                         bind[i].is_null = (my_bool *)&isNull;
    658                     } else {
    659                         bind[i].buffer_length = (unsigned long)strlen((char *)item->data.V);
    660                         bind[i].is_null = NULL;
    661                     }
    662                 } else {
    663                     // error, not a pointer to a string
    664                     mysql_rollback(dbh->mysql);
    665 
    666                     psFree(cursor);
    667                     psFree(bind);
    668                     mysql_stmt_close(stmt);
    669 
    670                     return false;
    671                 }
    672             }
    673 
    674             // increment field index
    675             i++;
    676         }
    677 
    678         psFree(cursor);
     626        if (!psDBPackRow(bind, row, paramCount)) {
     627            fprintf(stderr, "Failed to pack params into bind structure.\n");
     628
     629            mysql_rollback(dbh->mysql);
     630
     631            psFree(bind);
     632            mysql_stmt_close(stmt);
     633        }
    679634
    680635        if (mysql_stmt_bind_param(stmt, bind)) {
     
    700655        }
    701656    } // end loop over rows
    702 
    703     psFree(mysqlFieldType);
    704657
    705658    // point of no return
     
    807760    psHash          *mysqlFieldType;    // type lookup table
    808761    mysqlType       *mType;             // type tmp variable
    809     bool            isNull = true;      // used in a MYSQL_BIND to indicate NULL
     762    static bool     isNull = true;      // used in a MYSQL_BIND to indicate NULL,
     763                                        // this will be used outside of this func
    810764    char            *key;               // hash tmp variable
    811     int             i;
     765    psU32           i;                  // field index
    812766
    813767    // check size of values == paramCount ?
     
    846800                // error, not a pointer to a string
    847801                psFree(cursor);
     802                psFree(mysqlFieldType);
    848803
    849804                return false;
Note: See TracChangeset for help on using the changeset viewer.