userInterface.cpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:21k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* Copyright (C) 2003 MySQL AB
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.    This program is distributed in the hope that it will be useful,
  7.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9.    GNU General Public License for more details.
  10.    You should have received a copy of the GNU General Public License
  11.    along with this program; if not, write to the Free Software
  12.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  13. /***************************************************************
  14. * I N C L U D E D   F I L E S                                  *
  15. ***************************************************************/
  16. #include <ndb_global.h>
  17. #ifndef NDB_WIN32
  18. #include <sys/time.h>
  19. #endif
  20. #include "ndb_error.hpp"
  21. #include "userHandle.h"
  22. #include "userInterface.h"
  23. #include <NdbThread.h>
  24. #include <NdbTick.h>
  25. #include <NdbMutex.h>
  26. #include <NdbSleep.h>
  27. #include "ndb_schema.hpp"
  28. #include <NDBT.hpp>
  29. #include <NdbSchemaCon.hpp>
  30. /***************************************************************
  31. * L O C A L   C O N S T A N T S                                *
  32. ***************************************************************/
  33. /***************************************************************
  34. * L O C A L   D A T A   S T R U C T U R E S                    *
  35. ***************************************************************/
  36. /***************************************************************
  37. * L O C A L   F U N C T I O N S                                *
  38. ***************************************************************/
  39. extern int localDbPrepare(UserHandle *uh);
  40. static int dbCreate(UserHandle *uh);
  41. /***************************************************************
  42. * L O C A L   D A T A                                          *
  43. ***************************************************************/
  44. /***************************************************************
  45. * P U B L I C   D A T A                                        *
  46. ***************************************************************/
  47. /***************************************************************
  48. ****************************************************************
  49. * L O C A L   F U N C T I O N S   C O D E   S E C T I O N      *
  50. ****************************************************************
  51. ***************************************************************/
  52. /***************************************************************
  53. ****************************************************************
  54. * P U B L I C   F U N C T I O N S   C O D E   S E C T I O N    *
  55. ****************************************************************
  56. ***************************************************************/
  57. /*-----------------------------------*/
  58. /* Time related Functions            */
  59. /*                                   */
  60. /* Returns a double value in seconds */
  61. /*-----------------------------------*/
  62. double userGetTimeSync(void)
  63. {
  64.   static int initialized = 0;
  65.   static NDB_TICKS initSecs = 0;
  66.   static Uint32 initMicros = 0;
  67.   double timeValue = 0;
  68.   if ( !initialized ) {
  69.     initialized = 1;
  70.     NdbTick_CurrentMicrosecond(&initSecs, &initMicros);  
  71.     timeValue = 0.0;
  72.   } else {
  73.     NDB_TICKS secs = 0;
  74.     Uint32 micros = 0;
  75.   
  76.     NdbTick_CurrentMicrosecond(&secs, &micros);
  77.     double s  = (double)secs  - (double)initSecs;
  78.     double us = (double)secs - (double)initMicros;
  79.     
  80.     timeValue = s + (us / 1000000.0);
  81.   }
  82.   return timeValue;
  83. }
  84. // 0 - OK
  85. // 1 - Retry transaction
  86. // 2 - Permanent
  87. int 
  88. userDbCommit(UserHandle *uh){
  89.   if(uh->pCurrTrans != 0){
  90.     int check = uh->pCurrTrans->execute( Commit ); 
  91.     NdbError err = uh->pCurrTrans->getNdbError();
  92.     uh->pNDB->closeTransaction(uh->pCurrTrans);
  93.     uh->pCurrTrans = 0;
  94.     
  95.     if(err.status != NdbError::Success)
  96.       ndbout << err << endl;
  97.     
  98.     if(err.status == NdbError::TemporaryError && 
  99.        err.classification == NdbError::OverloadError){
  100.       NdbSleep_SecSleep(3);
  101.     }
  102.     
  103.     return err.status;
  104.   }
  105.   return 2;
  106. }
  107. /**
  108.  * TRUE - Normal table
  109.  * FALSE - Table w.o. checkpoing and logging
  110.  */
  111. #ifdef __cplusplus
  112. extern "C" {
  113. #endif
  114. extern int useTableLogging;
  115. extern int useIndexTables;
  116. #ifdef __cplusplus
  117. }
  118. #endif
  119. int
  120. create_table_server(Ndb * pNdb){
  121.   int check;
  122.   NdbSchemaCon * MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pNdb);
  123.   if( MySchemaTransaction == NULL )
  124.     error_handler("startSchemaTransaction", pNdb->getNdbError(), 0);
  125.   
  126.   NdbSchemaOp * MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
  127.   if( MySchemaOp == NULL ) 
  128.     error_handler("getNdbSchemaOp", MySchemaTransaction->getNdbError(), 0);
  129.   
  130.   // Create table
  131.   check = MySchemaOp->createTable( SERVER_TABLE,
  132.    8,       // Table size
  133.    TupleKey, // Key Type
  134.    1 // Nr of Pages
  135.    ,DistributionGroup,
  136.    6,
  137.    78,
  138.    80,
  139.    1,
  140.    useTableLogging
  141.                                    );
  142.   if( check == -1 ) 
  143.     error_handler("createTable", MySchemaTransaction->getNdbError(), 0);
  144.   
  145.   check = MySchemaOp->createAttribute
  146.     ( SERVER_SUBSCRIBER_SUFFIX,
  147.       TupleKey, 
  148.       sizeof(char) << 3,
  149.       SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
  150.       String, 
  151.       MMBased,
  152.       NotNullAttribute,
  153.       NormalStorageAttribute,
  154.       0,
  155.       1,
  156.       16);
  157.   if( check == -1 ) 
  158.     error_handler("createAttribute (subscriber suffix)", 
  159.   MySchemaTransaction->getNdbError(), 0);
  160.   // Create first column, primary key 
  161.   check = MySchemaOp->createAttribute( SERVER_ID,
  162.        TupleKey, 
  163.        sizeof(ServerId) << 3,
  164.        1,
  165.        UnSigned, 
  166.        MMBased,
  167.        NotNullAttribute );
  168.   if( check == -1 ) 
  169.     error_handler("createAttribute (serverid)", 
  170.   MySchemaTransaction->getNdbError(), 0);
  171.   check = MySchemaOp->createAttribute( SERVER_NAME,
  172.        NoKey, 
  173.        sizeof(char) << 3,
  174.        SERVER_NAME_LENGTH,
  175.        String, 
  176.        MMBased,
  177.        NotNullAttribute );
  178.   if( check == -1 ) 
  179.     error_handler("createAttribute (server name)", 
  180.   MySchemaTransaction->getNdbError(), 0);
  181.   
  182.   check = MySchemaOp->createAttribute( SERVER_READS,
  183.        NoKey, 
  184.        sizeof(Counter) << 3,
  185.        1,
  186.        UnSigned,
  187.        MMBased,
  188.        NotNullAttribute );
  189.   if( check == -1 ) 
  190.     error_handler("createAttribute (server reads)", 
  191.   MySchemaTransaction->getNdbError(), 0);
  192.   check = MySchemaOp->createAttribute( SERVER_INSERTS,
  193.        NoKey, 
  194.        sizeof(Counter) << 3,
  195.        1,
  196.        UnSigned,
  197.        MMBased,
  198.        NotNullAttribute );
  199.   if( check == -1 ) 
  200.     error_handler("createAttribute (server inserts)", 
  201.   MySchemaTransaction->getNdbError(), 0);
  202.   check = MySchemaOp->createAttribute( SERVER_DELETES,
  203.        NoKey, 
  204.        sizeof(Counter) << 3,
  205.        1,
  206.        UnSigned,
  207.        MMBased,
  208.        NotNullAttribute );
  209.   if( check == -1 ) 
  210.     error_handler("createAttribute (server deletes)", 
  211.   MySchemaTransaction->getNdbError(), 0);
  212.   
  213.   if( MySchemaTransaction->execute() == -1 ) {
  214.     error_handler("schemaTransaction->execute()", 
  215.   MySchemaTransaction->getNdbError(), 0);
  216.   }    
  217.   NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
  218.   return 0;
  219. }
  220. int
  221. create_table_group(Ndb * pNdb){
  222.   int check;
  223.   NdbSchemaCon * MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pNdb);
  224.   if( MySchemaTransaction == NULL )
  225.     error_handler("startSchemaTransaction", pNdb->getNdbError(), 0);
  226.   
  227.   NdbSchemaOp * MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
  228.   if( MySchemaOp == NULL ) 
  229.     error_handler("getNdbSchemaOp", MySchemaTransaction->getNdbError(), 0);
  230.   
  231.   // Create table
  232.   check = MySchemaOp->createTable( GROUP_TABLE,
  233.    8,       // Table size
  234.    TupleKey, // Key Type
  235.    1 // Nr of Pages
  236.    ,All,
  237.    6,
  238.    78,
  239.    80,
  240.    1,
  241.    useTableLogging
  242.                                    );
  243.   if( check == -1 ) 
  244.     error_handler("createTable", MySchemaTransaction->getNdbError(), 0);
  245.   
  246.   // Create first column, primary key 
  247.   check = MySchemaOp->createAttribute( GROUP_ID,
  248.        TupleKey, 
  249.        sizeof(GroupId) << 3,
  250.        1,
  251.        UnSigned, 
  252.        MMBased,
  253.        NotNullAttribute );
  254.   if( check == -1 ) 
  255.     error_handler("createAttribute (group id)", 
  256.   MySchemaTransaction->getNdbError(), 0);
  257.   check = MySchemaOp->createAttribute( GROUP_NAME,
  258.        NoKey,
  259.        sizeof(char) << 3,
  260.        GROUP_NAME_LENGTH,
  261.        String, 
  262.        MMBased,
  263.        NotNullAttribute );
  264.   if( check == -1 ) 
  265.     error_handler("createAttribute (group name)", 
  266.   MySchemaTransaction->getNdbError(), 0);
  267.   
  268.   check = MySchemaOp->createAttribute( GROUP_ALLOW_READ,
  269.        NoKey, 
  270.        sizeof(Permission) << 3,
  271.        1,
  272.        String, 
  273.        MMBased,
  274.        NotNullAttribute );
  275.   if( check == -1 ) 
  276.     error_handler("createAttribute (group read)", 
  277.   MySchemaTransaction->getNdbError(), 0);
  278.   
  279.   check = MySchemaOp->createAttribute( GROUP_ALLOW_INSERT,
  280.        NoKey, 
  281.        sizeof(Permission) << 3,
  282.        1,
  283.        UnSigned,
  284.        MMBased,
  285.        NotNullAttribute );
  286.   if( check == -1 ) 
  287.     error_handler("createAttribute (group insert)", 
  288.   MySchemaTransaction->getNdbError(), 0);
  289.   check = MySchemaOp->createAttribute( GROUP_ALLOW_DELETE,
  290.        NoKey, 
  291.        sizeof(Permission) << 3,
  292.        1,
  293.        UnSigned,
  294.        MMBased,
  295.        NotNullAttribute );
  296.   if( check == -1 ) 
  297.     error_handler("createAttribute (group delete)", 
  298.   MySchemaTransaction->getNdbError(), 0);
  299.   
  300.   if( MySchemaTransaction->execute() == -1 ) {
  301.     error_handler("schemaTransaction->execute()", 
  302.   MySchemaTransaction->getNdbError(), 0);
  303.   }    
  304.   NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
  305.   return 0;
  306. }
  307. int
  308. create_table_subscriber(Ndb * pNdb){
  309.   int check;
  310.   NdbSchemaCon * MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pNdb);
  311.   if( MySchemaTransaction == NULL )
  312.     error_handler("startSchemaTransaction", pNdb->getNdbError(), 0);
  313.   
  314.   NdbSchemaOp * MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
  315.   if( MySchemaOp == NULL ) 
  316.     error_handler("getNdbSchemaOp", MySchemaTransaction->getNdbError(), 0);
  317.   
  318.   // Create table
  319.   check = MySchemaOp->createTable( SUBSCRIBER_TABLE,
  320.    8,       // Table size
  321.    TupleKey, // Key Type
  322.    1 // Nr of Pages
  323.    ,DistributionGroup,
  324.    6,
  325.    78,
  326.    80,
  327.    1,
  328.    useTableLogging
  329.                                    );
  330.   if( check == -1 ) 
  331.     error_handler("createTable", MySchemaTransaction->getNdbError(), 0);
  332.   
  333.   // Create first column, primary key 
  334.   check = MySchemaOp->createAttribute
  335.     ( SUBSCRIBER_NUMBER,
  336.       TupleKey, 
  337.       sizeof(char) << 3,
  338.       SUBSCRIBER_NUMBER_LENGTH,
  339.       String, 
  340.       MMBased,
  341.       NotNullAttribute,
  342.       (useIndexTables ? IndexStorageAttribute : NormalStorageAttribute),
  343.       0,
  344.       1,
  345.       16);
  346.   if( check == -1 ) 
  347.     error_handler("createAttribute (subscriber number)", 
  348.   MySchemaTransaction->getNdbError(), 0);
  349.   
  350.   check = MySchemaOp->createAttribute( SUBSCRIBER_NAME,
  351.        NoKey, 
  352.        sizeof(char) << 3,
  353.        SUBSCRIBER_NAME_LENGTH,
  354.        String, 
  355.        MMBased,
  356.        NotNullAttribute );
  357.   if( check == -1 ) 
  358.     error_handler("createAttribute (subscriber name)", 
  359.   MySchemaTransaction->getNdbError(), 0);
  360.   
  361.   check = MySchemaOp->createAttribute( SUBSCRIBER_GROUP,
  362.        NoKey, 
  363.        sizeof(GroupId) << 3,
  364.        1,
  365.        UnSigned,
  366.        MMBased,
  367.        NotNullAttribute );
  368.   if( check == -1 ) 
  369.     error_handler("createAttribute (subscriber_group)", 
  370.   MySchemaTransaction->getNdbError(), 0);
  371.   
  372.   check = MySchemaOp->createAttribute( SUBSCRIBER_LOCATION,
  373.        NoKey, 
  374.        sizeof(Location) << 3,
  375.        1,
  376.        UnSigned,
  377.        MMBased,
  378.        NotNullAttribute );
  379.   if( check == -1 ) 
  380.     error_handler("createAttribute (server reads)", 
  381.   MySchemaTransaction->getNdbError(), 0);
  382.   check = MySchemaOp->createAttribute( SUBSCRIBER_SESSIONS,
  383.        NoKey, 
  384.        sizeof(ActiveSessions) << 3,
  385.        1,
  386.        UnSigned,
  387.        MMBased,
  388.        NotNullAttribute );
  389.   if( check == -1 ) 
  390.     error_handler("createAttribute (subscriber_sessions)", 
  391.   MySchemaTransaction->getNdbError(), 0);
  392.   check = MySchemaOp->createAttribute( SUBSCRIBER_CHANGED_BY,
  393.        NoKey, 
  394.        sizeof(char) << 3,
  395.        CHANGED_BY_LENGTH,
  396.        String,
  397.        MMBased,
  398.        NotNullAttribute );
  399.   if( check == -1 ) 
  400.     error_handler("createAttribute (subscriber_changed_by)", 
  401.   MySchemaTransaction->getNdbError(), 0);
  402.   check = MySchemaOp->createAttribute( SUBSCRIBER_CHANGED_TIME,
  403.        NoKey, 
  404.        sizeof(char) << 3,
  405.        CHANGED_TIME_LENGTH,
  406.        String,
  407.        MMBased,
  408.        NotNullAttribute );
  409.   if( check == -1 ) 
  410.     error_handler("createAttribute (subscriber_changed_time)", 
  411.   MySchemaTransaction->getNdbError(), 0);
  412.   
  413.   if( MySchemaTransaction->execute() == -1 ) {
  414.     error_handler("schemaTransaction->execute()", 
  415.   MySchemaTransaction->getNdbError(), 0);
  416.   }    
  417.   NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
  418.   return 0;
  419. }
  420. int
  421. create_table_session(Ndb * pNdb){
  422.   int check;
  423.   NdbSchemaCon * MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pNdb);
  424.   if( MySchemaTransaction == NULL )
  425.     error_handler("startSchemaTransaction", pNdb->getNdbError(), 0);
  426.   
  427.   NdbSchemaOp * MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
  428.   if( MySchemaOp == NULL ) 
  429.     error_handler("getNdbSchemaOp", 
  430.   MySchemaTransaction->getNdbError(), 0);
  431.   
  432.   // Create table
  433.   check = MySchemaOp->createTable( SESSION_TABLE,
  434.    8,       // Table size
  435.    TupleKey, // Key Type
  436.    1 // Nr of Pages
  437.    ,DistributionGroup,
  438.    6,
  439.    78,
  440.    80,
  441.    1,
  442.    useTableLogging
  443.                                    );
  444.   if( check == -1 ) 
  445.     error_handler("createTable", MySchemaTransaction->getNdbError(), 0);
  446.   
  447.   check = MySchemaOp->createAttribute( SESSION_SUBSCRIBER,
  448.        TupleKey, 
  449.        sizeof(char) << 3,
  450.        SUBSCRIBER_NUMBER_LENGTH,
  451.        String, 
  452.        MMBased,
  453.        NotNullAttribute,
  454.        NormalStorageAttribute,
  455.        0,
  456.        1,
  457.        16);
  458.   if( check == -1 ) 
  459.     error_handler("createAttribute (session_subscriber)", 
  460.   MySchemaTransaction->getNdbError(), 0);
  461.   // Create first column, primary key 
  462.   check = MySchemaOp->createAttribute( SESSION_SERVER,
  463.        TupleKey, 
  464.        sizeof(ServerId) << 3,
  465.        1,
  466.        UnSigned,
  467.        MMBased,
  468.        NotNullAttribute );
  469.   if( check == -1 ) 
  470.     error_handler("createAttribute (session_server)", 
  471.   MySchemaTransaction->getNdbError(), 0);
  472.   check = MySchemaOp->createAttribute( SESSION_DATA,
  473.        NoKey, 
  474.        sizeof(char) << 3,
  475.        SESSION_DETAILS_LENGTH,
  476.        String, 
  477.        MMBased,
  478.        NotNullAttribute );
  479.   if( check == -1 ) 
  480.     error_handler("createAttribute (session_data)", 
  481.   MySchemaTransaction->getNdbError(), 0);
  482.   
  483.   if( MySchemaTransaction->execute() == -1 ) {
  484.     error_handler("schemaTransaction->execute()", 
  485.   MySchemaTransaction->getNdbError(), 0);
  486.   }    
  487.   NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);
  488.   return 0;
  489. }
  490. void 
  491. create_table(const char * name, int (* function)(Ndb * pNdb), Ndb* pNdb){
  492.   printf("creating table %s...", name);
  493.   if(pNdb->getDictionary()->getTable(name) != 0){
  494.     printf(" it already existsn");
  495.     return;
  496.   } else {
  497.     printf("n");
  498.   }
  499.   function(pNdb);
  500.   printf("creating table %s... donen", name);
  501. }
  502. static int dbCreate(Ndb * pNdb)
  503. {
  504.   create_table(SUBSCRIBER_TABLE, create_table_subscriber, pNdb);
  505.   create_table(GROUP_TABLE     , create_table_group, pNdb);
  506.   create_table(SESSION_TABLE   , create_table_session, pNdb);
  507.   create_table(SERVER_TABLE    , create_table_server, pNdb);
  508.   return 0;
  509. }
  510. #ifndef NDB_WIN32
  511. #include <unistd.h>
  512. #endif
  513. static NdbMutex* startupMutex = NdbMutex_Create();
  514. UserHandle*
  515. userDbConnect(uint32 createDb, char *dbName)
  516. {
  517.   NdbMutex_Lock(startupMutex);
  518.   Ndb * pNdb = new Ndb("");
  519.   
  520.   //printf("Initializing...n");
  521.   pNdb->init();
  522.   
  523.   //printf("Waiting...");
  524.   while(pNdb->waitUntilReady() != 0){
  525.     //printf("...");
  526.   }
  527.   //  printf("donen");
  528.   
  529.   if( createDb )
  530.     dbCreate(pNdb);
  531.   
  532.   UserHandle * uh = new UserHandle;
  533.   uh->pNDB       = pNdb;
  534.   uh->pCurrTrans = 0;
  535.   NdbMutex_Unlock(startupMutex);
  536.   return uh;
  537. }
  538. void userDbDisconnect(UserHandle *uh)
  539. {
  540.   delete uh;
  541. }
  542. int userDbInsertServer(UserHandle       *uh,
  543.                        ServerId         serverId,
  544.                SubscriberSuffix suffix,
  545.                ServerName       name)
  546. {
  547.   int check;
  548.   uint32 noOfRead   = 0;
  549.   uint32 noOfInsert = 0;
  550.   uint32 noOfDelete = 0;
  551.   NdbConnection * MyTransaction = 0;
  552.   if(uh->pCurrTrans != 0){
  553.     MyTransaction = uh->pCurrTrans;
  554.   } else {
  555.     uh->pCurrTrans = MyTransaction = uh->pNDB->startTransaction();
  556.   }
  557.   if (MyTransaction == NULL)   
  558.     error_handler("startTranscation", uh->pNDB->getNdbError(), 0);
  559.   
  560.   NdbOperation *MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
  561.   CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);
  562.   
  563.   check = MyOperation->insertTuple();
  564.   CHECK_MINUS_ONE(check, "insert tuple", MyTransaction);  
  565.   
  566.   check = MyOperation->equal(SERVER_ID, (char*)&serverId);
  567.   CHECK_MINUS_ONE(check, "setValue id", MyTransaction);  
  568.   
  569.   check = MyOperation->setValue(SERVER_SUBSCRIBER_SUFFIX, suffix);
  570.   CHECK_MINUS_ONE(check, "setValue suffix", MyTransaction);  
  571.   check = MyOperation->setValue(SERVER_NAME, name);
  572.   CHECK_MINUS_ONE(check, "setValue name", MyTransaction);  
  573.   check = MyOperation->setValue(SERVER_READS, (char*)&noOfRead);
  574.   CHECK_MINUS_ONE(check, "setValue reads", MyTransaction);  
  575.   check = MyOperation->setValue(SERVER_INSERTS, (char*)&noOfInsert);
  576.   CHECK_MINUS_ONE(check, "setValue inserts", MyTransaction);  
  577.   check = MyOperation->setValue(SERVER_DELETES, (char*)&noOfDelete);
  578.   CHECK_MINUS_ONE(check, "setValue deletes", MyTransaction);  
  579.   return 0;
  580. }
  581. int userDbInsertSubscriber(UserHandle      *uh,
  582.                    SubscriberNumber number,
  583.                            uint32           groupId,
  584.                    SubscriberName   name)
  585. {
  586.   int check;
  587.   uint32 activeSessions = 0;
  588.   Location l = 0;
  589.   ChangedBy changedBy; snprintf(changedBy, sizeof(changedBy), "ChangedBy");
  590.   ChangedTime changedTime; snprintf(changedTime, sizeof(changedTime), "ChangedTime"); 
  591.   NdbConnection * MyTransaction = 0;
  592.   if(uh->pCurrTrans != 0){
  593.     MyTransaction = uh->pCurrTrans;
  594.   } else {
  595.     uh->pCurrTrans = MyTransaction = uh->pNDB->startTransaction();
  596.   }
  597.   if (MyTransaction == NULL)   
  598.     error_handler("startTranscation", uh->pNDB->getNdbError(), 0);
  599.   
  600.   NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
  601.   CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);
  602.   
  603.   check = MyOperation->insertTuple();
  604.   CHECK_MINUS_ONE(check, "insertTuple", MyTransaction);
  605.   
  606.   check = MyOperation->equal(SUBSCRIBER_NUMBER, number);
  607.   CHECK_MINUS_ONE(check, "equal", MyTransaction);
  608.   check = MyOperation->setValue(SUBSCRIBER_NAME, name);
  609.   CHECK_MINUS_ONE(check, "setValue name", MyTransaction);
  610.   check = MyOperation->setValue(SUBSCRIBER_GROUP, (char*)&groupId);
  611.   CHECK_MINUS_ONE(check, "setValue group", MyTransaction);
  612.   check = MyOperation->setValue(SUBSCRIBER_LOCATION, (char*)&l);
  613.   CHECK_MINUS_ONE(check, "setValue location", MyTransaction);
  614.   check = MyOperation->setValue(SUBSCRIBER_SESSIONS, (char*)&activeSessions);
  615.   CHECK_MINUS_ONE(check, "setValue sessions", MyTransaction);
  616.   check = MyOperation->setValue(SUBSCRIBER_CHANGED_BY, changedBy);
  617.   CHECK_MINUS_ONE(check, "setValue changedBy", MyTransaction);
  618.   check = MyOperation->setValue(SUBSCRIBER_CHANGED_TIME, changedTime);
  619.   CHECK_MINUS_ONE(check, "setValue changedTime", MyTransaction);
  620.   return 0;
  621. }
  622. int userDbInsertGroup(UserHandle *uh,
  623.       GroupId    groupId, 
  624.       GroupName  name,
  625.       Permission allowRead,
  626.       Permission allowInsert,
  627.       Permission allowDelete)
  628. {
  629.   int check;
  630.   
  631.   NdbConnection * MyTransaction = 0;
  632.   if(uh->pCurrTrans != 0){
  633.     MyTransaction = uh->pCurrTrans;
  634.   } else {
  635.     uh->pCurrTrans = MyTransaction = uh->pNDB->startTransaction();
  636.   }
  637.   if (MyTransaction == NULL)   
  638.     error_handler("startTranscation", uh->pNDB->getNdbError(), 0);
  639.   NdbOperation *MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
  640.   CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);  
  641.   
  642.   check = MyOperation->insertTuple();
  643.   CHECK_MINUS_ONE(check, "insertTuple", MyTransaction);  
  644.   
  645.   check = MyOperation->equal(GROUP_ID, (char*)&groupId);
  646.   CHECK_MINUS_ONE(check, "equal", MyTransaction);  
  647.   
  648.   check = MyOperation->setValue(GROUP_NAME, name);
  649.   CHECK_MINUS_ONE(check, "setValue name", MyTransaction);  
  650.   check = MyOperation->setValue(GROUP_ALLOW_READ, (char*)&allowRead);
  651.   CHECK_MINUS_ONE(check, "setValue allowRead", MyTransaction);  
  652.   check = MyOperation->setValue(GROUP_ALLOW_INSERT, (char*)&allowInsert);
  653.   CHECK_MINUS_ONE(check, "setValue allowInsert", MyTransaction);  
  654.   check = MyOperation->setValue(GROUP_ALLOW_DELETE, (char*)&allowDelete);
  655.   CHECK_MINUS_ONE(check, "setValue allowDelete", MyTransaction);  
  656.   
  657.   return 0;
  658. }