00001
00002
00003 #ifdef RODS_RCAT
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "rcatC_db_externs.h"
00016 #include "rodsC_rcat_externs.h"
00017 #include "icatGlobalsExtern.h"
00018 #include "rodsLog.h"
00019 #include "rods.h"
00020 #include <string.h>
00021
00022 #include <string>
00023
00024 int debugging4 = 0;
00025
00026 removeblanks(char *Str)
00027 {
00028 int i,j,k;
00029 k = 0;
00030 j = strlen(Str);
00031 for (i = 0; i < j ; i++){
00032 if (Str[i] != ' ') Str[k++] = Str[i];
00033 }
00034 Str[k] = '\0';
00035 }
00036
00037 int
00038 splitListString(char *List, char Array[][MAX_TOKEN], char Key)
00039 {
00040 int i,j, k, ln, b;
00041
00042 ln = strlen(List);
00043 j = 0; b = 1; k = 0;
00044 for (i = 0; i < ln ; i++) {
00045 if (b == 1 && List[i] == ' ') continue;
00046 b = 0;
00047 if (List[i] == ',' ) {
00048 Array[j][k] = '\0';
00049 b = 1;
00050 j++;
00051 k = 0;
00052 }
00053 else {
00054 Array[j][k] = List[i];
00055 k++;
00056 }
00057 }
00058 Array[j][k] = '\0';
00059 return(j+1);
00060 }
00061
00062 int
00063 getFkrelEntrySet(char *schemaset,
00064 rcat_metadata_fkrel_entry *fkrel_info,
00065 int max_fkrel_set_size)
00066
00067
00068 {
00069 int i,j, max_fkrel_entries;
00070 char tmpStr[1000];
00071
00072 sprintf(sqlq, "select t0.* from %sRCOREFK_RELATIONS t0 where t0.schema_name_in in (%s) and t0.schema_name_out in (%s) ",
00073 RCATSCHEMENAME, schemaset, schemaset);
00074
00075 i = exec_sql_db(henv, hdbc, &hstmt, (unsigned char *) sqlq);
00076 if (i != 0) return (i);
00077 i = get_no_of_columns_db(hstmt, &num_of_cols);
00078 if (i < 0) {
00079 done_with_result_db(hstmt);
00080 return (i);
00081 }
00082 i = bind_default_row_db(hstmt, data, data_size, &num_of_cols);
00083 if (i != 0) {
00084 done_with_result_db(hstmt);
00085 return (i);
00086 }
00087 i = get_row_db(hstmt);
00088 if (i != 0) {
00089 done_with_default_result_db(hstmt,data,data_size, num_of_cols);
00090 return (i);
00091 }
00092 max_fkrel_entries = 0;
00093 while (i == 0 )
00094 {
00095
00096 if (max_fkrel_entries == max_fkrel_set_size)
00097 {
00098 done_with_default_result_db(hstmt,data,data_size, num_of_cols);
00099 return (MCAT_MAX_FKREL_ENTRIES_OVERFLOW);
00100 }
00101 fkrel_info[max_fkrel_entries].tab1 = atoi((char *) data[0]);
00102 fkrel_info[max_fkrel_entries].tab2 = atoi((char *) data[2]);
00103 fkrel_info[max_fkrel_entries].fg1 = 0;
00104 fkrel_info[max_fkrel_entries].fg2 = 0;
00105 fkrel_info[max_fkrel_entries].fg3 = 0;
00106 truncate_end_blanks(data_size[20], data[20]);
00107 truncate_end_blanks(data_size[21], data[21]);
00108 truncate_end_blanks(data_size[22], data[22]);
00109 strcpy(tmpStr," ");
00110 if (strlen((char *) data[20])!= 0) sprintf(&tmpStr[strlen(tmpStr)],"%s(",data[20]);
00111 sprintf(&tmpStr[strlen(tmpStr)],"%i", atoi((char *) data[1]));
00112 if (atoi((char *)data[5]) >= 0) sprintf(&tmpStr[strlen(tmpStr)],",%i", atoi((char *) data[5]));
00113 if (atoi((char *)data[9]) >= 0) sprintf(&tmpStr[strlen(tmpStr)],",%i", atoi((char *) data[9]));
00114 if (atoi((char *)data[13])>= 0) sprintf(&tmpStr[strlen(tmpStr)],",%i", atoi((char *) data[13]));
00115 if (atoi((char *)data[17]) >= 0) sprintf(&tmpStr[strlen(tmpStr)],",%i", atoi((char *) data[17]));
00116 if (strlen((char *)data[20]) != 0) sprintf(&tmpStr[strlen(tmpStr)],")");
00117 sprintf(&tmpStr[strlen(tmpStr)]," %s ",data[22]);
00118 if (strlen((char *)data[21])!= 0) sprintf(&tmpStr[strlen(tmpStr)],"%s(",data[21]);
00119 sprintf(&tmpStr[strlen(tmpStr)],"%i", atoi((char *) data[3]));
00120 if (atoi((char *)data[7]) >= 0) sprintf(&tmpStr[strlen(tmpStr)],",%i", atoi((char *) data[7]));
00121 if (atoi((char *)data[11]) >= 0) sprintf(&tmpStr[strlen(tmpStr)],",%i", atoi((char *) data[11]));
00122 if (atoi((char *)data[15]) >= 0) sprintf(&tmpStr[strlen(tmpStr)],",%i", atoi((char *) data[15]));
00123 if (atoi((char *)data[19]) >= 0) sprintf(&tmpStr[strlen(tmpStr)],",%i", atoi((char *) data[19]));
00124 if (strlen((char *)data[21])!= 0) sprintf(&tmpStr[strlen(tmpStr)],") ");
00125 fkrel_info[max_fkrel_entries].pred =
00126 (char *) malloc((strlen(tmpStr) + 1) * sizeof(char));
00127 strcpy(fkrel_info[max_fkrel_entries].pred,tmpStr);
00128
00129 max_fkrel_entries++;
00130 i = get_row_db(hstmt);
00131
00132 }
00133 i = done_with_default_result_db(hstmt,data,data_size, num_of_cols);
00134 return(RCAT_SUCCESS);
00135 }
00136
00137
00138 int
00139 getGraphPathEntrySet(char *schemaset,
00140 rcat_metadata_graph_entry *graph_info,
00141 int max_graph_set_size)
00142
00143 {
00144 int i,j, max_graph_entries;
00145 char tmpStr[1000];
00146
00147 sprintf(sqlq, "select t1.table_name, t2.table_name, t3.attr_name, t4.attr_name, t5.attr_name, t6.attr_name, t7.attr_name, t8.attr_name, t9.attr_name, t10.attr_name, t11.attr_name, t12.attr_name, t0.func_in, t0.func_out,t0.attr_rel_name, t1.dbschema_name, t2.dbschema_name , t1.rsrc_id, t2.rsrc_id from %sRCOREFK_RELATIONS t0, %sRCOREtables t1, %srcore_tables t2, %srcore_attributes t3, %srcore_attributes t4, %srcore_attributes t5, %srcore_attributes t6, %srcore_attributes t7, %srcore_attributes t8, %srcore_attributes t9, %srcore_attributes t10, %srcore_attributes t11, %srcore_attributes t12 where t0.table_id_in1 =t1.table_id and t0.table_id_out1 =t2.table_id and t0.attr_id_in1 = t3.attr_id and t0.attr_id_in2 = t4.attr_id and t0.attr_id_in3 = t5.attr_id and t0.attr_id_in4 = t6.attr_id and t0.attr_id_in5 = t7.attr_id and t0.attr_id_out1 = t8.attr_id and t0.attr_id_out2 = t9.attr_id and t0.attr_id_out3 = t10.attr_id and t0.attr_id_out4 = t11.attr_id and t0.attr_id_out5 = t12.attr_id and t0.schema_name_in in (%s) and t0.schema_name_out in (%s) ",
00148 RCATSCHEMENAME,RCATSCHEMENAME,RCATSCHEMENAME,RCATSCHEMENAME,RCATSCHEMENAME,
00149 RCATSCHEMENAME,RCATSCHEMENAME,RCATSCHEMENAME,RCATSCHEMENAME,RCATSCHEMENAME,
00150 RCATSCHEMENAME,RCATSCHEMENAME,RCATSCHEMENAME, schemaset, schemaset);
00151
00152 i = exec_sql_db(henv, hdbc, &hstmt, (unsigned char *) sqlq);
00153 if (i != 0) return (i);
00154 i = get_no_of_columns_db(hstmt, &num_of_cols);
00155 if (i < 0) {
00156 done_with_result_db(hstmt);
00157 return (i);
00158 }
00159 i = bind_default_row_db(hstmt, data, data_size, &num_of_cols);
00160 if (i != 0) {
00161 done_with_result_db(hstmt);
00162 return (i);
00163 }
00164 i = get_row_db(hstmt);
00165 if ((i != 0) && (i != MCAT_NO_DATA_FOUND)) {
00166 done_with_default_result_db(hstmt,data,data_size, num_of_cols);
00167 return (i);
00168 }
00169
00170 max_graph_entries = 0;
00171 while (i == 0 )
00172 {
00173 if (max_graph_entries == max_graph_set_size)
00174 {
00175 done_with_default_result_db(hstmt,data,data_size, num_of_cols);
00176 return (MCAT_MAX_GRAPH_PATH_OVERFLOW);
00177 }
00178 for (j=0; j < num_of_cols;j++) {
00179 truncate_end_blanks(data_size[j], data[j]);
00180 }
00181 sprintf(graph_info[max_graph_entries].name1,"%s%s",
00182 (char *)data[15],(char *)data[0]);
00183
00184 sprintf(graph_info[max_graph_entries].name2,"%s%s",
00185 (char *)data[16], (char *)data[1]);
00186 graph_info[max_graph_entries].rsrc_id1 = atoi((char *)data[17]);
00187 graph_info[max_graph_entries].rsrc_id2 = atoi((char *)data[18]);
00188 strcpy(graph_info[max_graph_entries].relop, (char *)data[14]);
00189
00190 graph_info[max_graph_entries].fg1 = 0;
00191 graph_info[max_graph_entries].fg2 = 0;
00192 graph_info[max_graph_entries].fg3 = 0;
00193
00194 strcpy(tmpStr,"");
00195 if (strlen((char *) data[12])!= 0 || strcmp((char *) data[3],"$NULL")){
00196 sprintf(&tmpStr[strlen(tmpStr)],"%s(",(char *)data[12]);
00197 }
00198 sprintf(&tmpStr[strlen(tmpStr)],"%s", (char *)data[2]);
00199 for (j= 3; j < 7; j++) {
00200 if (strcmp((char *) data[j], "$NULL"))
00201 sprintf(&tmpStr[strlen(tmpStr)],",%s",(char *)data[j]);
00202 }
00203 if (strlen((char *) data[12])!= 0 || strcmp((char *) data[3],"$NULL")){
00204 sprintf(&tmpStr[strlen(tmpStr)],")");
00205 }
00206 strcpy(graph_info[max_graph_entries].att1,tmpStr);
00207 strcpy(tmpStr,"");
00208 if (strlen((char *) data[13])!= 0 || strcmp((char *) data[8],"$NULL")) {
00209 sprintf(&tmpStr[strlen(tmpStr)],"%s(",(char *)data[13]);
00210 }
00211 sprintf(&tmpStr[strlen(tmpStr)],"%s" , (char *)data[7]);
00212 for (j= 8; j < 12; j++) {
00213 if (strcmp((char *) data[j], "$NULL"))
00214 sprintf(&tmpStr[strlen(tmpStr)],",%s",(char *)data[j]);
00215 }
00216 if (strlen((char *) data[13])!= 0 || strcmp((char *) data[8],"$NULL")){
00217 sprintf(&tmpStr[strlen(tmpStr)],")");
00218 }
00219 strcpy(graph_info[max_graph_entries].att2,tmpStr);
00220 i = get_row_db(hstmt);
00221 max_graph_entries++;
00222
00223 }
00224 i = done_with_default_result_db(hstmt,data,data_size, num_of_cols);
00225 if (max_graph_entries != max_graph_set_size){
00226 strcpy(GENERATEDSQL,sqlq);
00227 printf("SQL:%s\n<br>",sqlq);
00228 printf("A:%i:%i\n", max_graph_entries,max_graph_set_size);
00229 return(MCAT_MAX_GRAPH_PATH_UNDERFLOW);
00230 }
00231 else
00232 return(RCAT_SUCCESS);
00233 }
00234
00235
00236 int
00237 getAttrEntrySet(char *schemaset,
00238 rcat_metadata_attr_entry *attr_info,
00239 int max_attr_set_size, char *known)
00240 {
00241 int i;
00242 int max_entries;
00243
00244
00245
00246 if (!strcmp(known,"all")) {
00247 sprintf(sqlq, "select t0.attr_id, schema_name, dbschema_name, database_name, table_name, attr_name, external_attr_name, attr_data_type, attr_iden_type, attr_val_type, t0.table_id, presentation, default_value, t0.sameas, t0.maxsize, t0.primary_key, t0.expose, t0.exter_attrib_id, rsrc_id, attr_dimension, at_comments, cluster_name from %srcore_attributes t0, %srcore_tables t1, %srcore_uschema_attr t2 where t0.table_id = t1.table_id and t0.attr_id = t2.attr_id and t2.user_schema_name in (%s) and t0.expose >= 0 order by 1",
00248 RCATSCHEMENAME,RCATSCHEMENAME, RCATSCHEMENAME, schemaset);
00249 }
00250 else {
00251 sprintf(sqlq, "select t0.attr_id, schema_name, dbschema_name, database_name, table_name, attr_name, external_attr_name, attr_data_type, attr_iden_type, attr_val_type, t0.table_id, presentation, default_value, t0.sameas, t0.maxsize, t0.primary_key, t0.expose, t0.exter_attrib_id, rsrc_id, attr_dimension, at_comments, cluster_name from %srcore_attributes t0, %srcore_tables t1, %srcore_uschema_attr t2 where t0.table_id = t1.table_id and t0.attr_id = t2.attr_id and t2.user_schema_name in (%s) and t0.expose = 1 order by 1",
00252 RCATSCHEMENAME,RCATSCHEMENAME, RCATSCHEMENAME, schemaset);
00253 }
00254
00255
00256
00257 i = exec_sql_db(henv, hdbc, &hstmt, (unsigned char *) sqlq);
00258 if (i != 0) return (i);
00259 i = get_no_of_columns_db(hstmt, &num_of_cols);
00260 if (i < 0) {
00261 done_with_result_db(hstmt);
00262 return (i);
00263 }
00264 i = bind_default_row_db(hstmt, data, data_size, &num_of_cols);
00265 if (i != 0) {
00266 done_with_result_db(hstmt);
00267 return (i);
00268 }
00269 i = get_row_db(hstmt);
00270 if (i != 0) {
00271 done_with_default_result_db(hstmt,data,data_size, num_of_cols);
00272 return (i);
00273 }
00274 max_entries = 0;
00275 while (i == 0 )
00276 {
00277 if (max_entries == max_attr_set_size)
00278 {
00279 done_with_default_result_db(hstmt,data,data_size, num_of_cols);
00280 return (MCAT_MAX_ATTR_ENTRIES_OVERFLOW);
00281 }
00282 for (j=0; j < num_of_cols;j++){
00283 truncate_end_blanks(data_size[j], data[j]);
00284 }
00285 attr_info[max_entries].schema_name =
00286 (char *) malloc((strlen((char *)data[1]) + 1) * sizeof(char));
00287 attr_info[max_entries].dbschema_name =
00288 (char *) malloc((strlen((char *)data[2]) + 1) * sizeof(char));
00289 attr_info[max_entries].database_name =
00290 (char *) malloc((strlen((char *)data[3]) + 1) * sizeof(char));
00291 attr_info[max_entries].table_name =
00292 (char *) malloc((strlen((char *)data[2]) + 2 + strlen((char *)data[4]) + 1) * sizeof(char));
00293 attr_info[max_entries].extended_table_name =
00294 (char *) malloc((strlen((char *)data[2]) + 2 + strlen((char *)data[4]) + 1) * sizeof(char));
00295 attr_info[max_entries].attr_name =
00296 (char *) malloc((strlen((char *)data[5]) + 1) * sizeof(char));
00297 attr_info[max_entries].ext_attr_name =
00298 (char *) malloc((strlen((char *)data[6]) + 1) * sizeof(char));
00299 attr_info[max_entries].attr_data_type =
00300 (char *) malloc((strlen((char *)data[7]) + 1) * sizeof(char));
00301 attr_info[max_entries].attr_iden_type =
00302 (char *) malloc((strlen((char *)data[8]) + 1) * sizeof(char));
00303 attr_info[max_entries].presentation =
00304 (char *) malloc((strlen((char *)data[11]) + 1) * sizeof(char));
00305 attr_info[max_entries].attr_dimension =
00306 (char *) malloc((strlen((char *)data[19]) + 1) * sizeof(char));
00307 attr_info[max_entries].default_value =
00308 (char *) malloc((strlen((char *)data[12]) + 1) * sizeof(char));
00309 attr_info[max_entries].at_comments =
00310 (char *) malloc((strlen((char *)data[20]) + 1) * sizeof(char));
00311 attr_info[max_entries].cluster_name =
00312 (char *) malloc((strlen((char *)data[21]) + 1) * sizeof(char));
00313
00314 attr_info[max_entries].attr_id = atoi((char *)data[0]);
00315 strcpy(attr_info[max_entries].schema_name,(char *)data[1]);
00316 strcpy(attr_info[max_entries].dbschema_name,(char *)data[2]);
00317 strcpy(attr_info[max_entries].database_name,(char *)data[3]);
00318 sprintf(attr_info[max_entries].extended_table_name,"%s%s",
00319 (char *)data[2], (char *)data[4]);
00320 sprintf(attr_info[max_entries].table_name,"%s",(char *)data[4]);
00321 strcpy(attr_info[max_entries].attr_name,(char *)data[5]);
00322 strcpy(attr_info[max_entries].ext_attr_name,(char *)data[6]);
00323 strcpy(attr_info[max_entries].attr_data_type,(char *)data[7]);
00324 strcpy(attr_info[max_entries].attr_iden_type,(char *)data[8]);
00325 attr_info[max_entries].attr_val_type = atoi((char *)data[9]);
00326 attr_info[max_entries].tab_id = atoi((char *)data[10]);
00327 strcpy(attr_info[max_entries].presentation,(char *)data[11]);
00328 strcpy(attr_info[max_entries].default_value ,(char *)data[12]);
00329 attr_info[max_entries].sameas = atoi((char *)data[13]);
00330 attr_info[max_entries].maxsize = atoi((char *)data[14]);
00331 attr_info[max_entries].primary_key = atoi((char *)data[15]);
00332 attr_info[max_entries].expose = atoi((char *)data[16]);
00333 attr_info[max_entries].exter_attrib_id = atoi((char *)data[17]);
00334 attr_info[max_entries].rsrc_id = atoi((char *)data[18]);
00335 strcpy(attr_info[max_entries].attr_dimension,(char *)data[19]);
00336 strcpy(attr_info[max_entries].at_comments,(char *)data[20]);
00337 strcpy(attr_info[max_entries].cluster_name,(char *)data[21]);
00338
00339 i = get_row_db(hstmt);
00340 max_entries++;
00341 }
00342 i = done_with_default_result_db(hstmt,data,data_size, num_of_cols);
00343
00344 if (max_entries != max_attr_set_size)
00345 return(MCAT_MAX_ATTR_ENTRIES_UNDERFLOW);
00346 else
00347 return(RCAT_SUCCESS);
00348
00349 }
00350
00351 void
00352 printFkrelEntrySet(rcat_metadata_fkrel_entry *fkrel_info,
00353 int max_entries)
00354 {
00355 int i;
00356
00357 for (i = 0; i < max_entries ; i++)
00358 {
00359 printf("%i %i %s\n",
00360 fkrel_info[i].tab1,
00361 fkrel_info[i].tab2,
00362 fkrel_info[i].pred );
00363 }
00364
00365 }
00366
00367 void
00368 printAttrEntrySet(rcat_metadata_attr_entry *attr_info,
00369 int max_entries)
00370 {
00371 int i;
00372
00373 for (i = 0; i < max_entries ; i++)
00374 {
00375 printf("%i %i %s %s %s %s.%s\n %s %s %s %s %s %s %s %s %i %i %i %i %i %i %i\n",
00376 attr_info[i].attr_id,
00377 attr_info[i].tab_id,
00378 attr_info[i].schema_name,
00379 attr_info[i].database_name,
00380 attr_info[i].dbschema_name,
00381 attr_info[i].table_name,
00382 attr_info[i].attr_name,
00383 attr_info[i].ext_attr_name,
00384 attr_info[i].attr_data_type,
00385 attr_info[i].attr_iden_type,
00386 attr_info[i].presentation,
00387 attr_info[i].attr_dimension,
00388 attr_info[i].at_comments,
00389 attr_info[i].cluster_name,
00390 attr_info[i].default_value,
00391 attr_info[i].attr_val_type,
00392 attr_info[i].sameas,
00393 attr_info[i].maxsize,
00394 attr_info[i].primary_key,
00395 attr_info[i].expose,
00396 attr_info[i].exter_attrib_id,
00397 attr_info[i].rsrc_id);
00398 }
00399 }
00400
00401
00402 void
00403 printGraphPathEntrySet(rcat_metadata_graph_entry graph_info[],
00404 int max_entries)
00405 {
00406 int i;
00407
00408 for (i = 0; i < max_entries ; i++)
00409 {
00410 printf("%s %s %s %s\n",
00411 graph_info[i].name1,
00412 graph_info[i].att1,
00413 graph_info[i].name2,
00414 graph_info[i].att2);
00415 }
00416
00417 }
00418
00419 int
00420 allocAttrEntrySet(rcat_metadata_attr_entry **attr_info, int max_entries)
00421 {
00422 if (attr_info == NULL) return (MEMORY_ALLOCATION_ERROR);
00423
00424 *attr_info = (rcat_metadata_attr_entry *)
00425 malloc(max_entries * sizeof(rcat_metadata_attr_entry));
00426 if (*attr_info == NULL) return (MEMORY_ALLOCATION_ERROR);
00427 else return (RCAT_SUCCESS);
00428
00429 }
00430
00431
00432 int
00433 allocFkrelEntrySet(rcat_metadata_fkrel_entry **fkrel_info, int max_entries)
00434 {
00435 if (fkrel_info == NULL) return (MEMORY_ALLOCATION_ERROR);
00436 *fkrel_info = (rcat_metadata_fkrel_entry *)
00437 malloc(max_entries * sizeof(rcat_metadata_fkrel_entry));
00438 if (*fkrel_info == NULL) return (MEMORY_ALLOCATION_ERROR);
00439 else return (RCAT_SUCCESS);
00440
00441 }
00442
00443
00444
00445 int
00446 allocGraphPathEntrySet(rcat_metadata_graph_entry **graph_info,
00447 int max_entries)
00448 {
00449 if (graph_info == NULL) return (MEMORY_ALLOCATION_ERROR);
00450 *graph_info = (rcat_metadata_graph_entry *)
00451 malloc(max_entries * sizeof(rcat_metadata_graph_entry));
00452 if (*graph_info == NULL) return (MEMORY_ALLOCATION_ERROR);
00453 else return (RCAT_SUCCESS);
00454
00455 }
00456
00457
00458
00459 void
00460 freeAttrEntrySet(rcat_metadata_attr_entry attr_info[],
00461 int actual_attr_set_size)
00462 {
00463 int i;
00464 for (i = 0; i < actual_attr_set_size ; i ++)
00465 {
00466 free(attr_info[i].schema_name );
00467 free(attr_info[i].dbschema_name );
00468 free(attr_info[i].database_name );
00469 free(attr_info[i].table_name );
00470 free(attr_info[i].extended_table_name );
00471 free(attr_info[i].attr_name );
00472 free(attr_info[i].ext_attr_name );
00473 free(attr_info[i].attr_data_type );
00474 free(attr_info[i].attr_iden_type );
00475 free(attr_info[i].presentation );
00476 free(attr_info[i].attr_dimension );
00477 free(attr_info[i].at_comments );
00478 free(attr_info[i].cluster_name );
00479 free(attr_info[i].default_value);
00480 }
00481 free(attr_info);
00482 }
00483 void
00484 freeFkrelEntrySet(rcat_metadata_fkrel_entry fkrel_info[],
00485 int actual_fkrel_set_size)
00486 {
00487 int i;
00488 for (i = 0; i < actual_fkrel_set_size ; i ++)
00489 {
00490 free(fkrel_info[i].pred );
00491 }
00492 free(fkrel_info);
00493 }
00494
00495 void
00496 freeGraphPathEntrySet(rcat_metadata_graph_entry graph_info[],
00497 int actual_graph_set_size)
00498 {
00499 int i;
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511 free(graph_info);
00512 }
00513
00514 int
00515 getAttrCountinSchemaSet(char *schemaset, char *known)
00516 {
00517 int i,cnt;
00518
00519
00520
00521
00522 if (!strcmp(known,"all")) {
00523 sprintf(sqlq, "select count(*) from %srcore_uschema_attr t0 where t0.user_schema_name in (%s) and t0.expose >= 0 ", RCATSCHEMENAME, schemaset);
00524 }
00525 else {
00526 sprintf(sqlq, "select count(*) from %srcore_uschema_attr t0 where t0.user_schema_name in (%s) and t0.expose = 1 ", RCATSCHEMENAME, schemaset);
00527 }
00528
00529 i = exec_sql_db(henv, hdbc, &hstmt, (unsigned char *) sqlq);
00530 if (i != 0) return (i);
00531 num_of_cols = 1;
00532 i = bind_default_row_db(hstmt, data, data_size, &num_of_cols);
00533 if (i != 0) {
00534 done_with_result_db(hstmt);
00535 return (i);
00536 }
00537 i = get_row_db(hstmt);
00538 if (i != 0) {
00539 done_with_default_result_db(hstmt,data,data_size, num_of_cols);
00540 return (i);
00541 }
00542 truncate_end_blanks(data_size[0], data[0]);
00543 cnt = atoi((char *)data[0]);
00544 done_with_default_result_db(hstmt,data,data_size,num_of_cols);
00545 return (cnt);
00546 }
00547
00548 int
00549 getFkrelCountinSchemaSet(char *schemaset)
00550 {
00551 int i,cnt;
00552 sprintf(sqlq, "select count(*) from %sRCORE_FK_RELATIONS t0 where t0.schema_name_in in (%s) and t0.schema_name_out in (%s) ",
00553 RCATSCHEMENAME, schemaset, schemaset);
00554
00555 i = exec_sql_db(henv, hdbc, &hstmt, (unsigned char *) sqlq);
00556 if (i != 0) return (i);
00557 num_of_cols = 1;
00558 i = bind_default_row_db(hstmt, data, data_size,&num_of_cols);
00559 if (i != 0) {
00560 done_with_result_db(hstmt);
00561 return (i);
00562 }
00563 i = get_row_db(hstmt);
00564 if (i != 0) {
00565 done_with_default_result_db(hstmt,data,data_size, num_of_cols);
00566 return (i);
00567 }
00568 truncate_end_blanks(data_size[0], data[0]);
00569 cnt = atoi((char *)data[0]);
00570 done_with_default_result_db(hstmt,data,data_size,num_of_cols);
00571 return (cnt);
00572 }
00573
00574 int
00575 getGraphPathCountinSchemaSet(char *schemaset)
00576 {
00577 int i,cnt;
00578 sprintf(sqlq, "select count(*) from %sRCORE_FK_RELATIONS t0 where t0.schema_name_in in (%s) and t0.schema_name_out in (%s) ",
00579 RCATSCHEMENAME, schemaset, schemaset);
00580
00581 i = exec_sql_db(henv, hdbc, &hstmt, (unsigned char *) sqlq);
00582 if (i != 0) return (i);
00583 num_of_cols = 1;
00584 i = bind_default_row_db(hstmt, data, data_size, &num_of_cols);
00585 if (i != 0) {
00586 done_with_result_db(hstmt);
00587 return (i);
00588 }
00589 i = get_row_db(hstmt);
00590 if (i != 0) {
00591 done_with_default_result_db(hstmt,data,data_size, num_of_cols);
00592 return (i);
00593 }
00594 truncate_end_blanks(data_size[0], data[0]);
00595 cnt = atoi((char *)data[0]);
00596 done_with_default_result_db(hstmt,data,data_size,num_of_cols);
00597 return (cnt);
00598 }
00599
00600
00601 int
00602 getFreeMcatContxtDesc()
00603 {
00604 int i;
00605
00606 for (i = 0; i < MAX_NO_OF_MCAT_CONTEXTS ; i++) {
00607 if (svrMcatContext[i].used == 0) return (i);
00608 }
00609 return (MCAT_NO_MORE_CONTEXTS);
00610
00611 }
00612
00613 int
00614 getParentSchemaSet(char *parschemaset,char *schemaset)
00615 {
00616 char tmpStr[MAX_TOKEN];
00617 char sqlq[HUGE_STRING];
00618 int colcount,i, jj;
00619 char cval[MAX_TOKEN][MAX_TOKEN];
00620
00621 sprintf(sqlq,"select PARENT_SCHEMA from %sRCORE_USER_SCHEMAS where user_schema_name in (%s)", RCATSCHEMENAME, schemaset);
00622 i = get_ctype_list_from_query(cval, &colcount,sqlq);
00623 if (i != RCAT_SUCCESS ) return(i);
00624 if (colcount == 0) return (UNKNOWN_USER_SCHEMASET);
00625 strcpy(parschemaset,"");
00626 for (jj = 0; jj < colcount; jj++) {
00627 if (jj == 0)
00628 sprintf(tmpStr," '%s'",cval[jj]);
00629 else
00630 sprintf(tmpStr,", '%s'",cval[jj]);
00631 strcat(parschemaset,tmpStr);
00632 }
00633 return(RCAT_SUCCESS);
00634
00635 }
00636
00637
00638 mcatContextDesc
00639 initializeMcatContext(char *schemaset)
00640 {
00641
00642 char parschemaset[HUGE_STRING];
00643 int i;
00644
00645 i = getParentSchemaSet(parschemaset,schemaset);
00646
00647 if (i != RCAT_SUCCESS ) return(i);
00648 return(initializeMcatContextInternal(parschemaset,schemaset));
00649 }
00650
00651
00652 mcatContextDesc
00653 initializeMcatContextInternal(char *schemaset, char *userschemaset)
00654 {
00655
00656 int i,cnta, cntf, cntg, cd;
00657 rcat_metadata_attr_entry *attr_info;
00658 rcat_metadata_fkrel_entry *fkrel_info;
00659 rcat_metadata_graph_entry *graph_info;
00660
00661 cnta = getAttrCountinSchemaSet(schemaset,"all");
00662 if (cnta < 0) return (cnta);
00663 i = allocAttrEntrySet(&attr_info, cnta);
00664 if (i < 0) {
00665 free( attr_info );
00666 return (i);
00667 }
00668 i = getAttrEntrySet(schemaset, attr_info, cnta,"all");
00669 if (i < 0) {
00670 freeAttrEntrySet(attr_info, cnta);
00671 return (i);
00672 }
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685 cntg = getGraphPathCountinSchemaSet(schemaset);
00686 if (cntg < 0) { free( attr_info ); return (cntg); }
00687 i = allocGraphPathEntrySet(&graph_info, cntg);
00688 if (i < 0) { free( attr_info ); free( graph_info ); return (i); }
00689 i = getGraphPathEntrySet(schemaset, graph_info, cntg);
00690 if (i < 0) {
00691 freeGraphPathEntrySet(graph_info, cntg);
00692 freeAttrEntrySet(attr_info, cnta);
00693 return (i);
00694 }
00695
00696 cd = getFreeMcatContxtDesc();
00697 if (cd < 0) { free( attr_info ); free( graph_info ); return(cd); }
00698
00699 svrMcatContext[cd].userContext = (char *)
00700 malloc(sizeof(char) * ( strlen(userschemaset) + 1));
00701 if (svrMcatContext[cd].userContext == NULL) {
00702 freeGraphPathEntrySet(graph_info, cntg);
00703 freeAttrEntrySet(attr_info, cnta);
00704 return (MEMORY_ALLOCATION_ERROR);
00705 }
00706 svrMcatContext[cd].serverContext = (char *)
00707 malloc(sizeof(char) * ( strlen(schemaset) + 1));
00708 if (svrMcatContext[cd].serverContext == NULL) {
00709 freeGraphPathEntrySet(graph_info, cntg);
00710 freeAttrEntrySet(attr_info, cnta);
00711 free(svrMcatContext[cd].userContext);
00712 return (MEMORY_ALLOCATION_ERROR);
00713 }
00714
00715
00716
00717 svrMcatContext[cd].used = 1;
00718 svrMcatContext[cd].attr_info = attr_info;
00719 svrMcatContext[cd].max_attr_entries = cnta;
00720
00721
00722
00723
00724 svrMcatContext[cd].graph_info = graph_info;
00725 svrMcatContext[cd].max_graph_entries = cntg;
00726 strcpy(svrMcatContext[cd].userContext,userschemaset);
00727 strcpy(svrMcatContext[cd].serverContext,schemaset);
00728
00729 return (cd);
00730 }
00731
00732 void
00733 freeMcatContext(mcatContextDesc cd)
00734 {
00735 freeAttrEntrySet(svrMcatContext[cd].attr_info,
00736 svrMcatContext[cd].max_attr_entries);
00737 freeFkrelEntrySet(svrMcatContext[cd].fkrel_info,
00738 svrMcatContext[cd].max_fkrel_entries);
00739 freeGraphPathEntrySet(svrMcatContext[cd].graph_info,
00740 svrMcatContext[cd].max_graph_entries);
00741 free(svrMcatContext[cd].userContext);
00742 free(svrMcatContext[cd].serverContext);
00743 svrMcatContext[cd].used = 0;
00744
00745
00746 }
00747
00748
00749
00750 struct varlena *
00751 getAttrEntrySetSmallfromContext(mcatContextDesc cd)
00752 {
00753
00754
00755 int resLen = SIZEOF32;
00756 int i, status;
00757 char *ptr;
00758 struct varlena *retVal;
00759 #if defined(PORTNAME_c90)
00760 struct int32Array *iptr;
00761 #endif
00762
00763 resLen = 0;
00764 for (i = 0; i < svrMcatContext[cd].max_attr_entries ; i++) {
00765 resLen += SIZEOF32;
00766 resLen += (strlen(svrMcatContext[cd].attr_info[i].schema_name) + 1);
00767 resLen += (strlen(svrMcatContext[cd].attr_info[i].ext_attr_name) + 1);
00768 }
00769
00770 retVal = (struct varlena *)malloc(VAROUTHDRSZ + resLen);
00771 VARSIZE(retVal) = resLen + VAROUTHDRSZ;
00772 VAROUTSTAT(retVal) = 0;
00773 ptr = VAROUTDATA(retVal);
00774 #if defined(PORTNAME_c90)
00775 iptr = (struct int32Array *) VAROUTDATA(retVal);
00776 #endif
00777
00778
00779 ptr = VARDATA(retVal);
00780
00781 #if defined(PORTNAME_c90)
00782 iptr->myInt0 = htonl (svrMcatContext[cd].max_attr_entries);
00783 ptr += SIZEOF32;
00784 #else
00785 *(int32 *) ptr = htonl (svrMcatContext[cd].max_attr_entries);
00786 ptr += SIZEOF32;
00787 #endif
00788
00789
00790
00791 for (i = 0; i < svrMcatContext[cd].max_attr_entries ; i = i + 2) {
00792 #if defined(PORTNAME_c90)
00793 iptr->myInt1 = htonl (svrMcatContext[cd].attr_info[i].attr_id);
00794 ptr += SIZEOF32;
00795 iptr = (struct int32Array *) ptr;
00796 if (i+1 < svrMcatContext[cd].max_attr_entries)
00797 {
00798 iptr->myInt0 = htonl (svrMcatContext[cd].attr_info[i+1].attr_id);
00799 ptr += SIZEOF32;
00800 }
00801 #else
00802 *(int32 *) ptr = htonl (svrMcatContext[cd].attr_info[i].attr_id);
00803 ptr += sizeof (int32);
00804 if (i+1 < svrMcatContext[cd].max_attr_entries)
00805 {
00806 *(int32 *) ptr = htonl (svrMcatContext[cd].attr_info[i+1].attr_id);
00807 ptr += sizeof (int32);
00808 }
00809 #endif
00810 }
00811 for (i = 0; i < svrMcatContext[cd].max_attr_entries ; i++) {
00812 strcpy (ptr, svrMcatContext[cd].attr_info[i].schema_name);
00813 ptr += strlen(svrMcatContext[cd].attr_info[i].schema_name);
00814 *ptr = '\0';
00815 ptr ++;
00816 strcpy (ptr, svrMcatContext[cd].attr_info[i].ext_attr_name);
00817 ptr += strlen(svrMcatContext[cd].attr_info[i].ext_attr_name);
00818 *ptr = '\0';
00819 ptr ++;
00820 }
00821 return retVal;
00822 }
00823
00824
00825 struct varlena *
00826 getAttrEntrySetLargefromContext(mcatContextDesc cd)
00827 {
00828
00829
00830
00831 int resLen = SIZEOF32;
00832 int i, status;
00833 char *ptr;
00834 struct varlena *retVal;
00835 #if defined(PORTNAME_c90)
00836 struct int32Array *iptr;
00837 #endif
00838
00839 resLen = 0;
00840 for (i = 0; i < svrMcatContext[cd].max_attr_entries ; i++) {
00841 resLen += SIZEOF32;
00842 resLen += (strlen(svrMcatContext[cd].attr_info[i].schema_name) + 1);
00843 resLen += (strlen(svrMcatContext[cd].attr_info[i].ext_attr_name) + 1);
00844 resLen += (strlen(svrMcatContext[cd].attr_info[i].attr_data_type) + 1);
00845 resLen += (strlen(svrMcatContext[cd].attr_info[i].presentation) + 1);
00846 resLen += (strlen(svrMcatContext[cd].attr_info[i].attr_dimension) + 1);
00847 resLen += (strlen(svrMcatContext[cd].attr_info[i].default_value) + 1);
00848
00849 }
00850
00851 retVal = (struct varlena *)malloc(VAROUTHDRSZ + resLen);
00852 VARSIZE(retVal) = resLen + VAROUTHDRSZ;
00853 VAROUTSTAT(retVal) = 0;
00854 ptr = VAROUTDATA(retVal);
00855 #if defined(PORTNAME_c90)
00856 iptr = (struct int32Array *) VAROUTDATA(retVal);
00857 #endif
00858
00859
00860 ptr = VARDATA(retVal);
00861
00862 #if defined(PORTNAME_c90)
00863 iptr->myInt0 = htonl (svrMcatContext[cd].max_attr_entries);
00864 ptr += SIZEOF32;
00865 #else
00866 *(int32 *) ptr = htonl (svrMcatContext[cd].max_attr_entries);
00867 ptr += SIZEOF32;
00868 #endif
00869
00870
00871
00872 for (i = 0; i < svrMcatContext[cd].max_attr_entries ; i = i + 2) {
00873 #if defined(PORTNAME_c90)
00874 iptr->myInt1 = htonl (svrMcatContext[cd].attr_info[i].attr_id);
00875 ptr += SIZEOF32;
00876 iptr = (struct int32Array *) ptr;
00877 if (i+1 < svrMcatContext[cd].max_attr_entries)
00878 {
00879 iptr->myInt0 = htonl (svrMcatContext[cd].attr_info[i+1].attr_id);
00880 ptr += SIZEOF32;
00881 }
00882 #else
00883 *(int32 *) ptr = htonl (svrMcatContext[cd].attr_info[i].attr_id);
00884 ptr += sizeof (int32);
00885 if (i+1 < svrMcatContext[cd].max_attr_entries)
00886 {
00887 *(int32 *) ptr = htonl (svrMcatContext[cd].attr_info[i+1].attr_id);
00888 ptr += sizeof (int32);
00889 }
00890 #endif
00891 }
00892
00893
00894 for (i = 0; i < svrMcatContext[cd].max_attr_entries ; i++) {
00895 strcpy (ptr, svrMcatContext[cd].attr_info[i].schema_name);
00896 ptr += strlen(svrMcatContext[cd].attr_info[i].schema_name);
00897 *ptr = '\0';
00898 ptr ++;
00899 strcpy (ptr, svrMcatContext[cd].attr_info[i].ext_attr_name);
00900 ptr += strlen(svrMcatContext[cd].attr_info[i].ext_attr_name);
00901 *ptr = '\0';
00902 ptr ++;
00903 strcpy (ptr, svrMcatContext[cd].attr_info[i].attr_data_type);
00904 ptr += strlen(svrMcatContext[cd].attr_info[i].attr_data_type);
00905 *ptr = '\0';
00906 ptr ++;
00907 strcpy (ptr, svrMcatContext[cd].attr_info[i].presentation);
00908 ptr += strlen(svrMcatContext[cd].attr_info[i].presentation);
00909 *ptr = '\0';
00910 ptr ++;
00911 strcpy (ptr, svrMcatContext[cd].attr_info[i].attr_dimension);
00912 ptr += strlen(svrMcatContext[cd].attr_info[i].attr_dimension);
00913 *ptr = '\0';
00914 ptr ++;
00915 strcpy (ptr, svrMcatContext[cd].attr_info[i].default_value);
00916 ptr += strlen(svrMcatContext[cd].attr_info[i].default_value);
00917 *ptr = '\0';
00918 ptr ++;
00919 }
00920 return retVal;
00921 }
00922
00923 int
00924 updateInSchemaByUser(int cd,
00925 int *attrId,
00926 char **attrValue,
00927 int attrCnt,
00928 int *qattrval,
00929 char **qval,
00930 int qcount,
00931 char *userName, char *userDomain)
00932 {
00933 int i, user_id;
00934
00935 user_id = get_user_id_in_domain(userName, userDomain);
00936 if (user_id < 0) { return (USER_NOT_IN_DOMN);}
00937 i = updateInSchema(cd, attrId, attrValue, attrCnt,
00938 qattrval, qval, qcount, user_id);
00939 return(i);
00940 }
00941
00942
00943 int
00944 updateInSchema(int cd,
00945 int *attrId,
00946 char **attrValue,
00947 int attrCnt,
00948 int *qattrval,
00949 char **qval,
00950 int qcount,
00951 int userId)
00952 {
00953 return(OPERATION_NOT_IMPLEMENTED);
00954 }
00955
00956 int deleteFromClusterByUser(int cd,
00957 char *clusterName,
00958 int *qattrval,
00959 char **qval,
00960 int qcount,
00961 char *userName, char *userDomain, char *delDimen[])
00962 {
00963 int i, user_id;
00964
00965 user_id = get_user_id_in_domain(userName, userDomain);
00966 if (user_id < 0) { return (USER_NOT_IN_DOMN);}
00967 i = deleteFromCluster(cd, clusterName,
00968 qattrval, qval, qcount, user_id,delDimen);
00969 return(i);
00970 }
00971 int deleteFromCluster(int cd,
00972 char *clusterName,
00973 int *qattrval,
00974 char **qval,
00975 int qcount,
00976 int userId,
00977 char *delDimen[])
00978 {
00979 return(OPERATION_NOT_IMPLEMENTED);
00980 }
00981 int
00982 updateAttrValueByUser(int cd, char *userName, char *userDomain,
00983 int *attr_id,
00984 char **attr_value,
00985 int attr_cnt,
00986 char *updDimen[])
00987 {
00988 int i, user_id;
00989
00990 user_id = get_user_id_in_domain(userName, userDomain);
00991 if (user_id < 0) { return (USER_NOT_IN_DOMN);}
00992 i = updateAttrValue(cd,
00993 attr_id, attr_value, attr_cnt, user_id,updDimen);
00994 return(i);
00995 }
00996
00997 int
00998 updateAttrValue(int cd,
00999 int *attr_id,
01000 char **attr_value,
01001 int attr_cnt, int real_user_id,
01002 char *updDimen[])
01003 {
01004 int i,ii,j,k;
01005 char **attr_name;
01006 char **table_name;
01007 int *in_rsrcid;
01008 int tabcnt;
01009 int tabflag;
01010 char qs[HUGE_STRING];
01011 char *iisAttrVal[MAX_QUERY_LIMIT];
01012
01013 strcpy(qs,"");
01014
01015
01016 attr_name = malloc(sizeof(char *) * attr_cnt);
01017 table_name = malloc(sizeof(char *) * attr_cnt);
01018 in_rsrcid = malloc(sizeof(int) * attr_cnt);
01019
01020 i = checkAccessMetaDataAttr(real_user_id, attr_id,attr_cnt);
01021 if (i != 0) { free( in_rsrcid ); return(i); }
01022 tabcnt = 0;
01023 for (i = 0; i < attr_cnt; i++) {
01024 for (j = 0; j < svrMcatContext[cd].max_attr_entries; j++) {
01025 if (svrMcatContext[cd].attr_info[j].attr_id == attr_id[i])
01026 { attr_name[i] = svrMcatContext[cd].attr_info[j].attr_name;
01027 tabflag = 0;
01028 for (k = 0 ; k < tabcnt; k++) {
01029 if (table_name[k] == svrMcatContext[cd].attr_info[j].extended_table_name)
01030 { tabflag = 1; break;}
01031 }
01032 if (tabflag == 0) {
01033 table_name[tabcnt] = svrMcatContext[cd].attr_info[j].extended_table_name;
01034 in_rsrcid[tabcnt] = svrMcatContext[cd].attr_info[j].rsrc_id;
01035 tabcnt++;
01036 }
01037 break;
01038 }
01039 }
01040 }
01041 if(debugging4) {
01042 printf("Calling convert_to_updatesql\n"); fflush(stdout);
01043 }
01044
01045
01046 for ( i = 0; i < attr_cnt; i++) {
01047 iisAttrVal[i] = malloc(sizeof(char) * (strlen(attr_value[i])*4 +3));
01048 if (iisAttrVal[i] == NULL) { free( in_rsrcid ); return(MEMORY_ALLOCATION_ERROR); }
01049 strcpy(iisAttrVal[i],attr_value[i]);
01050 }
01051 ii = castDimension(cd, updDimen, iisAttrVal, attr_id, attr_cnt);
01052 if (ii < 0) {
01053 for (i = 0;i <attr_cnt; i++) free(iisAttrVal[i]);
01054 free( in_rsrcid );
01055 return(ii);
01056 }
01057 ii = convert_to_updatesql(cd, tabcnt, table_name, in_rsrcid,
01058 attr_id, iisAttrVal, attr_cnt, qs);
01059 strcpy(GENERATEDSQL,qs);
01060 if (ii < 0) {
01061 for (i = 0;i <attr_cnt; i++) free(iisAttrVal[i]);
01062 return (ii);
01063 }
01064 i = ExecSqlDb(henv, hdbc, qs);
01065
01066 if (i < 0) {
01067 strcpy(GENERATEDSQL,qs);
01068 return(i);
01069 }
01070 return(0);
01071 }
01072
01073 int
01074 insertIntoSchemaByUser(int cd, char *userName, char *userDomain,
01075 int *attr_id,
01076 char **attr_value,
01077 int attr_cnt,
01078 char *insDimen[])
01079 {
01080 int i, user_id;
01081
01082 user_id = get_user_id_in_domain(userName, userDomain);
01083 if (user_id < 0) { return (USER_NOT_IN_DOMN);}
01084 i = insertIntoSchema(cd,
01085 attr_id, attr_value, attr_cnt, user_id,insDimen);
01086 return(i);
01087 }
01088
01089 int
01090 insertIntoSchema(int cd,
01091 int *attr_id,
01092 char **attr_value,
01093 int attr_cnt, int real_user_id,
01094 char *insDimen[])
01095 {
01096 int i,ii,j,k;
01097 char **attr_name;
01098 char **table_name;
01099 int *in_rsrcid;
01100 int tabcnt;
01101 int tabflag;
01102 int qsptr, query_stringptr;
01103 char query_string[HUGE_STRING];
01104 char qs[HUGE_STRING];
01105 char *iisAttrVal[MAX_QUERY_LIMIT];
01106 strcpy(query_string,"");
01107
01108
01109 attr_name = malloc(sizeof(char *) * attr_cnt);
01110 table_name = malloc(sizeof(char *) * attr_cnt);
01111 in_rsrcid = malloc(sizeof(int) * attr_cnt);
01112
01113 i = checkAccessMetaDataAttr(real_user_id, attr_id,attr_cnt);
01114 if (i != 0) {
01115 free( in_rsrcid ); return(i);
01116 }
01117
01118 tabcnt = 0;
01119
01120 for (i = 0; i < attr_cnt; i++) {
01121 for (j = 0; j < svrMcatContext[cd].max_attr_entries; j++) {
01122 if (svrMcatContext[cd].attr_info[j].attr_id == attr_id[i]) {
01123
01124 tabflag = 0;
01125 attr_name[i] = svrMcatContext[cd].attr_info[j].attr_name;
01126
01127 for (k = 0 ; k < tabcnt; k++) {
01128 if (table_name[k] == svrMcatContext[cd].attr_info[j].extended_table_name) {
01129 tabflag = 1;
01130 break;
01131 }
01132 }
01133
01134 if (tabflag == 0) {
01135 table_name[tabcnt] = svrMcatContext[cd].attr_info[j].extended_table_name;
01136 in_rsrcid[tabcnt] = svrMcatContext[cd].attr_info[j].rsrc_id;
01137 tabcnt++;
01138 }
01139
01140 break;
01141 }
01142 }
01143 }
01144
01145 if(debugging4)
01146 printf("Calling convert_to_insertsql\n"); fflush(stdout);
01147
01148 for ( i = 0; i < attr_cnt; i++) {
01149 iisAttrVal[i] = malloc(sizeof(char) * (strlen(attr_value[i])*4 +3));
01150 if (iisAttrVal[i] == NULL) { free( in_rsrcid ); return(MEMORY_ALLOCATION_ERROR); }
01151 strcpy(iisAttrVal[i],attr_value[i]);
01152 }
01153 ii = castDimension(cd, insDimen, iisAttrVal, attr_id, attr_cnt);
01154 if (ii < 0) {
01155 for (i = 0;i <attr_cnt; i++) free(iisAttrVal[i]);
01156 free( in_rsrcid );
01157 return(ii);
01158 }
01159
01160 ii = convert_to_insertsql(cd, tabcnt, table_name, in_rsrcid, attr_id,
01161 iisAttrVal, attr_cnt, query_string);
01162 strcpy(GENERATEDSQL,query_string);
01163 if (ii < 0) {
01164 for (i = 0;i <attr_cnt; i++) free(iisAttrVal[i]);
01165 return(ii);
01166 }
01167
01168 qsptr = 0;
01169 query_stringptr = 0;
01170 while (query_string[query_stringptr] != '\n'
01171 && query_stringptr < strlen(query_string)) {
01172 qs[qsptr] = query_string[query_stringptr];
01173 qsptr++;
01174 query_stringptr++;
01175 }
01176 qs[qsptr] = '\0';
01177 if (query_string[query_stringptr] == '\n') query_stringptr++;
01178 while (strlen(qs) > 0) {
01179 i = ExecSqlDb(henv, hdbc, qs);
01180 if (i < 0) {
01181 strcpy(GENERATEDSQL,qs);
01182 return(i);
01183 }
01184 qsptr = 0;
01185 while (query_string[query_stringptr] != '\n'
01186 && query_stringptr < strlen(query_string)) {
01187 qs[qsptr] = query_string[query_stringptr];
01188 qsptr++;
01189 query_stringptr++;
01190 }
01191 qs[qsptr] = '\0';
01192 if (query_string[query_stringptr] == '\n') query_stringptr++;
01193 }
01194 return(0);
01195 }
01196
01197
01198
01199
01200 const char* buildPhyiscalTableQuery( char **attr_name,
01201 char **attr_val,
01202 char *dbschema_name,
01203 char *table_name,
01204 int attr_count ) {
01205 std::string sqlq = "insert into " +
01206 string(dbschema_name) +
01207 string(table_name) +
01208 string(" ( ") +
01209 string( attr_name[0] );
01210
01211 for( i = 1; i < attr_count; i++ ) {
01212 sqlq += ", ";
01213 sqlq += string( attr_name[i] );
01214 }
01215
01216 sqlq += " ) values ( ";
01217 sqlq += string( attr_val[0] );
01218
01219 for( i = 1; i < attr_count; i++ ) {
01220 sqlq += ", ";
01221 sqlq += string( attr_val[i] );
01222 }
01223
01224 sqlq += ")";
01225
01226
01227 char* ret = new char[ sqlq.len()+1 ];
01228 strncpy( ret, sqlq.c_str(), sqlq.len() );
01229 ret[ sqlq.len() +1 ] = '\0';
01230
01231 return ret;
01232
01233 }
01234
01235
01236
01237 insertIntoPhysicalTable(char **attr_name,
01238 char **attr_val,
01239 char *dbschema_name,
01240 char *table_name,
01241 int attr_count)
01242 {
01243 #if 0 // JMC cppcheck - src & dest sprintf
01244 char sqlq[HUGE_STRING];
01245 int i;
01246
01247 sprintf(sqlq, "insert into %s%s (",dbschema_name, table_name);
01248 sprintf(sqlq, "%s %s", sqlq, attr_name[0]);
01249
01250 for (i = 1; i < attr_count; i++)
01251 {
01252 sprintf(sqlq, "%s , %s", sqlq, attr_name[i]);
01253 }
01254 sprintf(sqlq, "%s ) values (", sqlq);
01255 sprintf(sqlq, "%s %s", sqlq, attr_val[0]);
01256 for (i = 1; i < attr_count; i++)
01257 {
01258 sprintf(sqlq, "%s , %s", sqlq, attr_val[i]);
01259 }
01260 sprintf(sqlq, "%s )", sqlq);
01261 #else
01262 const char* sqlq = buildPhyiscalTableQuery( attr_name, attr_val, dbschema_name, table_name, attr_count );
01263 #endif
01264 i = ExecSqlDb(henv, hdbc, sqlq);
01265 if (i != 0)
01266 {
01267 sprintf(errmess,"Data Insertion Error: %s",sqlq);
01268 error_exit(errmess);
01269 failure = METADATA_INSERTION_ERROR;
01270 return(METADATA_INSERTION_ERROR);
01271 }
01272
01273 delete sqlq;
01274 return(RCAT_SUCCESS);
01275 }
01276 insertIntoPhysicalTableDontCare(char **attr_name,
01277 char **attr_val,
01278 char *dbschema_name,
01279 char *table_name,
01280 int attr_count)
01281 {
01282 #if 0 // JMC cppcheck - src & dest sprintf
01283 char sqlq[HUGE_STRING];
01284 int i;
01285
01286 sprintf(sqlq, "insert into %s%s (",dbschema_name, table_name);
01287 sprintf(sqlq, "%s %s", sqlq, attr_name[0]);
01288 for (i = 1; i < attr_count; i++)
01289 {
01290 sprintf(sqlq, "%s , %s", sqlq, attr_name[i]);
01291 }
01292 sprintf(sqlq, "%s ) values (", sqlq);
01293 sprintf(sqlq, "%s %s", sqlq, attr_val[0]);
01294 for (i = 1; i < attr_count; i++)
01295 {
01296 sprintf(sqlq, "%s , %s", sqlq, attr_val[i]);
01297 }
01298 sprintf(sqlq, "%s )", sqlq);
01299 #else
01300 const char* sqlq = buildPhyiscalTableQuery( attr_name, attr_val, dbschema_name, table_name, attr_count );
01301 #endif
01302 i = ExecSqlDb(henv, hdbc, sqlq);
01303 if (i != 0)
01304 {
01305 return(METADATA_INSERTION_ERROR);
01306 }
01307 delete sqlq;
01308 return(RCAT_SUCCESS);
01309 }
01310
01311
01312
01313 const char* buildDeleteFRomPhysicalTableQuery( char **attr_name,
01314 char **attr_val,
01315 char *dbschema_name,
01316 char *table_name,
01317 int attr_count ) {
01318 string sqlq = "delete from "+string( dbschema_name ) + string( table_name );
01319 for( i = 0; i < attr_count; i++ ) {
01320 if (i > 0) {
01321 sqlq += string( " AND " ) +
01322 string( attr_name[i] ) +
01323 string( " = " ) +
01324 string( attr_val[i] );
01325 } else {
01326 sqlq += " WHERE " + string( attr_name[i] ) + string( " = " ) + string ( attr_val[i] );
01327 }
01328 }
01329 }
01330
01331
01332
01333 int deleteFromPhysicalTable(char **attr_name,
01334 char **attr_val,
01335 char *dbschema_name,
01336 char *table_name,
01337 int attr_count)
01338 {
01339 #if 0
01340 char sqlq[HUGE_STRING];
01341 int i;
01342
01343 sprintf(sqlq, "delete from %s%s ",dbschema_name, table_name);
01344 for (i = 0; i < attr_count; i++)
01345 {
01346 if (i > 0){
01347 sprintf(sqlq, "%s AND %s = %s", sqlq,attr_name[i], attr_val[i]);
01348 }
01349 else {
01350 sprintf(sqlq, "%s WHERE %s = %s",sqlq, attr_name[i],attr_val[i]);
01351 }
01352 }
01353 #else
01354 const char* sqlq = buildDeleteFRomPhysicalTableQuery( attr_name, attr_val, dbschema_name, table_name, attr_count );
01355 #endif
01356
01357 i = ExecSqlDb(henv, hdbc, sqlq);
01358 if (i != 0)
01359 {
01360 sprintf(errmess,"Data Deletion Error: %s",sqlq);
01361 error_exit(errmess);
01362 failure = METADATA_DELETION_ERROR;
01363 return(METADATA_DELETION_ERROR);
01364 }
01365 return(RCAT_SUCCESS);
01366 }
01367 int deleteFromPhysicalTableDontCare(char **attr_name,
01368 char **attr_val,
01369 char *dbschema_name,
01370 char *table_name,
01371 int attr_count)
01372 {
01373 #if 0
01374 char sqlq[HUGE_STRING];
01375 int i;
01376
01377 sprintf(sqlq, "delete from %s%s ",dbschema_name, table_name);
01378 for (i = 0; i < attr_count; i++)
01379 {
01380 if (i > 0){
01381 sprintf(sqlq, "%s AND %s = %s", sqlq,attr_name[i], attr_val[i]);
01382 }
01383 else {
01384 sprintf(sqlq, "%s WHERE %s = %s",sqlq, attr_name[i],attr_val[i]);
01385 }
01386 }
01387 #else
01388 const char* sqlq = buildDeleteFRomPhysicalTableQuery( attr_name, attr_val, dbschema_name, table_name, attr_count );
01389 #endif
01390 i = ExecSqlDb(henv, hdbc, sqlq);
01391 if (i != 0)
01392 {
01393 return(METADATA_DELETION_ERROR);
01394 }
01395 return(RCAT_SUCCESS);
01396 }
01397
01398 int changeAttrValueInPhysicalTable(char **attr_name,
01399 char **attr_val,
01400 char *dbschema_name,
01401 char *table_name,
01402 int attr_count)
01403 {
01404
01405 sprintf(sqlq, "update %s%s set %s = %s ",dbschema_name, table_name,
01406 attr_name[0], attr_val[0]);
01407 for (i = 1; i < attr_count; i++)
01408 {
01409 if (i > 1) {
01410 sprintf(sqlq, "%s AND %s = %s", sqlq, attr_name[i], attr_val[i]);
01411 }
01412 else {
01413 sprintf(sqlq, "%s WHERE %s = %s",sqlq, attr_name[i], attr_val[i]);
01414 }
01415 }
01416 i = ExecSqlDb(henv, hdbc, sqlq);
01417 if (i != 0)
01418 {
01419 sprintf(errmess,"Data Update Error: %s",sqlq);
01420 error_exit(errmess);
01421 failure = METADATA_UPDATE_ERROR;
01422 return(METADATA_UPDATE_ERROR);
01423 }
01424 return(RCAT_SUCCESS);
01425 }
01426
01427 int changeAttrValueInPhysicalTableDontCare(char **attr_name,
01428 char **attr_val,
01429 char *dbschema_name,
01430 char *table_name,
01431 int attr_count)
01432 {
01433
01434 sprintf(sqlq, "update %s%s set %s = %s ",dbschema_name, table_name,
01435 attr_name[0], attr_val[0]);
01436 for (i = 1; i < attr_count; i++)
01437 {
01438 if (i > 1) {
01439 sprintf(sqlq, "%s AND %s = %s", sqlq, attr_name[i], attr_val[i]);
01440 }
01441 else {
01442 sprintf(sqlq, "%s WHERE %s = %s",sqlq, attr_name[i], attr_val[i]);
01443 }
01444 }
01445 i = ExecSqlDb(henv, hdbc, sqlq);
01446 if (i != 0)
01447 {
01448 return(METADATA_UPDATE_ERROR);
01449 }
01450 return(RCAT_SUCCESS);
01451 }
01452
01453
01454
01455
01456
01457
01458
01459
01460 rcatC_sql_result_struct *
01461 queryMcatInfo( mcatContextDesc incd,
01462 int *selval, int *aggrval,
01463 int *qattrval, char **qval,
01464 int selcount, int qcount, int numrows,
01465 int OuterJoin, void *qDimen,void *selDimen
01466 )
01467 {
01468 int x;
01469 int i,j;
01470 rcatC_sql_query_struct* info1;
01471 char *in_dti;
01472 char *qMIqval[MAX_QUERY_LIMIT];
01473 rcatC_sql_result_struct* result1;
01474
01475 failure = 0;
01476 info1 = (rcatC_sql_query_struct *)
01477 malloc(sizeof(rcatC_sql_query_struct));
01478 if (info1 == NULL) {
01479 failure = MEMORY_ALLOCATION_ERROR;
01480 return(NULL);
01481 }
01482 result1 = (rcatC_sql_result_struct *)
01483 malloc(sizeof(rcatC_sql_result_struct));
01484 if (result1 == NULL) {
01485 free(info1);
01486 failure = MEMORY_ALLOCATION_ERROR;
01487 return(NULL);
01488 }
01489
01490 for ( i = 0; i < qcount; i++) {
01491 qMIqval[i] = malloc(sizeof(char) * ( strlen(qval[i]) *4 + 3));
01492 if (qMIqval[i] == NULL) {
01493 for ( j = 0; j < i ; j++) {
01494 free(qMIqval[j]);
01495 }
01496 free(info1);
01497 free(result1);
01498 failure = MEMORY_ALLOCATION_ERROR;
01499 return(NULL);
01500 }
01501 strcpy(qMIqval[i],qval[i]);
01502 }
01503
01504 i = translateArraysQToSqlQStruct(incd, selval,aggrval,
01505 qattrval, qMIqval,
01506 selcount, qcount, numrows,
01507 info1, result1, qDimen,selDimen);
01508 if (i != 0) {
01509 for ( j = 0; j < qcount; j++) {
01510 free(qMIqval[j]);
01511 }
01512 free(info1);
01513 free(result1);
01514 failure = i;
01515 return(NULL);
01516 }
01517 outer_join_flag = OuterJoin;
01518 rcatC_db_info_inquire(&serverhndl[0], (rcatC_infoh*) info1 ,
01519 (rcatC_infoh*) result1, status, numrows, incd);
01520 distinct_flag = 1; outer_join_flag = 0; best_response_flag = 0;
01521
01522
01523 for ( i = 0; i < qcount; i++) {
01524 free(qMIqval[i]);
01525 }
01526 if (status[2] != RCAT_SUCCESS)
01527 {
01528 #ifdef DEBUGON
01529 rodsLog(NOTICE, "Error in Inquire Status:%i\n",status[2]);
01530 rodsLog(NOTICE, "Failed SQL:%s\n",GENERATEDSQL);
01531 #endif
01532 free(info1);
01533 free(result1);
01534 failure = MCAT_INQUIRE_ERROR;
01535 return(NULL);
01536 }
01537 free(info1);
01538 return (result1);
01539 }
01540
01541 int queryMcatInfoArrays( mcatContextDesc incd,
01542 int *selval, int *aggrval,
01543 int *qattrval, char **qval,
01544 int selcount, int qcount, int numrows,
01545 int *colcount,int *rowcount,
01546 int **rattrval, char **resval, int **rattrvalsize,
01547 int *continuation_index, int OuterJoin,
01548 void *qDimen,void *selDimen)
01549 {
01550 int i,j;
01551 rcatC_sql_result_struct* result1;
01552
01553 result1 = queryMcatInfo(incd,selval,aggrval,qattrval,qval,
01554 selcount,qcount, numrows, OuterJoin,
01555 qDimen,selDimen);
01556 if (result1 == NULL) return(failure);
01557
01558 i = translateSqlRStructToArraysR(result1, colcount, rowcount,
01559 rattrval, resval, rattrvalsize,
01560 continuation_index);
01561
01562 free(result1);
01563 return (i);
01564 }
01565
01566 int
01567 findAttrIndexFromId(mcatContextDesc cd, int attr_id)
01568 {
01569 int ii;
01570 for (ii = 0; ii < svrMcatContext[cd].max_attr_entries ; ii++) {
01571 if (svrMcatContext[cd].attr_info[ii].attr_id == attr_id)
01572 return(ii);
01573 }
01574 printf("wrong id:%i\n",attr_id);
01575 return(UNKNOWN_ATTRIBUTE_ID);
01576 }
01577
01578 int
01579 getAttributesfromMcatContext(mcatContextDesc cd, int *counta,
01580 rcat_metadata_attr_entry **AttrEntries)
01581 {
01582
01583 int i,cnta;
01584
01585 cnta = getAttrCountinSchemaSet(svrMcatContext[cd].userContext, "known");
01586 if (cnta < 0) return (cnta);
01587 i = allocAttrEntrySet(AttrEntries, cnta);
01588 if (i < 0) return (i);
01589 i = getAttrEntrySet(svrMcatContext[cd].userContext,
01590 *AttrEntries, cnta, "known");
01591 if (i < 0) {
01592 freeAttrEntrySet(*AttrEntries, cnta);
01593 return (i);
01594 }
01595 *counta = cnta;
01596 return(RCAT_SUCCESS);
01597 }
01598
01599 mcatAttrPropSet *
01600 getAttrPropertiesfromMcat(mcatContextDesc cd)
01601 {
01602 mcatAttrPropSet *mAPS;
01603 mAPS = (mcatAttrPropSet *) malloc(sizeof(mcatAttrPropSet));
01604 mAPS->attr_info = svrMcatContext[cd].attr_info;
01605 mAPS->max_attr_entries = svrMcatContext[cd].max_attr_entries;
01606 return(mAPS);
01607 }
01608
01609 int
01610 checkforownershipofschema(char *schemaName, int realUserId)
01611 {
01612 int i, user_id;
01613 failure = 0;
01614
01615
01616 sprintf(sqlq, "select schema_name from %sRCORE_SCHEMAS where \
01617 schema_name = '%s' and user_id = %i",
01618 RCATSCHEMENAME, schemaName, realUserId);
01619 if (check_exists(sqlq) != 0) {
01620 if (debugging4) printf("ACTION_NOT_ALLOWED_FOR_USER:%s,%i\n",
01621 schemaName, realUserId);
01622 return (ACTION_NOT_ALLOWED_FOR_USER);
01623 }
01624 return(RCAT_SUCCESS);
01625
01626 }
01627
01628 int
01629 checkforuniqueschemaname(char *schemaName)
01630 {
01631 int i;
01632 failure = 0;
01633 sprintf(sqlq, "select schema_name from %sRCORE_SCHEMAS where \
01634 schema_name = '%s'",
01635 RCATSCHEMENAME, schemaName);
01636 if (check_exists(sqlq) != 0) return (UNKNOWN_SCHEMA_NAME);
01637 return(RCAT_SUCCESS);
01638
01639 }
01640
01641 unsigned long int
01642 getMaxSize(char *attrDataType)
01643 {
01644 int i = 0;
01645 int j;
01646 int k = 0;
01647 unsigned long int m = 1;
01648 unsigned long int n = 0;
01649 char numb[20];
01650 j = strlen(attrDataType);
01651 if (strstr(attrDataType,"int") != NULL) return (DEFAULT_INTEGER_SPACE_SIZE);
01652 if (strstr(attrDataType,"integer") != NULL) return (DEFAULT_INTEGER_SPACE_SIZE);
01653 if (strstr(attrDataType,"INT") != NULL) return (DEFAULT_INTEGER_SPACE_SIZE);
01654 if (strstr(attrDataType,"INTEGER") != NULL) return (DEFAULT_INTEGER_SPACE_SIZE);
01655 if (strstr(attrDataType,"float") != NULL) return (DEFAULT_FLOAT_SPACE_SIZE);
01656 if (strstr(attrDataType,"FLOAT") != NULL) return (DEFAULT_FLOAT_SPACE_SIZE);
01657 if (strstr(attrDataType,"date") != NULL) return (DEFAULT_DATE_SPACE_SIZE);
01658 if (strstr(attrDataType,"DATE") != NULL) return (DEFAULT_DATE_SPACE_SIZE);
01659
01660 if (!strcmp(RCATDBTYPE,"oracle")) {
01661 if ((strstr(attrDataType,"blob") != NULL) ||
01662 (strstr(attrDataType,"BLOB") != NULL)) {
01663 strcpy(attrDataType,"LONG RAW");
01664 return (DEFAULT_ORACLE_BLOB_SPACE_SIZE);
01665 }
01666 else if ((strstr(attrDataType,"clob") != NULL) ||
01667 (strstr(attrDataType,"CLOB") != NULL)) {
01668 strcpy(attrDataType,"LONG");
01669 return (DEFAULT_ORACLE_CLOB_SPACE_SIZE);
01670 }
01671 }
01672 while (i < j && attrDataType[i] != '(')
01673 i++;
01674 if (i == j) return (SIZE_OF_ATTRIBUTE_UNKNOWN);
01675 i++;
01676 while ( attrDataType[i] != ')'
01677 && attrDataType[i] != 'K'
01678 && attrDataType[i] != 'M'
01679 && attrDataType[i] != 'G') {
01680 if (attrDataType[i] < '0' || attrDataType[i] > '9')
01681 return (SIZE_OF_ATTRIBUTE_UNKNOWN);
01682 numb[k] = attrDataType[i];
01683 i++;
01684 k++;
01685 }
01686 if (k == 0) return (SIZE_OF_ATTRIBUTE_UNKNOWN);
01687 for (i = k-1; i >= 0; i --) {
01688 n = n + (m * (int) (numb[i] - '0'));
01689 m = m * 10;
01690 }
01691 if (attrDataType[i] == 'K') { n = n * 1024 ; }
01692 else if (attrDataType[i] == 'M') { n = n * 1024 * 1024 ; }
01693 else if (attrDataType[i] == 'G') { n = n * 1024 * 1024 * 1024 ; }
01694 return (n);
01695
01696 }
01697
01698
01699 int
01700 getAttrIdForName(char *attrName, char *schemaName)
01701 {
01702 int i,j,k, attrId;
01703 char mySchemaName[MAX_TOKEN];
01704 char myAttrName[MAX_TOKEN];
01705 char sqlq[HUGE_STRING];
01706 char *tmpStr;
01707
01708 if ((tmpStr = strstr(attrName, ".")) != NULL) {
01709 strcpy(mySchemaName, attrName);
01710 mySchemaName[ tmpStr - attrName ] = '\0';
01711 strcpy(myAttrName, (char *) (tmpStr + 1));
01712 }
01713 else {
01714 strcpy(mySchemaName, schemaName);
01715 strcpy(myAttrName,attrName);
01716 }
01717
01718 failure = 0;
01719 sprintf(sqlq, "select attr_id from %sRCORE_ATTRIBUTES t1, %sRCORE_TABLES t2 \
01720 where t1.external_attr_name = '%s' and t1.table_id = t2.table_id and \
01721 t2.schema_name = '%s' ",
01722 RCATSCHEMENAME,RCATSCHEMENAME, myAttrName, mySchemaName);
01723 attrId = get_itype_value_from_query(sqlq);
01724 return(attrId);
01725 }
01726
01727 int
01728 getAttrInfoForToken(char *attrName, char *schemaName,
01729 char *outAttrName, int *attrTokenId,
01730 int *tabTokenId, char *mySchemaName,
01731 char *attrDataType, unsigned long int *maxsize,
01732 char *outExterAttrName, int *expose,
01733 char *presentation, char *default_value,
01734 int *exter_attrib_id, char *attr_dimension)
01735 {
01736 int i,j,k, attrId;
01737 char myAttrName[MAX_TOKEN];
01738 char sqlq[HUGE_STRING];
01739 char cval[15][MAX_TOKEN];
01740 int colcount;
01741 char *tmpStr;
01742 char attrIdenType[SMALL_TOKEN];
01743
01744 if ((tmpStr = strstr(attrName, ".")) != NULL) {
01745 strcpy(mySchemaName, attrName);
01746 mySchemaName[ tmpStr - attrName ] = '\0';
01747 strcpy(myAttrName, (char *) (tmpStr + 1));
01748 }
01749 else {
01750 strcpy(mySchemaName, schemaName);
01751 strcpy(myAttrName,attrName);
01752 }
01753
01754
01755
01756 failure = 0;
01757 sprintf(sqlq, "select attr_val_type, attr_iden_type, attr_id from %sRCORE_ATTRIBUTES t1, %sRCORE_TABLES t2 \
01758 where t1.external_attr_name = '%s' and t1.table_id = t2.table_id and \
01759 t2.schema_name = '%s' ",
01760 RCATSCHEMENAME,RCATSCHEMENAME, myAttrName, mySchemaName);
01761 colcount = 3;
01762 i = get_row_from_query(cval, &colcount,sqlq);
01763
01764 if (i < 0) {
01765 strcpy(GENERATEDSQL,sqlq);
01766 return(INVALID_TOKEN_NAME);
01767 }
01768 strcpy(attrIdenType,cval[1]);
01769 if (!strcmp(attrIdenType,"SR") ||
01770 !strcmp(attrIdenType,"LS") ||
01771 !strcmp(attrIdenType,"HR") ||
01772 !strcmp(attrIdenType,"PR") ||
01773 !strcmp(attrIdenType,"UR") ||
01774 !strcmp(attrIdenType,"ST") ||
01775 !strcmp(attrIdenType,"LT") ||
01776 !strcmp(attrIdenType,"HT") ||
01777 !strcmp(attrIdenType,"UT") ) {
01778 attrId = atoi(cval[0]);
01779 }
01780 else {
01781 attrId = atoi(cval[2]);
01782 }
01783
01784 sprintf(sqlq, "select attr_name, table_id, attr_data_type, maxsize, \
01785 external_attr_name, expose, presentation, default_value, exter_attrib_id, \
01786 attr_dimension from %sRCORE_ATTRIBUTES t1 where \
01787 t1.attr_id = %i ", RCATSCHEMENAME, attrId);
01788 colcount = 10;
01789 i = get_row_from_query(cval, &colcount,sqlq);
01790 if (failure != 0 || i < 0) {
01791 strcpy(GENERATEDSQL,sqlq);
01792 return(INVALID_TOKEN_NAME);
01793 }
01794 strcpy(outAttrName,cval[0]);
01795 *tabTokenId = atoi(cval[1]);
01796 strcpy(attrDataType,cval[2]);
01797 *maxsize = strtoul(cval[3], (char **)NULL, 10);
01798 strcpy(outExterAttrName,cval[4]);
01799 *attrTokenId = attrId;
01800 *expose = atoi(cval[5]);
01801 strcpy(presentation,cval[6]);
01802 strcpy(default_value,cval[7]);
01803 *exter_attrib_id = atoi(cval[8]);
01804 strcpy(attr_dimension,cval[9]);
01805 return(RCAT_SUCCESS);
01806 }
01807
01808
01809
01810 int
01811 getNewAttrName(char *attrExterName, char *tableName,
01812 char *attrName)
01813 {
01814 int i,k;
01815 int j = 1;
01816 char newattrName[MAX_TOKEN];
01817 char *tmpSTr;
01818 char sqlq[HUGE_STRING];
01819
01820 strcpy(newattrName,attrExterName);
01821 if (strlen(attrExterName) < MAX_SQL_NAME_LIMIT) {
01822 for (i = 0; i < strlen(newattrName) ; i++) {
01823 if (attrExterName[i] == ' ') attrName[i] = '_';
01824 else attrName[i] = attrExterName[i];
01825 }
01826 attrName[i] = '\0';
01827 return(RCAT_SUCCESS);
01828 }
01829 for (i = 0, j = 0; i < strlen(newattrName) ; i++) {
01830 if (newattrName[i] == ' ' || newattrName[i] == '_' ) continue;
01831 newattrName[j] = newattrName[i];
01832 j++;
01833 }
01834 newattrName[j] = '\0';
01835 strncpy(attrName,newattrName,MAX_SQL_NAME_LIMIT);
01836 failure = 0;
01837 sprintf(sqlq, "select attr_name from %sRCORE_ATTRIBUTES t1, %sRCORE_TABLES t2 where \
01838 t1.attr_name = '%s' and t2.table_name = '%s' and t1.table_id = t2.table_id",
01839 RCATSCHEMENAME, RCATSCHEMENAME, attrName,tableName);
01840 while (check_exists(sqlq) == RCAT_SUCCESS) {
01841 if (strlen(attrName) < 1) return (UNABLE_TO_MAKE_UNIQUE_ATTRIBUTE_NAME);
01842 failure = 0;
01843 i = random() % strlen(attrName);
01844 strcpy((char *) &attrName[i], (char *) &attrName[i+1]);
01845 sprintf(sqlq, "select attr_name from %sRCORE_ATTRIBUTES t1, %sRCORE_TABLES t2 where \
01846 t1.attr_name = '%s' and t2.table_name = '%s' and t1.table_id = t2.table_id",
01847 RCATSCHEMENAME, RCATSCHEMENAME, attrName,tableName);
01848 }
01849 for (i = 0; i< strlen(attrName) ; i++) {
01850 if ((attrName[i] == '_' && attrName[i+ 1] == '_' )){
01851 strcpy((char *) &attrName[i], (char *) &attrName[i+ 1]);
01852 i++;
01853 }
01854 }
01855 return(RCAT_SUCCESS);
01856 }
01857 int
01858 getNewTableName(char *schemaName,
01859 char *attrIdenType,
01860 char *attrName,
01861 char *tableName)
01862 {
01863 int i,k;
01864 int j = 1;
01865 char newattrName[MAX_TOKEN];
01866 char *tmpStr, *tmpPtr;
01867 char sqlq[HUGE_STRING];
01868 strcpy(newattrName,attrName);
01869 tableName[0] = schemaName[0];
01870 k= strlen(schemaName);
01871
01872
01873 for (i = 1; (i < k && j < 4) ; i++) {
01874 if (schemaName[i] == '_' || schemaName[i] == ' ')
01875 tableName[j++] = schemaName[i+1];
01876 }
01877 if (j < 4) {
01878 strncpy(tableName, schemaName, 4);
01879 tableName[4] = '\0';
01880 j = strlen(tableName);
01881 }
01882 tableName[j] = '\0';
01883
01884 if (!strcmp(attrIdenType,"SR") ||
01885 !strcmp(attrIdenType,"LS") ||
01886 !strcmp(attrIdenType,"HR") ||
01887 !strcmp(attrIdenType,"PR") ||
01888 !strcmp(attrIdenType,"UR") ||
01889 !strcmp(attrIdenType,"ST") ||
01890 !strcmp(attrIdenType,"LT") ||
01891 !strcmp(attrIdenType,"HT") ||
01892 !strcmp(attrIdenType,"UT") )
01893 sprintf((char *) &tableName[j], "%s", "_TD_");
01894 else
01895 sprintf((char *) &tableName[j], "%s", "_AD_");
01896 j = j + 4;
01897
01898
01899
01900 if ((tmpStr = strstr(newattrName,"Name")) != NULL) {
01901 strcpy(tmpStr, (char *) (tmpStr + 4)); }
01902 if ((tmpStr = strstr(newattrName,"NAME")) != NULL) {
01903 strcpy(tmpStr, (char *) (tmpStr + 4)); }
01904 if ((tmpStr = strstr(newattrName,"type")) != NULL) {
01905 strcpy(tmpStr, (char *) (tmpStr + 4)); }
01906 if ((tmpStr = strstr(newattrName,"TYPE")) != NULL) {
01907 strcpy(tmpStr, (char *) (tmpStr + 4)); }
01908 if ((tmpStr = strstr(newattrName,"Identifier")) != NULL) {
01909 strcpy(tmpStr, (char *) (tmpStr + 10)); }
01910 if ((tmpStr = strstr(newattrName,"IDENTIFIER")) != NULL) {
01911 strcpy(tmpStr, (char *) (tmpStr + 10)); }
01912 if ((tmpStr = strstr(newattrName,"Id")) != NULL) {
01913 strcpy(tmpStr, (char *) (tmpStr + 2)); }
01914 if ((tmpStr = strstr(newattrName,"ID")) != NULL) {
01915 strcpy(tmpStr, (char *) (tmpStr + 2)); }
01916 for (i = 0; i< strlen(newattrName) ; i++) {
01917 if (newattrName[i] == ' ') newattrName[i] = '_';
01918 if ((newattrName[i] == '_' && newattrName[i+ 1] == '_' ) ||
01919 (newattrName[i] == '_' && newattrName[i+ 1] == ' ' )){
01920 strcpy((char *) &newattrName[i], (char *) &newattrName[i+ 1]);
01921 i++;
01922 }
01923 }
01924
01925
01926 if (strlen(newattrName) < 9)
01927 strcat(tableName, newattrName);
01928 else {
01929 if ((tmpStr = strstr(newattrName,"_")) != NULL) {
01930 strncat(tableName, newattrName, 4);
01931 strcat(tableName,"_");
01932 strncat(tableName, tmpStr, 3);
01933 }
01934 else {
01935 strncat(tableName, newattrName, 8);
01936 }
01937 }
01938
01939 while (tableName[strlen(tableName) - 1] == '_')
01940 tableName[strlen(tableName) - 1] = '\0';
01941
01942 failure = 0;
01943 sprintf(sqlq, "select table_name from %sRCORE_TABLES t1 where \
01944 t1.table_name = '%s' and t1.schema_name = '%s'",
01945 RCATSCHEMENAME, tableName, schemaName);
01946 while (check_exists(sqlq) == RCAT_SUCCESS) {
01947 if (strlen(tableName) < 1) return (UNABLE_TO_MAKE_UNIQUE_TABLE_NAME);
01948 failure = 0;
01949
01950 if (((tmpPtr = strstr(tableName, "_TD_")) != NULL) ||
01951 ((tmpPtr = strstr(tableName, "_TD_")) != NULL) ) {
01952 i = (random() % (strlen(tableName) -
01953 ((int)tmpPtr - (int)tableName +4))) +
01954 ((int)tmpPtr - (int)tableName +4);
01955 }
01956 else {
01957 i = random() % strlen(tableName);
01958 }
01959 strcpy((char *) &tableName[i], (char *) &tableName[i+1]);
01960 sprintf(sqlq, "select table_name from %sRCORE_TABLES t1 where \
01961 t1.table_name = '%s' and t1.schema_name = '%s'",
01962 RCATSCHEMENAME, tableName, schemaName);
01963 }
01964 for (i = 0; i< strlen(tableName) ; i++) {
01965 if ((tableName[i] == '_' && tableName[i+ 1] == '_' )){
01966 strcpy((char *) &tableName[i], (char *) &tableName[i+ 1]);
01967 i++;
01968 }
01969 }
01970
01971 return(RCAT_SUCCESS);
01972 }
01973 int
01974 insert_into_rcore_fk_relations(int attrcnt,
01975 int tabList[], int attrList[],
01976 char *funcIn, char *funcOut,
01977 char *relOp,
01978 char *schemaIn, char *schemaOut)
01979 {
01980
01981
01982
01983
01984 int res,i,j;
01985 int tabId;
01986 char sqlq[HUGH_HUGE_STRING];
01987 failure = 0;
01988 tabId = get_next_counter_value("TABLE_ID");
01989 if (failure != 0) {
01990 return (TABLE_ID_COUNTER_ERROR);
01991 }
01992 sprintf(sqlq,
01993 "insert into %s%s (", RCATSCHEMENAME,"RCORE_FK_RELATIONS");
01994 for (i = 0; i < MAX_FK_REL_PAIRS ; i++){
01995 sprintf(&sqlq[strlen(sqlq)],
01996 "table_id_in%i , attr_id_in%i ,table_id_out%i , attr_id_out%i , ",
01997 i+1, i+1, i+1, i+1);
01998 }
01999 strcat(sqlq," func_in, func_out, attr_rel_name, schema_name_in, schema_name_out ) values ( ");
02000 for (i = 0; i < attrcnt ; i++){
02001 sprintf(&sqlq[strlen(sqlq)], "%i, %i, %i, %i, ",
02002 tabList[2*i],attrList[2*i],
02003 tabList[(2*i)+1],attrList[(2*i)+1] );
02004 }
02005 for (i = attrcnt; i < MAX_FK_REL_PAIRS; i++) {
02006 sprintf(&sqlq[strlen(sqlq)], "-1, -1, -1, -1, ");
02007
02008 }
02009 sprintf(&sqlq[strlen(sqlq)], " '%s', '%s', '%s', '%s', '%s' )",
02010 funcIn, funcOut, relOp, schemaIn, schemaOut);
02011 res = ExecSqlDb(henv, hdbc, sqlq);
02012 if (res < 0) {
02013 strcpy(GENERATEDSQL,sqlq);
02014 return(FKREL_METADATA_INSERTION_ERROR);
02015 }
02016 else
02017 return(RCAT_SUCCESS);
02018 }
02019
02020
02021 int
02022 insert_into_rcore_tables(char *table_name, char *database_name,
02023 char *schema_name, char *cluster_name,
02024 char *dbschema_name,
02025 char *tablespace_name, int user_id,
02026 int rsrc_id, int repl_enum,
02027 char *subject, char *comments,
02028 char *constraints, int sameas)
02029 {
02030 int res;
02031 int tabId;
02032 char sqlq[HUGH_HUGE_STRING];
02033 failure = 0;
02034 tabId = get_next_counter_value("TABLE_ID");
02035 if (failure != 0) {
02036 return (TABLE_ID_COUNTER_ERROR);
02037 }
02038 sprintf(sqlq,
02039 "insert into %s%s (table_id,table_name,database_name,schema_name, \
02040 dbschema_name,tablespace_name,user_id,rsrc_id,repl_enum,subject,comments, \
02041 constraints,sameas, cluster_name) values (%i,'%s','%s','%s','%s','%s',%i,%i,%i,'%s','%s','%s',%i,'%s')", RCATSCHEMENAME,"RCORE_TABLES",
02042 tabId,table_name,database_name,schema_name,dbschema_name,
02043 tablespace_name,user_id,rsrc_id,repl_enum,subject,comments,
02044 constraints,sameas,cluster_name);
02045 res = ExecSqlDb(henv, hdbc, sqlq);
02046 if (res < 0) {
02047 strcpy(GENERATEDSQL,sqlq);
02048 return(TABLE_METADATA_INSERTION_ERROR);
02049 }
02050 else
02051 return(tabId);
02052 }
02053
02054 int
02055 insert_into_rcore_attributes(char *schema_name,
02056 int table_id, char *attr_name,
02057 char *attr_data_type, char *attr_iden_type,
02058 char *external_attr_name, char *default_value,
02059 int attr_val_type, int sameas,
02060 char *at_comments, char *presentation,
02061 int primary_key, int expose,
02062 int exter_attrib_id, int maxsize,
02063 char *attr_dimension)
02064 {
02065 int res;
02066 int attrId;
02067 char sqlq[HUGH_HUGE_STRING];
02068
02069
02070 if(debugging4) {
02071 printf("Entering insert_into_rcore_attributes\n"); fflush(stdout);
02072 }
02073
02074 failure = 0;
02075 attrId = get_next_counter_value("ATTRIBUTE_ID");
02076 if (failure != 0) {
02077 return (ATTRIBUTE_ID_COUNTER_ERROR);
02078 }
02079
02080 sprintf(sqlq,
02081 "insert into %s%s (attr_id, table_id,attr_name,attr_data_type, \
02082 attr_iden_type,external_attr_name,default_value,attr_val_type,sameas, \
02083 at_comments,presentation,primary_key,expose,exter_attrib_id,maxsize, attr_dimension) \
02084 values (%i,%i,'%s','%s','%s','%s','%s',%i,%i,'%s','%s',%i,%i,%i,%i,'%s')",
02085 RCATSCHEMENAME,"RCORE_ATTRIBUTES",
02086 attrId, table_id,attr_name,attr_data_type, attr_iden_type,
02087 external_attr_name,default_value,attr_val_type,sameas,
02088 at_comments,presentation,primary_key,expose,exter_attrib_id,maxsize,
02089 attr_dimension);
02090 if(debugging4) {
02091 printf("Insert Statement:%s\n",sqlq); fflush(stdout);
02092 }
02093
02094 res = ExecSqlDb(henv, hdbc, sqlq);
02095 if (res < 0) {
02096 strcpy(GENERATEDSQL,sqlq);
02097 return(ATTRIBUTE_METADATA_INSERTION_ERROR);
02098 }
02099 sprintf(sqlq,
02100 "insert into %s%s (user_schema_name,attr_id,expose) values ('%s',%i,%i)",
02101 RCATSCHEMENAME,"RCORE_USCHEMA_ATTR",
02102 schema_name, attrId,expose);
02103 res = ExecSqlDb(henv, hdbc, sqlq);
02104 if (res < 0) {
02105 strcpy(GENERATEDSQL,sqlq);
02106 return(ATTRIBUTE_METADATA_INSERTION_ERROR);
02107 }
02108 return(attrId);
02109 }
02110 int
02111 createNewTable(int numattrs, char *tableName,
02112 char *Lattrnames[], char *Lattrdatatypes[],
02113 char *otherString, char *database_name,
02114 char *dbschema_name, char *tablespace_name,
02115 int user_id, int rsrc_id)
02116 {
02117 int i,j;
02118 char sqlq[HUGH_HUGE_STRING];
02119 char tmpStr[MAX_TOKEN];
02120 if (!strcmp(database_name,RCATDBNAME) &&
02121 !strcmp(dbschema_name,RCATSCHEMENAME) &&
02122 !strcmp(tablespace_name,RCATTABLESPACENAME) &&
02123 user_id == MCATUSERID &&
02124 rsrc_id == RCATRESOURCEID) {
02125 sprintf(sqlq, "create table %s%s ( ", dbschema_name,tableName);
02126 for (i = 0; i < numattrs ; i++) {
02127 if (i != 0)
02128 sprintf(tmpStr, ", %s %s ", Lattrnames[i],Lattrdatatypes[i]);
02129 else
02130 sprintf(tmpStr, " %s %s ", Lattrnames[i],Lattrdatatypes[i]);
02131 strcat(sqlq,tmpStr);
02132 }
02133 if (strlen(otherString) > 0) {
02134 strcat(sqlq,", ");
02135 strcat(sqlq,otherString);
02136 }
02137 strcat(sqlq," ) ");
02138 if (strlen(tablespace_name) > 0) {
02139 strcat(sqlq," tablespace ");
02140 strcat(sqlq,tablespace_name);
02141 }
02142
02143 res = ExecSqlDb(henv, hdbc, sqlq);
02144 if (res < 0) {
02145 strcpy(GENERATEDSQL, sqlq);
02146 return(MCAT_TABLE_CREATION_ERROR);
02147 }
02148 else return(RCAT_SUCCESS);
02149 }
02150 else {
02151 return (INSERT_INTO_NONLOCAL_MCAT_DATABASE);
02152 }
02153 }
02154
02155
02156 int
02157 addTokenAttrInSchemaByUser(char *schemaName, int attrCount,
02158 char *attrExtrName[], char *attrDataType[],
02159 char *attrIdenType[], char *defaultVal[],
02160 char *attrComments[], char *attrPresentation[],
02161 char *subjects, char *constraints,
02162 char *user, char *domain,char *attrDimension[])
02163 {
02164 int user_id;
02165
02166 user_id = get_user_id_in_domain(user, domain);
02167 if (user_id < 0) { return (USER_NOT_IN_DOMN);}
02168 return(addTokenAttrInSchema(schemaName,attrCount,attrExtrName,
02169 attrDataType,attrIdenType,defaultVal,
02170 attrComments,attrPresentation,subjects,
02171 constraints, user_id,attrDimension));
02172
02173 }
02174
02175 int
02176 addTokenAttrInSchema(char *schemaName, int attrCount,
02177 char *attrExtrName[], char *attrDataType[],
02178 char *attrIdenType[], char *defaultVal[],
02179 char *attrComments[], char *attrPresentation[],
02180 char *subjects, char *constraints,
02181 int realUserId,char *attrDimension[])
02182 {
02183 int i,j, k, tabid,attrid1,attrid2, startk, tokenId, user_id;
02184 unsigned long int maxsize;
02185 int numattrs = 1;
02186 char *attrName[MAX_TABLE_COLS];
02187 char *LocattrDataType[MAX_TABLE_COLS];
02188 char tableName[MAX_TOKEN];
02189 char idAttrDataType[MAX_TOKEN], idAttrIdenType[MAX_TOKEN];
02190
02191
02192 i = checkforuniqueschemaname(schemaName) ;
02193 if (i != 0) return (i);
02194
02195 i = checkforownershipofschema(schemaName,realUserId);
02196 if (i != 0) return (i);
02197
02198
02199 i = getNewTableName(schemaName,attrIdenType[0],
02200 attrExtrName[0], tableName);
02201 if (i < 0) return(i);
02202
02203 tabid = insert_into_rcore_tables(tableName, RCATDBNAME, schemaName,
02204 attrExtrName[0],
02205 RCATSCHEMENAME, RCATTABLESPACENAME,
02206 MCATUSERID , RCATRESOURCEID,
02207 0, subjects,attrComments[0], constraints,0);
02208 if (tabid < 0) return(tabid);
02209
02210 startk = 0;
02211
02212 if (!strcmp(attrIdenType[0],"SR") ||
02213 !strcmp(attrIdenType[0],"LS") ||
02214 !strcmp(attrIdenType[0],"UR")) {
02215 strcpy(idAttrIdenType,"ST");
02216 maxsize = DEFAULT_INTEGER_SPACE_SIZE;
02217 strcpy(idAttrDataType, "int");
02218 }
02219 else if (!strcmp(attrIdenType[0],"HR")){
02220 strcpy(idAttrIdenType,"HT");
02221 maxsize = DEFAULT_TOKEN_ID_MAXSIZE;
02222 sprintf(idAttrDataType, "char(%i)", DEFAULT_TOKEN_ID_MAXSIZE);
02223 }
02224 else {
02225 return (TOKEN_IDEN_TYPE_ERROR);
02226 }
02227 attrName[0] = (char *)malloc(sizeof(char) * MAX_TOKEN);
02228 if (attrName[0] == NULL) return (MEMORY_ALLOCATION_ERROR);
02229 startk = 1;
02230 i = getNewAttrName(attrExtrName[0], tableName, attrName[0]);
02231 if (i < 0) {
02232 free(attrName[0]);
02233 return(i);
02234 }
02235 if (strlen(attrName[0]) < (MAX_SQL_NAME_LIMIT - 4))
02236 strcat(attrName[0], "_mid");
02237 else
02238 strcat( (char *) (&attrName[0] + MAX_SQL_NAME_LIMIT - 4), "_mid");
02239 tokenId = insert_into_rcore_attributes(schemaName,tabid,attrName[0],
02240 idAttrDataType,
02241 idAttrIdenType, attrName[0],
02242 "",
02243 -1,-1,"MCAT created token identifier",
02244 "",
02245 1, 0,-1, maxsize,"");
02246
02247 if (tokenId < 0) {
02248 free(attrName[0]);
02249 return(tokenId);
02250 }
02251 strcat (idAttrDataType, " not null ");
02252 LocattrDataType[0] = idAttrDataType;
02253
02254
02255
02256
02257 for (k = 0; k < attrCount ; k++) {
02258 maxsize = getMaxSize(attrDataType[k]);
02259 if (maxsize < 0) {
02260 for (i = 0; i <= (k+startk); i++) {
02261 free(attrName[i]);
02262 }
02263 return(maxsize);
02264 }
02265 attrName[k+startk] = (char *)malloc(sizeof(char) * MAX_TOKEN);
02266 if (attrName[k+startk] == NULL) return (MEMORY_ALLOCATION_ERROR);
02267 LocattrDataType[k+startk] = attrDataType[k];
02268 j = getNewAttrName(attrExtrName[k], tableName, attrName[k+startk]);
02269 if (i < 0) {
02270 for (i = 0; i <= (k+startk); i++) {
02271 free(attrName[i]);
02272 }
02273 return(j);
02274 }
02275 attrid1 = insert_into_rcore_attributes(schemaName,tabid,attrName[k+startk],
02276 attrDataType[k],
02277 attrIdenType[k], attrExtrName[k],
02278 defaultVal[k],
02279 tokenId,-1,attrComments[k],
02280 attrPresentation[k],
02281 0, 1,-1, maxsize,attrDimension[k]);
02282
02283 if (attrid1 < 0) {
02284 for (i = 0; i <= (k+startk); i++) {
02285 free(attrName[i]);
02286 }
02287 return(attrid1);
02288 }
02289 }
02290 i = createNewTable(attrCount+startk, tableName, attrName,
02291 LocattrDataType, "",
02292 RCATDBNAME, RCATSCHEMENAME,
02293 RCATTABLESPACENAME,MCATUSERID , RCATRESOURCEID);
02294 for (k = 0; k < (attrCount+startk) ; k++) {
02295 free(attrName[k]);
02296 }
02297 return (i);
02298
02299 }
02300
02301 int
02302 registerLinkInSchemaByUser(char *schemaName, char *clusterName,
02303 char *rfschemaName, char *rfCluster,
02304 char *rfdbSchema, char *rftabName,
02305 char *forKeyAttr[], char *referAttr[],
02306 int rfCount, char *user, char *domain)
02307 {
02308 int user_id;
02309
02310 user_id = get_user_id_in_domain(user, domain);
02311 if (user_id < 0) { return (USER_NOT_IN_DOMN);}
02312 return(registerLinkInSchema(schemaName,clusterName,rfschemaName,
02313 rfCluster,rfdbSchema,rftabName,
02314 forKeyAttr,referAttr,rfCount,user_id));
02315 }
02316
02317 int
02318 registerLinkInSchema(char *schemaName, char *clusterName,
02319 char *rfschemaName, char *rfCluster,
02320 char *rfdbSchema, char *rftabName,
02321 char *forKeyAttr[], char *referAttr[],
02322 int rfCount, int realUserId)
02323 {
02324 int i,j, k;
02325 int tabIdList[MAX_TABLE_COLS];
02326 int attrIdList[MAX_TABLE_COLS];
02327 char exterSchemaName[MAX_TOKEN];
02328
02329 i = checkforownershipofschema(schemaName,realUserId);
02330 if (i != 0) return (i);
02331
02332 tabIdList[0] = getTabIdFromSchemaCluster(schemaName,clusterName);
02333 if (tabIdList[0] < 0) return (tabIdList[0]);
02334
02335
02336 if (rfCluster != NULL && strlen(rfCluster) > 0) {
02337 tabIdList[1] = getTabIdFromSchemaCluster(rfschemaName,rfCluster);
02338 if (tabIdList[1] < 0) return (tabIdList[1]);
02339 }
02340 else if (rftabName != NULL && strlen(rftabName) > 0) {
02341 tabIdList[1] = getTabIdFromDBSchemaTabName(rfdbSchema,rftabName);
02342 if (tabIdList[1] < 0) return (tabIdList[1]);
02343 }
02344 else {
02345 return(FK_REL_TABLE_ID_ERROR);
02346 }
02347 i = getSchemaNameFromTabId(exterSchemaName,tabIdList[1]);
02348 if (i != 0) return (i);
02349
02350 for (i = 1; i < rfCount; i++) {
02351 tabIdList[2*i] = tabIdList[0];
02352 tabIdList[(2*i)+1] = tabIdList[1];
02353 }
02354
02355 for (i = 0; i < rfCount; i++) {
02356 attrIdList[2*i] = getAttrIdFromTabIdAttrName(tabIdList[2*i],
02357 forKeyAttr[i]);
02358 if (attrIdList[2*i] < 0) return (attrIdList[2*i]);
02359 if (rftabName != NULL && strlen(rftabName) > 0)
02360 attrIdList[(2*i)+1] = getAttrIdFromTabIdAttrName(tabIdList[(2*i)+1],
02361 referAttr[i]);
02362 else
02363 attrIdList[(2*i)+1] = getAttrIdFromTabIdExterAttrName(tabIdList[(2*i)+1],
02364 referAttr[i]);
02365
02366 if (attrIdList[(2*i)+1] < 0) return (attrIdList[(2*i)+1]);
02367 }
02368
02369 j = insert_into_rcore_fk_relations(rfCount,tabIdList,attrIdList,"","",
02370 "=", exterSchemaName,schemaName);
02371 return(j);
02372 }
02373
02374 int
02375 registerTokenAttrInSchemaByUser(char *resourceName,char *dbSchemeName,
02376 char *tableSpaceName, char *tableName,
02377 char *schemaName, char *clusterName, int attrCount,
02378 char *attrExtrName[], char *attrDataType[],
02379 char *attrIdenType[], char *defaultVal[],
02380 char *attrComments[], char *attrPresentation[],
02381 char *subjects, char *constraints,
02382 char *user, char *domain,char *attrDimension[])
02383 {
02384 int user_id;
02385
02386 user_id = get_user_id_in_domain(user, domain);
02387 if (user_id < 0) { return (USER_NOT_IN_DOMN);}
02388 return(registerTokenAttrInSchema(resourceName, dbSchemeName,
02389 tableSpaceName,tableName,
02390 schemaName,clusterName,attrCount,attrExtrName,
02391 attrDataType,attrIdenType,defaultVal,
02392 attrComments,attrPresentation,subjects,
02393 constraints, user_id,attrDimension));
02394
02395 }
02396
02397 int
02398 registerTokenAttrInSchema(char *resourceName,char *dbSchemeName,
02399 char *tableSpaceName, char *tableName,
02400 char *schemaName, char *clusterName, int attrCount,
02401 char *attrName[], char *attrDataType[],
02402 char *attrIdenType[], char *defaultVal[],
02403 char *attrComments[], char *attrPresentation[],
02404 char *subjects, char *constraints,
02405 int realUserId,char *attrDimension[])
02406 {
02407 int i,j, k, tabid,attrid1,attrid2, startk, tokenId, user_id;
02408 unsigned long int maxsize;
02409 int numattrs = 1;
02410 char *LocattrDataType[MAX_TABLE_COLS];
02411 char myAttrPresentation[MAX_TOKEN];
02412 char idAttrDataType[MAX_TOKEN], idAttrIdenType[MAX_TOKEN];
02413
02414
02415 char databaseName[MAX_TOKEN];
02416 int resourceId;
02417
02418 i = checkforuniqueschemaname(schemaName) ;
02419 if (i != 0) return (i);
02420
02421 i = checkforownershipofschema(schemaName,realUserId);
02422 if (i != 0) return (i);
02423
02424 i = getDBResourceInfo(resourceName, &resourceId,
02425 databaseName);
02426 if (i != 0) return (i);
02427
02428 i = checkforexistsclusterNameinSchemaResourceId(clusterName,schemaName,
02429 resourceId);
02430 if (i != 0) return (i);
02431
02432
02433
02434 tabid = insert_into_rcore_tables(tableName, databaseName, schemaName,
02435 clusterName,
02436 dbSchemeName, tableSpaceName,
02437 realUserId, resourceId,
02438 0, subjects,attrComments[0], constraints,0);
02439 if (tabid < 0) return(tabid);
02440
02441 startk = 0;
02442
02443 if (strstr(attrDataType[0],"int") != NULL) {
02444 if (!strcmp(attrIdenType[0],"SR") ||
02445 !strcmp(attrIdenType[0],"LS") ||
02446 !strcmp(attrIdenType[0],"UR") ||
02447 !strcmp(attrIdenType[0],"ST") ||
02448 !strcmp(attrIdenType[0],"LT") ||
02449 !strcmp(attrIdenType[0],"UT") ||
02450 !strcmp(attrIdenType[0],"US")) {
02451 strcpy(idAttrIdenType,"ST");
02452 maxsize = DEFAULT_INTEGER_SPACE_SIZE;
02453 strcpy(idAttrDataType, "int");
02454 }
02455 else return (TOKEN_IDEN_TYPE_ERROR);
02456 }
02457 else if (strstr(attrDataType[0],"char") != NULL) {
02458 if (!strcmp(attrIdenType[0],"HR") ||
02459 !strcmp(attrIdenType[0],"HT")) {
02460 strcpy(idAttrIdenType,"HT");
02461 maxsize = DEFAULT_TOKEN_ID_MAXSIZE;
02462 sprintf(idAttrDataType, "char(%i)", DEFAULT_TOKEN_ID_MAXSIZE);
02463 }
02464 else {
02465 strcpy(idAttrIdenType,attrIdenType[0]);
02466 strcpy(idAttrDataType,attrDataType[0]);
02467 maxsize = getMaxSize(attrDataType[0]);
02468 }
02469 }
02470 else {
02471 return (TOKEN_IDEN_TYPE_ERROR);
02472 }
02473
02474
02475 tokenId = insert_into_rcore_attributes(schemaName,tabid,attrName[0],
02476 idAttrDataType,
02477 idAttrIdenType, attrName[0],
02478 "",
02479 -1,-1,"MCAT registered token identifier",
02480 "",
02481 1, 0,-1, maxsize,"");
02482
02483 if (tokenId < 0) {
02484 return(tokenId);
02485 }
02486 strcat (idAttrDataType, " not null ");
02487 LocattrDataType[0] = idAttrDataType;
02488
02489
02490
02491
02492 for (k = 1; k < attrCount ; k++) {
02493 maxsize = getMaxSize(attrDataType[k]);
02494 if (maxsize < 0) {
02495 return(maxsize);
02496 }
02497 if (attrPresentation[k] == NULL || strlen(attrPresentation[k]) == 0)
02498 strcpy(myAttrPresentation,"html:in:single_select_list");
02499 else
02500 strcpy(myAttrPresentation,attrPresentation[k]);
02501 attrid1 = insert_into_rcore_attributes(schemaName,tabid,attrName[k],
02502 attrDataType[k],
02503 attrIdenType[k], attrName[k],
02504 defaultVal[k],
02505 tokenId,-1,attrComments[k],
02506 myAttrPresentation,
02507 0, 1,-1, maxsize,attrDimension[k]);
02508
02509 if (attrid1 < 0) {
02510 return(attrid1);
02511 }
02512 }
02513 return (RCAT_SUCCESS);
02514 }
02515
02516
02517
02518 int
02519 addAttrClusterInSchemaByUser(char *schemaName, char *clusterName,
02520 int attrCount,
02521 char *attrExtrName[], char *attrDataType[],
02522 char *attrIdenType[], char *defaultVal[],
02523 char *attrComments[], char *attrPresentation[],
02524 char *sameas[], int primaryKey[],
02525 char *subjects, char *constraints,
02526 char *user, char *domain, char *attrDimension[])
02527 {
02528 int user_id;
02529
02530 user_id = get_user_id_in_domain(user, domain);
02531 if (user_id < 0) { return (USER_NOT_IN_DOMN);}
02532 return(addAttrClusterInSchema(schemaName,clusterName,
02533 attrCount,attrExtrName,
02534 attrDataType,attrIdenType,defaultVal,
02535 attrComments,attrPresentation,sameas,
02536 primaryKey, subjects,
02537 constraints, user_id,attrDimension));
02538
02539 }
02540
02541
02542 int
02543 addAttrClusterInSchema(char *schemaName, char *clusterName, int attrCount,
02544 char *attrExtrName[], char *attrDataType[],
02545 char *attrIdenType[], char *defaultVal[],
02546 char *attrComments[], char *attrPresentation[],
02547 char *sameas[], int primaryKey[],
02548 char *subjects, char *constraints,
02549 int realUserId, char *attrDimension[])
02550 {
02551 int i,j, k, tabid,attrid1,attrid2, startk,attrTokenId, tabTokenId;
02552 unsigned long int maxsize;
02553 int numattrs = 1;
02554 char *attrName[MAX_TABLE_COLS];
02555 char *LocattrDataType[MAX_TABLE_COLS];
02556 char tableName[MAX_TOKEN];
02557 char exterSchemaName[MAX_TOKEN];
02558 char idAttrDataType[MAX_TOKEN], idAttrIdenType[MAX_TOKEN];
02559 int tabIdList[15];
02560 int attrIdList[15];
02561 char tokenExterAttrName[MAX_TOKEN];
02562 int expose, exter_attrib_id;
02563 char presentation[MAX_TOKEN];
02564 char dimension[MAX_TOKEN];
02565 char default_value[MAX_TOKEN];
02566
02567
02568
02569 i = checkforuniqueschemaname(schemaName) ;
02570 if (i != 0) return (i);
02571
02572 i = checkforownershipofschema(schemaName, realUserId);
02573 if (i != 0) return (i);
02574 if(debugging4) {
02575 printf("Calling getNewTableName:%s:%s\n",schemaName,clusterName);
02576 fflush(stdout);
02577 }
02578
02579 i = getNewTableName(schemaName,attrIdenType[0],
02580 clusterName, tableName);
02581 if (i < 0) return(i);
02582 if(debugging4){
02583 printf("Calling insert_into_rcore_tables:%s\n",tableName); fflush(stdout);
02584 }
02585
02586 tabid = insert_into_rcore_tables(tableName, RCATDBNAME, schemaName,
02587 clusterName,
02588 RCATSCHEMENAME, RCATTABLESPACENAME,
02589 MCATUSERID , RCATRESOURCEID,
02590 0, subjects,attrComments[0], constraints,0);
02591
02592 if (tabid < 0) return(tabid);
02593
02594
02595 startk = 0;
02596 strcpy(idAttrIdenType,"SD");
02597 maxsize = DEFAULT_INTEGER_SPACE_SIZE;
02598 strcpy(idAttrDataType, "int");
02599 attrName[0] = (char *)malloc(sizeof(char) * MAX_TOKEN);
02600 if (attrName[0] == NULL) return (MEMORY_ALLOCATION_ERROR);
02601 startk = 1;
02602 i = getNewAttrName(attrExtrName[0], tableName, attrName[0]);
02603
02604 if (i < 0) {
02605 free(attrName[0]);
02606 return(i);
02607 }
02608 if (strlen(attrName[0]) < (MAX_SQL_NAME_LIMIT - 4))
02609 strcat(attrName[0], "_mid");
02610 else
02611 strcat( (char *) (&attrName[0] + MAX_SQL_NAME_LIMIT - 4), "_mid");
02612 if(debugging4)
02613 printf("Calling insert_into_rcore_attributes:%s\n",attrName[0]); fflush(stdout);
02614
02615 attrid1 = insert_into_rcore_attributes(schemaName,tabid,attrName[0],
02616 idAttrDataType,
02617 idAttrIdenType, attrName[0],
02618 "0",
02619 -1,-1,"MCAT created token identifier",
02620 "",
02621 1, 0,-1, maxsize,"");
02622
02623 if (attrid1 < 0) {
02624 free(attrName[0]);
02625 return(attrid1);
02626 }
02627 strcat (idAttrDataType, " not null ");
02628 LocattrDataType[0] = idAttrDataType;
02629
02630
02631
02632
02633 for (k = 0; k < attrCount ; k++) {
02634
02635
02636 attrName[k+startk] = (char *)malloc(sizeof(char) * MAX_TOKEN);
02637 if (attrName[k+startk] == NULL) return (MEMORY_ALLOCATION_ERROR);
02638 LocattrDataType[k+startk] = attrDataType[k];
02639
02640
02641
02642 if (!strcmp(attrIdenType[k],"SR") ||
02643 !strcmp(attrIdenType[k],"LS") ||
02644 !strcmp(attrIdenType[k],"HR") ||
02645 !strcmp(attrIdenType[k],"PR") ||
02646 !strcmp(attrIdenType[k],"UR") ||
02647 !strcmp(attrIdenType[k],"FK"))
02648 {
02649
02650
02651 LocattrDataType[k+startk] = (char *)malloc(sizeof(char) * MAX_TOKEN);
02652 if (LocattrDataType[k+startk] == NULL) return (MEMORY_ALLOCATION_ERROR);
02653 if(debugging4) {
02654 printf("Calling getAttrInfoForToken:%s<BR>\n",attrName[k+startk]); fflush(stdout);
02655 }
02656 j = getAttrInfoForToken(attrExtrName[k], schemaName,
02657 attrName[k+startk],
02658 &attrTokenId,&tabTokenId,exterSchemaName,
02659 LocattrDataType[k+startk],&maxsize,
02660 tokenExterAttrName, &expose,
02661 presentation, default_value,
02662 &exter_attrib_id,dimension);
02663
02664 if (j < 0) {
02665 for (i = 0; i <= (k+startk); i++) {
02666 free(attrName[i]);
02667 }
02668 return(j);
02669 }
02670 if (!strcmp(exterSchemaName,schemaName)) expose = 0;
02671
02672 if (attrPresentation[k] != NULL && strlen(attrPresentation[k]) != 0)
02673 strcpy(presentation,attrPresentation[k]);
02674 if (attrDimension[k] != NULL && strlen(attrDimension[k]) != 0)
02675 strcpy(dimension,attrDimension[k]);
02676 if(debugging4) {
02677 printf("Calling insert_into_rcore_attributes:%s\n",attrName[k+startk]); fflush(stdout);
02678 }
02679 attrid1 = insert_into_rcore_attributes(schemaName,tabid,
02680 attrName[k+startk], LocattrDataType[k+startk], "FK",
02681 tokenExterAttrName, default_value,-1, attrTokenId ,
02682 attrComments[k], presentation, primaryKey[k],
02683 expose,exter_attrib_id, maxsize,dimension);
02684
02685 if (attrid1 < 0) {
02686 for (i = 0; i <= (k+startk); i++) {
02687 free(attrName[i]);
02688 }
02689 return(attrid1);
02690 }
02691 tabIdList[0] = tabid;
02692 attrIdList[0] = attrid1;
02693 tabIdList[1] = tabTokenId;
02694 attrIdList[1] = attrTokenId;
02695
02696 j = insert_into_rcore_fk_relations(1,tabIdList,attrIdList,"","",
02697 "=", exterSchemaName,schemaName);
02698
02699 if (j < 0) {
02700 for (i = 0; i <= (k+startk); i++) {
02701 free(attrName[i]);
02702 }
02703 return(j);
02704 }
02705
02706
02707
02708 }
02709 else
02710 {
02711
02712
02713 maxsize = getMaxSize(attrDataType[k]);
02714 if (maxsize < 0) {
02715 for (i = 0; i <= (k+startk); i++) {
02716 free(attrName[i]);
02717 }
02718 return(maxsize);
02719 }
02720
02721 attrTokenId = 0;
02722 if (sameas[k] != NULL && strlen(sameas[k]) != 0 ) {
02723 attrTokenId = getAttrIdForName(sameas[k], schemaName);
02724
02725 if (attrTokenId < 0) {
02726 for (i = 0; i <= (k+startk); i++) {
02727 free(attrName[i]);
02728 }
02729 return(attrTokenId);
02730 }
02731 }
02732 i = getNewAttrName(attrExtrName[k], tableName, attrName[k+startk]);
02733
02734 if (i < 0) {
02735 for (j = 0; j <= (k+startk); j++) {
02736 free(attrName[j]);
02737 }
02738 return(i);
02739 }
02740 if(debugging4) {
02741 printf("Calling insert_into_rcore_attributes:%s\n",attrName[k+startk]); fflush(stdout);
02742 }
02743 attrid1 = insert_into_rcore_attributes(schemaName,tabid,
02744 attrName[k+startk], attrDataType[k], attrIdenType[k],
02745 attrExtrName[k], defaultVal[k], -1,attrTokenId,
02746 attrComments[k], attrPresentation[k], primaryKey[k],
02747 1,-1, maxsize,attrDimension[k]);
02748
02749 if (attrid1 < 0) {
02750 for (i = 0; i <= (k+startk); i++) {
02751 free(attrName[i]);
02752 }
02753 return(attrid1);
02754 }
02755
02756 }
02757
02758 }
02759
02760 i = createNewTable(attrCount+startk, tableName, attrName,
02761 LocattrDataType, "",
02762 RCATDBNAME, RCATSCHEMENAME,
02763 RCATTABLESPACENAME,MCATUSERID , RCATRESOURCEID);
02764
02765 for (k = 0; k < (attrCount+startk) ; k++) {
02766 free(attrName[k]);
02767 }
02768 return (i);
02769
02770 }
02771
02772
02773
02774
02775
02776 int
02777 registerClusterInSchemaByUser(char *resourceName,char *dbSchemeName,
02778 char *tableSpaceName, char *tableName,
02779 char *schemaName,
02780 char *clusterName, int attrCount,
02781 char *attrExtrName[], char *attrDataType[],
02782 char *attrIdenType[], char *defaultVal[],
02783 char *attrComments[], char *attrPresentation[],
02784 char *sameas[], int primaryKey[],
02785 char *subjects, char *constraints,
02786 char *user, char *domain, char *attrDimension[],
02787 int expose[])
02788 {
02789 int user_id;
02790
02791 user_id = get_user_id_in_domain(user, domain);
02792 if (user_id < 0) { return (USER_NOT_IN_DOMN);}
02793 return(registerClusterInSchema(resourceName, dbSchemeName,
02794 tableSpaceName,tableName,schemaName,
02795 clusterName,attrCount,attrExtrName,
02796 attrDataType,attrIdenType,defaultVal,
02797 attrComments,attrPresentation,sameas,
02798 primaryKey, subjects,
02799 constraints, user_id,attrDimension,
02800 expose));
02801
02802 }
02803
02804
02805 int
02806 registerClusterInSchema(char *resourceName,char *dbSchemeName,
02807 char *tableSpaceName, char *tableName,
02808 char *schemaName,
02809 char *clusterName, int attrCount,
02810 char *attrExtrName[], char *attrDataType[],
02811 char *attrIdenType[], char *defaultVal[],
02812 char *attrComments[], char *attrPresentation[],
02813 char *sameas[], int primaryKey[],
02814 char *subjects, char *constraints,
02815 int realUserId, char *attrDimension[],
02816 int expose[])
02817 {
02818 int i,j, k, tabid,attrid1,attrid2, startk,attrTokenId, tabTokenId;
02819 unsigned long int maxsize;
02820 int numattrs = 1;
02821 char *attrName[MAX_TABLE_COLS];
02822 char *LocattrDataType[MAX_TABLE_COLS];
02823 char exterSchemaName[MAX_TOKEN];
02824 char idAttrDataType[MAX_TOKEN], idAttrIdenType[MAX_TOKEN];
02825 int tabIdList[15];
02826 int attrIdList[15];
02827 char tokenExterAttrName[MAX_TOKEN];
02828 int exter_attrib_id;
02829 char presentation[MAX_TOKEN];
02830 char dimension[MAX_TOKEN];
02831 char default_value[MAX_TOKEN];
02832
02833 char databaseName[MAX_TOKEN];
02834 int resourceId;
02835
02836 if(debugging4) {
02837 printf("RN=%s:\n",resourceName); fflush(stdout);
02838 printf("DSN=%s:\n",dbSchemeName); fflush(stdout);
02839 printf("TSN=%s:\n",tableSpaceName); fflush(stdout);
02840 printf("TN=%s:\n",tableName); fflush(stdout);
02841 printf("SN=%s:\n",schemaName); fflush(stdout);
02842 printf("CN=%s:\n",clusterName); fflush(stdout);
02843 printf("ACN=%i:\n",attrCount); fflush(stdout);
02844 printf("AEN0=%s:\n",attrExtrName[0]); fflush(stdout);
02845 printf("ADT0=%s:\n",attrDataType[0]); fflush(stdout);
02846 printf("AEN1=%s:\n",attrExtrName[1]); fflush(stdout);
02847 printf("ADT1=%s:\n",attrDataType[1]); fflush(stdout);
02848 printf("UI=%i\n",realUserId); fflush(stdout);
02849 }
02850
02851 i = checkforuniqueschemaname(schemaName) ;
02852 if (i != 0) return (i);
02853
02854 i = checkforownershipofschema(schemaName, realUserId);
02855 if (i != 0) return (i);
02856 if(debugging4) {
02857 printf("Calling getDBResourceInfo:%s\n",resourceName);
02858 fflush(stdout);
02859 }
02860
02861 i = getDBResourceInfo(resourceName, &resourceId,
02862 databaseName);
02863 if (i != 0) return (i);
02864
02865 i = checkforexistsclusterNameinSchemaResourceId(clusterName,schemaName,
02866 resourceId);
02867 if (i != 0) return (i);
02868
02869
02870 if(debugging4){
02871 printf("Calling insert_into_rcore_tables:%s\n",tableName); fflush(stdout);
02872 }
02873 tabid = insert_into_rcore_tables(tableName, databaseName, schemaName,
02874 clusterName,
02875 dbSchemeName, tableSpaceName,
02876 realUserId, resourceId,
02877 0, subjects,attrComments[0], constraints,0);
02878
02879
02880 if (tabid < 0) return(tabid);
02881 for (k = 0; k < attrCount ; k++) {
02882 maxsize = getMaxSize(attrDataType[k]);
02883 if (maxsize < 0) return(maxsize);
02884 attrTokenId = 0;
02885 if (sameas[k] != NULL && strlen(sameas[k]) != 0 ) {
02886 attrTokenId = getAttrIdForName(sameas[k], schemaName);
02887 if (attrTokenId < 0) return(attrTokenId);
02888 }
02889 if(debugging4) {
02890 printf("Calling insert_into_rcore_attributes:%s\n",attrExtrName[k]);
02891 fflush(stdout);
02892 }
02893 if(debugging4) {
02894 printf("Calling insert_into_rcore_attributes:%s\n",attrExtrName[k]);
02895 fflush(stdout);
02896 }
02897
02898 attrid1 = insert_into_rcore_attributes(schemaName,tabid,
02899 attrExtrName[k], attrDataType[k], attrIdenType[k],
02900 attrExtrName[k], defaultVal[k], -1,attrTokenId,
02901 attrComments[k], attrPresentation[k], primaryKey[k],
02902 expose[k],-1, maxsize,attrDimension[k]);
02903
02904 if (attrid1 < 0) return(attrid1);
02905 }
02906 return(RCAT_SUCCESS);
02907
02908 }
02909
02910
02911 int
02912 createNewSchemaByUser(char *schemaName,
02913 char *subjects, char *comments,
02914 char *constraints, char *similarto,
02915 char *user, char *domain)
02916 {
02917 int user_id;
02918
02919 user_id = get_user_id_in_domain(user, domain);
02920 if (user_id < 0) { return (USER_NOT_IN_DOMN);}
02921 return(createNewSchema(schemaName, subjects,comments,
02922 constraints, similarto, user_id));
02923
02924 }
02925
02926
02927
02928 int
02929 createNewSchema(char *schema_name,
02930 char *subject,
02931 char *comments,
02932 char *constraints,
02933 char *similarto, int user_id)
02934 {
02935 int i,j;
02936 char sqlq[HUGE_STRING];
02937 i = checkforuniqueschemaname(schema_name);
02938 if (i == RCAT_SUCCESS) return (SCHEMA_NAME_NOT_UNIQUE_IN_CAT);
02939
02940 i = checkifallowedtocreateschema(user_id);
02941 if (i != RCAT_SUCCESS) {
02942 return (ACTION_NOT_ALLOWED_FOR_USER);
02943 }
02944
02945 sprintf(sqlq,
02946 "insert into %s%s (schema_name,subject,comments, \
02947 constraints,similarto, user_id) values ('%s','%s','%s','%s','%s',%i)",
02948 RCATSCHEMENAME,"RCORE_SCHEMAS",
02949 schema_name,subject,comments,
02950 constraints,similarto, user_id);
02951 res = ExecSqlDb(henv, hdbc, sqlq);
02952 if (res != RCAT_SUCCESS) {
02953 strcpy(GENERATEDSQL,sqlq);
02954 return(MCAT_SCHEMA_CREATION_ERROR);
02955 }
02956
02957 sprintf(sqlq,
02958 "insert into %s%s (user_schema_name,comments,parent_schema) \
02959 values ('%s','%s','%s')",
02960 RCATSCHEMENAME,"RCORE_USER_SCHEMAS",
02961 schema_name, "original schema", schema_name);
02962 res = ExecSqlDb(henv, hdbc, sqlq);
02963 if (res != RCAT_SUCCESS) {
02964 strcpy(GENERATEDSQL,sqlq);
02965 return(MCAT_SCHEMA_CREATION_ERROR);
02966 }
02967 return(RCAT_SUCCESS);
02968
02969 }
02970
02971
02972
02973 int
02974 createVuSchemaByUser(int cnt, int *AttrList, char *par_schema_list,
02975 char *schema_name, char *subject, char *comments,
02976 char *user, char *domain)
02977 {
02978 int user_id;
02979
02980 user_id = get_user_id_in_domain(user, domain);
02981 if (user_id < 0) { return (USER_NOT_IN_DOMN);}
02982 return(createVuSchema(cnt,AttrList,par_schema_list,
02983 schema_name, subject,comments, user_id));
02984
02985 }
02986 int
02987 createVuSchema(int cnt, int *AttrList, char *par_schema_list,
02988 char *schema_name, char *subject, char *comments,
02989 int user_id)
02990 {
02991 int i,j;
02992 char sqlq[HUGE_STRING];
02993 char scList[SMALL_TOKEN][MAX_TOKEN];
02994 i = checkforuniqueschemaname(schema_name);
02995 if (i == RCAT_SUCCESS) return (SCHEMA_NAME_NOT_UNIQUE_IN_CAT);
02996
02997
02998 sprintf(sqlq,
02999 "insert into %s%s (schema_name,subject,comments, \
03000 constraints,similarto, user_id) values ('%s','%s','%s','','',%i)",
03001 RCATSCHEMENAME,"RCORE_SCHEMAS",
03002 schema_name,subject,comments,user_id);
03003 res = ExecSqlDb(henv, hdbc, sqlq);
03004 if (res != RCAT_SUCCESS) {
03005 strcpy(GENERATEDSQL,sqlq);
03006 return(MCAT_SCHEMA_CREATION_ERROR);
03007 }
03008
03009 for (i = 0; i < cnt ; i++) {
03010 sprintf(sqlq,
03011 "insert into %s%s (user_schema_name,attr_id, expose) values ('%s', %i, 1)",
03012 RCATSCHEMENAME,"RCORE_USCHEMA_ATTR", schema_name,AttrList[i]);
03013
03014 res = ExecSqlDb(henv, hdbc, sqlq);
03015 if (res != RCAT_SUCCESS) {
03016 strcpy(GENERATEDSQL,sqlq);
03017 return(MCAT_SCHEMA_CREATION_ERROR);
03018 }
03019 }
03020 j = splitListString(par_schema_list,scList, ',');
03021 for (i = 0; i < j; i++) {
03022 sprintf(sqlq,
03023 "insert into %s%s (user_schema_name,comments,parent_schema) \
03024 values ('%s','%s',%s)",
03025 RCATSCHEMENAME,"RCORE_USER_SCHEMAS",
03026 schema_name, "sub schema", scList[i]);
03027 res = ExecSqlDb(henv, hdbc, sqlq);
03028 if (res != RCAT_SUCCESS) {
03029 strcpy(GENERATEDSQL,sqlq);
03030 return(MCAT_SCHEMA_CREATION_ERROR);
03031 }
03032 }
03033 return(RCAT_SUCCESS);
03034 }
03035
03036
03037 int
03038 dropClusterinCoreSchemaByUser(char *clusterName, char *schema_name,
03039 char *user, char *domain)
03040 {
03041 int user_id;
03042
03043 user_id = get_user_id_in_domain(user, domain);
03044 if (user_id < 0) { return (USER_NOT_IN_DOMN);}
03045 return(dropClusterinCoreSchema(clusterName, schema_name, user_id));
03046 }
03047
03048 int dropClusterinCoreSchema(char *clusterName,
03049 char *schemaName,
03050 int userId)
03051 {
03052 return(OPERATION_NOT_IMPLEMENTED);
03053 }
03054
03055 int
03056 dropAttrinCoreSchemaByUser(int AttrId, char *schema_name,
03057 char *user, char *domain)
03058 {
03059 int user_id;
03060
03061 user_id = get_user_id_in_domain(user, domain);
03062 if (user_id < 0) { return (USER_NOT_IN_DOMN);}
03063 return(dropAttrinCoreSchema(AttrId, schema_name, user_id));
03064 }
03065
03066 int
03067 dropAttrinCoreSchema(int AttrId, char *schema_name, int user_id)
03068 {
03069 int i,j;
03070 char sqlq[HUGE_STRING];
03071 int colcount, jj;
03072
03073 i = checkforownershipofschema(schema_name,user_id) ;
03074 if (i != 0) return (i);
03075
03076
03077 if (strstr(user,"rods") != NULL )
03078 return(INNER_CORE_SCHEMA_CANNOT_BE_DELETED);
03079 if (strstr(schema_name,"mcat") != NULL ||
03080 strstr(schema_name,"core") != NULL ||
03081 strstr(schema_name,"MCAT") != NULL ||
03082 strstr(schema_name,"CORE") != NULL)
03083 return(INNER_CORE_SCHEMA_CANNOT_BE_DELETED);
03084
03085
03086 sprintf(sqlq,
03087 "delete from %s%s where attr_id =%i",
03088 RCATSCHEMENAME,"RCORE_USCHEMA_ATTR", AttrId);
03089 res = ExecSqlDb(henv, hdbc, sqlq);
03090 if (res != RCAT_SUCCESS) {
03091 strcpy(GENERATEDSQL,sqlq);
03092 return(DELETE_ATTR_ERROR);
03093 }
03094 sprintf(sqlq,
03095 "delete from %s%s where attr_id =%i",
03096 RCATSCHEMENAME,"RCORE_ATTRIBUTES", AttrId);
03097 res = ExecSqlDb(henv, hdbc, sqlq);
03098 if (res != RCAT_SUCCESS) {
03099 strcpy(GENERATEDSQL,sqlq);
03100 return(DELETE_ATTR_ERROR);
03101 }
03102 return(RCAT_SUCCESS);
03103 }
03104
03105 int
03106 dropCoreSchemaByUser(char *schema_name,
03107 char *user, char *domain)
03108 {
03109 int user_id;
03110 if (strstr(user, "rods") != NULL )
03111 return(INNER_CORE_SCHEMA_CANNOT_BE_DELETED);
03112 user_id = get_user_id_in_domain(user, domain);
03113 if (user_id < 0) { return (USER_NOT_IN_DOMN);}
03114 return(dropCoreSchema(schema_name, user_id));
03115 }
03116
03117 int
03118 dropCoreSchema(char *schema_name, int user_id)
03119 {
03120 int i,j;
03121 char sqlq[HUGE_STRING];
03122 char tmpStr[MAX_TOKEN];
03123 int colcount, jj;
03124 char cval[MAX_NO_OF_TABLES][MAX_TOKEN];
03125 char cval2[MAX_NO_OF_TABLES][MAX_TOKEN];
03126 int noTablesFound = 0;
03127
03128
03129 if (user_id < 3)
03130 return(INNER_CORE_SCHEMA_CANNOT_BE_DELETED);
03131
03132
03133 if (strstr(schema_name,"mcat") != NULL ||
03134 strstr(schema_name,"core") != NULL ||
03135 strstr(schema_name,"MCAT") != NULL ||
03136 strstr(schema_name,"CORE") != NULL)
03137 return(INNER_CORE_SCHEMA_CANNOT_BE_DELETED);
03138
03139 i = checkforownershipofschema(schema_name,user_id);
03140 if (i != 0) return (i);
03141
03142
03143
03144
03145
03146
03147
03148
03149
03150
03151
03152 sprintf(sqlq,"select dbschema_name, table_name from %s%s where schema_name ='%s'",
03153 RCATSCHEMENAME,"RCORE_TABLES", schema_name);
03154 i = get_2ctype_list_from_query(cval,cval2, &colcount,sqlq);
03155 if (i != RCAT_SUCCESS ) {
03156 if (i == MCAT_NO_DATA_FOUND)
03157 noTablesFound=1;
03158 else
03159 return(i);
03160 }
03161 if (noTablesFound == 0) {
03162 if (colcount == 0) return (UNKNOWN_USER_SCHEMASET);
03163 for (jj = 0; jj < colcount; jj++) {
03164 sprintf(sqlq,"drop table %s%s ",cval[jj],cval2[jj]);
03165 res = ExecSqlDb(henv, hdbc, sqlq);
03166 if (res != RCAT_SUCCESS) {
03167 printf("Problem with Dropping Table:%s%s\n",cval[jj],cval2[jj]);
03168 }
03169 }
03170
03171 sprintf(sqlq,
03172 "delete from %s%s where user_schema_name ='%s'",
03173 RCATSCHEMENAME,"RCORE_USCHEMA_ATTR", schema_name);
03174 res = ExecSqlDb(henv, hdbc, sqlq);
03175 if (res != RCAT_SUCCESS) {
03176 printf("Problem with Deleting from RCORE_USCHEMA_ATTR\n");
03177 return(DELETE_SCHEMA_ERROR);
03178 }
03179 }
03180 sprintf(sqlq,
03181 "delete from %s%s where user_schema_name ='%s'",
03182 RCATSCHEMENAME,"RCORE_USER_SCHEMAS", schema_name);
03183 res = ExecSqlDb(henv, hdbc, sqlq);
03184 if (res != RCAT_SUCCESS) {
03185 printf("Problem with Deleting from RCORE_USER_SCHEMAS\n");
03186 return(DELETE_SCHEMA_ERROR);
03187 }
03188
03189 sprintf(sqlq,
03190 "delete from %s%s where parent_schema ='%s'",
03191 RCATSCHEMENAME,"RCORE_USER_SCHEMAS", schema_name);
03192 res = ExecSqlDb(henv, hdbc, sqlq);
03193 if (res != RCAT_SUCCESS) {
03194 printf("Problem with Deleting from RCORE_USER_SCHEMAS\n");
03195 return(DELETE_SCHEMA_ERROR);
03196 }
03197
03198 if (noTablesFound == 0) {
03199 sprintf(sqlq,
03200 "delete from %s%s t0 where t0.table_id in \
03201 ( select table_id from RCORE_TABLES where schema_name ='%s')",
03202 RCATSCHEMENAME,"RCORE_ATTRIBUTES", schema_name);
03203 res = ExecSqlDb(henv, hdbc, sqlq);
03204 if (res != RCAT_SUCCESS) {
03205 printf("Problem with Deleting from RCORE_ATTRIBUTES\n");
03206 return(DELETE_SCHEMA_ERROR);
03207 }
03208
03209 sprintf(sqlq,
03210 "delete from %s%s t0 where \
03211 t0.table_id_in1 in ( select table_id from RCORE_TABLES where schema_name ='%s') \
03212 or t0.table_id_out1 in ( select table_id from RCORE_TABLES where schema_name ='%s') \
03213 or t0.table_id_in2 in ( select table_id from RCORE_TABLES where schema_name ='%s') \
03214 or t0.table_id_out2 in ( select table_id from RCORE_TABLES where schema_name ='%s') \
03215 or t0.table_id_in3 in ( select table_id from RCORE_TABLES where schema_name ='%s') \
03216 or t0.table_id_out3 in ( select table_id from RCORE_TABLES where schema_name ='%s') \
03217 or t0.table_id_in4 in ( select table_id from RCORE_TABLES where schema_name ='%s') \
03218 or t0.table_id_out4 in ( select table_id from RCORE_TABLES where schema_name ='%s') \
03219 or t0.table_id_in5 in ( select table_id from RCORE_TABLES where schema_name ='%s') \
03220 or t0.table_id_out5 in ( select table_id from RCORE_TABLES where schema_name ='%s') ",
03221 RCATSCHEMENAME,"RCORE_FK_RELATIONS", schema_name, schema_name,
03222 schema_name, schema_name, schema_name, schema_name, schema_name,
03223 schema_name, schema_name, schema_name );
03224 res = ExecSqlDb(henv, hdbc, sqlq);
03225 if (res != RCAT_SUCCESS) {
03226 printf("Problem with Deleting from RCORE_FK_RELATIONS\n");
03227 return(DELETE_SCHEMA_ERROR);
03228 }
03229
03230 sprintf(sqlq,
03231 "delete from %s%s where schema_name ='%s'",
03232 RCATSCHEMENAME,"RCORE_TABLES", schema_name);
03233 res = ExecSqlDb(henv, hdbc, sqlq);
03234 if (res != RCAT_SUCCESS) {
03235 printf("Problem with Deleting from RCORE_TABLES\n");
03236 return(DELETE_SCHEMA_ERROR);
03237 }
03238 }
03239
03240 sprintf(sqlq,
03241 "delete from %s%s where schema_name ='%s'",
03242 RCATSCHEMENAME,"RCORE_SCHEMAS", schema_name);
03243 res = ExecSqlDb(henv, hdbc, sqlq);
03244 if (res != RCAT_SUCCESS) {
03245 printf("Problem with Deleting from RCORE_SCHEMAS\n");
03246 return(DELETE_SCHEMA_ERROR);
03247 }
03248
03249 return(RCAT_SUCCESS);
03250 }
03251
03252
03253
03254 int
03255 dropVuSchemaByUser(char *schema_name,
03256 char *user, char *domain)
03257 {
03258 int user_id;
03259
03260 user_id = get_user_id_in_domain(user, domain);
03261 if (user_id < 0) { return (USER_NOT_IN_DOMN);}
03262 return(dropVuSchema( schema_name, user_id));
03263 }
03264
03265
03266 int
03267 dropVuSchema(char *schema_name, int user_id)
03268 {
03269 int i,j;
03270 char sqlq[HUGE_STRING];
03271 char attrSet[HUGE_STRING];
03272
03273 i = checkforownershipofschema(schema_name,user_id) ;
03274 if (i != 0) return (i);
03275
03276 sprintf(sqlq,
03277 "delete from %s%s where user_schema_name ='%s'",
03278 RCATSCHEMENAME,"RCORE_USCHEMA_ATTR", schema_name);
03279 res = ExecSqlDb(henv, hdbc, sqlq);
03280 if (res != RCAT_SUCCESS) return(DELETE_SCHEMA_ERROR);
03281 sprintf(sqlq,
03282 "delete from %s%s where user_schema_name ='%s'",
03283 RCATSCHEMENAME,"RCORE_USER_SCHEMAS", schema_name);
03284 res = ExecSqlDb(henv, hdbc, sqlq);
03285 if (res != RCAT_SUCCESS) return(DELETE_SCHEMA_ERROR);
03286 sprintf(sqlq,
03287 "delete from %s%s where schema_name ='%s'",
03288 RCATSCHEMENAME,"RCORE_SCHEMAS", schema_name);
03289 res = ExecSqlDb(henv, hdbc, sqlq);
03290 if (res != RCAT_SUCCESS) {
03291 strcpy(GENERATEDSQL,sqlq);
03292 return(DELETE_SCHEMA_ERROR);
03293 }
03294 return(RCAT_SUCCESS);
03295 }
03296
03297
03298
03299
03300 int
03301 dropAttrinVuSchemaByUser(int cnt, int *AttrList, char *schema_name,
03302 char *user, char *domain)
03303 {
03304 int user_id;
03305
03306 user_id = get_user_id_in_domain(user, domain);
03307 if (user_id < 0) { return (USER_NOT_IN_DOMN);}
03308 return(dropAttrinVuSchema( cnt, AttrList,schema_name, user_id));
03309 }
03310
03311 int
03312 dropAttrinVuSchema(int cnt, int *AttrList, char *schema_name,
03313 int user_id)
03314 {
03315 int i,j;
03316 char sqlq[HUGE_STRING];
03317 char attrSet[HUGE_STRING];
03318
03319
03320 i = checkforownershipofschema(schema_name, user_id) ;
03321 if (i != 0) return (i);
03322
03323 sprintf(attrSet,"%i", AttrList[0]);
03324
03325 for (i = 1; i < cnt; i++)
03326 sprintf(&attrSet[strlen(attrSet)]," , %i", AttrList[i]);
03327
03328 sprintf(sqlq,
03329 "delete from %s%s where attr_id in ( %s ) and user_schema_name ='%s'",
03330 RCATSCHEMENAME,"RCORE_USCHEMA_ATTR", attrSet, schema_name);
03331 res = ExecSqlDb(henv, hdbc, sqlq);
03332 if (res != RCAT_SUCCESS) {
03333 strcpy(GENERATEDSQL,sqlq);
03334 return(DELETE_ATTR_ERROR);
03335 }
03336 return(RCAT_SUCCESS);
03337 }
03338
03339 int
03340 addAttrinVuSchemaByUser(int cnt, int *AttrList, char *schema_name,
03341 char *user, char *domain)
03342 {
03343 int user_id;
03344
03345 user_id = get_user_id_in_domain(user, domain);
03346 if (user_id < 0) { return (USER_NOT_IN_DOMN);}
03347 return(addAttrinVuSchema( cnt, AttrList,schema_name, user_id));
03348 }
03349 int
03350 addAttrinVuSchema(int cnt, int *AttrList, char *schema_name,
03351 int user_id)
03352 {
03353 int i,j;
03354 char sqlq[HUGE_STRING];
03355 char attrSet[HUGE_STRING];
03356
03357 i = checkforownershipofschema(schema_name, user_id) ;
03358 if (i != 0) return (i);
03359
03360
03361 for (i = 0; i < cnt ; i++) {
03362 sprintf(sqlq,
03363 "insert into %s%s (user_schema_name,attr_id, expose) values ('%s', %i, 1)",
03364 RCATSCHEMENAME,"RCORE_USCHEMA_ATTR", schema_name,AttrList[i]);
03365 res = ExecSqlDb(henv, hdbc, sqlq);
03366 if (res != RCAT_SUCCESS) {
03367 strcpy(GENERATEDSQL,sqlq);
03368 return(INSERT_ATTR_ERROR);
03369 }
03370 }
03371 return(RCAT_SUCCESS);
03372 }
03373
03374
03375 int
03376 getOutDimensions(char *inDim, char outDim[][MAX_TOKEN], int *rowcount)
03377 {
03378 char sqlq[2 *MAX_TOKEN];
03379 int i, j;
03380
03381 sprintf(sqlq,"select distinct OUT_ATTR_DIMEN from %sRCORE_ATTRDIMN11_FN where IN_ATTR_DIMEN = '%s'", RCATSCHEMENAME, inDim);
03382 i = get_ctype_list_from_query(outDim, &j,sqlq);
03383 if (i != RCAT_SUCCESS ) {
03384 strcpy(GENERATEDSQL,sqlq); return(i);
03385 }
03386 if (j == 0) return (UNKNOWN_USER_SCHEMASET);
03387 *rowcount = j;
03388 return(RCAT_SUCCESS);
03389 }
03390
03391 int
03392 getSchemaNames(char *type, char cval[][], int *rowcount)
03393 {
03394 char sqlq[HUGE_STRING];
03395 int i, j;
03396
03397
03398 if (!strcmp(type,"vu") )
03399 sprintf(sqlq,"select distinct USER_SCHEMA_NAME from %sRCORE_USER_SCHEMAS where PARENT_SCHEMA <> user_schema_name ", RCATSCHEMENAME);
03400 else if (!strcmp(type,"core") )
03401 sprintf(sqlq,"select distinct USER_SCHEMA_NAME from %sRCORE_USER_SCHEMAS where PARENT_SCHEMA = user_schema_name ", RCATSCHEMENAME);
03402 else if (!strcmp(type,"all") )
03403 sprintf(sqlq,"select distinct USER_SCHEMA_NAME from %sRCORE_USER_SCHEMAS", RCATSCHEMENAME);
03404 else return (UNKNOWN_USER_SCHEMASET);
03405
03406 i = get_ctype_list_from_query(cval, &j,sqlq);
03407 if (i != RCAT_SUCCESS ) {
03408 strcpy(GENERATEDSQL,sqlq); return(i);
03409 }
03410 if (j == 0) return (UNKNOWN_USER_SCHEMASET);
03411 *rowcount = j;
03412
03413 return(RCAT_SUCCESS);
03414 }
03415
03416
03417 int
03418 getRelatedAttr(char *AttrListStr,
03419 char AttrOutList[][MAX_TOKEN])
03420 {
03421 int i,j, k,jj;
03422 char sqlq[HUGE_STRING];
03423 char tmpStr[MAX_TOKEN];
03424 int colcount;
03425 char cval[MAX_TOKEN][MAX_TOKEN];
03426 char cval2[MAX_TOKEN][MAX_TOKEN];
03427 char cval3[MAX_TOKEN][MAX_TOKEN];
03428 char cval4[MAX_TOKEN][MAX_TOKEN];
03429 char cval5[MAX_TOKEN][MAX_TOKEN];
03430
03431
03432
03433 sprintf(sqlq,"select distinct t0.attr_id, t1.schema_name, t0.EXTERNAL_attr_name, t0.presentation, t0.attr_dimension \
03434 from rcore_attributes t0, rcore_tables t1, rcore_attributes t2 \
03435 where t2.attr_id in ( %s ) and \
03436 t2.table_id = t0.table_id and t1.table_id = t0.table_id and t0.expose = 1 \
03437 union \
03438 select distinct t10.attr_id, t11.schema_name, t10.attr_name, t10.presentation, t10.attr_dimension \
03439 from rcore_attributes t20, rcore_attributes t22 , rcore_attributes t10, rcore_tables t11, rcore_attributes t12 \
03440 where t22.attr_id in ( %s ) and \
03441 t22.table_id = t20.table_id and t20.attr_iden_type = 'FK' and t12.attr_id = t20.sameas and \
03442 t12.table_id = t10.table_id and t11.table_id = t10.table_id and t10.expose = 1\
03443 union \
03444 select distinct t40.attr_id, t41.schema_name, t40.attr_name,t40.presentation, t40.attr_dimension \
03445 from rcore_attributes t60, rcore_attributes t62 , rcore_attributes t50, rcore_attributes t52 , rcore_attributes t40, rcore_tables t41, rcore_attributes t42 \
03446 where t52.attr_id in ( %s ) and \
03447 t52.table_id = t50.table_id and t50.attr_iden_type = 'FK' and t62.attr_id = t50.sameas and \
03448 t62.table_id = t60.table_id and t60.attr_iden_type = 'FK' and t42.attr_id = t60.sameas and \
03449 t42.table_id = t40.table_id and t41.table_id = t40.table_id and t40.expose = 1",
03450 AttrListStr,AttrListStr,AttrListStr);
03451
03452 i = get_5ctype_list_from_query(cval,cval2,cval3,cval4,cval5,&colcount,sqlq);
03453 if (i != RCAT_SUCCESS ) {
03454 strcpy(GENERATEDSQL,sqlq);
03455 return(i);
03456 }
03457 if (colcount == 0) return (ATTRIBUTE_SET_EMPTY);
03458 for (jj = 0; jj < colcount; jj++) {
03459 sprintf(AttrOutList[jj],"%s#%s.%s###%s####%s",
03460 cval[jj],cval2[jj], cval3[jj], cval4[jj], cval5[jj]);
03461 }
03462 return(colcount);
03463
03464 }
03465
03466
03467 int
03468 getStylesForSchema(char *schemaset, char **styleName,
03469 int *rowcount)
03470 {
03471 char sqlq[HUGE_STRING];
03472 int i, j;
03473
03474 sprintf(sqlq,"select distinct STYLE_NAME from %sRCORE_SCHEMA_STYLES where SCHEMA_NAME in %s ", RCATSCHEMENAME,schemaset);
03475
03476 i = get_ctype_list_from_query(styleName, &j,sqlq);
03477
03478 if (i != RCAT_SUCCESS ) {
03479 strcpy(GENERATEDSQL,sqlq); return(i);
03480 }
03481
03482
03483
03484
03485 if (j == 0) return (MCAT_NO_DATA_FOUND);
03486 *rowcount = j;
03487
03488 return(RCAT_SUCCESS);
03489 }
03490
03491 int
03492 getProcForStyle(char *styleName, char *schemaName,char *styleProc)
03493 {
03494 char sqlq[MAX_TOKEN];
03495
03496 failure = 0;
03497 sprintf(sqlq,"select distinct STYLE_PROC from %sRCORE_SCHEMA_STYLES where SCHEMA_NAME = %s and STYLE_NAME = '%s' ",
03498 RCATSCHEMENAME, schemaName,styleName);
03499
03500 get_ctype_value_from_query(styleProc, sqlq);
03501 return(failure);
03502
03503 }
03504
03505
03506
03507 int
03508 getRelatedContexts(char *idList, char *context) {
03509 char cval[MAX_TOKEN][MAX_TOKEN];
03510 int i,jj;
03511 char sqlq[HUGE_STRING];
03512 char tmpStr[MAX_TOKEN];
03513 int colcount;
03514
03515 sprintf(sqlq,"select distinct t0.schema_name from %srcore_tables t0, %srcore_attributes t1 where t1.attr_id in (%s) and t0.table_id = t1.table_id",
03516 RCATSCHEMENAME,RCATSCHEMENAME, idList);
03517 i = get_ctype_list_from_query(cval, &colcount,sqlq);
03518 if (i != RCAT_SUCCESS ) return(i);
03519 if (colcount == 0) return (UNKNOWN_USER_SCHEMASET);
03520 strcpy(context,"");
03521 for (jj = 0; jj < colcount; jj++) {
03522 if (jj == 0)
03523 sprintf(tmpStr," '%s'",cval[jj]);
03524 else
03525 sprintf(tmpStr,", '%s'",cval[jj]);
03526 strcat(context,tmpStr);
03527 }
03528 return(RCAT_SUCCESS);
03529 }
03530
03531 int
03532 getTabIdFromDBSchemaTabName(char *dbSchema, char *tableName)
03533 {
03534 int i;
03535 char sqlq[HUGE_STRING];
03536
03537 sprintf(sqlq, "select table_id from %srcore_tables where DBSCHEMA_NAME = '%s' and TABLE_NAME ='%s'", RCATSCHEMENAME,dbSchema,tableName);
03538
03539 i = get_itype_value_from_query(sqlq);
03540 if (i < 0) strcpy(GENERATEDSQL,sqlq);
03541 return(i);
03542 }
03543
03544 int
03545 getAttrIdFromExterAttrNameInCD(char *attrName,
03546 rcat_metadata_attr_entry *AttrEntries,
03547 int countAttrs)
03548 {
03549 int i;
03550 for (i = 0; i < countAttrs ; i++) {
03551 if (!strcmp(AttrEntries[i].ext_attr_name,attrName))
03552 return(AttrEntries[i].attr_id);
03553 }
03554 return(UNKNOWN_ATTRIBUTE_NAME);
03555 }
03556 int
03557 getExternalAttrName(char *extAttrName,
03558 int attrId,
03559 rcat_metadata_attr_entry *AttrEntries,
03560 int countAttrs )
03561 {
03562 int i;
03563
03564 for (i = 0 ; i < countAttrs; i++) {
03565 if (AttrEntries[i].attr_id == attrId) {
03566 strcpy(extAttrName,AttrEntries[i].ext_attr_name);
03567 return(0);
03568 }
03569 }
03570 return ( UNKNOWN_ATTRIBUTE_ID);
03571
03572 }
03573
03574
03575
03576 int
03577 getAttrIdFromTabIdAttrName(int tableId, char *AttrName )
03578 {
03579 int i;
03580 char sqlq[HUGE_STRING];
03581
03582 sprintf(sqlq, "select attr_id from %srcore_attributes where TABLE_ID = %i and ATTR_NAME ='%s'", RCATSCHEMENAME,tableId,AttrName);
03583
03584 i = get_itype_value_from_query(sqlq);
03585 if (i < 0) strcpy(GENERATEDSQL,sqlq);
03586 return(i);
03587 }
03588
03589 int
03590 getAttrIdFromTabIdExterAttrName(int tableId, char *AttrName )
03591 {
03592 int i;
03593 char sqlq[HUGE_STRING];
03594
03595 sprintf(sqlq, "select attr_id from %srcore_attributes where TABLE_ID = %i and EXTERNAL_ATTR_NAME ='%s'", RCATSCHEMENAME,tableId,AttrName);
03596
03597 i = get_itype_value_from_query(sqlq);
03598 if (i < 0) strcpy(GENERATEDSQL,sqlq);
03599 return(i);
03600 }
03601
03602 int
03603 getTabIdFromSchemaCluster(char * schemaName, char *clusterName)
03604 {
03605 int i;
03606 char sqlq[HUGE_STRING];
03607
03608 sprintf(sqlq, "select table_id from %srcore_tables where SCHEMA_NAME = '%s' and CLUSTER_NAME ='%s'", RCATSCHEMENAME,schemaName,clusterName);
03609
03610 i = get_itype_value_from_query(sqlq);
03611 if (i < 0) strcpy(GENERATEDSQL,sqlq);
03612 return(i);
03613 }
03614
03615 int
03616 getSchemaNameFromTabId(char *schemaName, int tableId)
03617 {
03618 int i;
03619 char sqlq[HUGE_STRING];
03620 char cval[2][MAX_TOKEN];
03621 int colcount;
03622
03623 sprintf(sqlq, "select schema_name from %srcore_tables where TABLE_ID = %i ", RCATSCHEMENAME,tableId);
03624
03625 colcount = 1;
03626 i = get_row_from_query(cval, &colcount,sqlq);
03627 if (i < 0) strcpy(GENERATEDSQL,sqlq);
03628 if (i == 0)
03629 strcpy(schemaName,cval[0]);
03630 return(i);
03631 }
03632
03633 int
03634 checkforexistsclusterNameinSchemaResourceId(char *clusterName,
03635 char *schemaName, int resourceId)
03636 {
03637 int i;
03638
03639 sprintf(sqlq, "select cluster_name from %sRCORE_TABLES where \
03640 schema_name = '%s' and cluster_name = '%s' and rsrc_id = %i",
03641 RCATSCHEMENAME, schemaName, clusterName, resourceId);
03642 strcpy(GENERATEDSQL,sqlq);
03643 if (check_exists(sqlq) != 0) return (RCAT_SUCCESS);
03644
03645 return(CLUSTER_SCHEMA_EXISTS);
03646
03647 }
03648
03649 int
03650 getDBResourceInfo(char *resourceName,
03651 int *resourceId,
03652 char *databaseName)
03653 {
03654 int i,j, k,jj;
03655 char sqlq[HUGE_STRING];
03656 char tmpStr[MAX_TOKEN];
03657 int colcount;
03658 char cval[MAX_TOKEN][MAX_TOKEN];
03659
03660 if (strlen(resourceName) == 0 || !strcmp(resourceName,RCATRESOURCE)) {
03661 *resourceId = RCATRESOURCEID;
03662 strcpy(databaseName,RCATDBNAME);
03663 return(RCAT_SUCCESS);
03664 }
03665
03666 sprintf(sqlq,"select distinct t0.rsrc_id, t0.database_name from %s rcore_ar_db_rsrc t0 where t0.rsrc_name = '%s'",
03667 databaseName, resourceName);
03668 colcount = 2;
03669 i = get_row_from_query(cval, &colcount,sqlq);
03670 if (failure != 0 || i < 0) {
03671 strcpy(GENERATEDSQL,sqlq);
03672 return(RESOURCE_NOT_IN_CAT);
03673 }
03674 *resourceId = atoi(cval[0]);
03675 strcpy(databaseName,cval[1]);
03676 return(RCAT_SUCCESS);
03677
03678 }
03679
03680 int
03681 registerDbResourceInfo(char *resourceName,
03682 char *databaseName, char *dbLinkName,
03683 char *registrarName,char *registrarDomain,
03684 char *registrarPassword,
03685 char *userName, char *userPass,
03686 char *connectString)
03687 {
03688 char sqlq[HUGE_STRING];
03689 int i;
03690 int colcount;
03691 char cval[MAX_TOKEN][MAX_TOKEN];
03692
03693 strcpy(reg_registrar_name,registrarName);
03694 strcpy(reg_obj_name, resourceName);
03695 strcpy(reg_obj_code,"RCORE_CD_RSRC");
03696 strcpy(reg_action_name,"create resource");
03697 reg_obj_repl_enum = 0;
03698 failure = 0;
03699
03700 i = web_rcore_sys_authorization(registrarName, registrarPassword,
03701 registrarDomain);
03702 if ( i != 0)
03703 {
03704 sprintf(sqlq,
03705 "resource registry SYSAPI: Failed Password:%s,%s\n",
03706 registrarPassword,registrarName);
03707 error_exit(query_string);
03708 return(SYS_USER_AUTHORIZATION_ERROR);
03709 }
03710
03711 sprintf(sqlq,"select distinct t0.rsrc_id, t0.rsrc_typ_id from %srcore_ar_repl t0 where t0.rsrc_name = '%s'",RCATSCHEMENAME,
03712 resourceName);
03713 colcount = 2;
03714 i = get_row_from_query(cval, &colcount,sqlq);
03715 if (failure != 0 || i < 0) {
03716 strcpy(GENERATEDSQL,sqlq);
03717 return(RESOURCE_NOT_IN_CAT);
03718 }
03719 sprintf(sqlq,
03720 "insert into %s%s (rsrc_id,repl_enum,rsrc_name,rsrc_typ_id,rsrc_database_name,db_link_name,db_user_name,db_pass,db_connect_string) values (%i,%i,'%s','%s','%s','%s','%s','%s','%s')",
03721 RCATSCHEMENAME, "RCORE_AR_DB_RSRC",
03722 atoi(cval[0]), 0, resourceName, cval[1], databaseName,
03723 dbLinkName,userName,userPass,connectString);
03724
03725 res = ExecSqlDb(henv, hdbc, sqlq);
03726 if (res != 0)
03727 {error_exit("user registry API: CD resource insertion error");
03728 strcpy(GENERATEDSQL,sqlq);
03729 return(RCORE_AR_DB_RSRC_INSERTION_ERROR);}
03730
03731 nice_exit("resource registered by SYSAPI");
03732 return(RCAT_SUCCESS);
03733 }
03734
03735
03736
03737
03738
03739
03740 int
03741 checkifallowedtocreateschema(int user_id)
03742 {
03743 return(RCAT_SUCCESS);
03744 }
03745 int
03746 checkAccessMetaDataAttr(int real_user_id,
03747 int *attr_id,
03748 int attr_cnt)
03749 {
03750 return(RCAT_SUCCESS);
03751 }
03752
03753
03754
03755
03756
03757
03758
03759
03760
03761
03762
03763
03764
03765
03766
03767
03768
03769
03770
03771
03772
03773
03774
03775
03776
03777
03778
03779
03780
03781
03782
03783
03784
03785
03786
03787
03788 #endif
03789