Exemple #1
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}

    TableDef tabDef;
    for (int i=0;i<100;i++)
    {
	tabDef.addField("f1", typeInt);
	tabDef.dropField("f1");
    }
    int fieldcount=tabDef.getFieldCount();
    printf("Number of Fields = %d\n",fieldcount);
    rv=dbMgr->createTable("t1", tabDef);
    if(rv==OK) 
    { 
	printf("Table created without Fields\n"); 
	printf("Test failed\n");
	dbMgr->dropTable("t1");
	return 3;
    }
    
    dbMgr->dropTable("t1"); 
    conn.close();
    return 0;
}
Exemple #2
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
   
    TableDef tabDef;
    tabDef.addField("f1", typeInt, 0, NULL, true);
    tabDef.addField("f2", typeInt);
    tabDef.addField("f3", typeString, 1016);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; }
    printf("Table created\n");

    Table *table = dbMgr->openTable("t1");
    if (table == NULL) 
    { 
        printf("Unable to open table\n"); 
        dbMgr->dropTable("t1");
        conn.close();
        return -1; 
    }
    int id1 = 0, id2 = 5;
    char name[20] = "PRAVEEN";
    table->bindFld("f1", &id1);
    table->bindFld("f2", &id2);
    table->bindFld("f3", name);
    int icount =0;
    for (int i = 0 ; i < 1000 ; i++)
    {
        conn.startTransaction();
        for (int j = 0 ; j < 100 ; j++) {
            id1= icount++;
            rv = table->insertTuple();
            if (rv != OK) break;
        }
        conn.commit();
    }
    printf("Tuples inserted %d\n", icount);
    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");
    conn.close();
    if (rv == ErrNoMemory)
    {
       //insert is expected to fail
       printf("insert failed with return values %d\n", rv);
       return 0;
    } 
    return 1;
}
//creating index with non existing field
//It should fail
int main()
{

    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK)
    {
       printf("Error during connection %d\n", rv);
       return -1;
    }
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return -1;}
    TableDef tabDef;
    tabDef.addField("f1", typeInt, 0, NULL, true);
    tabDef.addField("f2", typeInt);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); return -1; }
    printf("Table created\n");
    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
    strcpy(idxInfo->tableName, "t1");
    idxInfo->list.append("notexist");
    idxInfo->indType = hashIndex;
#ifdef TREEINDEX
    idxInfo->indType = treeIndex;
#elif defined TRIEINDEX
    idxInfo->indType = trieIndex;
#endif
    int ret =0;
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv == OK) ret =1;
    delete idxInfo;
    dbMgr->dropTable("t1");
    conn.close();
    return ret;
}
Exemple #4
0
int main (int argc, char **argv)
{
  Connection conn;
  DbRetVal rv = conn.open("root","manager");
  printf ("Main open Returned %d\n", rv);
  pthread_t thread1, thread2;
  int message1 =1; 
  int message2 =2; 
  int status;

  pthread_create (&thread1, NULL,
		  &print_message_function, (void *) &message1);
  pthread_create (&thread2, NULL,
		  &print_message_function, (void *) &message2);

  pthread_join(thread1, (void **)&status);
  pthread_join(thread2, (void **)&status);


  DatabaseManager *dbMgr = conn.getDatabaseManager();
  if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
  dbMgr->dropTable("T1");
  dbMgr->dropTable("T2");

  rv = conn.close();
  printf ("Main Returned %d\n", rv);
  exit (0);
}
Exemple #5
0
int main()
{

    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) { printf("Error during connection %d\n", rv); return 1; }
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    int ret = createTable(dbMgr);
    if (ret != 0) { return 1; }

    pthread_t thr[2];
    int *status1, *status2;
    pthread_create (&thr[0], NULL, &runTest1,  NULL);
    pthread_create (&thr[1], NULL, &runTest2,  NULL);
    printf("All threads started\n");

    pthread_join(thr[0], (void**)&status1);
    pthread_join(thr[1], (void**)&status2);
    ret = 0;
    if (*status1 != 0 || *status2 != 0) ret = 1;
    if (p1RetVal) { delete p1RetVal; p1RetVal = NULL; }
    if (p2RetVal) { delete p2RetVal; p2RetVal = NULL; }
    dbMgr->dropTable("t1");
    conn.close();
    return ret;
}
Exemple #6
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root","manager");
    if(rv!=OK)return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if(dbMgr == NULL)
    {
       printf("Auth failed\n");
       return 2;
    }

    TableDef tabDef;
    tabDef.addField("f1",typeInt,0,NULL,true);
    tabDef.addField("f2",typeInt);
    
    rv = dbMgr->createTable("t1",tabDef);
    if(rv!=OK)
    {
      printf("Table created failed\n");
      conn.close();
      return 0;
    }

    
    Table *table = dbMgr->openTable("t1");
    long spaceused;
    spaceused = table->spaceUsed();
    printf("Total space used=%ld\n",spaceused);

   dbMgr->closeTable(table);
   dbMgr->dropTable("t1");
   conn.close();
   return 0;
}  	
Exemple #7
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}

    if ( createTable(dbMgr) != 0 ) { conn.close(); return 3; }
    if ( createIndex(dbMgr, false) != 0 ) { dbMgr->dropTable("t1");conn.close(); return 4;
 }
    int inscount =  insertTupleWithSameValue(dbMgr, conn);
    if (inscount != 10 ) { dbMgr->dropTable("t1"); conn.close(); return 5; }
    dbMgr->dropTable("t1");
    conn.close();
    return 0;

}
Exemple #8
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}

    if ( createTable(dbMgr) != 0 ) { conn.close(); return 3; }
    int inscount =  insertTuple(dbMgr, conn);
    //check the inscount and return error

    Table *table = dbMgr->openTable("t1");
    if (table == NULL)
    {
        printf("Unable to open table\n");
        return 0;
    }


    Condition p1,p2,p3,p4,p5;
    int val1 = 2, val2 = 3, val3 = 4;
    p1.setTerm("f1", OpEquals, &val3);
    p2.setTerm("f2", OpGreaterThan, &val2);
    p3.setTerm("f2", OpEquals, &val3);
    p4.setTerm("f1", OpLessThan, &val1);
    p5.setTerm("f1", OpGreaterThan, &val1);


    Condition cond1, cond1a;
    cond1.setTerm(p1.getPredicate(), OpAnd, p2.getPredicate());
    cond1a.setTerm(cond1.getPredicate(), OpOr, p4.getPredicate());
    table->setCondition(&cond1a);
    printf("Predicate: (f1 ==4 AND f2 >3) OR (f1< 2) \n");
    conn.startTransaction();
    execAndPrint(table);
    conn.commit();

    Condition cond2, cond2a;
    cond2.setTerm(p4.getPredicate(), OpAnd, p2.getPredicate());
    cond2a.setTerm(cond1.getPredicate(), OpOr, cond2.getPredicate());
    table->setCondition(&cond2a);
    printf("Predicate: (f1 ==4 AND f2 >3) OR (f1< 2 AND f2 > 4) \n");
    conn.startTransaction();
    execAndPrint(table);
    conn.commit();

    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");
    conn.close();
    return 0;

}
Exemple #9
0
//bind non exisiting field
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
   
    TableDef tabDef;
    tabDef.addField("f1", typeInt, 0, NULL, true);
    tabDef.addField("f2", typeInt);
    tabDef.addField("f3", typeString, 20);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; }
    printf("Table created\n");

    Table *table = dbMgr->openTable("t1");
    if (table == NULL) 
    { 
        printf("Unable to open table\n"); 
        dbMgr->dropTable("t1");
        conn.close();
        return -1; 
    }
    int id1 = 0, id2 = 5;
    int ret =0;
    char name[20] = "PRAVEEN";
    rv = table->bindFld("f1", &id1);
    if (rv != OK) ret = 1;
    rv  = table->bindFld("f5", &id2);
    if (rv == OK) ret = 1;
    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");
    conn.close();
    return ret;
}
Exemple #10
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}

    TableDef tabDef;

    tabDef.addField("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklabc", typeInt, 0, NULL, true);
    rv=dbMgr->createTable("t1", tabDef);
    if(rv==OK) 
    { 
	printf("Allowing fieldname more than 64 character\n");
	printf("Test Failed\n");
	dbMgr->dropTable("t1");
	return 3;
    }
    printf("Test Passed\n");
    conn.close();
    return 0;
}
Exemple #11
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
   
    TableDef tabDef;
    tabDef.addField("f1", typeInt, 0, NULL, true);
    tabDef.addField("f2", typeInt);
    tabDef.addField("f3", typeString, 2000);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; }
    printf("Table created\n");

    Table *table = dbMgr->openTable("t1");
    if (table == NULL) 
    { 
        printf("Unable to open table\n"); 
        dbMgr->dropTable("t1");
        conn.close();
        return -1; 
    }
    int id1 = 0, id2 = 5;
    char name[20] = "PRAVEEN";
    table->bindFld("f1", &id1);
    table->bindFld("f2", &id2);
    table->bindFld("f3", name);
    int i=0;
    for (i = 0 ; i < 4000; i++)
    {
        conn.startTransaction();
        id1= i;
        rv = table->insertTuple();
        if (rv != OK) break;
        conn.commit();
    }
    printf("%d records inserted\n", i);
    for (int k=0; k <100; k++) {
      table->setCondition(NULL);
      rv = table->execute();
      if (rv != OK) {
        printf("table execute failed rv:%d\n", rv);
        dbMgr->closeTable(table);
        conn.close();
        return 1;
      }
      void *tuple = NULL;
      for (i = 0 ; i < 1000 ; i++)
      {
        conn.startTransaction();
        tuple = table->fetchNoBind();
        if (tuple == NULL) { printf("No more records\n"); break; }
        rv = table->deleteTuple();
        if (rv != OK) { printf("Delete tuple failed\n"); break;}
        conn.commit();
      }
      table->closeScan();
      printf("Iteration:%d \n %d records deleted\n", k, i);
      i=0;
      for (i = 0 ; i < 1000 ; i++)
      {
        conn.startTransaction();
        id1= i;
        rv = table->insertTuple();
        if (rv != OK) break;
        conn.commit();
      }
      printf("%d records inserted\n", i);
    }

    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");
    conn.close();
    return 0;
}
Exemple #12
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}

    if ( createTable(dbMgr) != 0 ) { conn.close(); return 3; }
#ifdef WITHF1INDEX
    if (createIndex(dbMgr, "f1", "idx1") != 0) {dbMgr->dropTable("t1");
                                        conn.close();
                                        return 4;
                                       }
#endif
#ifdef WITHF1TREEINDEX
    if (createIndex(dbMgr, "f1", "idx1", true) != 0) {dbMgr->dropTable("t1");
                                        conn.close();
                                        return 4;
                                       }
#endif

#ifdef WITHF2INDEX
    if (createIndex(dbMgr, "f2", "idx2") != 0) {dbMgr->dropTable("t1");
                                        conn.close();
                                        return 4;
                                       }
#endif
#ifdef WITHF2TREEINDEX
    if (createIndex(dbMgr, "f2", "idx2", true) != 0) {dbMgr->dropTable("t1");
                                        conn.close();
                                        return 4;
                                       }
#endif

    int inscount =  insertTuple(dbMgr, conn);
    //check the inscount and return error

    Table *table = dbMgr->openTable("t1");
    if (table == NULL)
    {
        printf("Unable to open table\n");
        return 0;
    }


    Condition p1,p2,p3,p4,p5;
    int val1 = 2, val2 = 3, val3 = 4;
    p1.setTerm("f1", OpEquals, &val3);
    p2.setTerm("f2", OpGreaterThan, &val2);
    p3.setTerm("f2", OpEquals, &val3);
    p4.setTerm("f1", OpLessThan, &val3);
    p5.setTerm("f1", OpGreaterThan, &val1);


    Condition cond1, cond1a;
    cond1.setTerm(p1.getPredicate(), OpAnd, p2.getPredicate());
    cond1a.setTerm(cond1.getPredicate(), OpNot);
    table->setCondition(&cond1a);
    printf("Predicate: NOT(f1 ==4 AND f2 >3) \n");
    conn.startTransaction();
    execAndPrint(table);
    conn.commit();

    Condition cond2, cond2a;
    cond2.setTerm(p1.getPredicate(), OpAnd, p3.getPredicate());
    cond2a.setTerm(cond2.getPredicate(), OpNot);
    table->setCondition(&cond2a);
    printf("Predicate: NOT( f1 ==4 AND f2 ==4) \n");
    conn.startTransaction();
    execAndPrint(table);
    conn.commit();

    Condition cond3, cond3a;
    cond3.setTerm(p4.getPredicate(), OpAnd, p5.getPredicate());
    cond3a.setTerm(cond3.getPredicate(), OpNot);
    table->setCondition(&cond3a);
    printf("Predicate: NOT( f1 <4 AND f1 >2) \n");
    conn.startTransaction();
    execAndPrint(table);
    conn.commit();


    Condition cond4, cond4a;
    cond4.setTerm(p4.getPredicate(), OpAnd, p2.getPredicate());
    cond4a.setTerm(cond4.getPredicate(), OpNot);
    table->setCondition(&cond4a);
    printf("Predicate: NOT( f1 <4 AND f2 >3) \n");
    conn.startTransaction();
    execAndPrint(table);
    conn.commit();

    Condition cond5, cond5a;
    cond5.setTerm(p2.getPredicate(), OpNot);
    cond5a.setTerm(p4.getPredicate(), OpAnd, cond5.getPredicate());
    table->setCondition(&cond5a);
    printf("Predicate: ( f1 <4 AND (NOT(f2 >3)) \n");
    conn.startTransaction();
    execAndPrint(table);

    conn.commit();
    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");
    conn.close();
    return 0;

}
Exemple #13
0
int main()
{

    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK)
    {
       printf("Error during connection %d\n", rv);
       return 1;
    }


    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
    TableDef tabDef;
    tabDef.addField("f1", typeInt);
    tabDef.addField("f2", typeString, 196);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); return 3; }
    printf("Table created\n");
    Table *table = dbMgr->openTable("t1");
    if (table == NULL) { printf("Unable to open table\n"); return 4; }
    int id = 0;
    char name[196] = "PRABAKARAN";
    table->bindFld("f1", &id);
    table->bindFld("f2", name);
    int i;
    int icount =0;
    
    conn.startTransaction();
      rv = table->insertTuple();
      if (rv != OK) 
      {
         printf("Insertion failed \n");
         return 5;
      }
    conn.commit();
     
    conn.startTransaction();
    table->setCondition(NULL);
    rv = table->execute();
    if (rv != OK)
    {
       dbMgr->closeTable(table);
       dbMgr->dropTable("t1");
       conn.close();
       return 6;
    }
    void *fld2ptr, *tuple;

    while(true)
    {
        tuple = (char*)table->fetch() ;
        if (tuple == NULL) {break;}
        printf("Binded Tuple value is %d %s \n", id, name);

    }
    conn.commit();
    table->closeScan();
	dbMgr->closeTable(table);
    dbMgr->dropTable("t1");
    printf("test passed successfully\n");                      
    return 0;
}
Exemple #14
0
int main()
{

    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK)
    {
       printf("Error during connection %d\n", rv);
       return -1;
    }
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return -1;}
    TableDef tabDef;
    tabDef.addField("f1", typeInt, 0, NULL, true);
    tabDef.addField("f2", typeString, 50);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); return -1; }
    printf("Table created\n");
    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
    strcpy(idxInfo->tableName, "t1");
    idxInfo->list.append("f1");
    idxInfo->indType = hashIndex;
#ifdef F1TREE
    idxInfo->indType = treeIndex;
#endif
#ifdef F2TRIE
    idxInfo->indType = trieIndex;
#endif
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
    printf("Index created for f1\n");
    printf("size of index field list %d\n", idxInfo->list.size());
    idxInfo->list.remove("f1");
    printf("size of index field list %d\n", idxInfo->list.size());
    idxInfo->list.append("f2");
    printf("size of index field list %d\n", idxInfo->list.size());
    idxInfo->indType = hashIndex;
#ifdef F2TREE
    idxInfo->indType = treeIndex;
#endif
#ifdef F2TRIE
    idxInfo->indType = trieIndex;
#endif
    rv = dbMgr->createIndex("indx2", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
    printf("Index created for f2\n");
    delete idxInfo;
    Table *table = dbMgr->openTable("t1");
    if (table == NULL) { printf("Unable to open table\n"); return -1; }
    int id1 = 0;
    char id2[50] ="Aruna";
    table->bindFld("f1", &id1);
    table->bindFld("f2", id2);
    char *tuple;
    int ret;
    int i;
    int icount =0;
    rv = conn.startTransaction();
    if (rv != OK) exit(1);
    for(i = 0; i< 10; i++)
    {
        id1= i;
        sprintf(id2, "Aruna:%d", i);
        ret = table->insertTuple();
        if (ret != 0) break;
        icount++;
    }
    conn.commit();
    printf("Total tuples inserted: %d\n", icount);
    Condition p1, p2;
    int val1 = 0;
    char val2[50];
    p1.setTerm("f1", OpEquals, &val1);
    p2.setTerm("f2", OpEquals, &val2);
    table->setCondition(&p1);
    rv =conn.startTransaction();
    if (rv != OK) exit(1);
    for(i = 0; i< 10; i++)
    {    
        val1 = i;
        table->execute();
        tuple = (char*)table->fetch() ;
        if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;}
        printf("I:tuple value is %d %s \n", id1, id2);
        table->closeScan();
    }

    table->setCondition(&p2);
    for(i = 0; i< 10; i++)
    {    
        sprintf(val2, "Aruna:%d", i);
        table->execute();
        tuple = (char*)table->fetch() ;
        if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;}
        printf("II:tuple value is %d %s \n", id1, id2);
        table->closeScan();
    }
    conn.commit();

    rv =conn.startTransaction();
    if (rv != OK) exit(1);
    table->setCondition(&p1);
    val1 = 1;
    table->execute();
    tuple = (char*)table->fetch() ;
    if (tuple != NULL) {
        table->deleteTuple();
    }
    table->closeScan();
    table->setCondition(&p2);
    sprintf(val2, "Aruna:%d", 2);
    table->execute();
    tuple = (char*)table->fetch() ;
    if (tuple != NULL) {
        table->deleteTuple();
    }
    table->closeScan();
    conn.commit();

    int count =0;
    rv = conn.startTransaction();
    table->setCondition(NULL);
    if (rv != OK) exit (1);
    table->execute();
    while((tuple = (char*)table->fetch())!= NULL) {
        printf("tuple value is %d %s \n", id1, id2);
        count++;
    }
    table->closeScan();
    conn.commit();
    printf("Total rows selected %d\n", count);
    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");

    conn.close();
    return 0;
}
Exemple #15
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
   
    TableDef tabDef;
    tabDef.addField("f1", typeInt, 0, NULL, true);//NOT NULL
    tabDef.addField("f2", typeInt, 0, NULL, false);
    tabDef.addField("f3", typeString, 20);//Bydefault 'NOT NULL' is false
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; }
    printf("Table created\n");

    Table *table = dbMgr->openTable("t1");
    if (table == NULL) 
    { 
        printf("Unable to open table\n"); 
        dbMgr->dropTable("t1");
        conn.close();
        return -1; 
    }
    int id1 = 0, id2 = 5;
    char name[20] = "PRAVEEN";
    table->bindFld("f1", &id1);
    table->bindFld("f2", &id2);
    table->bindFld("f3", name);
    int icount =0;
    for (int i = 0 ; i < 5 ; i++)
    {
        conn.startTransaction();
        id1= i;
        if (i%2 == 0) table->markFldNull(3);
        rv = table->insertTuple();
        if (rv != OK) break;
        if (i%2 == 0) table->clearFldNull(3);
        icount++;
        conn.commit();

    }
    printf("Tuples inserted in 1/txn is %d\n", icount);
    table->setCondition(NULL);
    rv = table->execute();
    if (rv != OK)
    {
       dbMgr->closeTable(table);
       dbMgr->dropTable("t1");
       conn.close();
    }
    table->bindFld("f2", &id2);
    void *tuple = NULL; 
    while(true)
    {
        tuple = (char*)table->fetch() ;
        if (tuple == NULL) {break;}
        if (table->isFldNull(1)) printf("Column 1 is null\n");
        if (table->isFldNull(2)) printf("Column 2 is null\n");
        if (table->isFldNull(3)) printf("Column 3 is null\n");
        printf("Binded Tuple value is %d %d %s \n", id1, id2, name);

    }
    table->closeScan();
    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");
    conn.close();
    return 0;
}
Exemple #16
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) {
        printf("Auth failed\n");
        return 2;
    }

    TableDef tabDef;
    tabDef.addField("f1", typeInt, 0, NULL, true);
    tabDef.addField("f2", typeInt);
    tabDef.addField("f3", typeString, 20);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) {
        printf("Table creation failed\n");
        conn.close();
        return 3;
    }
    printf("Table created\n");

    Table *table = dbMgr->openTable("t1");
    if (table == NULL)
    {
        printf("Unable to open table\n");
        dbMgr->dropTable("t1");
        conn.close();
        return -1;
    }
    int id1 = 0, id2 = 5;
    char name[20] = "PRAVEEN";
    table->bindFld("f1", &id1);
    table->bindFld("f2", &id2);
    table->bindFld("f3", name);
    int icount =0;
    for (int i = 0 ; i < 10 ; i++)
    {
        conn.startTransaction();
        id1= i;
        rv = table->insertTuple();
        if (rv != OK) break;
        icount++;
        conn.commit();

    }
    printf("Tuples inserted in 1/txn is %d\n", icount);
    icount = 0;
    conn.startTransaction();
    for (int i = 20 ; i < 30 ; i++)
    {
        id1 = i;
        rv = table->insertTuple();
        if (rv != OK) break;
        icount++;
    }
    conn.commit();
    printf("Tuples inserted in 10/txn is %d\n", icount);
    table->setCondition(NULL);
    rv = table->execute();
    if (rv != OK)
    {
        dbMgr->closeTable(table);
        dbMgr->dropTable("t1");
        conn.close();
    }
    void *fld2ptr, *fld3ptr, *tuple;

    while(true)
    {
        tuple = (char*)table->fetch() ;
        if (tuple == NULL) {
            break;
        }
        fld2ptr = (char*)tuple + os::align(sizeof(int));
        fld3ptr = (char*)tuple + (2 * os::align(sizeof(int)));
        printf("Tuple value is %d %d %s \n", *((int*)tuple), *((int*)fld2ptr), (char*)fld3ptr );
        printf("Binded Tuple value is %d %d %s \n", id1, id2, name);

    }
    table->closeScan();
    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");
    conn.close();
    return 0;
}
Exemple #17
0
int main()
{

    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK)
    {
       printf("Error during connection %d\n", rv);
       return 1;
    }
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
    TableDef tabDef;
    tabDef.addField("f1", typeLongLong, 0, NULL, true);
    tabDef.addField("f2", typeString, 196);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); return 3; }
    printf("Table created\n");
#ifdef WITHINDEX
    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
    strcpy(idxInfo->tableName, "t1");
    idxInfo->list.append("f1");
    idxInfo->indType = hashIndex;
    idxInfo->isUnique = true;
    idxInfo->isPrimary = true;
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
    printf("Index created\n");
    delete idxInfo;
#endif
#ifdef WITHTREEINDEX
    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
    strcpy(idxInfo->tableName, "t1");
    idxInfo->list.append("f1");
    idxInfo->indType = treeIndex;
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
    printf("Index created\n");
    delete idxInfo;
#endif
#ifdef WITHTRIEINDEX
    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
    strcpy(idxInfo->tableName, "t1");
    idxInfo->list.append("f1");
    idxInfo->indType = trieIndex;
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
    printf("Index created\n");
    delete idxInfo;
#endif


    Table *table = dbMgr->openTable("t1");
    if (table == NULL) { printf("Unable to open table\n"); return 4; }
    table->bindFld("f1", &id);
    table->bindFld("f2", name);
    char *tuple;
    int ret;
    long long i;
    rv =conn.startTransaction();
    for(i = 0; i< 5; i++)
    {
        if (rv != OK) exit(5);
        id= i;
        strcpy(name, "PRABAKARAN0123456750590");
        ret = table->insertTuple();
        if (ret != 0) break;
    }
    conn.commit();

    conn.startTransaction();
    select(table, OpEquals);
    conn.commit();

    conn.startTransaction();
    select(table, OpNotEquals);
    conn.commit();

    conn.startTransaction();
    select(table, OpLessThan);
    conn.commit();

    conn.startTransaction();
    select( table, OpLessThanEquals);
    conn.commit();

    conn.startTransaction();
    select( table, OpGreaterThan);
    conn.commit();

    conn.startTransaction();
    select( table, OpGreaterThanEquals);
    conn.commit();

    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");

    conn.close();
    return 0;
}
Exemple #18
0
int main()
{

    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK)
    {
       printf("Error during connection %d\n", rv);
       return -1;
    }


    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return -1;}
    TableDef tabDef;
    tabDef.addField("f1", typeInt, 0, NULL, true );
    tabDef.addField("f2", typeString, 196);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); return -1; }
    printf("Table created\n");
    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
    strcpy(idxInfo->tableName, "t1");
    idxInfo->list.append("f1");
    idxInfo->indType = hashIndex;
    if (LOAD >0 )
       idxInfo->bucketSize = 100007;
    else
       idxInfo->bucketSize = 10007;
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
    printf("Index created\n");
    delete idxInfo;
    Table *table = dbMgr->openTable("t1");
    if (table == NULL) { printf("Unable to open table\n"); return -1; }
    int id = 0;
    char name[196] = "PRABAKARAN";
    table->bindFld("f1", &id);
    table->bindFld("f2", name);
    char *tuple;
    int ret;
    int i;
    int icount =0;
    if (LOAD > 0) {
      TableImpl *impl = (TableImpl*)table;
      impl->setUndoLogging(false);
      strcpy(name, "PRABAKARAN0123456750590");
      rv = conn.startTransaction();
      if (rv != OK) exit(1);
      for(i = 0; i< LOAD; i++)
      {
        id= i;
        ret = table->insertTuple();
        if (ret != 0) break;
        icount++;
        if (i % 100 == 0 ) { rv = conn.commit(); 
                             if (rv != OK) exit(1);
                             rv = conn.startTransaction(); 
                             if (rv != OK) exit(1);
                           }
        if (i %50000 == 0) printf("%d rows inserted\n", i);
      }
      conn.commit();
      impl->setUndoLogging(true);
      printf("Loaded %d records\n", icount);
    }
   
      //TableImpl *impl = (TableImpl*)table;
      //impl->setUndoLogging(false);
    i = 0; 
    NanoTimer timer;
    icount =0;
    for(i = LOAD; i< LOAD+ITERATIONS; i++)
    {
        timer.start();
        rv = conn.startTransaction();
        if (rv != OK) exit(1);
        id= i;
        strcpy(name, "PRABAKARAN0123456750590");
        ret = table->insertTuple();
        if (ret != 0) break;
    //    printf("%d\n ", i);
        icount++;
        conn.commit();
        timer.stop();
    }
   printf("%d rows inserted %lld %lld %lld\n",icount, timer.minc(), timer.maxc(), timer.avg());

    int offset1= os::align(sizeof(int));
    Condition p1;
    int val1 = 0;
    p1.setTerm("f1", OpEquals, &val1);
    table->setCondition(&p1);
    icount=0;
   

    timer.reset();
    for(i = LOAD; i< LOAD+ITERATIONS; i++)
    {    
        timer.start();
        rv =conn.startTransaction();
        if (rv != OK) exit(1);
        val1 = i;
        table->execute();
        tuple = (char*)table->fetch() ;
        if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;}
  //      printf(" %d tuple value is %d %s \n", i, *((int*)tuple), tuple+offset1);
        table->closeScan();
        icount++;
        conn.commit();
        timer.stop();
    }
    printf("%d rows selected %lld %lld %lld\n", icount, timer.minc(), timer.maxc(), timer.avg());
    timer.reset();

    for(i = LOAD; i< LOAD+ITERATIONS; i++)
    {
        timer.start();
        rv  = conn.startTransaction();
        if (rv != OK) exit (1);
        val1 = i;
        table->execute();
        tuple = (char*)table->fetch() ;
        if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;}
        strcpy(name, "PRABAKARAN0950576543210");
        table->updateTuple();
        table->closeScan();
        conn.commit();
        timer.stop();
    }
    printf("%d rows updated %lld %lld %lld\n", i- LOAD, timer.minc(), timer.maxc(), timer.avg());


    icount=0;
    for(i = LOAD; i< LOAD+ITERATIONS; i++)
    {
        timer.start();
        rv = conn.startTransaction();
        if (rv != OK) exit (1);
        val1 = i;
        table->execute();
        tuple = (char*)table->fetch() ;
        if (tuple == NULL) {printf("No record for %d\n", i);table->closeScan();break;}
        table->deleteTuple();
        icount++;
        table->closeScan();
        conn.commit();
        timer.stop();
    }
    printf("%d rows deleted %lld %lld %lld\n", icount, timer.minc(), timer.maxc(), timer.avg());


    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");
    printf("Table dropped\n");

    conn.close();
    return 0;
}
Exemple #19
0
int main()
{

    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK)
    {
       printf("Error during connection %d\n", rv);
       return -1;
    }
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return -1;}
    TableDef tabDef;
    tabDef.addField("f1", typeInt, 0, NULL, true, true);
    tabDef.addField("f2", typeString, 12);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); return -1; }
    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
    strcpy(idxInfo->tableName, "t1");
    idxInfo->list.append("f1");
    idxInfo->isPrimary = true;
    idxInfo->isUnique = true;
#ifdef HASH
    idxInfo->indType = hashIndex;
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
#endif
#ifdef TREE
    idxInfo->indType = treeIndex;
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
#endif
    delete idxInfo;
    pthread_t thr[THREADS];
    int message[THREADS];
    int status;
    for (int i=0; i <THREADS; i++) {
        message[i] = i;
        pthread_create (&thr[i], NULL,
                  &runInsTest, (void *) &message[i]);
    }
    for (int i=0; i <THREADS; i++) {
        pthread_join(thr[i], (void**)&status);
    }
    
    Table *table = dbMgr->openTable("t1");
    if (table == NULL) { printf("Unable to open table\n"); return -1; }
    table->setCondition(NULL);
    rv = conn.startTransaction();
    if (rv != OK) while (rv !=OK) rv = conn.startTransaction();
    table->execute();
    int count=0;
    void *tuple = NULL;
    while ((tuple = (char*) table->fetch())) {
         count++;
    }
    printf("Tuples found: %d\n", count);
    table->closeScan();
    conn.commit();

#ifdef HASH
    Condition p1;
    int valTerm = 0;
    p1.setTerm("f1", OpEquals, &valTerm);
    table->setCondition(&p1);
    int icount=0;
    for(int i = 0; i< THREADS * ITERATION; i++)
    {
        rv = conn.startTransaction();
        if (rv != OK) while (rv !=OK) rv = conn.startTransaction();
        valTerm = i+1;
        rv = table->execute();
        tuple = (char*)table->fetch() ;
        if (tuple == NULL)  break;
        icount++;
        table->closeScan();
        conn.commit();
        //if (i%ITERATION == 0) printf("%d\n", i);
    }
    printf("Index Tuples found: %d\n", icount);
#endif



    dbMgr->closeTable(table);

    for (int i=0; i <THREADS; i++) {
        message[i] = i;
        pthread_create (&thr[i], NULL,
                  &runSelTest, (void *) &message[i]);
    }
    for (int i=0; i <THREADS; i++) {
        pthread_join(thr[i], (void**)&status);
    }

    dbMgr->dropTable("t1");
    
    conn.close();
    return 0;
}
Exemple #20
0
int main()
{

    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK)
    {
       printf("Error during connection %d\n", rv);
       return 1;
    }


    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}


    TableDef tabDef;
    tabDef.addField("f1", typeInt);
    tabDef.addField("f2", typeString, 196);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); return 3; }
    printf("Table created\n");

    Table *table = dbMgr->openTable("t1");
    if (table == NULL) { printf("Unable to open table\n"); return 3; }
    int id;
    char name[200]="PRABA";
    table->bindFld("f1", &id);
    table->bindFld("f2", name);
    int icount = 0;
    int i;

    conn.startTransaction();
    for (i=0;i<10;i++)
    {
      id=i;
      rv=table->insertTuple();
      if(rv!=OK)
      {
         printf("Insertion failed at %d th tuple",i);
         dbMgr->closeTable(table);
         dbMgr->dropTable("t1");
         conn.close();
         return 4;
      }
    }
    conn.commit();

    conn.startTransaction();
    table->setCondition(NULL);
    rv = table->execute();
    if (rv != OK)
    {
       dbMgr->closeTable(table);
       dbMgr->dropTable("t1");
       conn.close();
       return 6;
    }
    printf("Scan before Deletion\n"); 
    printf("********************\n");
    void *fld2ptr, *tuple;
    while(true)
    {
        tuple = (char*)table->fetch() ;
        if (tuple == NULL) {break;}
        printf("Binded Tuple value is %d %s \n", id, name);

    }
    conn.commit();
    rv=table->closeScan();
    if(rv!=OK){ printf("Error in closing the table\n"); return 3;}
 
    Condition p1;
    int val1 = 5;
    p1.setTerm("f1",OpEquals, &val1);
    table->setCondition(&p1);
    conn.startTransaction();
    rv=table->execute();
    if (rv != OK)
    {
       dbMgr->closeTable(table);
       dbMgr->dropTable("t1");
       conn.close();
       return 4;   
    }

//    char *tuple; 
    //printf("Scan After:\n");
    while(true)
    {
        tuple = (char*)table->fetch() ;
        if (tuple == NULL) { break; }
        //strcpy(name,"Kanchana");
        table->deleteTuple();
    }
   conn.commit();
   table->closeScan(); 


    conn.startTransaction();

    table->setCondition(NULL);
    rv = table->execute();
    if (rv != OK)
    {
       dbMgr->closeTable(table);
       dbMgr->dropTable("t1");
       conn.close();
       return 6;
    }
    printf("Scan After Deletion\n");
    printf("********************\n");
    while(true)
    {
        tuple = (char*)table->fetch() ;
        if (tuple == NULL) {break;}
        printf("Binded Tuple value is %d %s \n", id, name);

    }
    conn.commit();

    //unset the condtion set as we need to delete all rows
    table->setCondition(NULL);
    table->closeScan();
    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");
    conn.close();
    printf("Test script passed ");
    return 0;
}