⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userinterface.cpp

📁 mysql-5.0.22.tar.gz源码包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
      sizeof(char) << 3,      SUBSCRIBER_NUMBER_LENGTH,      String,       MMBased,      NotNullAttribute,      0,      0,      1,      16);  if( check == -1 )     error_handler("createAttribute (subscriber number)", 		  MySchemaTransaction->getNdbError(), 0);    check = MySchemaOp->createAttribute( SUBSCRIBER_NAME,				       NoKey, 				       sizeof(char) << 3,				       SUBSCRIBER_NAME_LENGTH,				       String, 				       MMBased,				       NotNullAttribute );  if( check == -1 )     error_handler("createAttribute (subscriber name)", 		  MySchemaTransaction->getNdbError(), 0);    check = MySchemaOp->createAttribute( SUBSCRIBER_GROUP,				       NoKey, 				       sizeof(GroupId) << 3,				       1,				       UnSigned,				       MMBased,				       NotNullAttribute );  if( check == -1 )     error_handler("createAttribute (subscriber_group)", 		  MySchemaTransaction->getNdbError(), 0);    check = MySchemaOp->createAttribute( SUBSCRIBER_LOCATION,				       NoKey, 				       sizeof(Location) << 3,				       1,				       UnSigned,				       MMBased,				       NotNullAttribute );  if( check == -1 )     error_handler("createAttribute (server reads)", 		  MySchemaTransaction->getNdbError(), 0);  check = MySchemaOp->createAttribute( SUBSCRIBER_SESSIONS,				       NoKey, 				       sizeof(ActiveSessions) << 3,				       1,				       UnSigned,				       MMBased,				       NotNullAttribute );  if( check == -1 )     error_handler("createAttribute (subscriber_sessions)", 		  MySchemaTransaction->getNdbError(), 0);  check = MySchemaOp->createAttribute( SUBSCRIBER_CHANGED_BY,				       NoKey, 				       sizeof(char) << 3,				       CHANGED_BY_LENGTH,				       String,				       MMBased,				       NotNullAttribute );  if( check == -1 )     error_handler("createAttribute (subscriber_changed_by)", 		  MySchemaTransaction->getNdbError(), 0);  check = MySchemaOp->createAttribute( SUBSCRIBER_CHANGED_TIME,				       NoKey, 				       sizeof(char) << 3,				       CHANGED_TIME_LENGTH,				       String,				       MMBased,				       NotNullAttribute );  if( check == -1 )     error_handler("createAttribute (subscriber_changed_time)", 		  MySchemaTransaction->getNdbError(), 0);    if( MySchemaTransaction->execute() == -1 ) {    error_handler("schemaTransaction->execute()", 		  MySchemaTransaction->getNdbError(), 0);  }      NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);  return 0;}intcreate_table_session(Ndb * pNdb){  int check;  NdbSchemaCon * MySchemaTransaction = NdbSchemaCon::startSchemaTrans(pNdb);  if( MySchemaTransaction == NULL )    error_handler("startSchemaTransaction", pNdb->getNdbError(), 0);    NdbSchemaOp * MySchemaOp = MySchemaTransaction->getNdbSchemaOp();	  if( MySchemaOp == NULL )     error_handler("getNdbSchemaOp", 		  MySchemaTransaction->getNdbError(), 0);    // Create table  check = MySchemaOp->createTable( SESSION_TABLE,				   8,	     	// Table size				   TupleKey,	// Key Type				   1		// Nr of Pages				   ,DistributionGroup,				   6,				   78,				   80,				   1,				   useTableLogging                                   );  if( check == -1 )     error_handler("createTable", MySchemaTransaction->getNdbError(), 0);    check = MySchemaOp->createAttribute( SESSION_SUBSCRIBER,				       TupleKey, 				       sizeof(char) << 3,				       SUBSCRIBER_NUMBER_LENGTH,				       String, 				       MMBased,				       NotNullAttribute,				       0,				       0,				       1,				       16);  if( check == -1 )     error_handler("createAttribute (session_subscriber)", 		  MySchemaTransaction->getNdbError(), 0);  // Create first column, primary key   check = MySchemaOp->createAttribute( SESSION_SERVER,				       TupleKey, 				       sizeof(ServerId) << 3,				       1,				       UnSigned,				       MMBased,				       NotNullAttribute );  if( check == -1 )     error_handler("createAttribute (session_server)", 		  MySchemaTransaction->getNdbError(), 0);  check = MySchemaOp->createAttribute( SESSION_DATA,				       NoKey, 				       sizeof(char) << 3,				       SESSION_DETAILS_LENGTH,				       String, 				       MMBased,				       NotNullAttribute );  if( check == -1 )     error_handler("createAttribute (session_data)", 		  MySchemaTransaction->getNdbError(), 0);    if( MySchemaTransaction->execute() == -1 ) {    error_handler("schemaTransaction->execute()", 		  MySchemaTransaction->getNdbError(), 0);  }      NdbSchemaCon::closeSchemaTrans(MySchemaTransaction);  return 0;}void create_table(const char * name, int (* function)(Ndb * pNdb), Ndb* pNdb){  printf("creating table %s...", name);  if(pNdb->getDictionary()->getTable(name) != 0){    printf(" it already exists\n");    return;  } else {    printf("\n");  }  function(pNdb);  printf("creating table %s... done\n", name);}static int dbCreate(Ndb * pNdb){  create_table(SUBSCRIBER_TABLE, create_table_subscriber, pNdb);  create_table(GROUP_TABLE     , create_table_group, pNdb);  create_table(SESSION_TABLE   , create_table_session, pNdb);  create_table(SERVER_TABLE    , create_table_server, pNdb);  return 0;}#ifndef NDB_WIN32#include <unistd.h>#endifUserHandle*userDbConnect(uint32 createDb, char *dbName){  Ndb_cluster_connection *con= new Ndb_cluster_connection();  if(con->connect(12, 5, 1) != 0)  {    ndbout << "Unable to connect to management server." << endl;    return 0;  }  if (con->wait_until_ready(30,0) < 0)  {    ndbout << "Cluster nodes not ready in 30 seconds." << endl;    return 0;  }  Ndb * pNdb = new Ndb(con, dbName);    //printf("Initializing...\n");  pNdb->init();    //printf("Waiting...");  while(pNdb->waitUntilReady() != 0){    //printf("...");  }  //  printf("done\n");    if( createDb )    dbCreate(pNdb);    UserHandle * uh = new UserHandle;  uh->pNCC       = con;  uh->pNDB       = pNdb;  uh->pCurrTrans = 0;  return uh;}void userDbDisconnect(UserHandle *uh){  delete uh;}int userDbInsertServer(UserHandle       *uh,                       ServerId         serverId,	               SubscriberSuffix suffix,	               ServerName       name){  int check;  uint32 noOfRead   = 0;  uint32 noOfInsert = 0;  uint32 noOfDelete = 0;  NdbConnection * MyTransaction = 0;  if(uh->pCurrTrans != 0){    MyTransaction = uh->pCurrTrans;  } else {    uh->pCurrTrans = MyTransaction = uh->pNDB->startTransaction();  }  if (MyTransaction == NULL)	      error_handler("startTranscation", uh->pNDB->getNdbError(), 0);    NdbOperation *MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);  CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);    check = MyOperation->insertTuple();  CHECK_MINUS_ONE(check, "insert tuple", MyTransaction);      check = MyOperation->equal(SERVER_ID, (char*)&serverId);  CHECK_MINUS_ONE(check, "setValue id", MyTransaction);      check = MyOperation->setValue(SERVER_SUBSCRIBER_SUFFIX, suffix);  CHECK_MINUS_ONE(check, "setValue suffix", MyTransaction);    check = MyOperation->setValue(SERVER_NAME, name);  CHECK_MINUS_ONE(check, "setValue name", MyTransaction);    check = MyOperation->setValue(SERVER_READS, (char*)&noOfRead);  CHECK_MINUS_ONE(check, "setValue reads", MyTransaction);    check = MyOperation->setValue(SERVER_INSERTS, (char*)&noOfInsert);  CHECK_MINUS_ONE(check, "setValue inserts", MyTransaction);    check = MyOperation->setValue(SERVER_DELETES, (char*)&noOfDelete);  CHECK_MINUS_ONE(check, "setValue deletes", MyTransaction);    return 0;}int userDbInsertSubscriber(UserHandle      *uh,	                   SubscriberNumber number,                           uint32           groupId,	                   SubscriberName   name){  int check;  uint32 activeSessions = 0;  Location l = 0;  ChangedBy changedBy; snprintf(changedBy, sizeof(changedBy), "ChangedBy");  ChangedTime changedTime; snprintf(changedTime, sizeof(changedTime), "ChangedTime");   NdbConnection * MyTransaction = 0;  if(uh->pCurrTrans != 0){    MyTransaction = uh->pCurrTrans;  } else {    uh->pCurrTrans = MyTransaction = uh->pNDB->startTransaction();  }  if (MyTransaction == NULL)	      error_handler("startTranscation", uh->pNDB->getNdbError(), 0);    NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);  CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);    check = MyOperation->insertTuple();  CHECK_MINUS_ONE(check, "insertTuple", MyTransaction);    check = MyOperation->equal(SUBSCRIBER_NUMBER, number);  CHECK_MINUS_ONE(check, "equal", MyTransaction);  check = MyOperation->setValue(SUBSCRIBER_NAME, name);  CHECK_MINUS_ONE(check, "setValue name", MyTransaction);  check = MyOperation->setValue(SUBSCRIBER_GROUP, (char*)&groupId);  CHECK_MINUS_ONE(check, "setValue group", MyTransaction);  check = MyOperation->setValue(SUBSCRIBER_LOCATION, (char*)&l);  CHECK_MINUS_ONE(check, "setValue location", MyTransaction);  check = MyOperation->setValue(SUBSCRIBER_SESSIONS, (char*)&activeSessions);  CHECK_MINUS_ONE(check, "setValue sessions", MyTransaction);  check = MyOperation->setValue(SUBSCRIBER_CHANGED_BY, changedBy);  CHECK_MINUS_ONE(check, "setValue changedBy", MyTransaction);  check = MyOperation->setValue(SUBSCRIBER_CHANGED_TIME, changedTime);  CHECK_MINUS_ONE(check, "setValue changedTime", MyTransaction);  return 0;}int userDbInsertGroup(UserHandle *uh,		      GroupId    groupId, 		      GroupName  name,		      Permission allowRead,		      Permission allowInsert,		      Permission allowDelete){  int check;    NdbConnection * MyTransaction = 0;  if(uh->pCurrTrans != 0){    MyTransaction = uh->pCurrTrans;  } else {    uh->pCurrTrans = MyTransaction = uh->pNDB->startTransaction();  }  if (MyTransaction == NULL)	      error_handler("startTranscation", uh->pNDB->getNdbError(), 0);  NdbOperation *MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);  CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);      check = MyOperation->insertTuple();  CHECK_MINUS_ONE(check, "insertTuple", MyTransaction);      check = MyOperation->equal(GROUP_ID, (char*)&groupId);  CHECK_MINUS_ONE(check, "equal", MyTransaction);      check = MyOperation->setValue(GROUP_NAME, name);  CHECK_MINUS_ONE(check, "setValue name", MyTransaction);    check = MyOperation->setValue(GROUP_ALLOW_READ, (char*)&allowRead);  CHECK_MINUS_ONE(check, "setValue allowRead", MyTransaction);    check = MyOperation->setValue(GROUP_ALLOW_INSERT, (char*)&allowInsert);  CHECK_MINUS_ONE(check, "setValue allowInsert", MyTransaction);    check = MyOperation->setValue(GROUP_ALLOW_DELETE, (char*)&allowDelete);  CHECK_MINUS_ONE(check, "setValue allowDelete", MyTransaction);      return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -