00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "icatMidLevelHelpers.h"
00011 #include "icatMidLevelRoutines.h"
00012 #include "stringOpr.h"
00013 #include <stdio.h>
00014 #include <time.h>
00015
00016
00017
00018
00019
00020
00021 #if 0 // JMC - backport 4535
00022 char *cmlArrToSepStr(char *str,
00023 char *preStr,
00024 char *arr[],
00025 int arrLen,
00026 char *sep,
00027 int maxLen,
00028 int opt)
00029 {
00030
00031 int i;
00032
00033 rstrcpy(str, preStr, maxLen);
00034
00035 if (arrLen > 0)
00036 rstrcat(str, arr[0], maxLen);
00037 for (i = 1; i < arrLen; i++) {
00038 rstrcat(str, sep, maxLen);
00039 if (opt==1) rstrcat(str, "'", maxLen);
00040 if (opt==2 && *arr[i]!='(') rstrcat(str, "'", maxLen);
00041 rstrcat(str, arr[i], maxLen);
00042 if (opt==1) rstrcat(str, "'", maxLen);
00043 if (opt==2 && *arr[i]!='(') rstrcat(str, "'", maxLen);
00044 }
00045 return(str);
00046
00047 }
00048 #endif
00049
00050
00051
00052 #if 0 // JMC - backport 4535
00053 int columnIsText(char *column) {
00054 if (strstr(column, "_id") != NULL) return(0);
00055 if (strstr(column, "maxsize") != NULL) return(0);
00056 if (strstr(column, "data_size") != NULL) return(0);
00057 if (strstr(column, "data_map_id") != NULL) return(0);
00058 if (strstr(column, "attr_expose") != NULL) return(0);
00059 if (strstr(column, "fk_owner") != NULL) return(0);
00060 if (strstr(column, "uschema_owner") != NULL) return(0);
00061 if (strstr(column, "schema_owner") != NULL) return(0);
00062 if (strstr(column, "data_repl_num") != NULL) return(0);
00063 if (strstr(column, "data_is_dirty") != NULL) return(0);
00064 if (strstr(column, "data_map_id") != NULL) return(0);
00065 if (strstr(column, "rule_seq_num") != NULL) return(0);
00066 return(1);
00067 }
00068 #endif
00069
00070 #if 0 // JMC - backport 4535
00071 char *cmlArr2ToSepStr(char *str,
00072 char *preStr,
00073 char *arr[],
00074 char *arr2[],
00075 int arrLen,
00076 char *sep,
00077 int maxLen)
00078 {
00079
00080 int i;
00081
00082 rstrcpy(str, preStr, maxLen);
00083
00084 if (arrLen > 0) {
00085 rstrcat(str, arr[0], maxLen);
00086 rstrcat(str, arr2[0], maxLen);
00087 }
00088 for (i = 1; i < arrLen; i++) {
00089 rstrcat(str, sep, maxLen);
00090 rstrcat(str, arr[i], maxLen);
00091 rstrcat(str, arr2[i], maxLen);
00092 }
00093 return(str);
00094
00095 }
00096 #endif
00097
00098 #if 0 // JMC - backport 4535
00099 char *cmlArr2ToSep2Str(char *str,
00100 char *preStr,
00101 char *arr[],
00102 char *arr2[],
00103 int arrLen,
00104 char *sep,
00105 char *sep2,
00106 int maxLen)
00107 {
00108
00109 int i;
00110 int isText, hasQuote;
00111 char *cp;
00112
00113 rstrcpy(str, preStr, maxLen);
00114
00115 for (i = 0; i < arrLen; i++) {
00116 if (i>0) {
00117 rstrcat(str, sep2, maxLen);
00118 }
00119 rstrcat(str, arr[i], maxLen);
00120 rstrcat(str, sep, maxLen);
00121 isText = columnIsText(arr[i]);
00122 cp = arr[i];
00123 hasQuote = 0;
00124 if (*cp == '\'') hasQuote=1;
00125 if (isText && !hasQuote) {
00126 rstrcat(str, "'", maxLen);
00127 rstrcat(str, arr2[i], maxLen);
00128 rstrcat(str, "'", maxLen);
00129 }
00130 else {
00131 rstrcat(str, arr2[i], maxLen);
00132 }
00133 }
00134 return(str);
00135
00136 }
00137 #endif
00138
00139
00140
00141 char *cmlArraysToStrWithBind(char *str,
00142 char *preStr,
00143 char *arr[],
00144 char *arr2[],
00145 int arrLen,
00146 char *sep,
00147 char *sep2,
00148 int maxLen)
00149 {
00150 int i;
00151
00152 rstrcpy(str, preStr, maxLen);
00153
00154 for (i = 0; i < arrLen; i++) {
00155 if (i>0) {
00156 rstrcat(str, sep2, maxLen);
00157 }
00158 rstrcat(str, arr[i], maxLen);
00159 rstrcat(str, sep, maxLen);
00160 rstrcat(str, "?", maxLen);
00161 cllBindVars[cllBindVarCount++]=arr2[i];
00162 }
00163 return(str);
00164
00165 }
00166
00167
00168 #if 0 // JMC - backport 4535
00169 int cmlGetOneRowFromSingleTableUnused (char *tableName,
00170 char *cVal[],
00171 int cValSize[],
00172 char *selectCols[],
00173 char *whereCols[],
00174 char *whereConds[],
00175 int numOfSels,
00176 int numOfConds,
00177 icatSessionStruct *icss)
00178 {
00179 char tsql[MAX_SQL_SIZE];
00180 int i;
00181 char *rsql;
00182 char *tArr[2];
00183
00184 tArr[0] = tableName;
00185
00186 cmlArrToSepStr(tsql, "select ", selectCols, numOfSels, ", ",
00187 MAX_SQL_SIZE,0);
00188 i = strlen(tsql);
00189 rsql = tsql + i;
00190
00191 cmlArrToSepStr(rsql, " from ", tArr, 1, ", ", MAX_SQL_SIZE - i, 0);
00192 i = strlen(tsql);
00193 rsql = tsql + i;
00194
00195 cmlArr2ToSepStr(rsql, " where ", whereCols, whereConds, numOfConds, " and ",
00196 MAX_SQL_SIZE - i);
00197
00198 i = cmlGetOneRowFromSql (tsql, cVal, cValSize, numOfSels, icss);
00199 return(i);
00200 }
00201 #endif
00202
00203
00204 #if 0 // JMC - backport 4535
00205 int cmlDeleteFromSingleTableUnused (char *tableName,
00206 char *selectCols[],
00207 char *selectConds[],
00208 int numOfConds,
00209 icatSessionStruct *icss)
00210 {
00211 char tsql[MAX_SQL_SIZE];
00212 int i, l;
00213 char *rsql;
00214
00215 snprintf(tsql, MAX_SQL_SIZE, "delete from %s ", tableName);
00216 l = strlen(tsql);
00217 rsql = tsql + l;
00218
00219 cmlArr2ToSepStr(rsql, " where ", selectCols, selectConds, numOfConds,
00220 " and ", MAX_SQL_SIZE - l);
00221 i = cmlExecuteNoAnswerSql( tsql, icss);
00222 return(i);
00223
00224 }
00225 #endif
00226
00227
00228
00229 #if 0 // JMC - backport 4535
00230 int cmlInsertIntoSingleTableUnused(char *tableName,
00231 char *insertCols[],
00232 char *insertValues[],
00233 int numOfCols,
00234 icatSessionStruct *icss)
00235 {
00236 char tsql[MAX_SQL_SIZE];
00237 int i, len;
00238 char *rsql;
00239
00240 snprintf(tsql, MAX_SQL_SIZE, "insert into %s (", tableName );
00241 len = strlen(tsql);
00242 rsql = tsql + len;
00243
00244 cmlArrToSepStr(rsql, "", insertCols, numOfCols, ", ", MAX_SQL_SIZE - len, 0);
00245 len = strlen(tsql);
00246 rsql = tsql + len;
00247
00248 rstrcat(tsql, ") values (", MAX_SQL_SIZE);
00249 for (i=0;i<numOfCols;i++) {
00250 if (i==0) {
00251 rstrcat(tsql, "?", MAX_SQL_SIZE);
00252 }
00253 else {
00254 rstrcat(tsql, ",?", MAX_SQL_SIZE);
00255 }
00256 cllBindVars[cllBindVarCount++]=insertValues[i];
00257 }
00258
00259 rstrcat(tsql, ")", MAX_SQL_SIZE);
00260 i = cmlExecuteNoAnswerSql( tsql, icss);
00261 return(i);
00262 }
00263 #endif
00264
00265
00266
00267 #if 0 // JMC - backport 4535
00268 int cmlInsertIntoSingleTableV2Unused (char *tableName,
00269 char *insertCols,
00270 char *insertValues[],
00271 int numOfCols,
00272 icatSessionStruct *icss)
00273 {
00274 char tsql[MAX_SQL_SIZE];
00275 int i, l;
00276 char *rsql;
00277
00278 snprintf(tsql, MAX_SQL_SIZE, "insert into %s (", tableName );
00279 l = strlen(tsql);
00280 rsql = tsql + l;
00281
00282 rstrcat(tsql, insertCols, MAX_SQL_SIZE);
00283 l = strlen(tsql);
00284 rsql = tsql + l;
00285
00286 cmlArrToSepStr(rsql,") values (",insertValues, numOfCols, ", ", MAX_SQL_SIZE - l, 2);
00287
00288 rstrcat(tsql, ")", MAX_SQL_SIZE);
00289 i = cmlExecuteNoAnswerSql( tsql, icss);
00290 return(i);
00291 }
00292 #endif
00293
00294
00295 #if 0 // JMC - backport 4535
00296 int cmlGetUserIdUnused( char *userName, icatSessionStruct *icss) {
00297 int status;
00298 char tsql[MAX_SQL_SIZE];
00299 rodsLong_t iVal;
00300
00301
00302
00303
00304
00305 snprintf(tsql, MAX_SQL_SIZE,
00306 "select user_id from R_USER_MAIN where user_name = ?");
00307 status = cmlGetIntegerValueFromSql (tsql, &iVal, userName, 0, 0, 0, 0,icss);
00308 if (status == 0) return(iVal);
00309
00310
00311
00312 return(status);
00313 }
00314 #endif