IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7768


Ignore:
Timestamp:
Jun 30, 2006, 1:50:56 PM (20 years ago)
Author:
jhoblitt
Message:

fix MySQL time support (no searching support yet)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/db/psDB.c

    r7766 r7768  
    1212 *  @author Joshua Hoblitt
    1313 *
    14  *  @version $Revision: 1.68 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2006-06-30 02:20:06 $
     14 *  @version $Revision: 1.69 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2006-06-30 23:50:56 $
    1616 *
    1717 *  Copyright 2005 Joshua Hoblitt, University of Hawaii
     
    972972                psMetadataAdd(md, PS_LIST_TAIL, field[i].name, pType, "", atoi(data));
    973973            } else if (pType == PS_DATA_TIME) {
     974                psTime *time = psTimeStrptime((char *)data, "%EY-%m-%d%t%T");
     975                if (!time) {
     976                    psError(PS_ERR_UNKNOWN, true, "error parsing MySQL DateTime string");
     977                    return NULL;
     978                }
     979                psMetadataAddTime(md, PS_LIST_TAIL, field[i].name, 0, "", time);
     980                psFree(time);
     981                #if 0
     982                // this is the procedure needed for stmt
     983                MYSQL_TIME *myTime = (MYSQL_TIME *)&data;
     984                // convert MYSQL_TIME to struct tm
     985                struct tm tmTime;
     986                tmTime.tm_year  = (int)myTime->year - 1900;
     987                tmTime.tm_mon   = (int)myTime->month - 1;
     988                tmTime.tm_mday  = (int)myTime->day;
     989                tmTime.tm_hour  = (int)myTime->hour;
     990                tmTime.tm_min   = (int)myTime->minute;
     991                tmTime.tm_sec   = (int)myTime->second;
     992                // assume for the time being that we don't have negative time
     993                //(bool)myTime->neg
     994                // currently unused by mysql nor does struct tm support it
     995                // (unsigned long)myTime->second_part;
     996                psTime *time = psTimeFromTM(&tmTime);
    974997                psMetadataAddTime(md, PS_LIST_TAIL, field[i].name, 0, "",
    975                                   psTimeFromISO(data, PS_TIME_UTC));
     998                                  time);
     999                psFree(time);
     1000                #endif
     1001
    9761002            } else {
    9771003                // XXX: assume binary string ...
     
    10751101            // try to do the conversion
    10761102            if ((char *)item->data.V) {
    1077                 psTime *time = p_psTimeCopy((psTime *)item->data.V);
    1078                 psTimeConvert(time, PS_TIME_UTC);
    1079                 bind[i].buffer  = psTimeToISO(time);
    1080                 psFree(time);
    1081                 bind[i].buffer_length = (unsigned long)strlen((char *)bind[i].buffer);
     1103                psTime *time = (psTime *)item->data.V;
     1104                struct tm *tmTime = psTimeToTM(time);
     1105
     1106                // XXX it wouldn't hurt to make this conversion it's own
     1107                // function
     1108                // myTime is used as the 'buffer' so it doesn't have to be
     1109                // free'd
     1110                MYSQL_TIME *myTime = psAlloc(sizeof(MYSQL_TIME));
     1111                myTime->year    = (unsigned int)tmTime->tm_year + 1900;
     1112                myTime->month   = (unsigned int)tmTime->tm_mon + 1;
     1113                myTime->day     = (unsigned int)tmTime->tm_mday;
     1114                myTime->hour    = (unsigned int)tmTime->tm_hour;
     1115                myTime->minute  = (unsigned int)tmTime->tm_min;
     1116                myTime->second  = (unsigned int)tmTime->tm_sec;
     1117                // assume for the time being that we don't have negative time
     1118                // as ISO8601 doesn't support dates prior to 0
     1119                myTime->neg     = (my_bool)false;
     1120                // currently unused by mysql
     1121                myTime->second_part  = (unsigned long)time->nsec;
     1122                psFree(tmTime);
     1123
     1124                bind[i].buffer  = myTime;
     1125                bind[i].buffer_length = 0;
    10821126                bind[i].length  = &bind[i].buffer_length;
    10831127                bind[i].is_null = NULL;
     
    11621206    // find column name and type
    11631207    while ((item = psListGetAndIncrement(cursor))) {
    1164         if ((item->type == PS_DATA_S32)  || (item->type == PS_DATA_F32) || (item->type == PS_DATA_F64) ||
    1165                 (item->type == PS_TYPE_S32)  || (item->type == PS_TYPE_F32) || (item->type == PS_TYPE_F64) ||
    1166                 (item->type == PS_TYPE_BOOL) || (item->type == PS_DATA_BOOL)) {
     1208        if ((item->type == PS_DATA_S32)
     1209                || (item->type == PS_DATA_F32)
     1210                || (item->type == PS_DATA_F64)
     1211                || (item->type == PS_TYPE_S32)
     1212                || (item->type == PS_TYPE_F32)
     1213                || (item->type == PS_TYPE_F64)
     1214                || (item->type == PS_TYPE_BOOL)
     1215                || (item->type == PS_DATA_BOOL)
     1216                || (item->type == PS_DATA_TIME)
     1217           ) {
    11671218            // + column name + _ + column type
    11681219            colType = psDBPTypeToSQL(item->type);
Note: See TracChangeset for help on using the changeset viewer.