irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

general_update.cpp
Go to the documentation of this file.
1 
3 /*
4 
5  These routines provide the generalInsert and Delete row capabilities.
6  Admins (for now) are allowed to call these functions to add or remove
7  specified rows into certain tables. The arguments are similar to the
8  generalQuery in that columns are specified via the COL_ #defines.
9 
10  Currently, updates can only be done on a single table at a time.
11 
12  Initially, this was developed for use with a notification service which
13  was postponed and now may be used with rule tables.
14 */
15 #include "rodsGeneralUpdate.h"
16 
17 #include "rodsClient.h"
19 #include "mid_level.hpp"
20 #include "low_level.hpp"
21 
22 extern int sGetColumnInfo( int defineVal, char **tableName, char **columnName );
23 
24 extern int icatGeneralQuerySetup();
25 
26 int updateDebug = 0;
27 
28 extern int logSQLGenUpdate;
30 
31 int
32 generalInsert( generalUpdateInp_t generalUpdateInp ) {
33  int i, j;
34  char *tableName, *columnName;
35  char *firstTableName;
36  char nextSeqValueIndex = -1;
37  static char nextStr[MAX_NAME_LEN];
38  int doBind;
39  static char myTime[50];
40 
41  rstrcpy( tSQL, "insert into ", MAX_SQL_SIZE );
42 
43  for ( i = 0; i < generalUpdateInp.values.len; i++ ) {
44  j = sGetColumnInfo( generalUpdateInp.values.inx[i],
45  &tableName, &columnName );
46  if ( generalUpdateInp.values.inx[i] < MAX_CORE_TABLE_VALUE ) {
47  return ( CAT_TABLE_ACCESS_DENIED ); /* only extended icat tables allowed*/
48  }
49  if ( updateDebug ) {
50  printf( "j=%d\n", j );
51  }
52  if ( j == 0 ) {
53  if ( updateDebug ) {
54  printf( "tableName=%s\n", tableName );
55  }
56  if ( updateDebug ) {
57  printf( "columnName=%s\n", columnName );
58  }
59  }
60  else {
61  return j;
62  }
63 
64  doBind = 1;
65  if ( strncmp( generalUpdateInp.values.value[i],
67  /* caller requesting a next sequence */
68  cllNextValueString( "R_ExtObjectID", nextStr, MAX_NAME_LEN );
69  nextSeqValueIndex = i;
70  doBind = 0;
71  }
72  if ( i == 0 ) {
73  firstTableName = tableName;
75  rstrcat( tSQL, " (", MAX_SQL_SIZE );
77  if ( doBind ) {
78  if ( strncmp( generalUpdateInp.values.value[i],
79  UPDATE_NOW_TIME, MAX_NAME_LEN ) == 0 ) {
80  getNowStr( myTime );
81  cllBindVars[cllBindVarCount++] = myTime;
82  }
83  else {
84  cllBindVars[cllBindVarCount++] = generalUpdateInp.values.value[i];
85  }
86  }
87  }
88  else {
89  if ( strcmp( tableName, firstTableName ) != 0 ) {
90  return CAT_INVALID_ARGUMENT;
91  }
92  rstrcat( tSQL, ", ", MAX_SQL_SIZE );
94  if ( doBind ) {
95  if ( strncmp( generalUpdateInp.values.value[i],
96  UPDATE_NOW_TIME, MAX_NAME_LEN ) == 0 ) {
97  getNowStr( myTime );
98  cllBindVars[cllBindVarCount++] = myTime;
99  }
100  else {
101  cllBindVars[cllBindVarCount++] = generalUpdateInp.values.value[i];
102  }
103  }
104  }
105  }
106  if ( nextSeqValueIndex == 0 ) {
107  rstrcat( tSQL, ") values (", MAX_SQL_SIZE );
108  rstrcat( tSQL, nextStr, MAX_SQL_SIZE );
109  }
110  else {
111  rstrcat( tSQL, ") values (?", MAX_SQL_SIZE );
112  }
113  for ( i = 1; i < generalUpdateInp.values.len; i++ ) {
114  if ( nextSeqValueIndex == i ) {
115  rstrcat( tSQL, ", ", MAX_SQL_SIZE );
116  rstrcat( tSQL, nextStr, MAX_SQL_SIZE );
117  }
118  else {
119  rstrcat( tSQL, ", ?", MAX_SQL_SIZE );
120  }
121  }
122  rstrcat( tSQL, ")", MAX_SQL_SIZE );
123  if ( updateDebug ) {
124  printf( "tSQL: %s\n", tSQL );
125  }
126 
127  return 0;
128 }
129 
130 int
131 generalDelete( generalUpdateInp_t generalUpdateInp ) {
132  int i, j;
133  char *tableName, *columnName;
134  char *firstTableName;
135 
136  rstrcpy( tSQL, "delete from ", MAX_SQL_SIZE );
137 
138  for ( i = 0; i < generalUpdateInp.values.len; i++ ) {
139  if ( generalUpdateInp.values.inx[i] < MAX_CORE_TABLE_VALUE ) {
140  return ( CAT_TABLE_ACCESS_DENIED ); /* only extended icat tables allowed*/
141  }
142  j = sGetColumnInfo( generalUpdateInp.values.inx[i],
143  &tableName, &columnName );
144  if ( updateDebug ) {
145  printf( "j=%d\n", j );
146  }
147  if ( j == 0 ) {
148  if ( updateDebug ) {
149  printf( "tableName=%s\n", tableName );
150  }
151  if ( updateDebug ) {
152  printf( "columnName=%s\n", columnName );
153  }
154  }
155  else {
156  return j;
157  }
158  if ( i == 0 ) {
159  firstTableName = tableName;
161  rstrcat( tSQL, " where ", MAX_SQL_SIZE );
163  rstrcat( tSQL, " = ?", MAX_SQL_SIZE );
164  cllBindVars[cllBindVarCount++] = generalUpdateInp.values.value[i];
165  }
166  else {
167  if ( strcmp( tableName, firstTableName ) != 0 ) {
168  return CAT_INVALID_ARGUMENT;
169  }
170  rstrcat( tSQL, " and ", MAX_SQL_SIZE );
172  rstrcat( tSQL, " = ?", MAX_SQL_SIZE );
173  cllBindVars[cllBindVarCount++] = generalUpdateInp.values.value[i];
174  }
175  }
176  if ( updateDebug ) {
177  printf( "tSQL: %s\n", tSQL );
178  }
179  return 0;
180 }
181 
182 
183 /* General Update */
185  generalUpdateInp_t generalUpdateInp ) {
186  int status;
187  static int firstCall = 1;
189 
190  status = chlGetRcs( &icss );
191  if ( status < 0 || !icss ) {
192  return CAT_NOT_OPEN;
193  }
194 
195  /* result->rowCount=0; */
196 
197  if ( firstCall ) {
199  }
200  if ( generalUpdateInp.type == GENERAL_UPDATE_INSERT ) {
201  status = generalInsert( generalUpdateInp );
202  if ( status ) {
203  return status;
204  }
205  /* Since the sql string is lower case, this is not checked for
206  in ICAT test suite; removed since now this is only for
207  extented tables and so would be difficult to test */
208  if ( logSQLGenUpdate ) {
209  rodsLog( LOG_SQL, "chlGeneralUpdate sql 1" );
210  }
211  }
212  else {
213  if ( generalUpdateInp.type == GENERAL_UPDATE_DELETE ) {
214  status = generalDelete( generalUpdateInp );
215  if ( status ) {
216  return status;
217  }
218  if ( logSQLGenUpdate ) {
219  rodsLog( LOG_SQL, "chlGeneralUpdate sql 2" );
220  }
221  }
222  else {
223  return CAT_INVALID_ARGUMENT;
224  }
225  }
226 
228  if ( status != 0 ) {
229  rodsLog( LOG_NOTICE, "chlGeneralUpdate cmlExecuteNoAnswerSql insert failure %d", status );
230  int rollback_status = cmlExecuteNoAnswerSql( "rollback", icss ); // JMC - backport 4509
231  if ( rollback_status != 0 ) {
232  rodsLog( LOG_NOTICE, "rollback failed." );
233  }
234  return status;
235  }
236 
237  status = cmlExecuteNoAnswerSql( "commit", icss );
238  if ( status != 0 ) {
240  "chlGeneralUpdate cmlExecuteNoAnswerSql commit failure %d",
241  status );
242  return status;
243  }
244 
245  return 0;
246 }
247 
248 int
251  return 0;
252 }
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
rstrcat
char * rstrcat(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:75
irods.pyparsing.tableName
def tableName
Definition: pyparsing.py:3817
irods.pyparsing.columnName
def columnName
Definition: pyparsing.py:3815
UPDATE_NOW_TIME
#define UPDATE_NOW_TIME
Definition: rodsGeneralUpdate.h:24
logSQLGenUpdate
int logSQLGenUpdate
Definition: icatHighLevelRoutines.cpp:40
GeneralUpdateInp
Definition: rodsGeneralUpdate.h:27
rodsGeneralUpdate.h
chlDebugGenUpdate
int chlDebugGenUpdate(int mode)
Definition: general_update.cpp:249
CAT_NOT_OPEN
@ CAT_NOT_OPEN
Definition: rodsErrorTable.h:439
GENERAL_UPDATE_INSERT
#define GENERAL_UPDATE_INSERT
Definition: rodsGeneralUpdate.h:17
cllBindVarCount
int cllBindVarCount
Definition: low_level_odbc.cpp:47
updateDebug
int updateDebug
Definition: general_update.cpp:26
InxValPair::inx
int * inx
Definition: objInfo.h:215
getNowStr
void getNowStr(char *timeStr)
Definition: rcMisc.cpp:1590
tSQL
char tSQL[4000]
Definition: general_update.cpp:29
InxValPair::value
char ** value
Definition: objInfo.h:216
CAT_TABLE_ACCESS_DENIED
@ CAT_TABLE_ACCESS_DENIED
Definition: rodsErrorTable.h:457
GeneralUpdateInp::values
inxValPair_t values
Definition: rodsGeneralUpdate.h:29
sGetColumnInfo
int sGetColumnInfo(int defineVal, char **tableName, char **columnName)
Definition: general_query.cpp:235
cllNextValueString
int cllNextValueString(const char *itemName, char *outString, int maxSize)
Definition: low_level_odbc.cpp:928
GeneralUpdateInp::type
int type
Definition: rodsGeneralUpdate.h:28
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
mid_level.hpp
low_level.hpp
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
firstCall
int firstCall
Definition: general_query.cpp:51
cmlExecuteNoAnswerSql
int cmlExecuteNoAnswerSql(const char *sql, icatSessionStruct *icss)
Definition: mid_level_routines.cpp:151
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
InxValPair::len
int len
Definition: objInfo.h:214
icss
icatSessionStruct icss
Definition: db_plugin.cpp:97
generalInsert
int generalInsert(generalUpdateInp_t generalUpdateInp)
Definition: general_update.cpp:32
rodsClient.h
MAX_CORE_TABLE_VALUE
#define MAX_CORE_TABLE_VALUE
Definition: rodsGenQuery.h:113
GENERAL_UPDATE_DELETE
#define GENERAL_UPDATE_DELETE
Definition: rodsGeneralUpdate.h:18
icatHighLevelRoutines.hpp
LOG_SQL
#define LOG_SQL
Definition: rodsLog.h:9
CAT_INVALID_ARGUMENT
@ CAT_INVALID_ARGUMENT
Definition: rodsErrorTable.h:431
cllBindVars
const char * cllBindVars[32000]
Definition: low_level_odbc.cpp:48
generalDelete
int generalDelete(generalUpdateInp_t generalUpdateInp)
Definition: general_update.cpp:131
UPDATE_NEXT_SEQ_VALUE
#define UPDATE_NEXT_SEQ_VALUE
Definition: rodsGeneralUpdate.h:21
mode
int mode
Definition: filesystem.cpp:104
chlGetRcs
int chlGetRcs(icatSessionStruct **)
Definition: icatHighLevelRoutines.cpp:222
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
icatGeneralQuerySetup
int icatGeneralQuerySetup()
Definition: general_query_setup.cpp:35
chl_general_update_impl
int chl_general_update_impl(generalUpdateInp_t generalUpdateInp)
Definition: general_update.cpp:184
icatSessionStruct
Definition: icatStructs.hpp:26
MAX_SQL_SIZE
#define MAX_SQL_SIZE
Definition: icatDefines.h:16