1 /***************************************************************************
2 * Copyright (C) 2007 by Prabakaran Thirumalai *
3 * praba_tuty@yahoo.com *
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. *
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. *
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 ***************************************************************************/
24 #include <SqlLogStatement.h>
25 #include <SqlNwStatement.h>
26 #include <SqlNetworkHandler.h>
28 DbRetVal
PacketPrepare::marshall()
30 printDebug(DM_Network
, "PacketPrepare::marshall called\n");
31 bufferSize
= sizeof(int) * 4 + strlen(stmtString
) + 1;
32 printDebug(DM_Network
, "NOOFPARAMS %d buffer size %d\n", noParams
, bufferSize
);
33 printDebug(DM_Network
, "stmt %s size %d\n", stmtString
, strlen(stmtString
));
34 printDebug(DM_Network
, "noParams is %d\n", noParams
);
36 bufferSize
= bufferSize
+ 2 * sizeof(int) * noParams
;
37 buffer
= (char*) malloc(bufferSize
);
38 *(int*)buffer
= stmtID
;
39 char *bufIter
= buffer
+ sizeof(int);
40 *(int*)bufIter
= syncMode
;
41 bufIter
= bufIter
+ sizeof(int);
42 *(int*)bufIter
= strlen(stmtString
);
43 bufIter
= bufIter
+ sizeof(int);
44 *(int*)bufIter
= noParams
;
45 bufIter
= bufIter
+ sizeof(int);
47 memcpy(bufIter
, type
, sizeof(int) * noParams
);
48 bufIter
= bufIter
+ sizeof(int)* noParams
;
49 memcpy(bufIter
, length
, sizeof(int) * noParams
);
50 bufIter
= bufIter
+ sizeof(int)* noParams
;
52 strcpy(bufIter
, stmtString
);
53 printDebug(DM_Network
, "PacketPrepare::marshall ended\n");
56 DbRetVal
PacketPrepare::unmarshall()
58 printDebug(DM_Network
, "PacketPrepare::unmarshall called\n");
59 stmtID
= *(int*)buffer
;
60 printDebug(DM_Network
, "start of the buffer is %x\n", buffer
);
61 char *bufIter
= buffer
+ sizeof (int);
62 syncMode
= *(int*)bufIter
;
63 bufIter
= bufIter
+ sizeof(int);
64 stmtLength
= *(int*)bufIter
;
65 bufIter
= bufIter
+ sizeof(int);
66 noParams
= *(int*)bufIter
;
67 bufIter
= bufIter
+ sizeof(int);
69 type
= (int*) bufIter
;
70 bufIter
= bufIter
+ sizeof(int) * noParams
;
71 length
= (int*) bufIter
;
72 bufIter
= bufIter
+ sizeof(int) * noParams
;
75 printDebug(DM_Network
, "stmtString ptr is %x\n", stmtString
);
76 stmtString
[stmtLength
+1] = '\0';
77 printDebug(DM_Network
, "PacketPrepare::unmarshall ended\n");
80 DbRetVal
PacketFree::marshall()
82 bufferSize
= sizeof(int);
83 buffer
= (char*) malloc(bufferSize
);
84 *(int*)buffer
= stmtID
;
87 DbRetVal
PacketFree::unmarshall()
89 stmtID
= *(int*)buffer
;
92 void PacketExecute::setParams(List list
)
95 noParams
= list
.size();
96 paramValues
= new char*[noParams
];
97 BindSqlField
* bindField
= NULL
;
98 for (int i
= 0 ; i
< noParams
; i
++)
100 bindField
= (BindSqlField
*) paramList
.get(i
+1);
101 paramValues
[i
] = (char*) bindField
->value
;
106 SqlPacketExecute::SqlPacketExecute()
108 buffer
=NULL
; bufferSize
=0; pktType
= NW_PKT_EXECUTE
;
109 paramValues
= NULL
; nullInfo
= NULL
;
110 noParams
=0; stmtID
=0;
111 for (int i
=0; i
< 10; i
++) localBuf
[i
] =0;
113 SqlPacketExecute::~SqlPacketExecute()
115 if(noParams
>= 10) delete [] paramValues
;
116 if (nullInfo
) { free(nullInfo
); nullInfo
= NULL
; }
121 void SqlPacketExecute::setParams(List list
)
124 noParams
= list
.size();
125 if (!noParams
) return;
127 paramValues
= localBuf
;
129 paramValues
= new char*[noParams
];
130 BindSqlField
* bindField
= NULL
;
131 for (int i
= 0 ; i
< noParams
; i
++)
133 bindField
= (BindSqlField
*) paramList
.get(i
+1);
134 paramValues
[i
] = (char*) bindField
->value
;
139 void SqlPacketResultSet::setProjList(List list
)
142 noProjs
= list
.size();
143 projValues
= new char*[noProjs
];
144 BindSqlProjectField
* prjFld
= NULL
;
145 for (int i
= 0 ; i
< noProjs
; i
++)
147 prjFld
= (BindSqlProjectField
*) projList
.get(i
+1);
148 projValues
[i
] = (char*) prjFld
->value
;
153 void PacketExecute::setStatementList(List stmtlist
)
159 void SqlPacketExecute::setStatementList(List stmtlist
)
165 DbRetVal
PacketExecute::marshall()
167 bufferSize
= sizeof(int)+ sizeof(int);
168 BindSqlField
* bindField
= NULL
;
169 for (int i
= 0 ; i
< noParams
; i
++)
171 bindField
= (BindSqlField
*) paramList
.get(i
+1);
172 bufferSize
= bufferSize
+ AllDataType::size(bindField
->type
, bindField
->length
);
174 buffer
= (char*) malloc(bufferSize
);
175 *(int*)buffer
= stmtID
;
176 char* bufIter
= (char*) buffer
+ sizeof(int);
177 *(int*)bufIter
= noParams
;
178 bufIter
= (char*) bufIter
+ sizeof(int);
179 for (int i
= 0 ; i
< noParams
; i
++)
181 bindField
= (BindSqlField
*) paramList
.get(i
+1);
182 AllDataType::copyVal(bufIter
, bindField
->value
, bindField
->type
,bindField
->length
);
183 bufIter
= bufIter
+ AllDataType::size(bindField
->type
, bindField
->length
);
187 DbRetVal
PacketExecute::unmarshall()
189 stmtID
= *(int*)buffer
;
190 char *bufIter
= buffer
+ sizeof(int);
191 noParams
= *(int*)bufIter
;
192 bufIter
= bufIter
+sizeof(int);
193 ListIterator stmtIter
= stmtList
.getIterator();
195 while (stmtIter
.hasElement())
197 stmt
= (NetworkStmt
*) stmtIter
.nextElement();
198 //TODO::Also check teh srcNetworkID
199 if (stmt
->stmtID
== stmtID
) break;
201 if (noParams
== 0) return OK
;
202 paramValues
= new char*[noParams
];
203 ListIterator paramIter
= stmt
->paramList
.getIterator();
204 BindSqlField
*bindField
= NULL
;
205 for (int i
=0; i
<noParams
; i
++)
207 paramValues
[i
] = bufIter
;
208 bindField
= (BindSqlField
*) stmt
->paramList
.get(i
+1);
209 bufIter
= bufIter
+ AllDataType::size(bindField
->type
, bindField
->length
);
214 void PacketCommit::setExecPackets(int tid
, List list
)
217 noOfStmts
= list
.size();
218 stmtBufSize
= new int[noOfStmts
];
219 stmtBuffer
= new char*[noOfStmts
];
220 PacketExecute
* pkt
= NULL
;
222 for (int i
= 0 ; i
< noOfStmts
; i
++)
224 pkt
= (PacketExecute
*) list
.get(i
+1);
225 if (pkt
== NULL
) printError(ErrSysFatal
, "pkt is null.should never happen\n");
226 stmtBufSize
[i
] = pkt
->getBufferSize();
227 stmtBuffer
[i
] = pkt
->getMarshalledBuffer();
228 // *(int*)(((char*)stmtBuffer[i]) + 4));
229 totalSize
= totalSize
+ stmtBufSize
[i
];
231 totalSize
= sizeof(int) + sizeof(int) + noOfStmts
* sizeof(int) +
233 bufferSize
= totalSize
;
236 DbRetVal
PacketCommit::marshall()
238 buffer
= (char*) malloc(bufferSize
);
239 *(int*)buffer
= txnID
;
240 char* bufIter
= (char*) buffer
+ sizeof(int);
241 *(int*)bufIter
= noOfStmts
;
242 bufIter
= (char*) bufIter
+ sizeof(int);
243 memcpy(bufIter
, stmtBufSize
, noOfStmts
*sizeof(int));
244 bufIter
= (char*) bufIter
+ noOfStmts
* sizeof(int);
245 for (int i
=0; i
< noOfStmts
; i
++)
247 memcpy(bufIter
, stmtBuffer
[i
], stmtBufSize
[i
]);
248 bufIter
= bufIter
+ stmtBufSize
[i
];
252 DbRetVal
PacketCommit::unmarshall()
254 txnID
= *(int*)buffer
;
255 char *bufIter
= buffer
+ sizeof(int);
256 noOfStmts
= *(int*)bufIter
;
257 bufIter
= bufIter
+ sizeof(int);
258 stmtBufSize
= new int[noOfStmts
];
259 memcpy(stmtBufSize
, bufIter
, noOfStmts
*sizeof(int));
260 bufIter
= bufIter
+ noOfStmts
* sizeof(int);
261 stmtBuffer
= new char*[noOfStmts
];
262 for (int i
= 0 ; i
<noOfStmts
; i
++)
264 stmtBuffer
[i
] = bufIter
;
265 bufIter
= bufIter
+ stmtBufSize
[i
];
269 //call unmarshall before calling this
270 void PacketCommit::getExecPacketList(List stmtList
, List
&list
)
272 PacketExecute
* pkt
= NULL
;
273 for (int i
= 0 ; i
< noOfStmts
; i
++)
275 pkt
= new PacketExecute();
276 pkt
->setBuffer(stmtBuffer
[i
]);
277 pkt
->setBufferSize(stmtBufSize
[i
]);
278 pkt
->setStatementList(stmtList
);
284 DbRetVal
SqlPacketConnect::marshall()
286 printDebug(DM_Network
, "SqlPacketConnect::marshall called");
287 char *ptr
= buffer
; // moves over buffer
288 strncpy(ptr
, userName
, IDENTIFIER_LENGTH
);
289 printDebug(DM_Network
, "Username: %s", userName
);
290 ptr
= buffer
+IDENTIFIER_LENGTH
-1;
292 strncpy(ptr
, passWord
, IDENTIFIER_LENGTH
);
293 printDebug(DM_Network
, "Password: %s", passWord
);
294 ptr
= ptr
+ IDENTIFIER_LENGTH
-1;
296 *ptr
++ = sqlApiImplType
;
297 printDebug(DM_Network
, "SqlPacketConnect::marshall Ended");
301 DbRetVal
SqlPacketConnect::unmarshall()
303 printDebug(DM_Network
, "SqlPacketConnect::unmarshall called");
306 strncpy(userName
, ptr
, IDENTIFIER_LENGTH
);
307 printDebug(DM_Network
, "Username: %s", userName
);
308 ptr
+= IDENTIFIER_LENGTH
;
309 strncpy(passWord
, ptr
, IDENTIFIER_LENGTH
);
310 printDebug(DM_Network
, "Password: %s", passWord
);
311 ptr
+= IDENTIFIER_LENGTH
;
312 sqlApiImplType
= *ptr
++;
313 printDebug(DM_Network
, "SqlPacketConnect::unmarshall Ended");
317 DbRetVal
SqlPacketPrepare::marshall()
319 printDebug(DM_Network
, "PacketPrepare::marshall called\n");
320 bufferSize
= sizeof(int) + stmtLength
;
321 printDebug(DM_Network
, "Buffer size %d\n", bufferSize
);
322 printDebug(DM_Network
, "stmt %s size %d\n", stmtString
, strlen(stmtString
));
323 buffer
= (char*) malloc(bufferSize
);
324 *(int*)buffer
= stmtLength
;
325 char *bufIter
= buffer
+ sizeof(int);
326 strcpy(bufIter
, stmtString
);
327 bufIter
[strlen(stmtString
)] = '\0';
328 printDebug(DM_Network
, "PacketPrepare::marshall ended\n");
332 DbRetVal
SqlPacketPrepare::unmarshall()
334 printDebug(DM_Network
, "PacketPrepare::unmarshall called\n");
335 printDebug(DM_Network
, "start of the buffer is %x\n", buffer
);
336 stmtLength
= *(int*)buffer
;
337 char *bufIter
= buffer
+ sizeof(int);
338 stmtString
= bufIter
;
339 printDebug(DM_Network
, "stmtString ptr is %x\n", stmtString
);
340 stmtString
[strlen(stmtString
)] = '\0';
341 printDebug(DM_Network
, "PacketPrepare::unmarshall ended\n");
345 // the following marshall and unmarshall function is modified to accommodate
346 // the fix for MySQL Bug:1382
347 // SQLDescribeParam returns the same type information
348 // by sending type and length in exec packets.
349 DbRetVal
SqlPacketExecute::marshall()
351 bufferSize
= sizeof(int)+ sizeof(int);
352 BindSqlField
* bindField
= NULL
;
353 for (int i
= 0 ; i
< noParams
; i
++)
355 bufferSize
= bufferSize
+ 2 * sizeof(int);
356 bindField
= (BindSqlField
*) paramList
.get(i
+1);
357 if (bindField
->type
== typeBinary
)
358 bufferSize
= bufferSize
+ 2 * AllDataType::size(bindField
->type
, bindField
->length
);
360 bufferSize
= bufferSize
+ AllDataType::size(bindField
->type
, bindField
->length
);
362 //allocate null info for setNull info for dml parameterized statements.
363 if (noParams
) bufferSize
+= os::align(noParams
);
364 buffer
= (char*) malloc(bufferSize
);
365 *(int*)buffer
= stmtID
;
366 char* bufIter
= (char*) buffer
+ sizeof(int);
367 *(int*)bufIter
= noParams
;
368 bufIter
= (char*) bufIter
+ sizeof(int);
369 for (int i
= 0 ; i
< noParams
; i
++)
371 bindField
= (BindSqlField
*) paramList
.get(i
+1);
372 if (bindField
->type
== typeBinary
) {
373 *(int *)bufIter
= typeBinary
;
374 bufIter
= (char*) bufIter
+ sizeof(int);
375 *(int *)bufIter
= AllDataType::size(bindField
->type
, bindField
->length
);
376 bufIter
= (char*) bufIter
+ sizeof(int);
377 AllDataType::copyVal(bufIter
, bindField
->value
, bindField
->type
, 2 * bindField
->length
);
378 bufIter
= bufIter
+ 2 * AllDataType::size(bindField
->type
, bindField
->length
);
380 *(int *)bufIter
= bindField
->type
;
381 bufIter
= (char*) bufIter
+ sizeof(int);
382 *(int *)bufIter
= AllDataType::size(bindField
->type
, bindField
->length
);
383 bufIter
= (char*) bufIter
+ sizeof(int);
384 AllDataType::copyVal(bufIter
, bindField
->value
, bindField
->type
, bindField
->length
);
385 bufIter
= bufIter
+ AllDataType::size(bindField
->type
, bindField
->length
);
388 if(noParams
) memcpy(bufIter
, nullInfo
, os::align(noParams
));
392 DbRetVal
SqlPacketExecute::unmarshall()
394 stmtID
= *(int*)buffer
;
395 char *bufIter
= buffer
+ sizeof(int);
396 noParams
= *(int*)bufIter
;
397 bufIter
= bufIter
+sizeof(int);
398 ListIterator stmtIter
= stmtList
.getIterator();
400 while (stmtIter
.hasElement())
402 stmt
= (NetworkStmt
*) stmtIter
.nextElement();
403 //TODO::Also check teh srcNetworkID
404 if (stmt
->stmtID
== stmtID
) break;
406 if (noParams
== 0) return OK
;
408 paramValues
= localBuf
;
410 paramValues
= new char*[noParams
];
411 ListIterator paramIter
= stmt
->paramList
.getIterator();
412 BindSqlField
*bindField
= NULL
;
413 for (int i
=0; i
<noParams
; i
++)
415 bindField
= (BindSqlField
*) stmt
->paramList
.get(i
+1);
416 bindField
->type
= (DataType
) *(int *)bufIter
;
417 bufIter
= (char*) bufIter
+ sizeof(int);
418 bindField
->length
= *(int *)bufIter
;
419 bufIter
= (char*) bufIter
+ sizeof(int);
420 paramValues
[i
] = bufIter
;
421 bindField
->value
= paramValues
[i
];
422 if (bindField
->type
== typeBinary
)
423 bufIter
= bufIter
+ 2 * AllDataType::size(bindField
->type
, bindField
->length
);
425 bufIter
= bufIter
+ AllDataType::size(bindField
->type
, bindField
->length
);
427 nullInfo
= (char*) malloc(os::align(noParams
));
428 memcpy(nullInfo
, bufIter
, os::align(noParams
));
432 DbRetVal
SqlPacketParamMetadata::marshall()
434 printDebug(DM_Network
, "SqlPacketParamMetadata::marshall called\n");
435 bufferSize
= sizeof(int) * 2;
436 printDebug(DM_Network
, "NOOFPARAMS %d buffer size %d\n", noParams
, bufferSize
);
437 printDebug(DM_Network
, "noParams is %d\n", noParams
);
439 bufferSize
= bufferSize
+ sizeof(FieldInfo
) * noParams
;
440 buffer
= (char*) malloc(bufferSize
);
441 *(int*)buffer
= stmtID
;
442 char *bufIter
= buffer
+ sizeof(int);
443 *(int*)bufIter
= noParams
;
444 bufIter
= bufIter
+ sizeof(int);
445 ListIterator stmtIter
= SqlNetworkHandler::stmtList
.getIterator();
447 while (stmtIter
.hasElement())
449 stmt
= (NetworkStmt
*) stmtIter
.nextElement();
450 if (stmt
->stmtID
== stmtID
) break;
452 FieldInfo
*fldInfo
= new FieldInfo();
453 for (int i
=0; i
<noParams
; i
++) {
454 BindSqlField
*bindField
= (BindSqlField
*) stmt
->paramList
.get(i
+1);
455 strcpy(fldInfo
->fldName
, bindField
->fName
);
456 fldInfo
->type
= bindField
->type
;
457 fldInfo
->length
= bindField
->length
;
458 fldInfo
->offset
= bindField
->offset
;
459 fldInfo
->isNull
= bindField
->isNull
;
460 fldInfo
->isPrimary
= bindField
->isPrimary
;
461 fldInfo
->isDefault
= bindField
->isDefault
;
462 fldInfo
->isUnique
= bindField
->isUnique
;
463 strcpy(fldInfo
->defaultValueBuf
, bindField
->defaultValueBuf
);
464 *(FieldInfo
*) bufIter
= *fldInfo
;
465 bufIter
+= sizeof(FieldInfo
);
468 printDebug(DM_Network
, "SqlPacketParamMetadata::marshall ended\n");
472 DbRetVal
SqlPacketParamMetadata::unmarshall()
474 printDebug(DM_Network
, "SqlPacketParamMetadata::unmarshall called\n");
475 stmtID
= *(int*)buffer
;
476 printDebug(DM_Network
, "start of the buffer is %x\n", buffer
);
477 char *bufIter
= buffer
+ sizeof (int);
478 noParams
= *(int*)bufIter
;
479 bufIter
= bufIter
+ sizeof(int);
480 if(noParams
> 0) data
= bufIter
;
481 printDebug(DM_Network
, "SqlPacketParamMetadata::unmarshall ended\n");
485 DbRetVal
SqlPacketProjMetadata::marshall()
487 printDebug(DM_Network
, "SqlPacketParamMetadata::marshall called\n");
488 bufferSize
= sizeof(int) * 2;
489 printDebug(DM_Network
, "NOOFPROJS %d buffer size %d\n", noProjs
, bufferSize
);
490 printDebug(DM_Network
, "noParams is %d\n", noProjs
);
492 bufferSize
= bufferSize
+ sizeof(FieldInfo
) * noProjs
;
493 buffer
= (char*) malloc(bufferSize
);
494 *(int*)buffer
= stmtID
;
495 char *bufIter
= buffer
+ sizeof(int);
496 *(int*)bufIter
= noProjs
;
497 bufIter
= bufIter
+ sizeof(int);
498 ListIterator stmtIter
= SqlNetworkHandler::stmtList
.getIterator();
500 while (stmtIter
.hasElement())
502 stmt
= (NetworkStmt
*) stmtIter
.nextElement();
503 if (stmt
->stmtID
== stmtID
) break;
505 FieldInfo
*fldInfo
= new FieldInfo();
506 for (int i
=0; i
< noProjs
; i
++) {
507 BindSqlProjectField
*bindField
= (BindSqlProjectField
*) stmt
->projList
.get(i
+1);
508 strcpy(fldInfo
->fldName
, bindField
->fName
);
509 fldInfo
->type
= bindField
->type
;
510 fldInfo
->length
= bindField
->length
;
511 fldInfo
->offset
= bindField
->offset
;
512 fldInfo
->isNull
= bindField
->isNull
;
513 fldInfo
->isPrimary
= bindField
->isPrimary
;
514 fldInfo
->isDefault
= bindField
->isDefault
;
515 fldInfo
->isUnique
= bindField
->isUnique
;
516 strcpy(fldInfo
->defaultValueBuf
, bindField
->defaultValueBuf
);
517 fldInfo
->aType
= bindField
->aType
;
518 *(FieldInfo
*) bufIter
= *fldInfo
;
519 bufIter
+= sizeof(FieldInfo
);
522 printDebug(DM_Network
, "SqlPacketParamMetadata::marshall ended\n");
526 DbRetVal
SqlPacketProjMetadata::unmarshall()
528 printDebug(DM_Network
, "SqlPacketProjMetadata::unmarshall called\n");
529 stmtID
= *(int*)buffer
;
530 printDebug(DM_Network
, "start of the buffer is %x\n", buffer
);
531 char *bufIter
= buffer
+ sizeof (int);
532 noProjs
= *(int*)bufIter
;
533 bufIter
= bufIter
+ sizeof(int);
534 if(noProjs
> 0) data
= bufIter
;
535 printDebug(DM_Network
, "SqlPacketProjMetadata::unmarshall ended\n");
539 DbRetVal
SqlPacketFetch::marshall()
541 bufferSize
= sizeof(int);
542 buffer
= (char*) malloc(bufferSize
);
543 *(int*)buffer
= stmtID
;
547 DbRetVal
SqlPacketFetch::unmarshall()
549 stmtID
= *(int *)buffer
;
553 DbRetVal
SqlPacketFree::marshall()
555 bufferSize
= sizeof(int);
556 buffer
= (char*) malloc(bufferSize
);
557 *(int*)buffer
= stmtID
;
561 DbRetVal
SqlPacketFree::unmarshall()
563 stmtID
= *(int *)buffer
;
567 DbRetVal
SqlPacketResultSet::marshall()
569 bufferSize
= sizeof(int)+ sizeof(int);
570 BindSqlProjectField
* prjFld
= NULL
;
571 for (int i
= 0 ; i
< noProjs
; i
++)
573 prjFld
= (BindSqlProjectField
*) projList
.get(i
+1);
574 bufferSize
= bufferSize
+ AllDataType::size(prjFld
->type
, prjFld
->length
);
576 //allocate buffer for nullInfo
577 bufferSize
= bufferSize
+ os::align(noProjs
);
578 buffer
= (char*) malloc(bufferSize
);
579 *(int*)buffer
= hasData
;
580 char* bufIter
= (char*) buffer
+ sizeof(int);
581 *(int*)bufIter
= noProjs
;
582 bufIter
= (char*) bufIter
+ sizeof(int);
583 for (int i
= 0 ; i
< noProjs
; i
++)
585 prjFld
= (BindSqlProjectField
*) projList
.get(i
+1);
586 AllDataType::copyVal(bufIter
, prjFld
->value
, prjFld
->type
, prjFld
->length
);
587 bufIter
= bufIter
+ AllDataType::size(prjFld
->type
, prjFld
->length
);
589 memcpy(bufIter
, nullInfo
, os::align(noProjs
));
593 DbRetVal
SqlPacketResultSet::unmarshall()
595 hasData
= *(int*)buffer
;
596 char *bufIter
= buffer
+ sizeof(int);
597 noProjs
= *(int*)bufIter
;
598 bufIter
= bufIter
+ sizeof(int);
599 BindSqlProjectField
*prjFld
= NULL
;
600 for (int i
=0; i
<noProjs
; i
++)
602 prjFld
= (BindSqlProjectField
*) projList
.get(i
+1);
603 AllDataType::copyVal(prjFld
->value
, bufIter
, prjFld
->type
, prjFld
->length
);
604 bufIter
= bufIter
+ AllDataType::size(prjFld
->type
, prjFld
->length
);
606 memcpy(nullInfo
, bufIter
, os::align(noProjs
));
610 DbRetVal
SqlPacketShowTables::marshall()
612 bufferSize
= numOfTables
* IDENTIFIER_LENGTH
;
613 buffer
= (char*) malloc(bufferSize
);
614 char *bufIter
= buffer
;
615 Identifier
*elem
= NULL
;
616 ListIterator tblIter
= SqlNetworkHandler::tableNameList
.getIterator();
617 while (tblIter
.hasElement()) {
618 elem
= (Identifier
*) tblIter
.nextElement();
619 strncpy(bufIter
, elem
->name
, IDENTIFIER_LENGTH
);
620 bufIter
+= IDENTIFIER_LENGTH
;
625 DbRetVal
SqlPacketShowTables::unmarshall()
631 DbRetVal
SqlPacketIsTablePresent::marshall()
633 bufferSize
= IDENTIFIER_LENGTH
+ sizeof(int);
634 buffer
= (char*) malloc(bufferSize
);
636 strncpy(ptr
, tblName
, IDENTIFIER_LENGTH
);
637 ptr
+= IDENTIFIER_LENGTH
;
641 DbRetVal
SqlPacketIsTablePresent::unmarshall()
644 strncpy(tblName
, buffer
, IDENTIFIER_LENGTH
);
645 ptr
+= IDENTIFIER_LENGTH
;
649 DbRetVal
SqlPacketGetRecords::marshall()
651 printDebug(DM_Network
, "SqlPacketGetRecords: marshall called");
652 bufferSize
= IDENTIFIER_LENGTH
;
653 printDebug(DM_Network
, "Buffer Size = %d", bufferSize
);
654 buffer
= (char *) malloc(bufferSize
);
655 printDebug(DM_Network
, "start of the buffer is %x", buffer
);
656 strncpy(buffer
, tblName
, IDENTIFIER_LENGTH
);
657 printDebug(DM_Network
, "SqlPacketGetRecords: marshall Ended");
661 DbRetVal
SqlPacketGetRecords::unmarshall()
663 printDebug(DM_Network
, "SqlPacketGetRecords: unmarshall called");
664 strncpy(tblName
, buffer
, IDENTIFIER_LENGTH
);
665 printDebug(DM_Network
, "TableName %s", buffer
);
666 printDebug(DM_Network
, "SqlPacketGetRecords: unmarshall Ended");
670 DbRetVal
SqlPacketLoadRecords::marshall()
672 printDebug(DM_Network
, "SqlPacketLoadRecords:marshall called");
673 bufferSize
= sizeof (int) + PAGE_SIZE
* pages
;
674 printDebug(DM_Network
, "Buffer Size = %d", bufferSize
);
675 buffer
= (char *) malloc(bufferSize
);
676 printDebug(DM_Network
, "start of the buffer is %x", buffer
);
677 *(int *) buffer
= pages
;
678 printDebug(DM_Network
, "SqlPacketLoadRecords: marshall Ended");
682 DbRetVal
SqlPacketLoadRecords::unmarshall()
684 printDebug(DM_Network
, "SqlPacketLoadRecords: unmarshall called");
685 pages
= *(int *) buffer
;
686 printDebug(DM_Network
, "No of pages to be loaded: %d", pages
);
687 printDebug(DM_Network
, "SqlPacketLoadRecords: unmarshall Ended");