changes for windows jdbc driverw
[csql.git] / src / network / NetworkPacket.cxx
blobca5e59804f978165a873f1df4d5e42d49cce7daa
1 /***************************************************************************
2 * Copyright (C) 2007 by Prabakaran Thirumalai *
3 * praba_tuty@yahoo.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #include <os.h>
21 #include <CSql.h>
22 #include <Network.h>
23 #include <DataType.h>
24 //#include <SqlLogStatement.h>
25 #include <SqlNwStatement.h>
26 #ifndef CSQL_CLIENT_LIB
27 #include <SqlNetworkHandler.h>
28 #endif
29 DbRetVal PacketPrepare::marshall()
31 printDebug(DM_Network, "PacketPrepare::marshall called\n");
32 bufferSize = sizeof(int) * 4 + strlen(stmtString) + 1;
33 printDebug(DM_Network, "NOOFPARAMS %d buffer size %d\n", noParams, bufferSize);
34 printDebug(DM_Network, "stmt %s size %d\n", stmtString, strlen(stmtString));
35 printDebug(DM_Network, "noParams is %d\n", noParams);
36 if (noParams >0)
37 bufferSize = bufferSize + 2 * sizeof(int) * noParams;
38 buffer = (char*) malloc(bufferSize);
39 *(int*)buffer = stmtID;
40 char *bufIter = buffer + sizeof(int);
41 *(int*)bufIter = syncMode;
42 bufIter = bufIter + sizeof(int);
43 *(int*)bufIter = strlen(stmtString);
44 bufIter = bufIter + sizeof(int);
45 *(int*)bufIter = noParams;
46 bufIter = bufIter + sizeof(int);
47 if (noParams >0) {
48 memcpy(bufIter, type, sizeof(int) * noParams);
49 bufIter = bufIter + sizeof(int)* noParams;
50 memcpy(bufIter, length, sizeof(int) * noParams);
51 bufIter = bufIter + sizeof(int)* noParams;
53 strcpy(bufIter, stmtString);
54 printDebug(DM_Network, "PacketPrepare::marshall ended\n");
55 return OK;
57 DbRetVal PacketPrepare::unmarshall()
59 printDebug(DM_Network, "PacketPrepare::unmarshall called\n");
60 stmtID = *(int*)buffer;
61 printDebug(DM_Network, "start of the buffer is %x\n", buffer);
62 char *bufIter = buffer + sizeof (int);
63 syncMode = *(int*)bufIter;
64 bufIter = bufIter + sizeof(int);
65 stmtLength = *(int*)bufIter;
66 bufIter = bufIter + sizeof(int);
67 noParams = *(int*)bufIter;
68 bufIter = bufIter + sizeof(int);
69 if (noParams >0) {
70 type = (int*) bufIter;
71 bufIter = bufIter + sizeof(int) * noParams;
72 length = (int*) bufIter;
73 bufIter = bufIter + sizeof(int) * noParams;
75 stmtString = bufIter;
76 printDebug(DM_Network, "stmtString ptr is %x\n", stmtString);
77 stmtString[stmtLength+1] = '\0';
78 printDebug(DM_Network, "PacketPrepare::unmarshall ended\n");
79 return OK;
81 DbRetVal PacketFree::marshall()
83 bufferSize = sizeof(int);
84 buffer = (char*) malloc(bufferSize);
85 *(int*)buffer = stmtID;
86 return OK;
88 DbRetVal PacketFree::unmarshall()
90 stmtID = *(int*)buffer;
91 return OK;
93 void PacketExecute::setParams(List list)
95 paramList = list;
96 noParams = list.size();
97 paramValues = new char*[noParams];
98 BindSqlField* bindField = NULL;
99 for (int i = 0 ; i < noParams; i++)
101 bindField = (BindSqlField*) paramList.get(i+1);
102 paramValues[i] = (char*) bindField->value;
104 return;
107 SqlPacketExecute::SqlPacketExecute()
109 buffer=NULL; bufferSize =0; pktType = NW_PKT_EXECUTE;
110 paramValues = NULL; nullInfo = NULL;
111 noParams=0; stmtID=0;
112 for (int i=0; i < 10; i++) localBuf[i] =0;
114 SqlPacketExecute::~SqlPacketExecute()
116 if(noParams >= 10) delete [] paramValues;
117 if (nullInfo) { free(nullInfo); nullInfo = NULL; }
118 free(buffer);
119 bufferSize =0;
120 buffer = NULL;
122 void SqlPacketExecute::setParams(List list)
124 paramList = list;
125 noParams = list.size();
126 if (!noParams) return;
127 if (noParams <10)
128 paramValues = localBuf;
129 else
130 paramValues = new char*[noParams];
131 BindSqlField* bindField = NULL;
132 for (int i = 0 ; i < noParams; i++)
134 bindField = (BindSqlField*) paramList.get(i+1);
135 paramValues[i] = (char*) bindField->value;
137 return;
140 void SqlPacketResultSet::setProjList(List list)
142 projList = list;
143 noProjs = list.size();
144 projValues = new char*[noProjs];
145 BindSqlProjectField* prjFld = NULL;
146 for (int i = 0 ; i < noProjs; i++)
148 prjFld = (BindSqlProjectField*) projList.get(i+1);
149 projValues[i] = (char*) prjFld->value;
151 return;
154 void PacketExecute::setStatementList(List stmtlist)
156 stmtList = stmtlist;
157 return;
160 void SqlPacketExecute::setStatementList(List stmtlist)
162 stmtList = stmtlist;
163 return;
166 DbRetVal PacketExecute::marshall()
168 bufferSize = sizeof(int)+ sizeof(int);
169 BindSqlField* bindField = NULL;
170 for (int i = 0 ; i < noParams; i++)
172 bindField = (BindSqlField*) paramList.get(i+1);
173 bufferSize = bufferSize + AllDataType::size(bindField->type, bindField->length);
175 buffer = (char*) malloc(bufferSize);
176 *(int*)buffer = stmtID;
177 char* bufIter = (char*) buffer + sizeof(int);
178 *(int*)bufIter = noParams;
179 bufIter = (char*) bufIter + sizeof(int);
180 for (int i = 0 ; i < noParams; i++)
182 bindField = (BindSqlField*) paramList.get(i+1);
183 AllDataType::copyVal(bufIter, bindField->value, bindField->type,bindField->length);
184 bufIter = bufIter + AllDataType::size(bindField->type, bindField->length);
186 return OK;
188 DbRetVal PacketExecute::unmarshall()
190 stmtID = *(int*)buffer;
191 char *bufIter = buffer + sizeof(int);
192 noParams = *(int*)bufIter;
193 bufIter = bufIter +sizeof(int);
194 ListIterator stmtIter = stmtList.getIterator();
195 NetworkStmt *stmt;
196 while (stmtIter.hasElement())
198 stmt = (NetworkStmt*) stmtIter.nextElement();
199 //TODO::Also check teh srcNetworkID
200 if (stmt->stmtID == stmtID ) break;
202 if (noParams == 0) return OK;
203 paramValues = new char*[noParams];
204 ListIterator paramIter = stmt->paramList.getIterator();
205 BindSqlField *bindField = NULL;
206 for (int i=0; i <noParams; i++)
208 paramValues[i] = bufIter;
209 bindField = (BindSqlField*) stmt->paramList.get(i+1);
210 bufIter = bufIter + AllDataType::size(bindField->type, bindField->length);
212 return OK;
215 void PacketCommit::setExecPackets(int tid, List list)
217 txnID = tid;
218 noOfStmts = list.size();
219 stmtBufSize = new int[noOfStmts];
220 stmtBuffer = new char*[noOfStmts];
221 PacketExecute* pkt = NULL;
222 int totalSize =0;
223 for (int i = 0 ; i < noOfStmts; i++)
225 pkt = (PacketExecute*) list.get(i+1);
226 if (pkt == NULL) printError(ErrSysFatal, "pkt is null.should never happen\n");
227 stmtBufSize[i] = pkt->getBufferSize();
228 stmtBuffer[i] = pkt->getMarshalledBuffer();
229 // *(int*)(((char*)stmtBuffer[i]) + 4));
230 totalSize = totalSize + stmtBufSize[i];
232 totalSize = sizeof(int) + sizeof(int) + noOfStmts * sizeof(int) +
233 totalSize;
234 bufferSize = totalSize;
235 return;
237 DbRetVal PacketCommit::marshall()
239 buffer = (char*) malloc(bufferSize);
240 *(int*)buffer = txnID;
241 char* bufIter = (char*) buffer + sizeof(int);
242 *(int*)bufIter = noOfStmts;
243 bufIter = (char*) bufIter + sizeof(int);
244 memcpy(bufIter, stmtBufSize, noOfStmts*sizeof(int));
245 bufIter = (char*) bufIter + noOfStmts* sizeof(int);
246 for (int i=0; i < noOfStmts; i++)
248 memcpy(bufIter, stmtBuffer[i], stmtBufSize[i]);
249 bufIter = bufIter + stmtBufSize[i];
251 return OK;
253 DbRetVal PacketCommit::unmarshall()
255 txnID = *(int*)buffer;
256 char *bufIter = buffer + sizeof(int);
257 noOfStmts = *(int*)bufIter;
258 bufIter = bufIter + sizeof(int);
259 stmtBufSize = new int[noOfStmts];
260 memcpy(stmtBufSize, bufIter, noOfStmts*sizeof(int));
261 bufIter = bufIter + noOfStmts * sizeof(int);
262 stmtBuffer = new char*[noOfStmts];
263 for (int i = 0 ; i <noOfStmts; i++)
265 stmtBuffer[i] = bufIter;
266 bufIter = bufIter + stmtBufSize[i];
268 return OK;
270 //call unmarshall before calling this
271 void PacketCommit::getExecPacketList(List stmtList, List &list)
273 PacketExecute* pkt = NULL;
274 for (int i = 0 ; i < noOfStmts; i++)
276 pkt = new PacketExecute();
277 pkt->setBuffer(stmtBuffer[i]);
278 pkt->setBufferSize(stmtBufSize[i]);
279 pkt->setStatementList(stmtList);
280 pkt->unmarshall();
281 list.append(pkt);
285 DbRetVal SqlPacketConnect::marshall()
287 printDebug(DM_Network, "SqlPacketConnect::marshall called");
288 char *ptr = buffer; // moves over buffer
289 strncpy(ptr, userName, IDENTIFIER_LENGTH);
290 printDebug(DM_Network, "Username: %s", userName);
291 ptr = buffer+IDENTIFIER_LENGTH-1;
292 *ptr++ = '\0';
293 strncpy(ptr, passWord, IDENTIFIER_LENGTH);
294 printDebug(DM_Network, "Password: %s", passWord);
295 ptr = ptr + IDENTIFIER_LENGTH-1;
296 *ptr++ = '\0';
297 *ptr++ = sqlApiImplType;
298 printDebug(DM_Network, "SqlPacketConnect::marshall Ended");
299 return OK;
302 DbRetVal SqlPacketConnect::unmarshall()
304 printDebug(DM_Network, "SqlPacketConnect::unmarshall called");
305 char *ptr = buffer;
307 strncpy(userName, ptr, IDENTIFIER_LENGTH);
308 printDebug(DM_Network, "Username: %s", userName);
309 ptr += IDENTIFIER_LENGTH;
310 strncpy(passWord, ptr, IDENTIFIER_LENGTH);
311 printDebug(DM_Network, "Password: %s", passWord);
312 ptr += IDENTIFIER_LENGTH;
313 sqlApiImplType = *ptr++;
314 printDebug(DM_Network, "SqlPacketConnect::unmarshall Ended");
315 return OK;
318 DbRetVal SqlPacketPrepare::marshall()
320 printDebug(DM_Network, "PacketPrepare::marshall called\n");
321 bufferSize = sizeof(int) + stmtLength;
322 printDebug(DM_Network, "Buffer size %d\n", bufferSize);
323 printDebug(DM_Network, "stmt %s size %d\n", stmtString, strlen(stmtString));
324 buffer = (char*) malloc(bufferSize);
325 *(int*)buffer = stmtLength;
326 char *bufIter = buffer + sizeof(int);
327 strcpy(bufIter, stmtString);
328 bufIter[strlen(stmtString)] = '\0';
329 printDebug(DM_Network, "PacketPrepare::marshall ended\n");
330 return OK;
333 DbRetVal SqlPacketPrepare::unmarshall()
335 printDebug(DM_Network, "PacketPrepare::unmarshall called\n");
336 printDebug(DM_Network, "start of the buffer is %x\n", buffer);
337 stmtLength = *(int*)buffer;
338 char *bufIter = buffer + sizeof(int);
339 stmtString = bufIter;
340 printDebug(DM_Network, "stmtString ptr is %x\n", stmtString);
341 stmtString[strlen(stmtString)] = '\0';
342 printDebug(DM_Network, "PacketPrepare::unmarshall ended\n");
343 return OK;
346 // the following marshall and unmarshall function is modified to accommodate
347 // the fix for MySQL Bug:1382
348 // SQLDescribeParam returns the same type information
349 // by sending type and length in exec packets.
350 DbRetVal SqlPacketExecute::marshall()
352 bufferSize = sizeof(int)+ sizeof(int);
353 BindSqlField* bindField = NULL;
354 for (int i = 0 ; i < noParams; i++)
356 bufferSize = bufferSize + 2 * sizeof(int);
357 bindField = (BindSqlField*) paramList.get(i+1);
358 if (bindField->type == typeBinary)
359 bufferSize = bufferSize + 2 * AllDataType::size(bindField->type, bindField->length);
360 else
361 bufferSize = bufferSize + AllDataType::size(bindField->type, bindField->length);
363 //allocate null info for setNull info for dml parameterized statements.
364 if (noParams) bufferSize += os::align(noParams);
365 buffer = (char*) malloc(bufferSize);
366 *(int*)buffer = stmtID;
367 char* bufIter = (char*) buffer + sizeof(int);
368 *(int*)bufIter = noParams;
369 bufIter = (char*) bufIter + sizeof(int);
370 for (int i = 0 ; i < noParams; i++)
372 bindField = (BindSqlField*) paramList.get(i+1);
373 if (bindField->type == typeBinary) {
374 *(int *)bufIter = typeBinary;
375 bufIter = (char*) bufIter + sizeof(int);
376 *(int *)bufIter = AllDataType::size(bindField->type, bindField->length);
377 bufIter = (char*) bufIter + sizeof(int);
378 AllDataType::copyVal(bufIter, bindField->value, bindField->type, 2 * bindField->length);
379 bufIter = bufIter + 2 * AllDataType::size(bindField->type, bindField->length);
380 } else {
381 *(int *)bufIter = bindField->type;
382 bufIter = (char*) bufIter + sizeof(int);
383 *(int *)bufIter = AllDataType::size(bindField->type, bindField->length);
384 bufIter = (char*) bufIter + sizeof(int);
385 AllDataType::copyVal(bufIter, bindField->value, bindField->type, bindField->length);
386 bufIter = bufIter + AllDataType::size(bindField->type, bindField->length);
389 if(noParams) memcpy(bufIter, nullInfo, os::align(noParams));
390 return OK;
393 DbRetVal SqlPacketExecute::unmarshall()
395 stmtID = *(int*)buffer;
396 char *bufIter = buffer + sizeof(int);
397 noParams = *(int*)bufIter;
398 bufIter = bufIter +sizeof(int);
399 ListIterator stmtIter = stmtList.getIterator();
400 NetworkStmt *stmt;
401 while (stmtIter.hasElement())
403 stmt = (NetworkStmt*) stmtIter.nextElement();
404 //TODO::Also check teh srcNetworkID
405 if (stmt->stmtID == stmtID ) break;
407 if (noParams == 0) return OK;
408 if (noParams <10 )
409 paramValues = localBuf;
410 else
411 paramValues = new char*[noParams];
412 ListIterator paramIter = stmt->paramList.getIterator();
413 BindSqlField *bindField = NULL;
414 for (int i=0; i <noParams; i++)
416 bindField = (BindSqlField*) stmt->paramList.get(i+1);
417 bindField->type = (DataType) *(int *)bufIter;
418 bufIter = (char*) bufIter + sizeof(int);
419 bindField->length = *(int *)bufIter;
420 bufIter = (char*) bufIter + sizeof(int);
421 paramValues[i] = bufIter;
422 bindField->value = paramValues[i];
423 if (bindField->type == typeBinary)
424 bufIter = bufIter + 2 * AllDataType::size(bindField->type, bindField->length);
425 else
426 bufIter = bufIter + AllDataType::size(bindField->type, bindField->length);
428 nullInfo = (char*) malloc(os::align(noParams));
429 memcpy(nullInfo, bufIter, os::align(noParams));
430 return OK;
433 DbRetVal SqlPacketParamMetadata::marshall()
435 #ifndef CSQL_CLIENT_LIB
436 printDebug(DM_Network, "SqlPacketParamMetadata::marshall called\n");
437 bufferSize = sizeof(int) * 2;
438 printDebug(DM_Network, "NOOFPARAMS %d buffer size %d\n", noParams, bufferSize);
439 printDebug(DM_Network, "noParams is %d\n", noParams);
440 if (noParams >0)
441 bufferSize = bufferSize + sizeof(FieldInfo) * noParams;
442 buffer = (char*) malloc(bufferSize);
443 *(int*)buffer = stmtID;
444 char *bufIter = buffer + sizeof(int);
445 *(int*)bufIter = noParams;
446 bufIter = bufIter + sizeof(int);
447 ListIterator stmtIter = SqlNetworkHandler::stmtList.getIterator();
448 NetworkStmt *stmt;
449 while (stmtIter.hasElement())
451 stmt = (NetworkStmt*) stmtIter.nextElement();
452 if (stmt->stmtID == stmtID ) break;
454 FieldInfo *fldInfo = new FieldInfo();
455 for (int i=0; i <noParams; i++) {
456 BindSqlField *bindField = (BindSqlField*) stmt->paramList.get(i+1);
457 strcpy(fldInfo->fldName, bindField->fName);
458 fldInfo->type = bindField->type;
459 fldInfo->length = bindField->length;
460 fldInfo->offset = bindField->offset;
461 fldInfo->isNull = bindField->isNull;
462 fldInfo->isPrimary = bindField->isPrimary;
463 fldInfo->isDefault = bindField->isDefault;
464 fldInfo->isUnique = bindField->isUnique;
465 strcpy(fldInfo->defaultValueBuf, bindField->defaultValueBuf);
466 *(FieldInfo *) bufIter = *fldInfo;
467 bufIter += sizeof(FieldInfo);
469 delete fldInfo;
470 printDebug(DM_Network, "SqlPacketParamMetadata::marshall ended\n");
471 #endif
472 return OK;
475 DbRetVal SqlPacketParamMetadata::unmarshall()
477 printDebug(DM_Network, "SqlPacketParamMetadata::unmarshall called\n");
478 stmtID = *(int*)buffer;
479 printDebug(DM_Network, "start of the buffer is %x\n", buffer);
480 char *bufIter = buffer + sizeof (int);
481 noParams = *(int*)bufIter;
482 bufIter = bufIter + sizeof(int);
483 if(noParams > 0) data = bufIter;
484 printDebug(DM_Network, "SqlPacketParamMetadata::unmarshall ended\n");
485 return OK;
488 DbRetVal SqlPacketProjMetadata::marshall()
490 #ifndef CSQL_CLIENT_LIB
491 printDebug(DM_Network, "SqlPacketParamMetadata::marshall called\n");
492 bufferSize = sizeof(int) * 2;
493 printDebug(DM_Network, "NOOFPROJS %d buffer size %d\n", noProjs, bufferSize);
494 printDebug(DM_Network, "noParams is %d\n", noProjs);
495 if (noProjs >0)
496 bufferSize = bufferSize + sizeof(FieldInfo) * noProjs;
497 buffer = (char*) malloc(bufferSize);
498 *(int*)buffer = stmtID;
499 char *bufIter = buffer + sizeof(int);
500 *(int*)bufIter = noProjs;
501 bufIter = bufIter + sizeof(int);
502 ListIterator stmtIter = SqlNetworkHandler::stmtList.getIterator();
503 NetworkStmt *stmt;
504 while (stmtIter.hasElement())
506 stmt = (NetworkStmt*) stmtIter.nextElement();
507 if (stmt->stmtID == stmtID ) break;
509 FieldInfo *fldInfo = new FieldInfo();
510 for (int i=0; i < noProjs; i++) {
511 BindSqlProjectField *bindField = (BindSqlProjectField*) stmt->projList.get(i+1);
512 strcpy(fldInfo->fldName, bindField->fName);
513 fldInfo->type = bindField->type;
514 fldInfo->length = bindField->length;
515 fldInfo->offset = bindField->offset;
516 fldInfo->isNull = bindField->isNull;
517 fldInfo->isPrimary = bindField->isPrimary;
518 fldInfo->isDefault = bindField->isDefault;
519 fldInfo->isUnique = bindField->isUnique;
520 strcpy(fldInfo->defaultValueBuf, bindField->defaultValueBuf);
521 fldInfo->aType = bindField->aType;
522 *(FieldInfo *) bufIter = *fldInfo;
523 bufIter += sizeof(FieldInfo);
525 delete fldInfo;
526 printDebug(DM_Network, "SqlPacketParamMetadata::marshall ended\n");
527 #endif
528 return OK;
531 DbRetVal SqlPacketProjMetadata::unmarshall()
533 printDebug(DM_Network, "SqlPacketProjMetadata::unmarshall called\n");
534 stmtID = *(int*)buffer;
535 printDebug(DM_Network, "start of the buffer is %x\n", buffer);
536 char *bufIter = buffer + sizeof (int);
537 noProjs = *(int*)bufIter;
538 bufIter = bufIter + sizeof(int);
539 if(noProjs > 0) data = bufIter;
540 printDebug(DM_Network, "SqlPacketProjMetadata::unmarshall ended\n");
541 return OK;
544 DbRetVal SqlPacketFetch::marshall()
546 bufferSize = sizeof(int);
547 buffer = (char*) malloc(bufferSize);
548 *(int*)buffer = stmtID;
549 return OK;
552 DbRetVal SqlPacketFetch::unmarshall()
554 stmtID = *(int *)buffer;
555 return OK;
558 DbRetVal SqlPacketFree::marshall()
560 bufferSize = sizeof(int);
561 buffer = (char*) malloc(bufferSize);
562 *(int*)buffer = stmtID;
563 return OK;
566 DbRetVal SqlPacketFree::unmarshall()
568 stmtID = *(int *)buffer;
569 return OK;
572 DbRetVal SqlPacketResultSet::marshall()
574 bufferSize = sizeof(int)+ sizeof(int);
575 BindSqlProjectField* prjFld = NULL;
576 for (int i = 0 ; i < noProjs; i++)
578 prjFld = (BindSqlProjectField*) projList.get(i+1);
579 bufferSize = bufferSize + AllDataType::size(prjFld->type, prjFld->length);
581 //allocate buffer for nullInfo
582 bufferSize = bufferSize + os::align(noProjs);
583 buffer = (char*) malloc(bufferSize);
584 *(int*)buffer = hasData;
585 char* bufIter = (char*) buffer + sizeof(int);
586 *(int*)bufIter = noProjs;
587 bufIter = (char*) bufIter + sizeof(int);
588 for (int i = 0 ; i < noProjs; i++)
590 prjFld = (BindSqlProjectField*) projList.get(i+1);
591 AllDataType::copyVal(bufIter, prjFld->value, prjFld->type, prjFld->length);
592 bufIter = bufIter + AllDataType::size(prjFld->type, prjFld->length);
594 memcpy(bufIter, nullInfo, os::align(noProjs));
595 return OK;
598 DbRetVal SqlPacketResultSet::unmarshall()
600 hasData = *(int*)buffer;
601 char *bufIter = buffer + sizeof(int);
602 noProjs = *(int*)bufIter;
603 bufIter = bufIter + sizeof(int);
604 BindSqlProjectField *prjFld = NULL;
605 for (int i=0; i <noProjs; i++)
607 prjFld = (BindSqlProjectField*) projList.get(i+1);
608 AllDataType::copyVal(prjFld->value, bufIter, prjFld->type, prjFld->length);
609 bufIter = bufIter + AllDataType::size(prjFld->type, prjFld->length);
611 memcpy(nullInfo, bufIter, os::align(noProjs));
612 return OK;
615 DbRetVal SqlPacketShowTables::marshall()
617 #ifndef CSQL_CLIENT_LIB
618 bufferSize = numOfTables * IDENTIFIER_LENGTH;
619 buffer = (char*) malloc(bufferSize);
620 char *bufIter = buffer;
621 Identifier *elem = NULL;
622 ListIterator tblIter = SqlNetworkHandler::tableNameList.getIterator();
623 while (tblIter.hasElement()) {
624 elem = (Identifier*) tblIter.nextElement();
625 strncpy(bufIter, elem->name, IDENTIFIER_LENGTH);
626 bufIter += IDENTIFIER_LENGTH;
628 #endif
629 return OK;
632 DbRetVal SqlPacketShowTables::unmarshall()
634 data = buffer;
635 return OK;
638 DbRetVal SqlPacketIsTablePresent::marshall()
640 bufferSize = IDENTIFIER_LENGTH + sizeof(int);
641 buffer = (char*) malloc(bufferSize);
642 char *ptr = buffer;
643 strncpy(ptr, tblName, IDENTIFIER_LENGTH);
644 ptr += IDENTIFIER_LENGTH;
645 return OK;
648 DbRetVal SqlPacketIsTablePresent::unmarshall()
650 char *ptr = buffer;
651 strncpy(tblName, buffer, IDENTIFIER_LENGTH);
652 ptr += IDENTIFIER_LENGTH;
653 return OK;
656 DbRetVal SqlPacketGetRecords::marshall()
658 printDebug(DM_Network, "SqlPacketGetRecords: marshall called");
659 bufferSize = IDENTIFIER_LENGTH;
660 printDebug(DM_Network, "Buffer Size = %d", bufferSize);
661 buffer = (char *) malloc(bufferSize);
662 printDebug(DM_Network, "start of the buffer is %x", buffer);
663 strncpy(buffer, tblName, IDENTIFIER_LENGTH);
664 printDebug(DM_Network, "SqlPacketGetRecords: marshall Ended");
665 return OK;
668 DbRetVal SqlPacketGetRecords::unmarshall()
670 printDebug(DM_Network, "SqlPacketGetRecords: unmarshall called");
671 strncpy(tblName, buffer, IDENTIFIER_LENGTH);
672 printDebug(DM_Network, "TableName %s", buffer);
673 printDebug(DM_Network, "SqlPacketGetRecords: unmarshall Ended");
674 return OK;
677 DbRetVal SqlPacketLoadRecords::marshall()
679 printDebug(DM_Network, "SqlPacketLoadRecords:marshall called");
680 bufferSize = sizeof (int) + PAGE_SIZE * pages;
681 printDebug(DM_Network, "Buffer Size = %d", bufferSize);
682 buffer = (char *) malloc(bufferSize);
683 printDebug(DM_Network, "start of the buffer is %x", buffer);
684 *(int *) buffer = pages;
685 printDebug(DM_Network, "SqlPacketLoadRecords: marshall Ended");
686 return OK;
689 DbRetVal SqlPacketLoadRecords::unmarshall()
691 printDebug(DM_Network, "SqlPacketLoadRecords: unmarshall called");
692 pages = *(int *) buffer;
693 printDebug(DM_Network, "No of pages to be loaded: %d", pages);
694 printDebug(DM_Network, "SqlPacketLoadRecords: unmarshall Ended");
695 return OK;