IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 18, 2006, 10:08:33 AM (20 years ago)
Author:
Paul Price
Message:

Applying patch from Josh --- 'It adds support for multi column/field primary keys'

File:
1 edited

Legend:

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

    r7078 r7143  
    1212 *  @author Joshua Hoblitt
    1313 *
    14  *  @version $Revision: 1.51 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2006-05-05 23:56:51 $
     14 *  @version $Revision: 1.52 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2006-05-18 20:08:33 $
    1616 *
    1717 *  Copyright 2005 Joshua Hoblitt, University of Hawaii
     
    11341134    }
    11351135
     1136
     1137    // find database indexes
     1138    // check for Primary Keys first as they have to be part of the same Primary
     1139    // Key stmt
    11361140    // Reset iterator to head of list
    11371141    psListIteratorSet(cursor, 0);
    1138 
    1139     // find database indexes
     1142    psArray *pKeys = psArrayAlloc(1);
    11401143    while ((item = psListGetAndIncrement(cursor))) {
    1141         // XXX NOTE: check for "Primary Key" first before "Key".  Yes we're
    1142         // playing fast and loose here, but I think it's fine...
    11431144        if (strstr(item->comment, "Primary Key")) {
    1144             psStringAppend(&query, ", PRIMARY KEY(%s)", item->name);
    1145         } else if (strstr(item->comment, "Key")) {
     1145            psArrayAdd(pKeys, 0, item->name);
     1146        }
     1147    }
     1148    if (psArrayLength(pKeys)) {
     1149        psStringAppend(&query, ", PRIMARY KEY(");
     1150        for (int i = 0; i < psArrayLength(pKeys); i++) {
     1151            if (i < 1) {
     1152                psStringAppend(&query, "%s", pKeys->data[i]);
     1153            } else {
     1154                psStringAppend(&query, ", %s", pKeys->data[i]);
     1155            }
     1156        }
     1157        psStringAppend(&query, ")");
     1158    }
     1159    psFree(pKeys);
     1160
     1161    // Reset iterator to head of list
     1162    psListIteratorSet(cursor, 0);
     1163    // look for regular keys
     1164    while ((item = psListGetAndIncrement(cursor))) {
     1165        if (strstr(item->comment, "Key")) {
    11461166            psStringAppend(&query, ", KEY(%s)", item->name);
    11471167        } else if (strstr(item->comment, "AUTO_INCREMENT")) {
Note: See TracChangeset for help on using the changeset viewer.