當前位置: 首頁>>代碼示例>>C++>>正文


C++ Database_close函數代碼示例

本文整理匯總了C++中Database_close函數的典型用法代碼示例。如果您正苦於以下問題:C++ Database_close函數的具體用法?C++ Database_close怎麽用?C++ Database_close使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Database_close函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: main

int main(int argc, char *argv[])
{
  if(argc < 3) die("USAGE: ex17 <dbfile> <action> [action params]");

  char *filename = argv[1];
  char action = argv[2][0];
  struct Connection *conn = Database_open(filename, action);
  int id = 0;
  char *name = "\0";

  if(strcmp(argv[2],"f")==0){
    name = argv[3];
  }
  else if(argc > 3) {
    id = atoi(argv[3]);
  }
  
  if(id >= MAX_ROWS) die("There's not that many records");

  switch(action) {
  case 'c':
    Database_create(conn);
    Database_write(conn);
    break;
  case 'g':
    if(argc != 4) die("Need an id to get");

    Database_get(conn, id);
    break;
  case 'd':
    if(argc != 4) die("Need id to delete");

    Database_delete(conn, id);
    Database_write(conn);
    break;

  case 's':
    if(argc != 6) die("need id, name, email to set");

    Database_set(conn, id, argv[4], argv[5]);
    Database_write(conn);
    break;

  case 'l':
    Database_list(conn);
    break;

  case 'f':
    Database_find(conn, name);
    break;

  default:
    die("Invalid action, only: c=create, g=get, s=set, d=del, l=list");
  }

  Database_close(conn);
  
  return 0;
}
開發者ID:imnotthomas,項目名稱:cthehardway,代碼行數:59,代碼來源:ex17.c

示例2: main

int main(int argc, char *argv[]) {
if (argc < 3)
die("USAGE: ex17 <dbfile> <action> [action params]");
char *filename = argv[1];
char action = argv[2][0];
Database_open(filename, action);
int id = 0;
if (action != 'c' && action != 'f' && argc > 3) {
id = atoi(argv[3]);
if (id >= conn->db->max_rows)
	die("There are not that many records.");
}
switch (action) {
// Create
case 'c':
if (argc != 5)
	die("MAX_DATA and MAX_ROWS required.");
conn->db->max_data = atoi(argv[3]);
conn->db->max_rows = atoi(argv[4]);
Database_create();
Database_write();
break;
// Get
case 'g':
if (argc != 4)
	die("Need an ID to get.");
Database_get(id);
break;
// Set
case 's':
if (argc != 6)
	die("Need ID, name, and email to set.");
Database_set(id, argv[4], argv[5]);
Database_write();
break;
// Find
case 'f':
if (argc != 4)
	die("Need a name or email to search for.");
Database_find(argv[3]);
break;
// Delete
case 'd':
if (argc != 4)
	die("Need ID to delete.");
Database_delete(id);
Database_write();
break;
// List
case 'l':
Database_list();
break;
default:
die("Invalid action, only: c=create, g=get, s=set, d=delete, l=list");
}
Database_close();
return 0;
}
開發者ID:edek437,項目名稱:justcode,代碼行數:58,代碼來源:ex17noglob.c

示例3: main

int main(int argc, char *argv[])
{
	if(argc < 3) die("USAGE: ex17 <dbfile> <action> [action params]", NULL);

	int max_data = MAX_DATA;
	int max_rows = MAX_ROWS;
	char *filename = argv[1];
	char action = argv[2][0];
	struct Connection *conn = Database_open(filename, action);
	int id = 0;

	if(argc > 3) id = atoi(argv[3]);
	if(id >= MAX_ROWS) die("There's not that many records.", conn);

	switch(action) {
		case 'f':
			if(argc != 4) die("Need a name to find", conn);
			Database_find(conn, argv[3]);
			break;

		case 'c':
			max_data = argv[3] ? atoi(argv[3]) : MAX_DATA;
			max_rows = argv[4] ? atoi(argv[4]) : MAX_ROWS;
			Database_create(conn, max_data, max_rows);
			Database_write(conn);
			break;

		case 'g':
			if(argc != 4) die("Need an id to get", conn);
			Database_get(conn,id);
			break;

		case 's':
			if(argc != 6) die("Need id, name, email to set", conn);

			Database_set(conn, id, argv[4], argv[5]);
			Database_write(conn);
			break;

		case 'd':
			if(argc != 4) die("Need id to delete", conn);

			Database_delete(conn, id);
			Database_write(conn);
			break;

		case 'l':
			Database_list(conn);
			break;
		default:
			die("Invalid action, only: c=create, g=get, s=set, d=del, l=list", conn);
	}

	Database_close(conn);

	return 0;
}
開發者ID:paulogeyer,項目名稱:lcthw,代碼行數:57,代碼來源:ex17.c

示例4: die

void die(const char* message, struct Connection* conn){
	if(errno){
		perror(message);
	} else {
		printf("ERROR:%s\n", message);
	}
	Database_close(conn);
	exit(1);
}
開發者ID:jadan,項目名稱:LCTHW,代碼行數:9,代碼來源:ex17.c

示例5: die

void die(const char *message) {
	if (errno) {
		perror(message);
	} else {
		printf("ERROR: %s\n", message);
	}
	Database_close();
	exit(1);
}
開發者ID:edek437,項目名稱:justcode,代碼行數:9,代碼來源:ex17noglob.c

示例6: main

int main(int argc, char *argv[])
{
  char usage[64];
  sprintf(usage, "USAGE: %s <dbfile> <action> [action params]", basename(argv[0]));

  if(argc < 3) die(usage, NULL);

  char *filename = argv[1];
  char action = argv[2][0];
  struct Connection *conn = Database_open(filename, action);
  int id = 0;

  if(argc > 3) id = atoi(argv[3]);
  if(id >= MAX_ROWS) die("There's not that many records.", conn);

  switch(action) {
    case 'c':
      Database_create(conn);
      Database_write(conn);
      break;

    case 'g':
      if(argc != 4) die("Need an id to get", conn);

      Database_get(conn, id);
      break;

    case 's':
      if(argc != 7) die("Need id, name, email, and street to set", conn);

      Database_set(conn, id, argv[4], argv[5], argv[6]);
      Database_write(conn);
      break;

    case 'd':
      if(argc != 4) die("Need id to delete", conn);

      Database_delete(conn, id);
      Database_write(conn);
      break;

    case 'f':
      if(argc != 4) die("Need something to find", conn);
      Database_find(conn, argv[3]);
      break;

    case 'l':
      Database_list(conn);
      break;
    default:
      die("Invalid action, only: c=create, g=get, s=set, d=del, l=list, f=find", conn);
  }

  Database_close(conn);

  return 0;
}
開發者ID:meatballhat,項目名稱:box-o-sand,代碼行數:57,代碼來源:ex17-ec.c

示例7: main

int main(int argc, char *argv[])
{
	if(argc < 3) die("USAGE: ex17 <dbfile> <action> [action params]", NULL);

	char *filename = argv[1];
	char action = argv[2][0];
	struct Connection *conn = Database_open(filename, action);
	int id = 0;

	if((argc > 3) && (action != 'c') && (action != 'f')) id = atoi(argv[3]);
	//if(id >= conn->db->MAX_ROWS) die("There's not that many records.", conn);

	switch(action) {
		case 'c':
			Database_create(conn, atoi(argv[3]), atoi(argv[4]));
			Database_write(conn);
			break;

		case 'g':
			if(argc != 4) die("Need an id to get", conn);

			Database_get(conn, id);
			break;

		case 's':
			if(argc != 7) die("Need id, name, email and age to set", conn);

			Database_set(conn, id, argv[4], argv[5], atoi(argv[6]));
			Database_write(conn);
			break;

		case 'd':
			if(argc != 4) die("Need an id to delete", conn);

			Database_delete(conn, id);
			Database_write(conn);
			break;

		case 'l':
			Database_list(conn);
			break;

		case 'f':
			Database_find(conn, argv[3], argv[4]);
			break;

		default:
			die("Invalid action, only: c=create, g=get, s=set, d=delete, l=list", conn);
	}

	Database_close(conn);

	return 0;
}
開發者ID:osynetskyi,項目名稱:hardc,代碼行數:54,代碼來源:ex17.c

示例8: die

void die(Connection* c, const char* message) {
         if(errno) {
                 perror(message);
         } else {
                 printf("ERROR: %s\n", message);
         }

         if(c) { Database_close(c); }

         exit(1);
}
開發者ID:fosskers,項目名稱:playground,代碼行數:11,代碼來源:db.c

示例9: die

// function for aborting with an error
void die(const char *message, struct Connection *conn)
{
  if(errno) { // for when a function returns an error
    perror(message);
  } else { // for otherwise
    printf("ERROR: %s\n", message);
  }

  Database_close(conn);

  exit(1);
}
開發者ID:JonathanFrederick,項目名稱:learn-c-the-hard-way,代碼行數:13,代碼來源:ex17.c

示例10: main

int main(int argc, char *argv[])
{
	if(argc < 3) die("USAGE: ex17 <dbfile> <action> [action params]");
	
	char *filename = argv[1];
	char action = argv[2][0];
	Database_open(filename, action);	
	int id = 0;
	
	if(argc > 3) id = atoi(argv[3]);
	if(id >= MAX_ROWS) die("There's not that many records.");
	
	switch(action) {
		case 'c':
			Database_create();
			Database_write();
			break;
			
		case 'g':
			if(argc != 4) die("Need an id to get");
			
			Database_get(id);
			break;
		
		case 's':
			if(argc != 6) die("Need id, name, email to set");
			
			Database_set(id, argv[4], argv[5]);
			Database_write();
			break;
			
		case 'd':
			if(argc != 4) die("Need an id to delete)");
			
			Database_delete(id);
			Database_write();
			break;
			
		case 'l':
			Database_list();
			break;
		
		case 'f':
			Database_find(argv[3]);
			break;
		default:
			die("Invalid action, only c=create, g=get, s=set, d=del, l=list");
	}
	
	Database_close();
	return 0;
}
開發者ID:smwhit,項目名稱:LearnCTheHardWay,代碼行數:52,代碼來源:ex17a.c

示例11: main

int main(int argc, char *argv[])
{
    char *filename = argv[1];
    char action = argv[2][0];
    struct Connection *conn = Database_open(filename, action);
    int id = 0;

    if (argc < 3) die("USAGE: ex17 <dbfile> <action> [action params]", conn);

    if(argc > 3) id = atoi(argv[3]);
    if(id >= MAX_ROWS) die("There's not that many records.", conn);

    switch(action) {
    case 'c':
        if(argc == 5) Database_create(conn, atoi(argv[3]), atoi(argv[4]));
        else Database_create(conn, 0, 0);
        Database_write(conn);
        break;

    case 'g':
        if(argc != 4) die("Need an id to get", conn);

        Database_get(conn, id);
        break;

    case 's':
        if(argc != 6) die("Need id, name, email to set.", conn);

        Database_set(conn, id, argv[4], argv[5]);
        Database_write(conn);
        break;

    case 'd':
        if(argc != 4) die("Need id to delete", conn);

        Database_delete(conn, id);
        Database_write(conn);
        break;

    case 'l':
        Database_list(conn);
        break;

    default:
        die("Invalid action, only: c=create, g=get, s=set, d=del, l=list, r=resize", conn);
    }

    Database_close(conn);

    return 0;
}
開發者ID:tnesbit450,項目名稱:learning,代碼行數:51,代碼來源:ex17.c

示例12: die

void die(struct Connection *conn, const char *message) {
    if (conn) {
        Database_close(conn);
    }

    if (errno) {
        // perror prints error message to stderr
        perror(message);
    } else {
        printf("ERROR: %s\n", message);
    }
    // exit with non-zero code 1 to indicate a problem occurred
    exit(1);
}
開發者ID:beepscore,項目名稱:LearnCTheHardWay,代碼行數:14,代碼來源:ex17.c

示例13: die

/*
 * Unified error logging and clean up
 */
void die(const char *message, struct Connection *conn)
{
    if(NULL != conn){
        Database_close(conn);
    }

    if (errno){ //if a system call fails, this value will be set
        perror(message); //this will print the error message to stderror
    } else {
        printf("ERROR: %s\n", message);
    }
    
    exit(1);
}
開發者ID:ssugrim,項目名稱:LCTHWex,代碼行數:17,代碼來源:ex17_ec.c

示例14: main

int main(int argc, char *argv[])
{
    if(argc < 3) die("USAGE: mydb <dbfile> <action> [action params]");

    char *filename=argv[1];
    char action = argv[2][0];

    // will open file. Only creates file if action is 'c'
    struct Connection *conn = Database_open(filename, action);

    int id = 0;

    if(argc > 3) id = atoi(argv[3]);

    if(id >= MAX_ROWS) die("There's not that many records.");

    switch(action) {
        case 'c':
            Database_create(conn);
            Database_write(conn);
            break;
        case 'g':
            if (argc != 4) die("Need an id to get");
            Database_get(conn, id);
            break;
        case 's':
            if (argc != 6) die("Need id, name, email to set");
            Database_set(conn, id, argv[4], argv[5]);
            Database_write(conn);
            break;
        case 'l':
            Database_list(conn);
            break;
        default:
            die("Invalid action, only: c=create, g=get, s=set, d=del, l=list");
    }

    Database_close(conn);

    return 0;
}
開發者ID:baloi,項目名稱:c_me,代碼行數:41,代碼來源:mydb.c

示例15: Database_create


//.........這裏部分代碼省略.........
}

void Database_set(struct Connection *conn, int id, const char *name, const char *email)
{
    struct Address *addr = &conn->db->rows[id]; //get the i element of rows, which is in db, which is in conn, then get the address of the above
    if(addr->set) die("Already set, delete it first.");

    addr->set = 1;
    
    char *res = strncpy(addr->name, name, MAX_DATA);
    // just fix prinf in address call, far easier
    if (!res) die("Name copy failed");

    res = strncpy(addr->email, email, MAX_DATA);
    if(!res) die("Email copy failed");
}

void Database_get(struct Connection *conn, int id) //fetch the database with a certain id
{
    struct Address *addr = &conn->db->rows[id];

    if(addr->set){ 
        Address_print(addr); //print address
    } else {
        die("ID is not set.");
    }
}


void Database_delete(struct Connection *conn, int id) //this function deletes the database
{
    struct Address addr = {.id = id, .set = 0}; //set temporary local address tonull
    conn->db->rows[id] = addr;
}

void Database_list(struct Connection *conn) //list the databases
{
    int i = 0;
    struct Database *db = conn->db; //new pointer

    for(i = 0; i < MAX_ROWS; i++) {
        struct Address *cur = &db->rows[i]; //set the rows to the address of db

        if(cur->set) {
            Address_print(cur);
        }
    }
}

int main(int argc, char *argv[])
{
    if(argc < 3) die ("USAGE: ex17 <dbfile> <action> [action params]");

    char *filename = argv[1]; //our filename
    char action = argv[2][0];
    struct Connection *conn = Database_open(filename, action); //open a database
    int id = 0;

    if(argc > 3) id = atoi(argv[3]);
    if(id >= MAX_ROWS) die("There's not that many records.");

    switch(action) {
        case 'c':
            Database_create(conn);
            Database_write(conn);
            break;

        case 'g':
            if(argc != 4) die("Need an id to get.");

            Database_get(conn, id);
            break;

        case 's':
            if(argc != 6) die("Need id, name, email to set");

            Database_set(conn, id, argv[4], argv[5]);
            Database_write(conn);
            break;

        case 'd':
            if(argc != 4) die("Need id to delete.");

            Database_delete(conn, id);
            Database_write(conn);
            break;

        case 'l':
            Database_list(conn);
            break;
            
        default: 
            die("Invalid action, only: c=create, g=get, s=set, d=del, l=list");
    }
    
    Database_close(conn);

    return 0;

}
開發者ID:OppenheimerAndTheMartians,項目名稱:LearnCTheHardWay,代碼行數:101,代碼來源:ex17.c


注:本文中的Database_close函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。