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