1 #include <ei.h>
2 
3 #include <unistd.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <sqlrelay/sqlrclientwrapper.h>
8 
9 #define BUF_SIZE 2000
10 #define COL_NAME_SIZE 512 	// max length of column names
11 #define FILE_NAME_SIZE 512 	// max length of file name
12 #define TRUE 0
13 #define FALSE 1
14 #define DEBUG 0		// set to 1 for debugging, otherwise set to 0
15 
16 // define error codes
17 #define ERR_BINARY_TERM 	-1
18 #define ERR_PROTOCOL 		-2
19 #define ERR_NUMBER_OF_ARGS 	-3
20 #define ERR_DECODING_ARGS	-4
21 #define ERR_ENCODING_ARGS	-5
22 #define ERR_PREPARING_RESULTS	-6
23 #define ERR_PROCESSING_QUERY	-7
24 #define ERR_ROW_OUT_OF_RANGE	-8
25 #define ERR_COL_OUT_OF_RANGE	-9
26 
27 // type definitions
28 typedef char byte;
29 typedef unsigned long ulong;
30 
31 // global variables
32 sqlrcon con;
33 sqlrcur cur;
34 
35 // define functions
36 int read_cmd(byte *buf, int *size);
37 int write_cmd(ei_x_buff* x);
38 int read_exact(byte *buf, int len);
39 int write_exact(byte *buf, int len);
40 int rowCount();
41 int colCount();
42 
43 #define ENCODE_VOID 	if (ei_x_encode_atom(&result, "ok") || ei_x_encode_string(&result, "void")) { return ERR_ENCODING_ARGS; }
44 
45 
46 /*-----------------------------------------------------------------
47  * Utility functions
48  *----------------------------------------------------------------*/
49 
50 // check that the given row is within the limits of the cursor
checkRowLimitsOK(int row)51 int checkRowLimitsOK(int row) {
52 	if (row < 0 || row >= rowCount(cur)) {
53 		return FALSE;
54 	} else {
55 		return TRUE;
56 	}
57 }
58 
59 // check that the given column is within the limits of the cursor
checkColLimitsOK(int col)60 int checkColLimitsOK(int col) {
61 	if (col < 0 || col >= colCount(cur)) {
62 		return FALSE;
63 	} else {
64 		return TRUE;
65 	}
66 }
67 
signalError(ei_x_buff * result,long err)68 void signalError(ei_x_buff *result, long err) {
69 	ei_x_encode_atom(result, "error");
70 	ei_x_encode_long(result, err);
71 }
72 
73 /*-----------------------------------------------------------------
74  * API functions
75  *----------------------------------------------------------------*/
76 
alloc(char * server,ulong port,char * socket,char * user,char * password,ulong retrytime,ulong tries)77 long alloc(char *server, ulong port, char *socket, char *user, char *password, ulong retrytime, ulong tries) {
78 	if (DEBUG) {
79 		fprintf(stderr, "Processing alloc with arguments: %s, %ld, %s, %s, %s, %ld, %ld\n\r", server, port, socket, user, password, retrytime, tries);
80 	}
81 
82 	con = sqlrcon_alloc(server, port, socket, user, password, retrytime, tries);
83 
84 	return 0;
85 }
86 
87 
88 
sendQuery(char * sql)89 int sendQuery(char *sql) {
90 	if (DEBUG) {
91 		fprintf(stderr, "Processing sendQuery %s\n\r", sql);
92 	}
93 
94 	cur = sqlrcur_alloc(con);
95 	return(sqlrcur_sendQuery(cur, sql));
96 }
97 
sendQueryWithLength(char * sql,uint32_t length)98 int sendQueryWithLength(char *sql, uint32_t length) {
99 	cur = sqlrcur_alloc(con);
100 	return(sqlrcur_sendQueryWithLength(cur, sql, length));
101 }
102 
sendFileQuery(char * path,char * filename)103 int sendFileQuery(char *path, char *filename) {
104 	cur = sqlrcur_alloc(con);
105 	return(sqlrcur_sendFileQuery(cur, path, filename));
106 }
107 
prepareQuery(char * sql)108 int prepareQuery(char *sql) {
109 	if (DEBUG) {
110 		fprintf(stderr, "Processing prepareQuery %s\n\r", sql);
111 	}
112 
113 	cur = sqlrcur_alloc(con);
114 	sqlrcur_prepareQuery(cur, sql);
115 	return 0;
116 }
117 
prepareQueryWithLength(char * sql,uint32_t length)118 int prepareQueryWithLength(char *sql, uint32_t length) {
119 	cur = sqlrcur_alloc(con);
120 	sqlrcur_prepareQueryWithLength(cur, sql, length);
121 	return 0;
122 }
123 
prepareFileQuery(char * path,char * filename)124 int prepareFileQuery(char *path, char *filename) {
125 	cur = sqlrcur_alloc(con);
126 	sqlrcur_prepareFileQuery(cur, path, filename);
127 	return 0;
128 }
129 
130 
131 
colCount()132 int colCount() {
133 	return (sqlrcur_colCount(cur));
134 }
135 
rowCount()136 int rowCount() {
137 	return (sqlrcur_rowCount(cur));
138 }
139 
140 
141 
142 
143 
144 /*-----------------------------------------------------------------
145  * MAIN
146  *----------------------------------------------------------------*/
main()147 int main() {
148   	byte 	  *buf;
149   	int       size = BUF_SIZE;
150   	char      command[MAXATOMLEN];
151   	int       index, version, arity;
152 	int 	  err;
153   	ei_x_buff result;
154 
155   	if ((buf = (byte *) malloc(size)) == NULL)
156     		return -1;
157 
158 	// main loop
159   	while (read_cmd(buf, &size) > 0) {
160     		// Reset the index, so that ei functions can decode terms from the  beginning of the buffer
161     		index = 0;
162 
163     		// Ensure that we are receiving the binary term by reading and stripping the version byte
164     		if (ei_decode_version(buf, &index, &version)) {
165 			return ERR_BINARY_TERM;
166 		}
167 
168     		// Get the number of arguments
169     		if (ei_decode_tuple_header(buf, &index, &arity)) {
170 			return ERR_PROTOCOL;
171 		} else {
172 			--arity;	// remove the command name from the argument count
173 		}
174 
175 		// Get the command
176     		if (ei_decode_atom(buf, &index, command)) {
177 			return ERR_PROTOCOL;
178 		}
179 
180     		// Prepare the output buffer that will hold {ok, Result} or {error, Reason}
181     		if (ei_x_new_with_version(&result) || ei_x_encode_tuple_header(&result, 2)) {
182 			return ERR_PREPARING_RESULTS;
183 		}
184 
185 
186 		//
187 		// process command
188 		//
189 		if (DEBUG) {
190 			fprintf(stderr, "Received command %s, number of arguments is %d\n\r", command, arity);
191    		}
192 
193 		if (strcmp("alloc", command) == TRUE) {
194 			char server[30];
195                 	unsigned long port;
196                 	char socket[30];
197                 	char user[30];
198                 	char password[30];
199                 	unsigned long retrytime;
200                 	unsigned long tries;
201 			long c;
202 
203 			// check number of arguments
204 		    	if (arity != 7) return ERR_NUMBER_OF_ARGS;
205 
206 			// get input parameters
207 			if (ei_decode_string(buf, &index, &server[0])) {
208 				return ERR_DECODING_ARGS;
209 			}
210 			if (ei_decode_ulong(buf, &index, &port)) {
211 				return ERR_DECODING_ARGS;
212 			}
213 			if (ei_decode_string(buf, &index, &socket[0])) {
214 				return ERR_DECODING_ARGS;
215 			}
216 			if (ei_decode_string(buf, &index, &user[0])) {
217 				return ERR_DECODING_ARGS;
218 			}
219 			if (ei_decode_string(buf, &index, &password[0])) {
220 				return ERR_DECODING_ARGS;
221 			}
222 			if (ei_decode_ulong(buf, &index, &retrytime)) {
223 				return ERR_DECODING_ARGS;
224 			}
225 			if (ei_decode_ulong(buf, &index, &tries)) {
226 				return ERR_DECODING_ARGS;
227 			}
228 
229 			// call function
230 			c = alloc(server, port, socket, user, password, retrytime, tries);
231 
232 			// encode result
233 			if (ei_x_encode_atom(&result, "ok") ||
234 				ei_x_encode_long(&result, c)) {
235 				return ERR_ENCODING_ARGS;
236 			}
237 		}
238 
239 		if (strcmp("ping", command) == TRUE) {
240 			// check number of arguments
241 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
242 
243 			// call function and encode result
244 			if (ei_x_encode_atom(&result, "ok") ||
245 				ei_x_encode_long(&result, sqlrcon_ping(con))) {
246 				return ERR_ENCODING_ARGS;
247 			}
248 		}
249 
250 		if (strcmp("connectionFree", command) == TRUE) {
251 			// check number of arguments
252 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
253 
254 			// call function and encode result
255 			sqlrcon_free(con);
256 			ENCODE_VOID;
257 		}
258 
259 		if (strcmp("cursorFree", command) == TRUE) {
260 			// check number of arguments
261 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
262 
263 			// call function and encode result
264 			sqlrcur_free(cur);
265 			ENCODE_VOID;
266 		}
267 
268 
269 		if (strcmp("setConnectTimeout", command) == TRUE) {
270                 	long timeoutsec;
271                 	long timeoutusec;
272 
273 			// check number of arguments
274 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
275 
276 			if (ei_decode_long(buf, &index, &timeoutsec)) {
277 				return ERR_DECODING_ARGS;
278 			}
279 
280 			if (ei_decode_long(buf, &index, &timeoutusec)) {
281 				return ERR_DECODING_ARGS;
282 			}
283 
284 			// call function and encode result
285 			sqlrcon_setConnectTimeout(con,timeoutsec,timeoutusec);
286 			ENCODE_VOID;
287 		}
288 
289 
290 		if (strcmp("setAuthenticationTimeout", command) == TRUE) {
291                 	long timeoutsec;
292                 	long timeoutusec;
293 
294 			// check number of arguments
295 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
296 
297 			if (ei_decode_long(buf, &index, &timeoutsec)) {
298 				return ERR_DECODING_ARGS;
299 			}
300 
301 			if (ei_decode_long(buf, &index, &timeoutusec)) {
302 				return ERR_DECODING_ARGS;
303 			}
304 
305 			// call function and encode result
306 			sqlrcon_setAuthenticationTimeout(con,timeoutsec,timeoutusec);
307 			ENCODE_VOID;
308 		}
309 
310 
311 		if (strcmp("setResponseTimeout", command) == TRUE) {
312                 	long timeoutsec;
313                 	long timeoutusec;
314 
315 			// check number of arguments
316 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
317 
318 			if (ei_decode_long(buf, &index, &timeoutsec)) {
319 				return ERR_DECODING_ARGS;
320 			}
321 
322 			if (ei_decode_long(buf, &index, &timeoutusec)) {
323 				return ERR_DECODING_ARGS;
324 			}
325 
326 			// call function and encode result
327 			sqlrcon_setResponseTimeout(con,timeoutsec,timeoutusec);
328 			ENCODE_VOID;
329 		}
330 
331 		if (strcmp("setBindVariableDelimiters", command) == TRUE) {
332 			char delimiters[128];
333 
334 			// check number of arguments
335 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
336 
337 			// get input parameters
338 			if (ei_decode_string(buf, &index, &delimiters[0])) {
339 				return ERR_DECODING_ARGS;
340 			}
341 
342 			sqlrcon_setBindVariableDelimiters(con, delimiters);
343 			ENCODE_VOID;
344 		}
345 
346 		if (strcmp("getBindVariableDelimiterQuestionMarkSupported", command) == TRUE) {
347 			// check number of arguments
348 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
349 
350 			// call function and encode result
351 			if (ei_x_encode_atom(&result, "ok") ||
352 				ei_x_encode_long(&result, sqlrcon_getBindVariableDelimiterQuestionMarkSupported(con))) {
353 				return ERR_ENCODING_ARGS;
354 			}
355 		}
356 
357 		if (strcmp("getBindVariableDelimiterColonSupported", command) == TRUE) {
358 			// check number of arguments
359 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
360 
361 			// call function and encode result
362 			if (ei_x_encode_atom(&result, "ok") ||
363 				ei_x_encode_long(&result, sqlrcon_getBindVariableDelimiterColonSupported(con))) {
364 				return ERR_ENCODING_ARGS;
365 			}
366 		}
367 
368 		if (strcmp("getBindVariableDelimiterAtSignSupported", command) == TRUE) {
369 			// check number of arguments
370 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
371 
372 			// call function and encode result
373 			if (ei_x_encode_atom(&result, "ok") ||
374 				ei_x_encode_long(&result, sqlrcon_getBindVariableDelimiterAtSignSupported(con))) {
375 				return ERR_ENCODING_ARGS;
376 			}
377 		}
378 
379 		if (strcmp("getBindVariableDelimiterDollarSignSupported", command) == TRUE) {
380 			// check number of arguments
381 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
382 
383 			// call function and encode result
384 			if (ei_x_encode_atom(&result, "ok") ||
385 				ei_x_encode_long(&result, sqlrcon_getBindVariableDelimiterDollarSignSupported(con))) {
386 				return ERR_ENCODING_ARGS;
387 			}
388 		}
389 
390 		if (strcmp("enableKerberos", command) == TRUE) {
391                 	char service[128];
392 			char mech[128];
393 			char flags[512];
394 
395 			// check number of arguments
396 		    	if (arity != 3) return ERR_NUMBER_OF_ARGS;
397 
398 			// get arguments
399 			if (ei_decode_string(buf, &index, &service[0])) {
400 				return ERR_DECODING_ARGS;
401 			}
402 			if (ei_decode_string(buf, &index, &mech[0])) {
403 				return ERR_DECODING_ARGS;
404 			}
405 			if (ei_decode_string(buf, &index, &flags[0])) {
406 				return ERR_DECODING_ARGS;
407 			}
408 
409 			sqlrcon_enableKerberos(con,service,mech,flags);
410 			ENCODE_VOID;
411 		}
412 
413 		if (strcmp("enableTls", command) == TRUE) {
414                 	char version[128];
415                 	char cert[1024];
416 			char password[128];
417 			char ciphers[1024];
418 			char validate[16];
419 			char ca[1024];
420 			long depth;
421 
422 			// check number of arguments
423 		    	if (arity != 3) return ERR_NUMBER_OF_ARGS;
424 
425 			// get arguments
426 			if (ei_decode_string(buf, &index, &version[0])) {
427 				return ERR_DECODING_ARGS;
428 			}
429 			if (ei_decode_string(buf, &index, &cert[0])) {
430 				return ERR_DECODING_ARGS;
431 			}
432 			if (ei_decode_string(buf, &index, &password[0])) {
433 				return ERR_DECODING_ARGS;
434 			}
435 			if (ei_decode_string(buf, &index, &ciphers[0])) {
436 				return ERR_DECODING_ARGS;
437 			}
438 			if (ei_decode_string(buf, &index, &validate[0])) {
439 				return ERR_DECODING_ARGS;
440 			}
441 			if (ei_decode_string(buf, &index, &ca[0])) {
442 				return ERR_DECODING_ARGS;
443 			}
444 			if (ei_decode_long(buf, &index, &depth)) {
445 				return ERR_DECODING_ARGS;
446 			}
447 
448 			sqlrcon_enableTls(con,version,cert,password,ciphers,validate,ca,depth);
449 			ENCODE_VOID;
450 		}
451 
452 		if (strcmp("disableEncryption", command) == TRUE) {
453 			// check number of arguments
454 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
455 
456 			// call function and encode result
457 			sqlrcon_disableEncryption(con);
458 			ENCODE_VOID;
459 		}
460 
461 		if (strcmp("endSession", command) == TRUE) {
462 			// check number of arguments
463 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
464 
465 			// call function and encode result
466 			sqlrcon_endSession(con);
467 			ENCODE_VOID;
468 		}
469 
470 		if (strcmp("suspendSession", command) == TRUE) {
471 			// check number of arguments
472 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
473 
474 			// call function and encode result
475 			sqlrcon_suspendSession(con);
476 			ENCODE_VOID;
477 		}
478 
479 		if (strcmp("getConnectionPort", command) == TRUE) {
480 			// check number of arguments
481 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
482 
483 			// call function and encode result
484 			if (ei_x_encode_atom(&result, "ok") ||
485 				ei_x_encode_long(&result, sqlrcon_getConnectionPort(con))) {
486 				return ERR_ENCODING_ARGS;
487 			}
488 		}
489 
490 		if (strcmp("getConnectionSocket", command) == TRUE) {
491 			// check number of arguments
492 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
493 
494 			// call function and encode result
495 			if (ei_x_encode_atom(&result, "ok") ||
496 				ei_x_encode_string(&result, sqlrcon_getConnectionSocket(con))) {
497 				return ERR_ENCODING_ARGS;
498 			}
499 		}
500 
501 		if (strcmp("resumeSession", command) == TRUE) {
502                 	unsigned long port;
503                 	char socket[30];
504 
505 			// check number of arguments
506 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
507 
508 			// get arguments
509 			if (ei_decode_ulong(buf, &index, &port)) {
510 				return ERR_DECODING_ARGS;
511 			}
512 			if (ei_decode_string(buf, &index, &socket[0])) {
513 				return ERR_DECODING_ARGS;
514 			}
515 
516 			// encode result
517 			if (ei_x_encode_atom(&result, "ok") ||
518 				ei_x_encode_long(&result,  sqlrcon_resumeSession(con, port, socket))) {
519 				return ERR_ENCODING_ARGS;
520 			}
521 		}
522 
523 		if (strcmp("identify", command) == TRUE) {
524 			// check number of arguments
525 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
526 
527 			// encode result
528 			if (ei_x_encode_atom(&result, "ok") ||
529 				ei_x_encode_string(&result, sqlrcon_identify(con) )) {
530 				return ERR_ENCODING_ARGS;
531 			}
532 		}
533 
534 		if (strcmp("dbVersion", command) == TRUE) {
535 			// check number of arguments
536 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
537 
538 			// encode result
539 			if (ei_x_encode_atom(&result, "ok") ||
540 				ei_x_encode_string(&result, sqlrcon_dbVersion(con))) {
541 				return ERR_ENCODING_ARGS;
542 			}
543 		}
544 
545 		if (strcmp("dbHostName", command) == TRUE) {
546 			// check number of arguments
547 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
548 
549 			// encode result
550 			if (ei_x_encode_atom(&result, "ok") ||
551 				ei_x_encode_string(&result, sqlrcon_dbHostName(con))) {
552 				return ERR_ENCODING_ARGS;
553 			}
554 		}
555 
556 		if (strcmp("dbIpAddress", command) == TRUE) {
557 			// check number of arguments
558 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
559 
560 			// encode result
561 			if (ei_x_encode_atom(&result, "ok") ||
562 				ei_x_encode_string(&result, sqlrcon_dbIpAddress(con))) {
563 				return ERR_ENCODING_ARGS;
564 			}
565 		}
566 
567 		if (strcmp("bindFormat", command) == TRUE) {
568 			// check number of arguments
569 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
570 
571 			// encode result
572 			if (ei_x_encode_atom(&result, "ok") ||
573 				ei_x_encode_string(&result, sqlrcon_bindFormat(con))) {
574 				return ERR_ENCODING_ARGS;
575 			}
576 		}
577 
578 		if (strcmp("selectDatabase", command) == TRUE) {
579 			char database[2000];
580 
581 			// check number of arguments
582 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
583 
584 			// get input parameters
585 			if (ei_decode_string(buf, &index, &database[0])) {
586 				return ERR_DECODING_ARGS;
587 			}
588 
589 			// call function and encode result
590 			sqlrcon_selectDatabase(con, database);
591 			ENCODE_VOID;
592 		}
593 
594 		if (strcmp("getCurrentDatabase", command) == TRUE) {
595 			// check number of arguments
596 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
597 
598 			// encode result
599 			if (ei_x_encode_atom(&result, "ok") ||
600 				ei_x_encode_string(&result, sqlrcon_getCurrentDatabase(con))) {
601 				return ERR_ENCODING_ARGS;
602 			}
603 		}
604 
605 		if (strcmp("getLastInsertId", command) == TRUE) {
606 			// check number of arguments
607 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
608 
609 			// encode result
610 			if (ei_x_encode_atom(&result, "ok") ||
611 				ei_x_encode_long(&result, sqlrcon_getLastInsertId(con))) {
612 				return ERR_ENCODING_ARGS;
613 			}
614 		}
615 
616 		if (strcmp("autoCommitOn", command) == TRUE) {
617 			// check number of arguments
618 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
619 
620 			// call function and encode result
621 			if (ei_x_encode_atom(&result, "ok") ||
622 				ei_x_encode_long(&result, sqlrcon_autoCommitOn(con))) {
623 				return ERR_ENCODING_ARGS;
624 			}
625 		}
626 
627 		if (strcmp("autoCommitOff", command) == TRUE) {
628 			// check number of arguments
629 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
630 
631 			// call function and encode result
632 			if (ei_x_encode_atom(&result, "ok") ||
633 				ei_x_encode_long(&result, sqlrcon_autoCommitOff(con))) {
634 				return ERR_ENCODING_ARGS;
635 			}
636 		}
637 
638 		if (strcmp("beginTransaction", command) == TRUE) {
639 			// check number of arguments
640 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
641 
642 			// call function and encode result
643 			if (ei_x_encode_atom(&result, "ok") ||
644 				ei_x_encode_long(&result, sqlrcon_begin(con))) {
645 				return ERR_ENCODING_ARGS;
646 			}
647 		}
648 
649 		if (strcmp("commit", command) == TRUE) {
650 			// check number of arguments
651 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
652 
653 			// call function and encode result
654 			if (ei_x_encode_atom(&result, "ok") ||
655 				ei_x_encode_long(&result, sqlrcon_commit(con))) {
656 				return ERR_ENCODING_ARGS;
657 			}
658 		}
659 
660 		if (strcmp("rollback", command) == TRUE) {
661 			// check number of arguments
662 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
663 
664 			// call function and encode result
665 			if (ei_x_encode_atom(&result, "ok") ||
666 				ei_x_encode_long(&result, sqlrcon_rollback(con))) {
667 				return ERR_ENCODING_ARGS;
668 			}
669 		}
670 
671 		if (strcmp("connectionErrorMessage", command) == TRUE) {
672 			// check number of arguments
673 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
674 
675 			// encode result
676 			if (ei_x_encode_atom(&result, "ok") ||
677 				ei_x_encode_string(&result, sqlrcon_errorMessage(con) )) {
678 				return ERR_ENCODING_ARGS;
679 			}
680 		}
681 
682 		if (strcmp("connectionErrorNumber", command) == TRUE) {
683 			// check number of arguments
684 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
685 
686 			// encode result
687 			if (ei_x_encode_atom(&result, "ok") ||
688 				ei_x_encode_long(&result, sqlrcon_errorNumber(con) )) {
689 				return ERR_ENCODING_ARGS;
690 			}
691 		}
692 
693 		if (strcmp("debugOn", command) == TRUE) {
694 			// check number of arguments
695 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
696 
697 			// call function and encode result
698 			sqlrcon_debugOn(con);
699 			ENCODE_VOID;
700 		}
701 
702 		if (strcmp("debugOff", command) == TRUE) {
703 			// check number of arguments
704 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
705 
706 			// call function and encode result
707 			sqlrcon_debugOff(con);
708 			ENCODE_VOID;
709 		}
710 
711 		if (strcmp("getDebug", command) == TRUE) {
712 			// check number of arguments
713 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
714 
715 			// call function and encode result
716 			if (ei_x_encode_atom(&result, "ok") ||
717 				ei_x_encode_long(&result, sqlrcon_getDebug(con))) {
718 				return ERR_ENCODING_ARGS;
719 			}
720 		}
721 
722 		if (strcmp("setDebugFile", command) == TRUE) {
723 			char debugfile[2000];
724 
725 			// check number of arguments
726 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
727 
728 			// get input parameters
729 			if (ei_decode_string(buf, &index, &debugfile[0])) {
730 				return ERR_DECODING_ARGS;
731 			}
732 
733 			// call function and encode result
734 			sqlrcon_setDebugFile(con, debugfile);
735 			ENCODE_VOID;
736 		}
737 
738 		if (strcmp("setClientInfo", command) == TRUE) {
739 			char clientinfo[2000];
740 
741 			// check number of arguments
742 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
743 
744 			// get input parameters
745 			if (ei_decode_string(buf, &index, &clientinfo[0])) {
746 				return ERR_DECODING_ARGS;
747 			}
748 
749 			// call function and encode result
750 			sqlrcon_setClientInfo(con, clientinfo);
751 			ENCODE_VOID;
752 		}
753 
754 		if (strcmp("getClientInfo", command) == TRUE) {
755 			// check number of arguments
756 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
757 
758 			// encode result
759 			if (ei_x_encode_atom(&result, "ok") ||
760 				ei_x_encode_string(&result, sqlrcon_getClientInfo(con))) {
761 				return ERR_ENCODING_ARGS;
762 			}
763 		}
764 
765 		if (strcmp("setResultSetBufferSize", command) == TRUE) {
766                 	unsigned long rows;
767 
768 			// check number of arguments
769 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
770 
771 			// get input parameters
772 			if (ei_decode_long(buf, &index, &rows)) {
773 				return ERR_DECODING_ARGS;
774 			}
775 
776 			// call function and encode result
777 			sqlrcur_setResultSetBufferSize(cur, rows);
778 			ENCODE_VOID;
779 		}
780 
781 		if (strcmp("getResultSetBufferSize", command) == TRUE) {
782 			// check number of arguments
783 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
784 
785 			// call function and encode result
786 			if (ei_x_encode_atom(&result, "ok") ||
787 				ei_x_encode_long(&result, sqlrcur_getResultSetBufferSize(cur))) {
788 				return ERR_ENCODING_ARGS;
789 			}
790 		}
791 
792 		if (strcmp("dontGetColumnInfo", command) == TRUE) {
793 			// check number of arguments
794 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
795 
796 			// call function and encode result
797 			sqlrcur_dontGetColumnInfo(cur);
798 			ENCODE_VOID;
799 		}
800 
801 		if (strcmp("getColumnInfo", command) == TRUE) {
802 			// check number of arguments
803 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
804 
805 			// call function and encode result
806 			sqlrcur_getColumnInfo(cur);
807 			ENCODE_VOID;
808 		}
809 
810 		if (strcmp("mixedCaseColumnNames", command) == TRUE) {
811 			// check number of arguments
812 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
813 
814 			// call function and encode result
815 			sqlrcur_mixedCaseColumnNames(cur);
816 			ENCODE_VOID;
817 		}
818 
819 		if (strcmp("upperCaseColumnNames", command) == TRUE) {
820 			// check number of arguments
821 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
822 
823 			// call function and encode result
824 			sqlrcur_upperCaseColumnNames(cur);
825 			ENCODE_VOID;
826 		}
827 
828 		if (strcmp("lowerCaseColumnNames", command) == TRUE) {
829 			// check number of arguments
830 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
831 
832 			// call function and encode result
833 			sqlrcur_lowerCaseColumnNames(cur);
834 			ENCODE_VOID;
835 		}
836 
837 		if (strcmp("cacheToFile", command) == TRUE) {
838 			char filename[2000];
839 
840 			// check number of arguments
841 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
842 
843 			// get input parameters
844 			if (ei_decode_string(buf, &index, &filename[0])) {
845 				return ERR_DECODING_ARGS;
846 			}
847 
848 			// call function and encode result
849 			sqlrcur_cacheToFile(cur, filename);
850 			ENCODE_VOID;
851 		}
852 
853 		if (strcmp("setCacheTtl", command) == TRUE) {
854                 	unsigned long ttl;
855 
856 			// check number of arguments
857 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
858 
859 			// get input parameters
860 			if (ei_decode_long(buf, &index, &ttl)) {
861 				return ERR_DECODING_ARGS;
862 			}
863 
864 			// call function and encode result
865 			sqlrcur_setCacheTtl(cur, ttl);
866 			ENCODE_VOID;
867 		}
868 
869 		if (strcmp("getCacheFileName", command) == TRUE) {
870 			// check number of arguments
871 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
872 
873 			// call function and encode result
874 			if (ei_x_encode_atom(&result, "ok") ||
875 				ei_x_encode_string(&result, sqlrcur_getCacheFileName(cur))) {
876 				return ERR_ENCODING_ARGS;
877 			}
878 		}
879 
880 		if (strcmp("getDatabaseList", command) == TRUE) {
881 			char wild[2000];
882 
883 			// check number of arguments
884 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
885 
886 			// get input parameters
887 			if (ei_decode_string(buf, &index, &wild[0])) {
888 				return ERR_DECODING_ARGS;
889 			}
890 
891 			// call function and encode result
892 			sqlrcur_getDatabaseList(cur, wild);
893 			ENCODE_VOID;
894 		}
895 
896 		if (strcmp("getTableList", command) == TRUE) {
897 			char wild[2000];
898 
899 			// check number of arguments
900 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
901 
902 			// get input parameters
903 			if (ei_decode_string(buf, &index, &wild[0])) {
904 				return ERR_DECODING_ARGS;
905 			}
906 
907 			// call function and encode result
908 			sqlrcur_getTableList(cur, wild);
909 			ENCODE_VOID;
910 		}
911 
912 		if (strcmp("getColumnList", command) == TRUE) {
913 			char table[2000];
914 			char wild[2000];
915 
916 			// check number of arguments
917 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
918 
919 			// get input parameters
920 			if (ei_decode_string(buf, &index, &table[0])) {
921 				return ERR_DECODING_ARGS;
922 			}
923 			if (ei_decode_string(buf, &index, &wild[0])) {
924 				return ERR_DECODING_ARGS;
925 			}
926 
927 			// call function and encode result
928 			sqlrcur_getColumnList(cur, table, wild);
929 			ENCODE_VOID;
930 		}
931 
932 		if (strcmp("cacheOff", command) == TRUE) {
933 			// check number of arguments
934 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
935 
936 			// call function and encode result
937 			sqlrcur_cacheOff(cur);
938 			ENCODE_VOID;
939 		}
940 
941 
942 		if (strcmp("sendQuery", command) == TRUE) {
943 			char sql[2000];
944 
945 			// check number of arguments
946 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
947 
948 			// get input parameters
949 			if (ei_decode_string(buf, &index, &sql[0])) {
950 				return ERR_DECODING_ARGS;
951 			}
952 
953 			// encode result
954 			if (ei_x_encode_atom(&result, "ok") ||
955 				ei_x_encode_long(&result, sendQuery(sql))) {
956 				return ERR_ENCODING_ARGS;
957 			}
958 		}
959 
960 		if (strcmp("sendQueryWithLength", command) == TRUE) {
961 			char sql[2000];
962 			long length;
963 
964 			// check number of arguments
965 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
966 
967 			// get input parameters
968 			if (ei_decode_string(buf, &index, &sql[0])) {
969 				return ERR_DECODING_ARGS;
970 			}
971 			if (ei_decode_long(buf, &index, &length)) {
972 				return ERR_DECODING_ARGS;
973 			}
974 
975 			// encode result
976 			if (ei_x_encode_atom(&result, "ok") ||
977 				ei_x_encode_long(&result, sendQueryWithLength(sql, length))) {
978 				return ERR_ENCODING_ARGS;
979 			}
980 		}
981 
982 		if (strcmp("sendFileQuery", command) == TRUE) {
983 			char path[2000];
984 			char filename[2000];
985 
986 			// check number of arguments
987 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
988 
989 			// get input parameters
990 			if (ei_decode_string(buf, &index, &path[0])) {
991 				return ERR_DECODING_ARGS;
992 			}
993 			if (ei_decode_string(buf, &index, &filename[0])) {
994 				return ERR_DECODING_ARGS;
995 			}
996 
997 			// encode result
998 			if (ei_x_encode_atom(&result, "ok") ||
999 				ei_x_encode_long(&result, sendFileQuery(path, filename))) {
1000 				return ERR_ENCODING_ARGS;
1001 			}
1002 		}
1003 
1004 		if (strcmp("prepareQuery", command) == TRUE) {
1005 			char sql[2000];
1006 
1007 			// check number of arguments
1008 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
1009 
1010 			// get input parameters
1011 			if (ei_decode_string(buf, &index, &sql[0])) {
1012 				return ERR_DECODING_ARGS;
1013 			}
1014 
1015 			// encode result
1016 			if (ei_x_encode_atom(&result, "ok") ||
1017 				ei_x_encode_long(&result, prepareQuery(sql))) {
1018 				return ERR_ENCODING_ARGS;
1019 			}
1020 		}
1021 
1022 		if (strcmp("prepareQueryWithLength", command) == TRUE) {
1023 			char sql[2000];
1024 			long length;
1025 
1026 			// check number of arguments
1027 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
1028 
1029 			// get input parameters
1030 			if (ei_decode_string(buf, &index, &sql[0])) {
1031 				return ERR_DECODING_ARGS;
1032 			}
1033 			if (ei_decode_long(buf, &index, &length)) {
1034 				return ERR_DECODING_ARGS;
1035 			}
1036 
1037 			// encode result
1038 			if (ei_x_encode_atom(&result, "ok") ||
1039 				ei_x_encode_long(&result, prepareQueryWithLength(sql, length))) {
1040 				return ERR_ENCODING_ARGS;
1041 			}
1042 		}
1043 
1044 		if (strcmp("prepareFileQuery", command) == TRUE) {
1045 			char path[2000];
1046 			char filename[2000];
1047 
1048 			// check number of arguments
1049 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
1050 
1051 			// get input parameters
1052 			if (ei_decode_string(buf, &index, &path[0])) {
1053 				return ERR_DECODING_ARGS;
1054 			}
1055 			if (ei_decode_string(buf, &index, &filename[0])) {
1056 				return ERR_DECODING_ARGS;
1057 			}
1058 
1059 			// encode result
1060 			if (ei_x_encode_atom(&result, "ok") ||
1061 				ei_x_encode_long(&result, prepareFileQuery(path, filename) )) {
1062 				return ERR_ENCODING_ARGS;
1063 			}
1064 		}
1065 
1066 
1067 		if (strcmp("subString", command) == TRUE) {
1068 			char variable[2000];
1069 			char value[2000];
1070 
1071 			// check number of arguments
1072 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
1073 
1074 			// get input parameters
1075 			if (ei_decode_string(buf, &index, &variable[0])) {
1076 				return ERR_DECODING_ARGS;
1077 			}
1078 			if (ei_decode_string(buf, &index, &value[0])) {
1079 				return ERR_DECODING_ARGS;
1080 			}
1081 
1082 			// call function and encode result
1083 			sqlrcur_subString(cur, variable, value);
1084 			ENCODE_VOID;
1085 		}
1086 
1087 
1088 		if (strcmp("subLong", command) == TRUE) {
1089 			char variable[2000];
1090 			long value;
1091 
1092 			// check number of arguments
1093 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
1094 
1095 			// get input parameters
1096 			if (ei_decode_string(buf, &index, &variable[0])) {
1097 				return ERR_DECODING_ARGS;
1098 			}
1099 			if (ei_decode_long(buf, &index, &value)) {
1100 				return ERR_DECODING_ARGS;
1101 			}
1102 
1103 			// call function and encode result
1104 			sqlrcur_subLong(cur, variable, value);
1105 			ENCODE_VOID;
1106 		}
1107 
1108 		if (strcmp("subDouble", command) == TRUE) {
1109 			char variable[2000];
1110 			double value;
1111 			long precision;
1112 			long scale;
1113 
1114 			// check number of arguments
1115 		    	if (arity != 4) return ERR_NUMBER_OF_ARGS;
1116 
1117 			// get input parameters
1118 			if (ei_decode_string(buf, &index, &variable[0])) {
1119 				return ERR_DECODING_ARGS;
1120 			}
1121 			if (ei_decode_double(buf, &index, &value)) {
1122 				return ERR_DECODING_ARGS;
1123 			}
1124 			if (ei_decode_long(buf, &index, &precision)) {
1125 				return ERR_DECODING_ARGS;
1126 			}
1127 			if (ei_decode_long(buf, &index, &scale)) {
1128 				return ERR_DECODING_ARGS;
1129 			}
1130 
1131 			// call function and encode result
1132 			sqlrcur_subDouble(cur, variable, value, precision, scale);
1133 			ENCODE_VOID;
1134 		}
1135 
1136 		if (strcmp("clearBinds", command) == TRUE) {
1137 			// check number of arguments
1138 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
1139 
1140 			// call function and encode result
1141 			sqlrcur_clearBinds(cur);
1142 			ENCODE_VOID;
1143 		}
1144 
1145 		if (strcmp("countBindVariables", command) == TRUE) {
1146 			// check number of arguments
1147 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
1148 
1149 			// encode result
1150 			if (ei_x_encode_atom(&result, "ok") ||
1151 				ei_x_encode_long(&result, sqlrcur_countBindVariables(cur) )) {
1152 				return ERR_ENCODING_ARGS;
1153 			}
1154 		}
1155 
1156 
1157 		if (strcmp("inputBindString", command) == TRUE) {
1158 			char variable[2000];
1159 			char value[2000];
1160 
1161 			// check number of arguments
1162 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
1163 
1164 			// get input parameters
1165 			if (ei_decode_string(buf, &index, &variable[0])) {
1166 				return ERR_DECODING_ARGS;
1167 			}
1168 			if (ei_decode_string(buf, &index, &value[0])) {
1169 				return ERR_DECODING_ARGS;
1170 			}
1171 
1172 			// call function and encode result
1173 			sqlrcur_inputBindString(cur, variable, value);
1174 			ENCODE_VOID;
1175 		}
1176 
1177 		if (strcmp("inputBindStringWithLength", command) == TRUE) {
1178 			char variable[2000];
1179 			char value[2000];
1180 			long length;
1181 
1182 			// check number of arguments
1183 		    	if (arity != 3) return ERR_NUMBER_OF_ARGS;
1184 
1185 			// get input parameters
1186 			if (ei_decode_string(buf, &index, &variable[0])) {
1187 				return ERR_DECODING_ARGS;
1188 			}
1189 			if (ei_decode_string(buf, &index, &value[0])) {
1190 				return ERR_DECODING_ARGS;
1191 			}
1192 			if (ei_decode_long(buf, &index, &length)) {
1193 				return ERR_DECODING_ARGS;
1194 			}
1195 
1196 			// call function and encode result
1197 			sqlrcur_inputBindStringWithLength(cur, variable, value, length);
1198 			ENCODE_VOID;
1199 		}
1200 
1201 
1202 		if (strcmp("inputBindLong", command) == TRUE) {
1203 			char variable[2000];
1204 			long value;
1205 
1206 			// check number of arguments
1207 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
1208 
1209 			// get input parameters
1210 			if (ei_decode_string(buf, &index, &variable[0])) {
1211 				return ERR_DECODING_ARGS;
1212 			}
1213 			if (ei_decode_long(buf, &index, &value)) {
1214 				return ERR_DECODING_ARGS;
1215 			}
1216 
1217 			// call function and encode result
1218 			sqlrcur_inputBindLong(cur, variable, value);
1219 			ENCODE_VOID;
1220 		}
1221 
1222 		if (strcmp("inputBindDouble", command) == TRUE) {
1223 			char variable[2000];
1224 			double value;
1225 			long precision;
1226 			long scale;
1227 
1228 			// check number of arguments
1229 		    	if (arity != 4) return ERR_NUMBER_OF_ARGS;
1230 
1231 			// get input parameters
1232 			if (ei_decode_string(buf, &index, &variable[0])) {
1233 				return ERR_DECODING_ARGS;
1234 			}
1235 			if (ei_decode_double(buf, &index, &value)) {
1236 				return ERR_DECODING_ARGS;
1237 			}
1238 			if (ei_decode_long(buf, &index, &precision)) {
1239 				return ERR_DECODING_ARGS;
1240 			}
1241 			if (ei_decode_long(buf, &index, &scale)) {
1242 				return ERR_DECODING_ARGS;
1243 			}
1244 
1245 			// call function and encode result
1246 			sqlrcur_inputBindDouble(cur, variable, value, precision, scale);
1247 			ENCODE_VOID;
1248 		}
1249 
1250 		if (strcmp("inputBindBlob", command) == TRUE) {
1251 			char variable[2000];
1252 			char value[2000];
1253 			long size;
1254 
1255 			// check number of arguments
1256 		    	if (arity != 3) return ERR_NUMBER_OF_ARGS;
1257 
1258 			// get input parameters
1259 			if (ei_decode_string(buf, &index, &variable[0])) {
1260 				return ERR_DECODING_ARGS;
1261 			}
1262 			if (ei_decode_string(buf, &index, &value[0])) {
1263 				return ERR_DECODING_ARGS;
1264 			}
1265 			if (ei_decode_long(buf, &index, &size)) {
1266 				return ERR_DECODING_ARGS;
1267 			}
1268 
1269 			// call function and encode result
1270 			sqlrcur_inputBindBlob(cur, variable, value, size);
1271 			ENCODE_VOID;
1272 		}
1273 
1274 		if (strcmp("inputBindClob", command) == TRUE) {
1275 			char variable[2000];
1276 			char value[2000];
1277 			long size;
1278 
1279 			// check number of arguments
1280 		    	if (arity != 3) return ERR_NUMBER_OF_ARGS;
1281 
1282 			// get input parameters
1283 			if (ei_decode_string(buf, &index, &variable[0])) {
1284 				return ERR_DECODING_ARGS;
1285 			}
1286 			if (ei_decode_string(buf, &index, &value[0])) {
1287 				return ERR_DECODING_ARGS;
1288 			}
1289 			if (ei_decode_long(buf, &index, &size)) {
1290 				return ERR_DECODING_ARGS;
1291 			}
1292 
1293 			// call function and encode result
1294 			sqlrcur_inputBindClob(cur, variable, value, size);
1295 			ENCODE_VOID;
1296 		}
1297 
1298 		if (strcmp("defineOutputBindString", command) == TRUE) {
1299 			char variable[2000];
1300 			long length;
1301 
1302 			// check number of arguments
1303 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
1304 
1305 			// get input parameters
1306 			if (ei_decode_string(buf, &index, &variable[0])) {
1307 				return ERR_DECODING_ARGS;
1308 			}
1309 			if (ei_decode_long(buf, &index, &length)) {
1310 				return ERR_DECODING_ARGS;
1311 			}
1312 
1313 			// call function and encode result
1314 			sqlrcur_defineOutputBindString(cur, variable, length);
1315 			ENCODE_VOID;
1316 		}
1317 
1318 		if (strcmp("defineOutputBindInteger", command) == TRUE) {
1319 			char variable[2000];
1320 
1321 			// check number of arguments
1322 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
1323 
1324 			// get input parameters
1325 			if (ei_decode_string(buf, &index, &variable[0])) {
1326 				return ERR_DECODING_ARGS;
1327 			}
1328 
1329 			// call function and encode result
1330 			sqlrcur_defineOutputBindInteger(cur, variable);
1331 			ENCODE_VOID;
1332 		}
1333 
1334 		if (strcmp("defineOutputBindDouble", command) == TRUE) {
1335 			char variable[2000];
1336 
1337 			// check number of arguments
1338 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
1339 
1340 			// get input parameters
1341 			if (ei_decode_string(buf, &index, &variable[0])) {
1342 				return ERR_DECODING_ARGS;
1343 			}
1344 
1345 			// call function and encode result
1346 			sqlrcur_defineOutputBindDouble(cur, variable);
1347 			ENCODE_VOID;
1348 		}
1349 
1350 		if (strcmp("defineOutputBindBlob", command) == TRUE) {
1351 			char variable[2000];
1352 
1353 			// check number of arguments
1354 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
1355 
1356 			// get input parameters
1357 			if (ei_decode_string(buf, &index, &variable[0])) {
1358 				return ERR_DECODING_ARGS;
1359 			}
1360 
1361 			// call function and encode result
1362 			sqlrcur_defineOutputBindBlob(cur, variable);
1363 			ENCODE_VOID;
1364 		}
1365 
1366 		if (strcmp("defineOutputBindClob", command) == TRUE) {
1367 			char variable[2000];
1368 
1369 			// check number of arguments
1370 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
1371 
1372 			// get input parameters
1373 			if (ei_decode_string(buf, &index, &variable[0])) {
1374 				return ERR_DECODING_ARGS;
1375 			}
1376 
1377 			// call function and encode result
1378 			sqlrcur_defineOutputBindClob(cur, variable);
1379 			ENCODE_VOID;
1380 		}
1381 
1382 		if (strcmp("defineOutputBindCursor", command) == TRUE) {
1383 			char variable[2000];
1384 
1385 			// check number of arguments
1386 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
1387 
1388 			// get input parameters
1389 			if (ei_decode_string(buf, &index, &variable[0])) {
1390 				return ERR_DECODING_ARGS;
1391 			}
1392 
1393 			// call function and encode result
1394 			sqlrcur_defineOutputBindCursor(cur, variable);
1395 			ENCODE_VOID;
1396 		}
1397 
1398 		if (strcmp("validateBinds", command) == TRUE) {
1399 
1400 			// check number of arguments
1401 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
1402 
1403 			// call function and encode result
1404 			sqlrcur_validateBinds(cur);
1405 			ENCODE_VOID;
1406 		}
1407 
1408 		if (strcmp("validBind", command) == TRUE) {
1409 			char variable[2000];
1410 
1411 			// check number of arguments
1412 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
1413 
1414 			// get input parameters
1415 			if (ei_decode_string(buf, &index, &variable[0])) {
1416 				return ERR_DECODING_ARGS;
1417 			}
1418 
1419 			// call function and encode result
1420 			if (ei_x_encode_atom(&result, "ok") ||
1421 				ei_x_encode_long(&result, sqlrcur_validBind(cur, variable) )) {
1422 				return ERR_ENCODING_ARGS;
1423 			}
1424 		}
1425 
1426 
1427 		if (strcmp("executeQuery", command) == TRUE) {
1428 			// check number of arguments
1429 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
1430 
1431 			// call function and encode result
1432 			if (ei_x_encode_atom(&result, "ok") ||
1433 				ei_x_encode_long(&result, sqlrcur_executeQuery(cur) )) {
1434 				return ERR_ENCODING_ARGS;
1435 			}
1436 		}
1437 
1438 		if (strcmp("fetchFromBindCursor", command) == TRUE) {
1439 			// check number of arguments
1440 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
1441 
1442 			// call function and encode result
1443 			if (ei_x_encode_atom(&result, "ok") ||
1444 				ei_x_encode_long(&result, sqlrcur_fetchFromBindCursor(cur) )) {
1445 				return ERR_ENCODING_ARGS;
1446 			}
1447 		}
1448 
1449 		if (strcmp("getOutputBindString", command) == TRUE) {
1450 			char variable[2000];
1451 
1452 			// check number of arguments
1453 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
1454 
1455 			// get input parameters
1456 			if (ei_decode_string(buf, &index, &variable[0])) {
1457 				return ERR_DECODING_ARGS;
1458 			}
1459 
1460 			// call function and encode result
1461 			if (ei_x_encode_atom(&result, "ok") ||
1462 				ei_x_encode_string(&result, sqlrcur_getOutputBindString(cur, variable) )) {
1463 				return ERR_ENCODING_ARGS;
1464 			}
1465 		}
1466 
1467 		if (strcmp("getOutputBindBlob", command) == TRUE) {
1468 			char variable[2000];
1469 
1470 			// check number of arguments
1471 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
1472 
1473 			// get input parameters
1474 			if (ei_decode_string(buf, &index, &variable[0])) {
1475 				return ERR_DECODING_ARGS;
1476 			}
1477 
1478 			// call function and encode result
1479 			if (ei_x_encode_atom(&result, "ok") ||
1480 				ei_x_encode_string(&result, sqlrcur_getOutputBindBlob(cur, variable) )) {
1481 				return ERR_ENCODING_ARGS;
1482 			}
1483 		}
1484 
1485 		if (strcmp("getOutputBindClob", command) == TRUE) {
1486 			char variable[2000];
1487 
1488 			// check number of arguments
1489 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
1490 
1491 			// get input parameters
1492 			if (ei_decode_string(buf, &index, &variable[0])) {
1493 				return ERR_DECODING_ARGS;
1494 			}
1495 
1496 			// call function and encode result
1497 			if (ei_x_encode_atom(&result, "ok") ||
1498 				ei_x_encode_string(&result, sqlrcur_getOutputBindClob(cur, variable) )) {
1499 				return ERR_ENCODING_ARGS;
1500 			}
1501 		}
1502 
1503 		if (strcmp("getOutputBindInteger", command) == TRUE) {
1504 			char variable[2000];
1505 
1506 			// check number of arguments
1507 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
1508 
1509 			// get input parameters
1510 			if (ei_decode_string(buf, &index, &variable[0])) {
1511 				return ERR_DECODING_ARGS;
1512 			}
1513 
1514 			// call function and encode result
1515 			if (ei_x_encode_atom(&result, "ok") ||
1516 				ei_x_encode_long(&result, sqlrcur_getOutputBindInteger(cur, variable) )) {
1517 				return ERR_ENCODING_ARGS;
1518 			}
1519 		}
1520 
1521 		if (strcmp("getOutputBindDouble", command) == TRUE) {
1522 			char variable[2000];
1523 
1524 			// check number of arguments
1525 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
1526 
1527 			// get input parameters
1528 			if (ei_decode_string(buf, &index, &variable[0])) {
1529 				return ERR_DECODING_ARGS;
1530 			}
1531 
1532 			// call function and encode result
1533 			if (ei_x_encode_atom(&result, "ok") ||
1534 				ei_x_encode_double(&result, sqlrcur_getOutputBindDouble(cur, variable) )) {
1535 				return ERR_ENCODING_ARGS;
1536 			}
1537 		}
1538 
1539 		if (strcmp("getOutputBindLength", command) == TRUE) {
1540 			char variable[2000];
1541 
1542 			// check number of arguments
1543 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
1544 
1545 			// get input parameters
1546 			if (ei_decode_string(buf, &index, &variable[0])) {
1547 				return ERR_DECODING_ARGS;
1548 			}
1549 
1550 			// call function and encode result
1551 			if (ei_x_encode_atom(&result, "ok") ||
1552 				ei_x_encode_long(&result, sqlrcur_getOutputBindLength(cur, variable) )) {
1553 				return ERR_ENCODING_ARGS;
1554 			}
1555 		}
1556 
1557 		if (strcmp("openCachedResultSet", command) == TRUE) {
1558 			char filename[2000];
1559 
1560 			// check number of arguments
1561 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
1562 
1563 			// get input parameters
1564 			if (ei_decode_string(buf, &index, &filename[0])) {
1565 				return ERR_DECODING_ARGS;
1566 			}
1567 
1568 			// call function and encode result
1569 			if (ei_x_encode_atom(&result, "ok") ||
1570 				ei_x_encode_long(&result, sqlrcur_openCachedResultSet(cur, filename) )) {
1571 				return ERR_ENCODING_ARGS;
1572 			}
1573 		}
1574 
1575 		if (strcmp("colCount", command) == TRUE) {
1576 			// check number of arguments
1577 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
1578 
1579 			// encode result
1580 			if (ei_x_encode_atom(&result, "ok") ||
1581 				ei_x_encode_long(&result, colCount() )) {
1582 				return ERR_ENCODING_ARGS;
1583 			}
1584 		}
1585 
1586 		if (strcmp("rowCount", command) == TRUE) {
1587 			// check number of arguments
1588 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
1589 
1590 			// encode result
1591 			if (ei_x_encode_atom(&result, "ok") ||
1592 				ei_x_encode_long(&result, rowCount() )) {
1593 				return ERR_ENCODING_ARGS;
1594 			}
1595 		}
1596 
1597 		if (strcmp("totalRows", command) == TRUE) {
1598 			// check number of arguments
1599 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
1600 
1601 			// call function and encode result
1602 			if (ei_x_encode_atom(&result, "ok") ||
1603 				ei_x_encode_long(&result, sqlrcur_totalRows(cur) )) {
1604 				return ERR_ENCODING_ARGS;
1605 			}
1606 		}
1607 
1608 		if (strcmp("affectedRows", command) == TRUE) {
1609 			// check number of arguments
1610 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
1611 
1612 			// call function and encode result
1613 			if (ei_x_encode_atom(&result, "ok") ||
1614 				ei_x_encode_long(&result, sqlrcur_affectedRows(cur) )) {
1615 				return ERR_ENCODING_ARGS;
1616 			}
1617 		}
1618 
1619 		if (strcmp("firstRowIndex", command) == TRUE) {
1620 			// check number of arguments
1621 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
1622 
1623 			// call function and encode result
1624 			if (ei_x_encode_atom(&result, "ok") ||
1625 				ei_x_encode_long(&result, sqlrcur_firstRowIndex(cur) )) {
1626 				return ERR_ENCODING_ARGS;
1627 			}
1628 		}
1629 
1630 		if (strcmp("endOfResultSet", command) == TRUE) {
1631 			// check number of arguments
1632 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
1633 
1634 			// call function and encode result
1635 			if (ei_x_encode_atom(&result, "ok") ||
1636 				ei_x_encode_long(&result, sqlrcur_endOfResultSet(cur) )) {
1637 				return ERR_ENCODING_ARGS;
1638 			}
1639 		}
1640 
1641 		if (strcmp("errorMessage", command) == TRUE) {
1642 			// check number of arguments
1643 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
1644 
1645 			// encode result
1646 			if (ei_x_encode_atom(&result, "ok") ||
1647 				ei_x_encode_string(&result, sqlrcur_errorMessage(cur) )) {
1648 				return ERR_ENCODING_ARGS;
1649 			}
1650 		}
1651 
1652 		if (strcmp("errorNumber", command) == TRUE) {
1653 			// check number of arguments
1654 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
1655 
1656 			// encode result
1657 			if (ei_x_encode_atom(&result, "ok") ||
1658 				ei_x_encode_long(&result, sqlrcur_errorNumber(cur) )) {
1659 				return ERR_ENCODING_ARGS;
1660 			}
1661 		}
1662 
1663 		if (strcmp("getNullsAsEmptyStrings", command) == TRUE) {
1664 			// check number of arguments
1665 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
1666 
1667 			// call function and encode result
1668 			sqlrcur_getNullsAsEmptyStrings(cur);
1669 			ENCODE_VOID;
1670 		}
1671 
1672 		if (strcmp("getNullsAsNulls", command) == TRUE) {
1673 			// check number of arguments
1674 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
1675 
1676 			// call function and encode result
1677 			sqlrcur_getNullsAsNulls(cur);
1678 			ENCODE_VOID;
1679 		}
1680 
1681 		if (strcmp("getFieldByIndex", command) == TRUE) {
1682 			long row;
1683 			long col;
1684 			err = 0;
1685 
1686 			// check number of arguments
1687 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
1688 
1689 			// get input parameters
1690 			if (ei_decode_long(buf, &index, &row)) {
1691 				return ERR_DECODING_ARGS;
1692 			}
1693 			if (ei_decode_long(buf, &index, &col)) {
1694 				return ERR_DECODING_ARGS;
1695 			}
1696 
1697 			// check sanity of row and col values
1698 			if (checkRowLimitsOK(row) == FALSE) {
1699 				err = ERR_COL_OUT_OF_RANGE;
1700 			}
1701 			if (checkColLimitsOK(col) == FALSE) {
1702 				err = ERR_COL_OUT_OF_RANGE;
1703 			}
1704 
1705 			// encode result
1706 			if (err) {
1707 				signalError(&result, err);
1708 			} else {
1709 				if (ei_x_encode_atom(&result, "ok") ||
1710 					ei_x_encode_string(&result, sqlrcur_getFieldByIndex(cur, row, col))) {
1711 						return ERR_ENCODING_ARGS;
1712 				}
1713 			}
1714 		}
1715 
1716 		if (strcmp("getFieldByName", command) == TRUE) {
1717 			long row;
1718 			char col[COL_NAME_SIZE];
1719 			err = 0;
1720 
1721 			// check number of arguments
1722 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
1723 
1724 			// get input parameters
1725 			if (ei_decode_long(buf, &index, &row)) {
1726 				return ERR_DECODING_ARGS;
1727 			}
1728 			if (ei_decode_string(buf, &index, &col[0])) {
1729 				return ERR_DECODING_ARGS;
1730 			}
1731 
1732 			// check sanity of row values
1733 			if (checkRowLimitsOK(row) == FALSE) {
1734 				err = ERR_ROW_OUT_OF_RANGE;
1735 			}
1736 
1737 			// encode result
1738 			if (err) {
1739 				signalError(&result, err);
1740 			} else {
1741 				if (ei_x_encode_atom(&result, "ok") ||
1742 					ei_x_encode_string(&result, sqlrcur_getFieldByName(cur, row, col))) {
1743 					return ERR_ENCODING_ARGS;
1744 				}
1745 			}
1746 		}
1747 
1748 		if (strcmp("getFieldAsIntegerByIndex", command) == TRUE) {
1749 			long row;
1750 			long col;
1751 			err = 0;
1752 
1753 			// check number of arguments
1754 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
1755 
1756 			// get input parameters
1757 			if (ei_decode_long(buf, &index, &row)) {
1758 				return ERR_DECODING_ARGS;
1759 			}
1760 			if (ei_decode_long(buf, &index, &col)) {
1761 				return ERR_DECODING_ARGS;
1762 			}
1763 
1764 			// check sanity of row and col values
1765 			if (checkRowLimitsOK(row) == FALSE) {
1766 				err = ERR_ROW_OUT_OF_RANGE;
1767 			}
1768 			if (checkColLimitsOK(col) == FALSE) {
1769 				err = ERR_COL_OUT_OF_RANGE;
1770 			}
1771 
1772 			// encode result
1773 			if (err) {
1774 				signalError(&result, err);
1775 			} else {
1776 				if (ei_x_encode_atom(&result, "ok") ||
1777 				ei_x_encode_long(&result, sqlrcur_getFieldAsIntegerByIndex(cur, row, col) )) {
1778 					return ERR_ENCODING_ARGS;
1779 				}
1780 			}
1781 		}
1782 
1783 		if (strcmp("getFieldAsIntegerByName", command) == TRUE) {
1784 			long row;
1785 			char col[COL_NAME_SIZE];
1786 			err = 0;
1787 
1788 			// check number of arguments
1789 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
1790 
1791 			// get input parameters
1792 			if (ei_decode_long(buf, &index, &row)) {
1793 				return ERR_DECODING_ARGS;
1794 			}
1795 			if (ei_decode_string(buf, &index, &col[0])) {
1796 				return ERR_DECODING_ARGS;
1797 			}
1798 
1799 			// check sanity of row values
1800 			if (checkRowLimitsOK(row) == FALSE) {
1801 				err = ERR_ROW_OUT_OF_RANGE;
1802 			}
1803 
1804 			// encode result
1805 			if (err) {
1806 				signalError(&result, err);
1807 			} else {
1808 				if (ei_x_encode_atom(&result, "ok") ||
1809 					ei_x_encode_long(&result, sqlrcur_getFieldAsIntegerByName(cur, row, col))) {
1810 					return ERR_ENCODING_ARGS;
1811 				}
1812 			}
1813 		}
1814 
1815 		if (strcmp("getFieldAsDoubleByIndex", command) == TRUE) {
1816 			long row;
1817 			long col;
1818 			err = 0;
1819 
1820 			// check number of arguments
1821 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
1822 
1823 			// get input parameters
1824 			if (ei_decode_long(buf, &index, &row)) {
1825 				return ERR_DECODING_ARGS;
1826 			}
1827 			if (ei_decode_long(buf, &index, &col)) {
1828 				return ERR_DECODING_ARGS;
1829 			}
1830 
1831 			// check sanity of row and col values
1832 			if (checkRowLimitsOK(row) == FALSE) {
1833 				err = ERR_ROW_OUT_OF_RANGE;
1834 			}
1835 			if (checkColLimitsOK(col) == FALSE) {
1836 				err = ERR_COL_OUT_OF_RANGE;
1837 			}
1838 
1839 			// encode result
1840 			if (err) {
1841 				signalError(&result, err);
1842 			} else {
1843 				if (ei_x_encode_atom(&result, "ok") ||
1844 				ei_x_encode_double(&result, sqlrcur_getFieldAsDoubleByIndex(cur, row, col) )) {
1845 					return ERR_ENCODING_ARGS;
1846 				}
1847 			}
1848 		}
1849 
1850 		if (strcmp("getFieldAsDoubleByName", command) == TRUE) {
1851 			long row;
1852 			char col[COL_NAME_SIZE];
1853 			err = 0;
1854 
1855 			// check number of arguments
1856 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
1857 
1858 			// get input parameters
1859 			if (ei_decode_long(buf, &index, &row)) {
1860 				return ERR_DECODING_ARGS;
1861 			}
1862 			if (ei_decode_string(buf, &index, &col[0])) {
1863 				return ERR_DECODING_ARGS;
1864 			}
1865 
1866 			// check sanity of row values
1867 			if (checkRowLimitsOK(row) == FALSE) {
1868 				err = ERR_ROW_OUT_OF_RANGE;
1869 			}
1870 
1871 			// encode result
1872 			if (err) {
1873 				signalError(&result, err);
1874 			} else {
1875 				if (ei_x_encode_atom(&result, "ok") ||
1876 					ei_x_encode_double(&result, sqlrcur_getFieldAsDoubleByName(cur, row, col))) {
1877 					return ERR_ENCODING_ARGS;
1878 				}
1879 			}
1880 		}
1881 
1882 
1883 		if (strcmp("getFieldLengthByIndex", command) == TRUE) {
1884 			long row;
1885 			long col;
1886 			err = 0;
1887 
1888 			// check number of arguments
1889 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
1890 
1891 			// get input parameters
1892 			if (ei_decode_long(buf, &index, &row)) {
1893 				return ERR_DECODING_ARGS;
1894 			}
1895 			if (ei_decode_long(buf, &index, &col)) {
1896 				return ERR_DECODING_ARGS;
1897 			}
1898 
1899 			// check sanity of row and col values
1900 			if (checkRowLimitsOK(row) == FALSE) {
1901 				err = ERR_ROW_OUT_OF_RANGE;
1902 			}
1903 			if (checkColLimitsOK(col) == FALSE) {
1904 				err = ERR_COL_OUT_OF_RANGE;
1905 			}
1906 
1907 			// encode result
1908 			if (err) {
1909 				signalError(&result, err);
1910 			} else {
1911 				if (ei_x_encode_atom(&result, "ok") ||
1912 				ei_x_encode_long(&result, sqlrcur_getFieldLengthByIndex(cur, row, col) )) {
1913 					return ERR_ENCODING_ARGS;
1914 				}
1915 			}
1916 		}
1917 
1918 		if (strcmp("getFieldLengthByName", command) == TRUE) {
1919 			long row;
1920 			char col[COL_NAME_SIZE];
1921 			err = 0;
1922 
1923 			// check number of arguments
1924 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
1925 
1926 			// get input parameters
1927 			if (ei_decode_long(buf, &index, &row)) {
1928 				return ERR_DECODING_ARGS;
1929 			}
1930 			if (ei_decode_string(buf, &index, &col[0])) {
1931 				return ERR_DECODING_ARGS;
1932 			}
1933 
1934 			// check sanity of row values
1935 			if (checkRowLimitsOK(row) == FALSE) {
1936 				err = ERR_ROW_OUT_OF_RANGE;
1937 			}
1938 
1939 			// encode result
1940 			if (err) {
1941 				signalError(&result, err);
1942 			} else {
1943 				if (ei_x_encode_atom(&result, "ok") ||
1944 					ei_x_encode_long(&result, sqlrcur_getFieldLengthByName(cur, row, col))) {
1945 					return ERR_ENCODING_ARGS;
1946 				}
1947 			}
1948 		}
1949 
1950 		if (strcmp("getRow", command) == TRUE) {
1951 			long row;
1952 			err = 0;
1953 
1954 			// check number of arguments
1955 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
1956 
1957 			// get input parameters
1958 			if (ei_decode_long(buf, &index, &row)) {
1959 				return ERR_DECODING_ARGS;
1960 			}
1961 
1962 			// check sanity of row values
1963 			if (checkRowLimitsOK(row) == FALSE) {
1964 				err = ERR_ROW_OUT_OF_RANGE;
1965 			}
1966 
1967 			// encode result
1968 			if (err) {
1969 				signalError(&result, err);
1970 			} else {
1971 				if (ei_x_encode_atom(&result, "ok") ||
1972 					ei_x_encode_string(&result, (char *) sqlrcur_getRow(cur, row))) {
1973 					return ERR_ENCODING_ARGS;
1974 				}
1975 			}
1976 		}
1977 
1978 		if (strcmp("getRowLengths", command) == TRUE) {
1979 			long row;
1980 			err = 0;
1981 
1982 			// check number of arguments
1983 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
1984 
1985 			// get input parameters
1986 			if (ei_decode_long(buf, &index, &row)) {
1987 				return ERR_DECODING_ARGS;
1988 			}
1989 
1990 			// check sanity of row values
1991 			if (checkRowLimitsOK(row) == FALSE) {
1992 				err = ERR_ROW_OUT_OF_RANGE;
1993 			}
1994 
1995 			// encode result
1996 			if (err) {
1997 				signalError(&result, err);
1998 			} else {
1999 				if (ei_x_encode_atom(&result, "ok") ||
2000 					ei_x_encode_long(&result, (long) sqlrcur_getRowLengths(cur, row))) {
2001 					return ERR_ENCODING_ARGS;
2002 				}
2003 			}
2004 		}
2005 
2006 		if (strcmp("getColumnNames", command) == TRUE) {
2007 			// call function and encode result
2008 			if (ei_x_encode_atom(&result, "ok") ||
2009 				ei_x_encode_string(&result, (char *) sqlrcur_getColumnNames(cur))) {
2010 				return ERR_ENCODING_ARGS;
2011 			}
2012 		}
2013 
2014 		if (strcmp("getColumnName", command) == TRUE) {
2015 			long col;
2016 			err = 0;
2017 
2018 			// check number of arguments
2019 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2020 
2021 			// get input parameters
2022 			if (ei_decode_long(buf, &index, &col)) {
2023 				return ERR_DECODING_ARGS;
2024 			}
2025 
2026 			// check sanity of column value
2027 			if (checkColLimitsOK(col) == FALSE) {
2028 				err = ERR_COL_OUT_OF_RANGE;
2029 			}
2030 
2031 			// encode result
2032 			if (err) {
2033 				signalError(&result, err);
2034 			} else {
2035 				if (ei_x_encode_atom(&result, "ok") ||
2036 					ei_x_encode_string(&result, sqlrcur_getColumnName(cur, col))) {
2037 					return ERR_ENCODING_ARGS;
2038 				}
2039 			}
2040 		}
2041 
2042 /***/
2043 		if (strcmp("getColumnTypeByIndex", command) == TRUE) {
2044 			long col;
2045 			err = 0;
2046 
2047 			// check number of arguments
2048 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2049 
2050 			// get input parameters
2051 			if (ei_decode_long(buf, &index, &col)) {
2052 				return ERR_DECODING_ARGS;
2053 			}
2054 
2055 			// check sanity of column value
2056 			if (checkColLimitsOK(col) == FALSE) {
2057 				err = ERR_COL_OUT_OF_RANGE;
2058 			}
2059 
2060 			// encode result
2061 			if (err) {
2062 				signalError(&result, err);
2063 			} else {
2064 				if (ei_x_encode_atom(&result, "ok") ||
2065 					ei_x_encode_string(&result, sqlrcur_getColumnTypeByIndex(cur, col))) {
2066 					return ERR_ENCODING_ARGS;
2067 				}
2068 			}
2069 		}
2070 
2071 		if (strcmp("getColumnTypeByName", command) == TRUE) {
2072 			char col[COL_NAME_SIZE];
2073 
2074 			// check number of arguments
2075 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2076 
2077 			// get input parameters
2078 			if (ei_decode_string(buf, &index, &col[0])) {
2079 				return ERR_DECODING_ARGS;
2080 			}
2081 
2082 			// encode result
2083 			if (ei_x_encode_atom(&result, "ok") ||
2084 				ei_x_encode_string(&result, sqlrcur_getColumnTypeByName(cur, col))) {
2085 				return ERR_ENCODING_ARGS;
2086 			}
2087 		}
2088 
2089 		if (strcmp("getColumnLengthByIndex", command) == TRUE) {
2090 			long col;
2091 			err = 0;
2092 
2093 			// check number of arguments
2094 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2095 
2096 			// get input parameters
2097 			if (ei_decode_long(buf, &index, &col)) {
2098 				return ERR_DECODING_ARGS;
2099 			}
2100 
2101 			// check sanity of column value
2102 			if (checkColLimitsOK(col) == FALSE) {
2103 				err = ERR_COL_OUT_OF_RANGE;
2104 			}
2105 
2106 			// encode result
2107 			if (err) {
2108 				signalError(&result, err);
2109 			} else {
2110 				if (ei_x_encode_atom(&result, "ok") ||
2111 					ei_x_encode_long(&result, sqlrcur_getColumnLengthByIndex(cur, col))) {
2112 					return ERR_ENCODING_ARGS;
2113 				}
2114 			}
2115 		}
2116 
2117 		if (strcmp("getColumnLengthByName", command) == TRUE) {
2118 			char col[COL_NAME_SIZE];
2119 
2120 			// check number of arguments
2121 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2122 
2123 			// get input parameters
2124 			if (ei_decode_string(buf, &index, &col[0])) {
2125 				return ERR_DECODING_ARGS;
2126 			}
2127 
2128 			// encode result
2129 			if (ei_x_encode_atom(&result, "ok") ||
2130 				ei_x_encode_long(&result, sqlrcur_getColumnLengthByName(cur, col))) {
2131 				return ERR_ENCODING_ARGS;
2132 			}
2133 		}
2134 
2135 
2136 		if (strcmp("getColumnPrecisionByIndex", command) == TRUE) {
2137 			long col;
2138 			err = 0;
2139 
2140 			// check number of arguments
2141 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2142 
2143 			// get input parameters
2144 			if (ei_decode_long(buf, &index, &col)) {
2145 				return ERR_DECODING_ARGS;
2146 			}
2147 
2148 			// check sanity of column value
2149 			if (checkColLimitsOK(col) == FALSE) {
2150 				err = ERR_COL_OUT_OF_RANGE;
2151 			}
2152 
2153 			// encode result
2154 			if (err) {
2155 				signalError(&result, err);
2156 			} else {
2157 				if (ei_x_encode_atom(&result, "ok") ||
2158 					ei_x_encode_long(&result, sqlrcur_getColumnPrecisionByIndex(cur, col))) {
2159 					return ERR_ENCODING_ARGS;
2160 				}
2161 			}
2162 		}
2163 
2164 		if (strcmp("getColumnPrecisionByName", command) == TRUE) {
2165 			char col[COL_NAME_SIZE];
2166 
2167 			// check number of arguments
2168 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2169 
2170 			// get input parameters
2171 			if (ei_decode_string(buf, &index, &col[0])) {
2172 				return ERR_DECODING_ARGS;
2173 			}
2174 
2175 			// encode result
2176 			if (ei_x_encode_atom(&result, "ok") ||
2177 				ei_x_encode_long(&result, sqlrcur_getColumnPrecisionByName(cur, col))) {
2178 				return ERR_ENCODING_ARGS;
2179 			}
2180 		}
2181 
2182 		if (strcmp("getColumnScaleByIndex", command) == TRUE) {
2183 			long col;
2184 			err = 0;
2185 
2186 			// check number of arguments
2187 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2188 
2189 			// get input parameters
2190 			if (ei_decode_long(buf, &index, &col)) {
2191 				return ERR_DECODING_ARGS;
2192 			}
2193 
2194 			// check sanity of column value
2195 			if (checkColLimitsOK(col) == FALSE) {
2196 				err = ERR_COL_OUT_OF_RANGE;
2197 			}
2198 
2199 			// encode result
2200 			if (err) {
2201 				signalError(&result, err);
2202 			} else {
2203 				if (ei_x_encode_atom(&result, "ok") ||
2204 					ei_x_encode_long(&result, sqlrcur_getColumnScaleByIndex(cur, col))) {
2205 					return ERR_ENCODING_ARGS;
2206 				}
2207 			}
2208 		}
2209 
2210 		if (strcmp("getColumnScaleByName", command) == TRUE) {
2211 			char col[COL_NAME_SIZE];
2212 
2213 			// check number of arguments
2214 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2215 
2216 			// get input parameters
2217 			if (ei_decode_string(buf, &index, &col[0])) {
2218 				return ERR_DECODING_ARGS;
2219 			}
2220 
2221 			// encode result
2222 			if (ei_x_encode_atom(&result, "ok") ||
2223 				ei_x_encode_long(&result, sqlrcur_getColumnScaleByName(cur, col))) {
2224 				return ERR_ENCODING_ARGS;
2225 			}
2226 		}
2227 
2228 
2229 		if (strcmp("getColumnIsNullableByIndex", command) == TRUE) {
2230 			long col;
2231 			err = 0;
2232 
2233 			// check number of arguments
2234 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2235 
2236 			// get input parameters
2237 			if (ei_decode_long(buf, &index, &col)) {
2238 				return ERR_DECODING_ARGS;
2239 			}
2240 
2241 			// check sanity of column value
2242 			if (checkColLimitsOK(col) == FALSE) {
2243 				err = ERR_COL_OUT_OF_RANGE;
2244 			}
2245 
2246 			// encode result
2247 			if (err) {
2248 				signalError(&result, err);
2249 			} else {
2250 				if (ei_x_encode_atom(&result, "ok") ||
2251 					ei_x_encode_long(&result, sqlrcur_getColumnIsNullableByIndex(cur, col))) {
2252 					return ERR_ENCODING_ARGS;
2253 				}
2254 			}
2255 		}
2256 
2257 		if (strcmp("getColumnIsNullableByName", command) == TRUE) {
2258 			char col[COL_NAME_SIZE];
2259 
2260 			// check number of arguments
2261 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2262 
2263 			// get input parameters
2264 			if (ei_decode_string(buf, &index, &col[0])) {
2265 				return ERR_DECODING_ARGS;
2266 			}
2267 
2268 			// encode result
2269 			if (ei_x_encode_atom(&result, "ok") ||
2270 				ei_x_encode_long(&result, sqlrcur_getColumnIsNullableByName(cur, col))) {
2271 				return ERR_ENCODING_ARGS;
2272 			}
2273 		}
2274 
2275 		if (strcmp("getColumnIsPrimaryKeyByIndex", command) == TRUE) {
2276 			long col;
2277 			err = 0;
2278 
2279 			// check number of arguments
2280 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2281 
2282 			// get input parameters
2283 			if (ei_decode_long(buf, &index, &col)) {
2284 				return ERR_DECODING_ARGS;
2285 			}
2286 
2287 			// check sanity of column value
2288 			if (checkColLimitsOK(col) == FALSE) {
2289 				err = ERR_COL_OUT_OF_RANGE;
2290 			}
2291 
2292 			// encode result
2293 			if (err) {
2294 				signalError(&result, err);
2295 			} else {
2296 				if (ei_x_encode_atom(&result, "ok") ||
2297 					ei_x_encode_long(&result, sqlrcur_getColumnIsPrimaryKeyByIndex(cur, col))) {
2298 					return ERR_ENCODING_ARGS;
2299 				}
2300 			}
2301 		}
2302 
2303 		if (strcmp("getColumnIsPrimaryKeyByName", command) == TRUE) {
2304 			char col[COL_NAME_SIZE];
2305 
2306 			// check number of arguments
2307 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2308 
2309 			// get input parameters
2310 			if (ei_decode_string(buf, &index, &col[0])) {
2311 				return ERR_DECODING_ARGS;
2312 			}
2313 
2314 			// encode result
2315 			if (ei_x_encode_atom(&result, "ok") ||
2316 				ei_x_encode_long(&result, sqlrcur_getColumnIsPrimaryKeyByName(cur, col))) {
2317 				return ERR_ENCODING_ARGS;
2318 			}
2319 		}
2320 
2321 		if (strcmp("getColumnIsUniqueByIndex", command) == TRUE) {
2322 			long col;
2323 			err = 0;
2324 
2325 			// check number of arguments
2326 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2327 
2328 			// get input parameters
2329 			if (ei_decode_long(buf, &index, &col)) {
2330 				return ERR_DECODING_ARGS;
2331 			}
2332 
2333 			// check sanity of column value
2334 			if (checkColLimitsOK(col) == FALSE) {
2335 				err = ERR_COL_OUT_OF_RANGE;
2336 			}
2337 
2338 			// encode result
2339 			if (err) {
2340 				signalError(&result, err);
2341 			} else {
2342 				if (ei_x_encode_atom(&result, "ok") ||
2343 					ei_x_encode_long(&result, sqlrcur_getColumnIsUniqueByIndex(cur, col))) {
2344 					return ERR_ENCODING_ARGS;
2345 				}
2346 			}
2347 		}
2348 
2349 		if (strcmp("getColumnIsUniqueByName", command) == TRUE) {
2350 			char col[COL_NAME_SIZE];
2351 
2352 			// check number of arguments
2353 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2354 
2355 			// get input parameters
2356 			if (ei_decode_string(buf, &index, &col[0])) {
2357 				return ERR_DECODING_ARGS;
2358 			}
2359 
2360 			// encode result
2361 			if (ei_x_encode_atom(&result, "ok") ||
2362 				ei_x_encode_long(&result, sqlrcur_getColumnIsUniqueByName(cur, col))) {
2363 				return ERR_ENCODING_ARGS;
2364 			}
2365 		}
2366 
2367 		if (strcmp("getColumnIsPartOfKeyByIndex", command) == TRUE) {
2368 			long col;
2369 			err = 0;
2370 
2371 			// check number of arguments
2372 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2373 
2374 			// get input parameters
2375 			if (ei_decode_long(buf, &index, &col)) {
2376 				return ERR_DECODING_ARGS;
2377 			}
2378 
2379 			// check sanity of column value
2380 			if (checkColLimitsOK(col) == FALSE) {
2381 				err = ERR_COL_OUT_OF_RANGE;
2382 			}
2383 
2384 			// encode result
2385 			if (err) {
2386 				signalError(&result, err);
2387 			} else {
2388 				if (ei_x_encode_atom(&result, "ok") ||
2389 					ei_x_encode_long(&result, sqlrcur_getColumnIsPartOfKeyByIndex(cur, col))) {
2390 					return ERR_ENCODING_ARGS;
2391 				}
2392 			}
2393 		}
2394 
2395 		if (strcmp("getColumnIsPartOfKeyByName", command) == TRUE) {
2396 			char col[COL_NAME_SIZE];
2397 
2398 			// check number of arguments
2399 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2400 
2401 			// get input parameters
2402 			if (ei_decode_string(buf, &index, &col[0])) {
2403 				return ERR_DECODING_ARGS;
2404 			}
2405 
2406 			// encode result
2407 			if (ei_x_encode_atom(&result, "ok") ||
2408 				ei_x_encode_long(&result, sqlrcur_getColumnIsPartOfKeyByName(cur, col))) {
2409 				return ERR_ENCODING_ARGS;
2410 			}
2411 		}
2412 
2413 		if (strcmp("getColumnIsUnsignedByIndex", command) == TRUE) {
2414 			long col;
2415 			err = 0;
2416 
2417 			// check number of arguments
2418 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2419 
2420 			// get input parameters
2421 			if (ei_decode_long(buf, &index, &col)) {
2422 				return ERR_DECODING_ARGS;
2423 			}
2424 
2425 			// check sanity of column value
2426 			if (checkColLimitsOK(col) == FALSE) {
2427 				err = ERR_COL_OUT_OF_RANGE;
2428 			}
2429 
2430 			// encode result
2431 			if (err) {
2432 				signalError(&result, err);
2433 			} else {
2434 				if (ei_x_encode_atom(&result, "ok") ||
2435 					ei_x_encode_long(&result, sqlrcur_getColumnIsUnsignedByIndex(cur, col))) {
2436 					return ERR_ENCODING_ARGS;
2437 				}
2438 			}
2439 		}
2440 
2441 		if (strcmp("getColumnIsUnsignedByName", command) == TRUE) {
2442 			char col[COL_NAME_SIZE];
2443 
2444 			// check number of arguments
2445 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2446 
2447 			// get input parameters
2448 			if (ei_decode_string(buf, &index, &col[0])) {
2449 				return ERR_DECODING_ARGS;
2450 			}
2451 
2452 			// encode result
2453 			if (ei_x_encode_atom(&result, "ok") ||
2454 				ei_x_encode_long(&result, sqlrcur_getColumnIsUnsignedByName(cur, col))) {
2455 				return ERR_ENCODING_ARGS;
2456 			}
2457 		}
2458 
2459 
2460 		if (strcmp("getColumnIsZeroFilledByIndex", command) == TRUE) {
2461 			long col;
2462 			err = 0;
2463 
2464 			// check number of arguments
2465 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2466 
2467 			// get input parameters
2468 			if (ei_decode_long(buf, &index, &col)) {
2469 				return ERR_DECODING_ARGS;
2470 			}
2471 
2472 			// check sanity of column value
2473 			if (checkColLimitsOK(col) == FALSE) {
2474 				err = ERR_COL_OUT_OF_RANGE;
2475 			}
2476 
2477 			// encode result
2478 			if (err) {
2479 				signalError(&result, err);
2480 			} else {
2481 				if (ei_x_encode_atom(&result, "ok") ||
2482 					ei_x_encode_long(&result, sqlrcur_getColumnIsZeroFilledByIndex(cur, col))) {
2483 					return ERR_ENCODING_ARGS;
2484 				}
2485 			}
2486 		}
2487 
2488 		if (strcmp("getColumnIsZeroFilledByName", command) == TRUE) {
2489 			char col[COL_NAME_SIZE];
2490 
2491 			// check number of arguments
2492 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2493 
2494 			// get input parameters
2495 			if (ei_decode_string(buf, &index, &col[0])) {
2496 				return ERR_DECODING_ARGS;
2497 			}
2498 
2499 			// encode result
2500 			if (ei_x_encode_atom(&result, "ok") ||
2501 				ei_x_encode_long(&result, sqlrcur_getColumnIsZeroFilledByName(cur, col))) {
2502 				return ERR_ENCODING_ARGS;
2503 			}
2504 		}
2505 
2506 
2507 
2508 		if (strcmp("getColumnIsBinaryByIndex", command) == TRUE) {
2509 			long col;
2510 			err = 0;
2511 
2512 			// check number of arguments
2513 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2514 
2515 			// get input parameters
2516 			if (ei_decode_long(buf, &index, &col)) {
2517 				return ERR_DECODING_ARGS;
2518 			}
2519 
2520 			// check sanity of column value
2521 			if (checkColLimitsOK(col) == FALSE) {
2522 				err = ERR_COL_OUT_OF_RANGE;
2523 			}
2524 
2525 			// encode result
2526 			if (err) {
2527 				signalError(&result, err);
2528 			} else {
2529 				if (ei_x_encode_atom(&result, "ok") ||
2530 					ei_x_encode_long(&result, sqlrcur_getColumnIsBinaryByIndex(cur, col))) {
2531 					return ERR_ENCODING_ARGS;
2532 				}
2533 			}
2534 		}
2535 
2536 		if (strcmp("getColumnIsBinaryByName", command) == TRUE) {
2537 			char col[COL_NAME_SIZE];
2538 
2539 			// check number of arguments
2540 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2541 
2542 			// get input parameters
2543 			if (ei_decode_string(buf, &index, &col[0])) {
2544 				return ERR_DECODING_ARGS;
2545 			}
2546 
2547 			// encode result
2548 			if (ei_x_encode_atom(&result, "ok") ||
2549 				ei_x_encode_long(&result, sqlrcur_getColumnIsBinaryByName(cur, col))) {
2550 				return ERR_ENCODING_ARGS;
2551 			}
2552 		}
2553 
2554 
2555 		if (strcmp("getColumnIsAutoIncrementByIndex", command) == TRUE) {
2556 			long col;
2557 			err = 0;
2558 
2559 			// check number of arguments
2560 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2561 
2562 			// get input parameters
2563 			if (ei_decode_long(buf, &index, &col)) {
2564 				return ERR_DECODING_ARGS;
2565 			}
2566 
2567 			// check sanity of column value
2568 			if (checkColLimitsOK(col) == FALSE) {
2569 				err = ERR_COL_OUT_OF_RANGE;
2570 			}
2571 
2572 			// encode result
2573 			if (err) {
2574 				signalError(&result, err);
2575 			} else {
2576 				if (ei_x_encode_atom(&result, "ok") ||
2577 					ei_x_encode_long(&result, sqlrcur_getColumnIsAutoIncrementByIndex(cur, col))) {
2578 					return ERR_ENCODING_ARGS;
2579 				}
2580 			}
2581 		}
2582 
2583 		if (strcmp("getColumnIsAutoIncrementByName", command) == TRUE) {
2584 			char col[COL_NAME_SIZE];
2585 
2586 			// check number of arguments
2587 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2588 
2589 			// get input parameters
2590 			if (ei_decode_string(buf, &index, &col[0])) {
2591 				return ERR_DECODING_ARGS;
2592 			}
2593 
2594 			// encode result
2595 			if (ei_x_encode_atom(&result, "ok") ||
2596 				ei_x_encode_long(&result, sqlrcur_getColumnIsAutoIncrementByName(cur, col))) {
2597 				return ERR_ENCODING_ARGS;
2598 			}
2599 		}
2600 
2601 
2602 		if (strcmp("getLongestByIndex", command) == TRUE) {
2603 			long col;
2604 			err = 0;
2605 
2606 			// check number of arguments
2607 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2608 
2609 			// get input parameters
2610 			if (ei_decode_long(buf, &index, &col)) {
2611 				return ERR_DECODING_ARGS;
2612 			}
2613 
2614 			// check sanity of column value
2615 			if (checkColLimitsOK(col) == FALSE) {
2616 				err = ERR_COL_OUT_OF_RANGE;
2617 			}
2618 
2619 			// encode result
2620 			if (err) {
2621 				signalError(&result, err);
2622 			} else {
2623 				if (ei_x_encode_atom(&result, "ok") ||
2624 					ei_x_encode_long(&result, sqlrcur_getLongestByIndex(cur, col))) {
2625 					return ERR_ENCODING_ARGS;
2626 				}
2627 			}
2628 		}
2629 
2630 		if (strcmp("getLongestByName", command) == TRUE) {
2631 			char col[COL_NAME_SIZE];
2632 
2633 			// check number of arguments
2634 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2635 
2636 			// get input parameters
2637 			if (ei_decode_string(buf, &index, &col[0])) {
2638 				return ERR_DECODING_ARGS;
2639 			}
2640 
2641 			// encode result
2642 			if (ei_x_encode_atom(&result, "ok") ||
2643 				ei_x_encode_long(&result, sqlrcur_getLongestByName(cur, col))) {
2644 				return ERR_ENCODING_ARGS;
2645 			}
2646 		}
2647 
2648 		if (strcmp("suspendResultSet", command) == TRUE) {
2649 			// check number of arguments
2650 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
2651 
2652 			// call function and encode result
2653 			sqlrcur_suspendResultSet(cur);
2654 			ENCODE_VOID;
2655 		}
2656 
2657 		if (strcmp("getResultSetId", command) == TRUE) {
2658 			// check number of arguments
2659 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
2660 
2661 			// call function and encode result
2662 			if (ei_x_encode_atom(&result, "ok") ||
2663 				ei_x_encode_long(&result, sqlrcur_getResultSetId(cur))) {
2664 				return ERR_ENCODING_ARGS;
2665 			}
2666 		}
2667 
2668 		if (strcmp("resumeResultSet", command) == TRUE) {
2669 			long id;
2670 
2671 			// check number of arguments
2672 		    	if (arity != 1) return ERR_NUMBER_OF_ARGS;
2673 
2674 			// get input parameters
2675 			if (ei_decode_long(buf, &index, &id)) {
2676 				return ERR_DECODING_ARGS;
2677 			}
2678 
2679 			// call function and encode result
2680 			if (ei_x_encode_atom(&result, "ok") ||
2681 				ei_x_encode_long(&result, sqlrcur_resumeResultSet(cur, id))) {
2682 				return ERR_ENCODING_ARGS;
2683 			}
2684 		}
2685 
2686 		if (strcmp("resumeCachedResultSet", command) == TRUE) {
2687 			long id;
2688 			char filename[FILE_NAME_SIZE];
2689 
2690 			// check number of arguments
2691 		    	if (arity != 2) return ERR_NUMBER_OF_ARGS;
2692 
2693 			// get input parameters
2694 			if (ei_decode_long(buf, &index, &id)) {
2695 				return ERR_DECODING_ARGS;
2696 			}
2697 			if (ei_decode_string(buf, &index, &filename[0])) {
2698 				return ERR_DECODING_ARGS;
2699 			}
2700 
2701 			// call function and encode result
2702 			if (ei_x_encode_atom(&result, "ok") ||
2703 				ei_x_encode_long(&result, sqlrcur_resumeCachedResultSet(cur, id, filename))) {
2704 				return ERR_ENCODING_ARGS;
2705 			}
2706 		}
2707 
2708 		if (strcmp("closeResultSet", command) == TRUE) {
2709 			// check number of arguments
2710 		    	if (arity != 0) return ERR_NUMBER_OF_ARGS;
2711 
2712 			// call function and encode result
2713 			sqlrcur_closeResultSet(cur);
2714 			ENCODE_VOID;
2715 		}
2716 
2717 
2718 
2719 		// write the result buffer back to the
2720 		// calling Erlang program
2721 		write_cmd(&result);
2722 
2723 		// free memory structure
2724     		ei_x_free(&result);
2725   	} // end of while statement
2726 
2727   	return 0;
2728 }
2729