MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
celloDb.cpp
1 /*
2  Copyright (C) 2003-2006 MySQL AB
3  All rights reserved. Use is subject to license terms.
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; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 
20 /* ***************************************************
21  BASIC TEST 1
22  Test basic functions and status of NDB
23 
24  Arguments:
25  none
26 
27  Returns:
28  0 - Test passed
29  -1 - Test failed
30  1 - Invalid arguments
31 flexBench
32  * *************************************************** */
33 
34 #include <NdbApi.hpp>
35 #include <NdbMain.h>
36 
37 #define MAXATTR 4
38 #define MAXTABLES 4
39 #define PAGESIZE 8192
40 #define OVERHEAD 0.02
41 #define NUMBEROFRECORDS 10
42 #define PKSIZE 1
43 #define ATTRNAMELEN 16
44 
45 
46 static void createTable_IPACCT(Ndb*);
47 static void createTable_RPACCT(Ndb*);
48 static void createTable_SBMCALL(Ndb*);
49 static void createTable_TODACCT(Ndb*);
50 
51 static void error_handler(const char*);
52 static bool error_handler2(const char*, int) ;
53 
54 static void setAttrNames(void);
55 static void setTableNames(void);
56 static void create_table(Ndb*);
57 static void insert_rows(Ndb*);
58 static void update_rows(Ndb*);
59 static void delete_rows(Ndb*);
60 static void verify_deleted(Ndb*);
61 static void read_and_verify_rows(Ndb*);
62 
63 static void insert_IPACCT(Ndb*, Uint32, Uint32, Uint32, Uint32, Uint32); //3 for Pk, and two data. just to test;
64 
65 static void read_IPACCT(Ndb* , Uint32 , Uint32 , Uint32 );
66 
67 static int tAttributeSize;
68 static int bTestPassed;
69 
70 static char tableName[MAXTABLES][ATTRNAMELEN];static char attrName[MAXATTR][ATTRNAMELEN];
71 static int attrValue[NUMBEROFRECORDS];
72 static int pkValue[NUMBEROFRECORDS];
73 static int failed = 0 ;
74 #include <NdbOut.hpp>
75 
76 NDB_COMMAND(celloDb, "celloDb", "celloDb", "celloDb", 65535)
77 {
78  ndb_init();
79 
80  int tTableId;
81  int i;
82  Ndb MyNdb( "CELLO-SESSION-DB" );
83 
84  MyNdb.init();
85 
86  // Assume test passed
87  bTestPassed = 0;
88  /*
89  // Initialize global variables
90  for (i = 0; i < NUMBEROFRECORDS; i ++)
91  pkValue[i] = i;
92 
93  for (i = 0; i < NUMBEROFRECORDS; i ++)
94  attrValue[i] = i;
95  */
96  tAttributeSize = 1;
97 
98  // Wait for Ndb to become ready
99  if (MyNdb.waitUntilReady() == 0) {
100  ndbout << endl << "Cello session db - Starting " << endl;
101  ndbout << "Test basic functions and status of NDB" << endl;
102 
103 
104 
105  createTable_SBMCALL (&MyNdb );
106  createTable_RPACCT (&MyNdb );
107  createTable_TODACCT (&MyNdb );
108  createTable_IPACCT (&MyNdb );
109 
110  insert_IPACCT(&MyNdb, 1,2,1,2,2);
111  read_IPACCT(&MyNdb, 1, 2 , 1);
112  /*
113  insert_rows(&MyNdb);
114 
115  read_and_verify_rows(&MyNdb);
116 
117 
118  // Create some new values to use for update
119  for (i = 0; i < NUMBEROFRECORDS; i++)
120  attrValue[i] = NUMBEROFRECORDS-i;
121 
122  update_rows(&MyNdb);
123 
124  read_and_verify_rows(&MyNdb);
125 
126  delete_rows(&MyNdb);
127 
128  verify_deleted(&MyNdb);
129  */
130  }
131  else {
132  bTestPassed = -1;
133  }
134 
135 
136  if (bTestPassed == 0)
137  {
138  // Test passed
139  ndbout << "OK - Test passed" << endl;
140  }
141  else
142  {
143  // Test failed
144  ndbout << "FAIL - Test failed" << endl;
145  exit(-1);
146  }
147  return NULL;
148 }
149 
150 static void
151 error_handler(const char* errorText)
152 {
153  // Test failed
154  ndbout << endl << "ErrorMessage: " << errorText << endl;
155  bTestPassed = -1;
156 }
157 
158 static void
159 createTable_SBMCALL ( Ndb* pMyNdb )
160 {
161  /****************************************************************
162  * Create table and attributes.
163  *
164  * create table SBMCALL(
165  * for attribs, see the REQ SPEC for cello session DB
166  * )
167  *
168  ***************************************************************/
169 
170  const char* tname = "SBMCALL";
171  Uint32 recordsize = 244; //including 12 byte overhead
172  Uint32 pksize = 8; //size of total prim. key. in bytes. sum of entire composite PK.
173  Uint32 tTableId = pMyNdb->getTable()->openTable(tname);
174 
175  if (tTableId == -1) {
176  Uint32 check;
177  Uint32 i;
178  NdbSchemaCon *MySchemaTransaction;
179  NdbSchemaOp *MySchemaOp;
180 
181  ndbout << "Creating " << tname << "..." << endl;
182 
183  MySchemaTransaction = pMyNdb->startSchemaTransaction();
184  if( ( MySchemaTransaction == NULL ) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
185  exit (-1) ;
186 
187  MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
188  if( ( MySchemaOp == NULL ) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
189  exit (-1) ;
190 
191 
192  // Createtable
193 
194  Uint32 tablesize=(recordsize*NUMBEROFRECORDS + OVERHEAD * NUMBEROFRECORDS)/1024;
195  Uint32 noPages=(pksize*NUMBEROFRECORDS)/PAGESIZE;
196 
197  ndbout << "table size " << tablesize << "for table name " << tname << endl;
198 
199  check = MySchemaOp->createTable( tname,
200  tablesize, // Table Size
201  TupleKey, // Key Type
202  noPages, // Nr of Pages
203  All,
204  6,
205  78,
206  80,
207  1,
208  true
209  );
210 
211  if( check == -1 ) {
212  error_handler(MySchemaTransaction->getNdbErrorString());
213  exit(-1);
214  }
215 
216 
217 
218  // Create first column, primary key
219  check = MySchemaOp->createAttribute( "SPBBOARDID",
220  TupleKey,
221  32,
222  PKSIZE,
223  UnSigned,
224  MMBased,
225  NotNullAttribute );
226 
227  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
228  exit (-1) ;
229 
230 
231  // Create second column, primary key
232  check = MySchemaOp->createAttribute( "CALLID",
233  TupleKey,
234  32,
235  PKSIZE,
236  UnSigned,
237  MMBased,
238  NotNullAttribute );
239 
240  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
241  exit (-1) ;
242 
243 
244  // Creat thrid column, RP Session info, byte[16] represented as (String, 16)
245  check = MySchemaOp->createAttribute( "RPSESS",
246  NoKey,
247  32,
248  16,
249  String,
250  MMBased,
251  NullAttribute );
252 
253  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
254  exit (-1) ;
255 
256 // Creat fourth column, GRE Tunnel info, byte[16] represented as (String, 16)
257  check = MySchemaOp->createAttribute( "GRETUNNEL",
258  NoKey,
259  32,
260  16,
261  String,
262  MMBased,
263  NullAttribute );
264 
265  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
266  exit (-1) ;
267 
268 // Creat fifth column, PPP Session info, byte[24] represented as (String, 24)
269  check = MySchemaOp->createAttribute( "PPPSESS",
270  NoKey,
271  32,
272  24,
273  String,
274  MMBased,
275  NullAttribute );
276 
277  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
278  exit (-1) ;
279 
280 
281  if( (MySchemaTransaction->execute() == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
282  exit (-1) ;
283 
284  pMyNdb->closeSchemaTransaction(MySchemaTransaction);
285  ndbout << "done" << endl;
286 
287 
288  } //if
289 
290  //else table already created , proceed
291 }
292 
293 
294 
295 static void
296 createTable_RPACCT(Ndb*pMyNdb)
297 {
298 
299  /****************************************************************
300  * Create table and attributes.
301  *
302  * create table RPACCT(
303  * for attribs, see the REQ SPEC for cello session DB
304  * )
305  *
306  ***************************************************************/
307 
308  const char* tname = "RPACCT";
309  Uint32 recordsize = 380; //including 12 byte overhead
310  Uint32 pksize = 8; //size of total prim. key. in bytes.
311  Uint32 tTableId = pMyNdb->getTable()->openTable(tname);
312 
313  if (tTableId == -1) {
314  Uint32 check;
315  Uint32 i;
316  NdbSchemaCon *MySchemaTransaction;
317  NdbSchemaOp *MySchemaOp;
318 
319  ndbout << "Creating " << tname << "..." << endl;
320 
321  MySchemaTransaction = pMyNdb->startSchemaTransaction();
322  if( MySchemaTransaction == NULL )
323  error_handler(MySchemaTransaction->getNdbErrorString());
324 
325  MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
326  if( MySchemaOp == NULL )
327  error_handler(MySchemaTransaction->getNdbErrorString());
328 
329  // Createtable
330 
331  Uint32 tablesize=(recordsize*NUMBEROFRECORDS + OVERHEAD * NUMBEROFRECORDS)/1024;
332  Uint32 noPages=(pksize*NUMBEROFRECORDS)/PAGESIZE;
333 
334  ndbout << "table size " << tablesize << "for table name " << tname << endl;
335 
336  check = MySchemaOp->createTable( tname,
337  tablesize, // Table Size
338  TupleKey, // Key Type
339  noPages // Nr of Pages
340  );
341 
342  if( check == -1 )
343  error_handler(MySchemaTransaction->getNdbErrorString());
344 
345 
346 
347  // Create first column, primary key
348  check = MySchemaOp->createAttribute( "SPBBOARDID",
349  TupleKey,
350  32,
351  PKSIZE,
352  UnSigned,
353  MMBased,
354  NotNullAttribute );
355 
356  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
357  exit (-1) ;
358 
359 
360  // Create second column, primary key
361  check = MySchemaOp->createAttribute( "CALLID",
362  TupleKey,
363  32,
364  PKSIZE,
365  UnSigned,
366  MMBased,
367  NotNullAttribute );
368 
369  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
370  exit (-1) ;
371 
372 
373  // Creat thrid column MS ID, 4 byte unsigned
374  check = MySchemaOp->createAttribute( "MSID",
375  NoKey,
376  32,
377  1,
378  UnSigned,
379  MMBased,
380  NullAttribute );
381 
382  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
383  exit (-1) ;
384 
385 
386  // Create PDSN FA Address, 4 byte unsigned
387  check = MySchemaOp->createAttribute( "PDSN",
388  NoKey,
389  32,
390  1,
391  UnSigned,
392  MMBased,
393  NullAttribute );
394 
395  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
396  exit (-1) ;
397 
398 
399  // Create Serving PCF, 4 byte unsigned
400  check = MySchemaOp->createAttribute( "SPCF",
401  NoKey,
402  32,
403  1,
404  UnSigned,
405  MMBased,
406  NullAttribute );
407 
408  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
409  exit (-1) ;
410 
411 
412 
413  // Create BS ID, 12 byte char, represented as String,12
414  check = MySchemaOp->createAttribute( "BSID",
415  NoKey,
416  32,
417  12,
418  String,
419  MMBased,
420  NullAttribute );
421 
422  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
423  exit (-1) ;
424 
425 
426 
427 
428 
429  // Create User Zone, 4 byte unsigned
430  check = MySchemaOp->createAttribute( "UZ",
431  NoKey,
432  32,
433  1,
434  UnSigned,
435  MMBased,
436  NullAttribute );
437 
438  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
439  exit (-1) ;
440 
441 
442  // Create Forward Multiplex, 4 byte unsigned
443  check = MySchemaOp->createAttribute( "FMO",
444  NoKey,
445  32,
446  1,
447  UnSigned,
448  MMBased,
449  NullAttribute );
450 
451  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
452  exit (-1) ;
453 
454 
455  // Create Reverse Multiplex, 4 byte unsigned
456  check = MySchemaOp->createAttribute( "RMO",
457  NoKey,
458  32,
459  1,
460  UnSigned,
461  MMBased,
462  NullAttribute );
463 
464  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
465  exit (-1) ;
466 
467 
468  // Create Forward Fund rate, 4 byte unsigned
469  check = MySchemaOp->createAttribute( "FFR",
470  NoKey,
471  32,
472  1,
473  UnSigned,
474  MMBased,
475  NullAttribute );
476 
477  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
478  exit (-1) ;
479 
480 
481  // Create Reverse Fund rate, 4 byte unsigned
482  check = MySchemaOp->createAttribute( "RFR",
483  NoKey,
484  32,
485  1,
486  UnSigned,
487  MMBased,
488  NullAttribute );
489 
490  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
491  exit (-1) ;
492 
493 
494 
495  // Create Service Option, 4 byte unsigned
496  check = MySchemaOp->createAttribute( "SO",
497  NoKey,
498  32,
499  1,
500  UnSigned,
501  MMBased,
502  NullAttribute );
503 
504  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
505  exit (-1) ;
506 
507 
508 
509 
510  // Create Forward Traffic Type, 4 byte unsigned
511  check = MySchemaOp->createAttribute( "FTT",
512  NoKey,
513  32,
514  1,
515  UnSigned,
516  MMBased,
517  NullAttribute );
518 
519  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
520  exit (-1) ;
521 
522 
523 
524 // Create Reverse Traffic Type, 4 byte unsigned
525  check = MySchemaOp->createAttribute( "RTT",
526  NoKey,
527  32,
528  1,
529  UnSigned,
530  MMBased,
531  NullAttribute );
532 
533  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
534  exit (-1) ;
535 
536 
537 
538 // Create Fund Frame Size, 4 byte unsigned
539  check = MySchemaOp->createAttribute( "FFS",
540  NoKey,
541  32,
542  1,
543  UnSigned,
544  MMBased,
545  NullAttribute );
546 
547  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
548  exit (-1) ;
549 
550 
551 
552 // Create Forware Fund RC, 4 byte unsigned
553  check = MySchemaOp->createAttribute( "FFRC",
554  NoKey,
555  32,
556  1,
557  UnSigned,
558  MMBased,
559  NullAttribute );
560 
561  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
562  exit (-1) ;
563 
564 
565 
566  // Create Reverse Fund RC, 4 byte unsigned
567  check = MySchemaOp->createAttribute( "RFRC",
568  NoKey,
569  32,
570  1,
571  UnSigned,
572  MMBased,
573  NullAttribute );
574 
575  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
576  exit (-1) ;
577 
578 
579  // Create DCCH Frame Format, 4 byte unsigned
580  check = MySchemaOp->createAttribute( "DCCH",
581  NoKey,
582  32,
583  1,
584  UnSigned,
585  MMBased,
586  NullAttribute );
587 
588  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
589  exit (-1) ;
590 
591 
592  // Create Airlink QOS, 4 byte unsigned
593  check = MySchemaOp->createAttribute( "AQOS",
594  NoKey,
595  32,
596  1,
597  UnSigned,
598  MMBased,
599  NullAttribute );
600 
601  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
602  exit (-1) ;
603 
604 
605 
606 // Create Bad PPP Frame Count , 4 byte unsigned
607  check = MySchemaOp->createAttribute( "BPPPFC",
608  NoKey,
609  32,
610  1,
611  UnSigned,
612  MMBased,
613  NullAttribute );
614 
615  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
616  exit (-1) ;
617 
618 
619 
620 
621 // Create Active Time , 4 byte unsigned
622  check = MySchemaOp->createAttribute( "AT",
623  NoKey,
624  32,
625  1,
626  UnSigned,
627  MMBased,
628  NullAttribute );
629 
630  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
631  exit (-1) ;
632 
633 
634 
635 // Create Nb Active Transitions , 4 byte unsigned
636  check = MySchemaOp->createAttribute( "NBAT",
637  NoKey,
638  32,
639  1,
640  UnSigned,
641  MMBased,
642  NullAttribute );
643 
644  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
645  exit (-1) ;
646 
647 
648 // Create SDB Octet Count In , 4 byte unsigned
649  check = MySchemaOp->createAttribute( "SDBOCI",
650  NoKey,
651  32,
652  1,
653  UnSigned,
654  MMBased,
655  NullAttribute );
656 
657  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
658  exit (-1) ;
659 
660 
661 
662 
663 // Create Nb SDB In, 4 byte unsigned
664  check = MySchemaOp->createAttribute( "NBSDBI",
665  NoKey,
666  32,
667  1,
668  UnSigned,
669  MMBased,
670  NullAttribute );
671 
672  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
673  exit (-1) ;
674 
675 
676 
677 
678 // Create Nb SDB Out, 4 byte unsigned
679  check = MySchemaOp->createAttribute( "NBSDBO",
680  NoKey,
681  32,
682  1,
683  UnSigned,
684  MMBased,
685  NullAttribute );
686 
687  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
688  exit (-1) ;
689 
690 
691 
692 
693 // Create HDLC Bytes received, 4 byte unsigned
694  check = MySchemaOp->createAttribute( "HDLC",
695  NoKey,
696  32,
697  1,
698  UnSigned,
699  MMBased,
700  NullAttribute );
701 
702  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
703  exit (-1) ;
704 
705 
706 
707  if( (MySchemaTransaction->execute() == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
708  exit (-1) ;
709 
710  pMyNdb->closeSchemaTransaction(MySchemaTransaction);
711  ndbout << "done" << endl;
712 
713  } //if
714 
715  //else table already created , proceed
716  }
717 
718 
719 static void
720 createTable_IPACCT(Ndb* pMyNdb)
721 {
722 
723 
724  /****************************************************************
725  * Create table and attributes.
726  *
727  * create table IPACCT(
728  * for attribs, see the REQ SPEC for cello session DB
729  * )
730  *
731  ***************************************************************/
732 
733  const char* tname = "IPACCT";
734  Uint32 recordsize = 70; //including 12 byte overhead
735  Uint32 pksize = 12; //size of total prim. key. in bytes.
736  Uint32 tTableId = pMyNdb->getTable()->openTable(tname);
737 
738  if (tTableId == -1) {
739  Uint32 check;
740  Uint32 i;
741  NdbSchemaCon *MySchemaTransaction;
742  NdbSchemaOp *MySchemaOp;
743 
744  ndbout << "Creating " << tname << "..." << endl;
745 
746  MySchemaTransaction = pMyNdb->startSchemaTransaction();
747  if( MySchemaTransaction == NULL )
748  error_handler(MySchemaTransaction->getNdbErrorString());
749 
750  MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
751  if( MySchemaOp == NULL )
752  error_handler(MySchemaTransaction->getNdbErrorString());
753 
754  // Createtable
755 
756  Uint32 tablesize=(recordsize*NUMBEROFRECORDS + OVERHEAD * NUMBEROFRECORDS)/1024;
757  Uint32 noPages=(pksize*NUMBEROFRECORDS)/PAGESIZE;
758 
759  ndbout << "table size " << tablesize << "for table name " << tname << endl;
760 
761  check = MySchemaOp->createTable( tname,
762  tablesize, // Table Size
763  TupleKey, // Key Type
764  noPages // Nr of Pages
765  );
766 
767  if( check == -1 )
768  error_handler(MySchemaTransaction->getNdbErrorString());
769 
770 
771 
772  // Create first column, primary key
773  check = MySchemaOp->createAttribute( "SPBBOARDID",
774  TupleKey,
775  32,
776  PKSIZE,
777  UnSigned,
778  MMBased,
779  NotNullAttribute );
780 
781  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
782  exit (-1) ;
783 
784 
785  // Create second column, primary key
786  check = MySchemaOp->createAttribute( "CALLID",
787  TupleKey,
788  32,
789  PKSIZE,
790  UnSigned,
791  MMBased,
792  NotNullAttribute );
793 
794  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
795  exit (-1) ;
796 
797  // Create third column, primary key
798  check = MySchemaOp->createAttribute( "IPADDR",
799  TupleKey,
800  32,
801  PKSIZE,
802  String,
803  MMBased,
804  NotNullAttribute );
805 
806  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
807  exit (-1) ;
808 
809 
810 
811 
812 // Create Acct session id 4 byte unsigned
813  check = MySchemaOp->createAttribute( "ASID",
814  NoKey,
815  32,
816  1,
817  UnSigned,
818  MMBased,
819  NullAttribute );
820 
821  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
822  exit (-1) ;
823 
824 
825 // Create Correlation ID, 4 byte unsigned
826  check = MySchemaOp->createAttribute( "CID",
827  NoKey,
828  32,
829  1,
830  UnSigned,
831  MMBased,
832  NullAttribute );
833 
834  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
835  exit (-1) ;
836 
837 
838 // Create MIP HA Address, 4 byte unsigned
839  check = MySchemaOp->createAttribute( "MIPHA",
840  NoKey,
841  32,
842  1,
843  UnSigned,
844  MMBased,
845  NullAttribute );
846 
847  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
848  exit (-1) ;
849 
850 
851 
852 
853 
854 // Create IP technology, 4 byte unsigned
855  check = MySchemaOp->createAttribute( "IPT",
856  NoKey,
857  32,
858  1,
859  UnSigned,
860  MMBased,
861  NullAttribute );
862 
863  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
864  exit (-1) ;
865 
866 
867 
868 // Create Compuls Tunnel ID, 4 byte unsigned
869  check = MySchemaOp->createAttribute( "CTID",
870  NoKey,
871  32,
872  1,
873  UnSigned,
874  MMBased,
875  NullAttribute );
876 
877  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
878  exit (-1) ;
879 
880 // Create IP QOS, 4 byte unsigned
881  check = MySchemaOp->createAttribute( "IPQOS",
882  NoKey,
883  32,
884  1,
885  UnSigned,
886  MMBased,
887  NullAttribute );
888 
889  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
890  exit (-1) ;
891 
892 
893  // Create Data octet count in, 4 byte unsigned
894  check = MySchemaOp->createAttribute( "DOCI",
895  NoKey,
896  32,
897  1,
898  UnSigned,
899  MMBased,
900  NullAttribute );
901 
902  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
903  exit (-1) ;
904 
905  // Create Data octet count out, 4 byte unsigned
906  check = MySchemaOp->createAttribute( "DOCO",
907  NoKey,
908  32,
909  1,
910  UnSigned,
911  MMBased,
912  NullAttribute );
913 
914  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
915  exit (-1) ;
916 
917  // Create Event time, 4 byte unsigned
918  check = MySchemaOp->createAttribute( "ET",
919  NoKey,
920  32,
921  1,
922  UnSigned,
923  MMBased,
924  NullAttribute );
925 
926  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
927  exit (-1) ;
928 
929  // Create In mip sig count, 4 byte unsigned
930  check = MySchemaOp->createAttribute( "IMSC",
931  NoKey,
932  32,
933  1,
934  UnSigned,
935  MMBased,
936  NullAttribute );
937 
938  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
939  exit (-1) ;
940 
941 // Create Out mip sig count, 4 byte unsigned
942  check = MySchemaOp->createAttribute( "OMSC",
943  NoKey,
944  32,
945  1,
946  UnSigned,
947  MMBased,
948  NullAttribute );
949 
950  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
951  exit (-1) ;
952 
953 
954  if( (MySchemaTransaction->execute() == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
955  exit (-1) ;
956 
957  pMyNdb->closeSchemaTransaction(MySchemaTransaction);
958  ndbout << "done" << endl;
959 
960 
961 
962  } //if
963 
964  //else table already created , proceed
965 }
966 
967 
968 static void
969 createTable_TODACCT(Ndb* pMyNdb)
970 {
971 
972 
973  /****************************************************************
974  * Create table and attributes.
975  *
976  * create table TODACCT(
977  * for attribs, see the REQ SPEC for cello session DB
978  * )
979  *
980  ***************************************************************/
981 
982  const char* tname = "TODACCT";
983  Uint32 recordsize = 92; //including 12 byte overhead
984  Uint32 pksize = 12; //size of total prim. key. in bytes.
985  Uint32 tTableId = pMyNdb->getTable()->openTable(tname);
986 
987  if (tTableId == -1) {
988  Uint32 check;
989  Uint32 i;
990  NdbSchemaCon *MySchemaTransaction;
991  NdbSchemaOp *MySchemaOp;
992 
993  ndbout << "Creating " << tname << "..." << endl;
994 
995  MySchemaTransaction = pMyNdb->startSchemaTransaction();
996  if( MySchemaTransaction == NULL )
997  error_handler(MySchemaTransaction->getNdbErrorString());
998 
999  MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
1000  if( MySchemaOp == NULL )
1001  error_handler(MySchemaTransaction->getNdbErrorString());
1002 
1003  // Createtable
1004 
1005  Uint32 tablesize=(recordsize*NUMBEROFRECORDS + OVERHEAD * NUMBEROFRECORDS)/1024;
1006  Uint32 noPages=(pksize*NUMBEROFRECORDS)/PAGESIZE;
1007 
1008  ndbout << "table size " << tablesize << "for table name " << tname << endl;
1009 
1010  check = MySchemaOp->createTable( tname,
1011  tablesize, // Table Size
1012  TupleKey, // Key Type
1013  noPages // Nr of Pages
1014  );
1015 
1016  if( check == -1 )
1017  error_handler(MySchemaTransaction->getNdbErrorString());
1018 
1019 
1020 
1021  // Create first column, primary key
1022  check = MySchemaOp->createAttribute( "SPBBOARDID",
1023  TupleKey,
1024  32,
1025  PKSIZE,
1026  UnSigned,
1027  MMBased,
1028  NotNullAttribute );
1029 
1030  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
1031  exit (-1) ;
1032 
1033 
1034  // Create second column, primary key
1035  check = MySchemaOp->createAttribute( "CALLID",
1036  TupleKey,
1037  32,
1038  PKSIZE,
1039  UnSigned,
1040  MMBased,
1041  NotNullAttribute );
1042 
1043  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
1044  exit (-1) ;
1045 
1046  // Create third column, primary key
1047  check = MySchemaOp->createAttribute( "IPADDR",
1048  TupleKey,
1049  32,
1050  PKSIZE,
1051  String,
1052  MMBased,
1053  NotNullAttribute );
1054 
1055  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
1056  exit (-1) ;
1057 
1058 
1059 
1060  // Create third column, primary key
1061  check = MySchemaOp->createAttribute( "INDEX",
1062  TupleKey,
1063  32,
1064  PKSIZE,
1065  UnSigned,
1066  MMBased,
1067  NotNullAttribute );
1068 
1069  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
1070  exit (-1) ;
1071 
1072 
1073 
1074 
1075 // Create Acct session id 4 byte unsigned
1076  check = MySchemaOp->createAttribute( "TOD",
1077  NoKey,
1078  32,
1079  16,
1080  String,
1081  MMBased,
1082  NullAttribute );
1083 
1084 
1085  if( (check == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
1086  exit (-1) ;
1087 
1088 
1089 
1090  if( (MySchemaTransaction->execute() == -1) && (!error_handler2((const char*)MySchemaTransaction->getNdbErrorString(), MySchemaTransaction->getNdbError())) )
1091  exit (-1) ;
1092 
1093  pMyNdb->closeSchemaTransaction(MySchemaTransaction);
1094  ndbout << "done" << endl;
1095 
1096  } //if
1097 
1098  //else table already created , proceed
1099 }
1100 
1101 
1102 
1103 
1104 
1105 
1106 static void read_IPACCT(Ndb* pMyNdb, Uint32 CALLID, Uint32 SPBBOARDID , Uint32 IPADDR)
1107 {
1108 
1109 
1110  int check;
1111  int loop_count_ops;
1112  int count;
1113  int count_attributes;
1114  char* value;
1115  NdbConnection *MyTransaction;
1116  NdbOperation *MyOperation;
1117  NdbRecAttr* tTmp;
1118 
1119 
1120 
1121  MyTransaction = pMyNdb->startTransaction();
1122  if (MyTransaction == NULL)
1123  error_handler(pMyNdb->getNdbErrorString());
1124 
1125  MyOperation = MyTransaction->getNdbOperation("IPACCT");
1126  if (MyOperation == NULL)
1127  error_handler( MyTransaction->getNdbErrorString());
1128 
1129  check = MyOperation->readTuple();
1130  if( check == -1 )
1131  error_handler( MyTransaction->getNdbErrorString());
1132 
1133  check = MyOperation->equal( "SPBBOARDID",SPBBOARDID );
1134  if( check == -1 )
1135  error_handler( MyTransaction->getNdbErrorString());
1136 
1137 
1138  check = MyOperation->equal( "IPADDR","IPADDR" );
1139  if( check == -1 )
1140  error_handler( MyTransaction->getNdbErrorString());
1141 
1142 
1143  check = MyOperation->equal( "CALLID",CALLID );
1144  if( check == -1 )
1145  error_handler( MyTransaction->getNdbErrorString());
1146 
1147 
1148 
1149 
1150  tTmp = MyOperation->getValue("IPQOS", NULL );
1151  if( tTmp == NULL )
1152  error_handler( MyTransaction->getNdbErrorString());
1153  ndbout << " tTmp " << tTmp->isNULL() << endl;
1154  MyTransaction->execute(Commit);
1155 
1156  ndbout << " value read " << tTmp->int32_value() << endl;
1157 
1158 }
1159 
1160 
1161 
1162 static void insert_IPACCT(Ndb* pMyNdb, Uint32 CALLID, Uint32 SPBBOARDID , Uint32 IPADDR, Uint32 ASID, Uint32 IPQOS)
1163 {
1164  /****************************************************************
1165  * Insert rows
1166  *
1167  ***************************************************************/
1168 
1169  int check;
1170  int loop_count_ops;
1171  int count;
1172  int i;
1173  NdbConnection *MyTransaction;
1174  NdbOperation *MyOperation;
1175 
1176  ndbout << "Inserting records..." << flush;
1177 
1178  MyTransaction = pMyNdb->startTransaction();
1179  if (MyTransaction == NULL)
1180  error_handler(pMyNdb->getNdbErrorString());
1181 
1182  MyOperation = MyTransaction->getNdbOperation("IPACCT");
1183  if (MyOperation == NULL)
1184  error_handler(MyTransaction->getNdbErrorString());
1185 
1186 
1187 
1188  check = MyOperation->insertTuple();
1189  if( check == -1 )
1190  error_handler(MyTransaction->getNdbErrorString());
1191 
1192  ndbout << "insertTuple" << endl;
1193 
1194  check = MyOperation->equal("CALLID",CALLID );
1195  if( check == -1 )
1196  error_handler(MyTransaction->getNdbErrorString());
1197  ndbout << "equal" << endl;
1198 
1199 
1200  check = MyOperation->equal("SPBBOARDID",SPBBOARDID );
1201  if( check == -1 )
1202  error_handler(MyTransaction->getNdbErrorString());
1203  ndbout << "equal" << endl;
1204 
1205 
1206  check = MyOperation->equal("IPADDR","IPADDR" );
1207  if( check == -1 )
1208  error_handler(MyTransaction->getNdbErrorString());
1209  ndbout << "equal" << endl;
1210 
1211 
1212  check = MyOperation->setValue( "IPQOS", IPQOS);
1213  if( check == -1 )
1214  error_handler(MyTransaction->getNdbErrorString());
1215  ndbout << "Set Value" << endl;
1216 
1217 
1218 
1219  check = MyOperation->setValue( "ASID", ASID);
1220  if( check == -1 )
1221  error_handler(MyTransaction->getNdbErrorString());
1222  ndbout << "Set Value" << endl;
1223 
1224 
1225  check = MyTransaction->execute( Commit );
1226  if(check == -1 ) {
1227  ndbout << "error at commit" << endl;
1228  error_handler(MyTransaction->getNdbErrorString());
1229  }
1230  else
1231  ;//ndbout << ".";
1232 
1233  pMyNdb->closeTransaction(MyTransaction);
1234 
1235 
1236 
1237  ndbout << "OK" << endl;
1238 
1239  return;
1240 }
1241 
1242 static void
1243 update_rows(Ndb* pMyNdb){
1244  /****************************************************************
1245  * Update rows in SimpleTable
1246  *
1247  ***************************************************************/
1248 
1249  int check;
1250  int loop_count_ops;
1251  int count;
1252  int i;
1253  NdbConnection *MyTransaction;
1254  NdbOperation *MyOperation;
1255 
1256  ndbout << "Updating records..." << flush;
1257 
1258  loop_count_ops = NUMBEROFRECORDS;
1259 
1260  for (count=0 ; count < loop_count_ops ; count++) {
1261 
1262  MyTransaction = pMyNdb->startTransaction();
1263  if (MyTransaction == NULL)
1264  error_handler( pMyNdb->getNdbErrorString() );
1265 
1266  MyOperation = MyTransaction->getNdbOperation(tableName[0]);
1267  if (MyOperation == NULL)
1268  error_handler(MyTransaction->getNdbErrorString());
1269 
1270  check = MyOperation->updateTuple();
1271  if( check == -1 )
1272  error_handler(MyTransaction->getNdbErrorString());
1273 
1274  check = MyOperation->equal( attrName[0], (char*)&pkValue[count] );
1275  if( check == -1 )
1276  error_handler(MyTransaction->getNdbErrorString());
1277 
1278  for (i = 1; i < MAXATTR; i++)
1279  {
1280  check = MyOperation->setValue( attrName[i], (char*)&attrValue[count]);
1281  if( check == -1 )
1282  error_handler(MyTransaction->getNdbErrorString());
1283  }
1284 
1285  if( MyTransaction->execute( Commit ) == -1 )
1286  error_handler(MyTransaction->getNdbErrorString());
1287  else
1288  ;//ndbout << ".";
1289 
1290  pMyNdb->closeTransaction(MyTransaction);
1291 
1292  }
1293 
1294  ndbout << "OK" << endl;
1295  return;
1296 
1297 };
1298 
1299 static void
1300 delete_rows(Ndb* pMyNdb){
1301 
1302  /****************************************************************
1303  * Delete rows from SimpleTable
1304  *
1305  ***************************************************************/
1306 
1307  int check;
1308  int loop_count_ops;
1309  int count;
1310  NdbConnection *MyTransaction;
1311  NdbOperation *MyOperation;
1312 
1313  ndbout << "Deleting records..."<< flush;
1314 
1315  loop_count_ops = NUMBEROFRECORDS;
1316 
1317  for (count=0 ; count < loop_count_ops ; count++) {
1318 
1319  MyTransaction = pMyNdb->startTransaction();
1320  if (MyTransaction == NULL)
1321  error_handler( pMyNdb->getNdbErrorString() );
1322 
1323  MyOperation = MyTransaction->getNdbOperation(tableName[0]);
1324  if (MyOperation == NULL)
1325  error_handler(MyTransaction->getNdbErrorString());
1326 
1327 
1328  check = MyOperation->deleteTuple();
1329  if( check == -1 )
1330  error_handler(MyTransaction->getNdbErrorString());
1331 
1332  check = MyOperation->equal( attrName[0], (char*)&pkValue[count] );
1333  if( check == -1 )
1334  error_handler(MyTransaction->getNdbErrorString());
1335 
1336 
1337  if( MyTransaction->execute( Commit ) == -1 )
1338  error_handler(MyTransaction->getNdbErrorString());
1339  else
1340  ;// ndbout << ".";
1341 
1342  pMyNdb->closeTransaction(MyTransaction);
1343 
1344  }
1345 
1346  ndbout << "OK" << endl;
1347  return;
1348 
1349 };
1350 
1351 static void
1352 verify_deleted(Ndb* pMyNdb){
1353  int check;
1354  int loop_count_ops;
1355  int count;
1356  NdbConnection *MyTransaction;
1357  NdbOperation *MyOperation;
1358 
1359  ndbout << "Verifying deleted records..."<< flush;
1360 
1361  loop_count_ops = NUMBEROFRECORDS;
1362 
1363  for (count=0 ; count < loop_count_ops ; count++)
1364  {
1365  MyTransaction = pMyNdb->startTransaction();
1366  if (MyTransaction == NULL)
1367  error_handler(pMyNdb->getNdbErrorString());
1368 
1369  MyOperation = MyTransaction->getNdbOperation(tableName[0]);
1370  if (MyOperation == NULL)
1371  error_handler( MyTransaction->getNdbErrorString());
1372 
1373  check = MyOperation->readTuple();
1374  if( check == -1 )
1375  error_handler( MyTransaction->getNdbErrorString());
1376 
1377  check = MyOperation->equal( attrName[0],(char*)&pkValue[count] );
1378  if( check == -1 )
1379  error_handler( MyTransaction->getNdbErrorString());
1380 
1381  // Exepect to receive an error
1382  if( MyTransaction->execute( Commit ) != -1 )
1383  error_handler(MyTransaction->getNdbErrorString());
1384  else
1385  {
1386  ;//ndbout << ".";
1387  }
1388 
1389  pMyNdb->closeTransaction(MyTransaction);
1390 
1391  }
1392 
1393  ndbout << "OK" << endl;
1394  return;
1395 };
1396 
1397 static void
1398 read_and_verify_rows(Ndb* pMyNdb)
1399 {
1400 
1401  int check;
1402  int loop_count_ops;
1403  int count;
1404  int count_attributes;
1405 
1406  NdbConnection *MyTransaction;
1407  NdbOperation *MyOperation;
1408  NdbRecAttr* tTmp;
1409 
1410  int readValue[MAXATTR];
1411 
1412  ndbout << "Verifying records..."<< flush;
1413 
1414  loop_count_ops = NUMBEROFRECORDS;
1415 
1416  for (count=0 ; count < loop_count_ops ; count++)
1417  {
1418  MyTransaction = pMyNdb->startTransaction();
1419  if (MyTransaction == NULL)
1420  error_handler(pMyNdb->getNdbErrorString());
1421 
1422  MyOperation = MyTransaction->getNdbOperation(tableName[0]);
1423  if (MyOperation == NULL)
1424  error_handler( MyTransaction->getNdbErrorString());
1425 
1426  check = MyOperation->readTuple();
1427  if( check == -1 )
1428  error_handler( MyTransaction->getNdbErrorString());
1429 
1430  check = MyOperation->equal( attrName[0],(char*)&pkValue[count] );
1431  if( check == -1 )
1432  error_handler( MyTransaction->getNdbErrorString());
1433 
1434  for (count_attributes = 1; count_attributes < MAXATTR; count_attributes++)
1435  {
1436  tTmp = MyOperation->getValue( (char*)attrName[count_attributes], (char*)&readValue[count_attributes] );
1437  if( tTmp == NULL )
1438  error_handler( MyTransaction->getNdbErrorString());
1439  }
1440 
1441  if( MyTransaction->execute( Commit ) == -1 )
1442  error_handler(MyTransaction->getNdbErrorString());
1443  else
1444  {
1445  // Check value in db against value in mem
1446 
1447  //ndbout << readValue[1] << " == " << attrValue[count] << endl;
1448 
1449  if ( readValue[1]!=attrValue[count] )
1450  error_handler("Verification error!");
1451  else
1452  if ( readValue[2]!=attrValue[count] )
1453  error_handler("Verification error!");
1454  else
1455  if ( readValue[3]!=attrValue[count] )
1456  error_handler("Verification error!");
1457  else
1458  {
1459  ;//ndbout << ".";
1460  }
1461  }
1462  pMyNdb->closeTransaction(MyTransaction);
1463 
1464  }
1465 
1466  ndbout << "OK" << endl;
1467  return;
1468 
1469 
1470 
1471 };
1472 
1473 
1474 static void
1475 setAttrNames()
1476 {
1477  int i;
1478 
1479  for (i = 0; i < MAXATTR ; i++)
1480  {
1481  sprintf(&attrName[i][0], "Col%d", i);
1482  }
1483 }
1484 
1485 static void
1486 setTableNames()
1487 {
1488  int i;
1489 
1490  sprintf(&tableName[0][0], "SBMCALL", 0);
1491  sprintf(&tableName[1][0], "RPACCT", 0);
1492  sprintf(&tableName[2][0], "IPACCT", 0);
1493  sprintf(&tableName[3][0], "TODACCT", 0);
1494 
1495 }
1496 
1497 
1498 bool error_handler2(const char* error_string, int error_int) {
1499  failed++ ;
1500  ndbout << error_string << endl ;
1501  if ( 4008==error_int || 721==error_int || 266==error_int ){
1502  ndbout << endl << "Attempting to recover and continue now..." << endl ;
1503  return true ; // return true to retry
1504  }
1505  return false ; // return false to abort
1506 }