MCPcopy Create free account
hub / github.com/acl-dev/acl / dbopen

Method dbopen

lib_acl_cpp/src/db/db_pgsql.cpp:440–527  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

438}
439
440bool db_pgsql::dbopen(const char* /* charset = NULL */)
441{
442 if (conn_) {
443 return true;
444 }
445
446 char tmpbuf[256];
447 char *db_host, *db_unix;
448 int db_port;
449
450 char* ptr = strchr(dbaddr_, '/');
451 if (ptr == NULL) {
452 ACL_SAFE_STRNCPY(tmpbuf, dbaddr_, sizeof(tmpbuf));
453 ptr = strchr(tmpbuf, ':');
454 if (ptr == NULL || *(ptr + 1) == 0) {
455 logger_error("invalid db_addr=%s", dbaddr_);
456 return false;
457 } else {
458 *ptr++ = 0;
459 }
460 db_host = tmpbuf;
461
462 db_port = atoi(ptr);
463 if (db_port <= 0) {
464 logger_error("invalid port=%d", db_port);
465 return false;
466 }
467 db_unix = NULL;
468 } else {
469 db_unix = dbaddr_;
470 db_host = db_unix;
471 db_port = 0;
472 }
473
474 int* dummy;
475
476 if (acl_pthread_once(&__thread_once_control, thread_once) != 0) {
477 logger_error("call thread_once error: %s", acl_last_serror());
478 } else if (!(dummy = (int*) acl_pthread_getspecific(__thread_key))) {
479 dummy = (int*) acl_mymalloc(sizeof(int));
480 *dummy = 1;
481 if (acl_pthread_setspecific(__thread_key, dummy) != 0) {
482 abort();
483 }
484
485 if ((unsigned long) acl_pthread_self()
486 == acl_main_thread_self()) {
487
488 __main_dummy = dummy;
489#ifndef HAVE_NO_ATEXIT
490 atexit(main_free_dummy);
491#endif
492 }
493 }
494
495 string info;
496 info.format("host=%s dbname=%s", db_host, dbname_);
497 if (db_unix == NULL) {

Callers 2

mainFunction · 0.45
runMethod · 0.45

Calls 8

acl_pthread_onceFunction · 0.85
acl_last_serrorFunction · 0.85
acl_pthread_getspecificFunction · 0.85
acl_pthread_setspecificFunction · 0.85
acl_pthread_selfFunction · 0.85
acl_main_thread_selfFunction · 0.85
formatMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected