Public Member Functions | Public Attributes

mysqlpl::MSqlConnection Class Reference

simple MySQL login to database More...

Collaboration diagram for mysqlpl::MSqlConnection:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 this (MSqlEnv env, in char[] username, in char[] password, in char[] db_name, in char[] host="localhost", uint port=3306, uint clientflag=0)
void connect (in char[] username, in char[] password, in char[] db_name, in char[] host="localhost", uint port=3306, uint clientflag=0)
 ~this ()
 version (MYSQLPL_PREP_STMT)

Public Attributes

MYSQL * _db
bool _connected

Detailed Description

simple MySQL login to database

Definition at line 445 of file mysqlpl.d.


Constructor & Destructor Documentation

mysqlpl::MSqlConnection::this ( MSqlEnv  env,
in char[]  username,
in char[]  password,
in char[]  db_name,
in char[]  host = "localhost",
uint  port = 3306,
uint  clientflag = 0 
) [inline]

Definition at line 447 of file mysqlpl.d.

    {
        _env = env;
        _db = null;
        _connected = false;

        connect(username, password, db_name, host, port, clientflag);
    }
mysqlpl::MSqlConnection::~this (  ) [inline]

Definition at line 478 of file mysqlpl.d.

    {
        /*see MSqlEnv::~MSqlEnv()
        if (_connected)
            mysqlpl_close(_mysql);
        */
    }

Member Function Documentation

void mysqlpl::MSqlConnection::connect ( in char[]  username,
in char[]  password,
in char[]  db_name,
in char[]  host = "localhost",
uint  port = 3306,
uint  clientflag = 0 
) [inline]

Definition at line 457 of file mysqlpl.d.

References mysqlpl::mysqlpl_check_error(), and mysqlpl::version().

    {
        _connected = false;

        _db = mysqlpl_real_connect(_env(), toStringz(host), toStringz(username), toStringz(password), toStringz(db_name), port, null, clientflag);

        if (!_db)
            throw new MSqlException(_env());

        _connected = true;

      version(MYSQLPL_PREP_STMT) {
         // disable auto commit mode
        my_bool res = mysqlpl_autocommit(_db, 0);
        mysqlpl_check_error(_env(), res);
      } else {
        (new SqlStatement(this)).execute("set autocommit=0");   // "set autocommit=0" is not supported before MySQL 4.1
      }
    }

Here is the call graph for this function:

mysqlpl::MSqlConnection::version ( MYSQLPL_PREP_STMT   ) [inline]

Definition at line 487 of file mysqlpl.d.

                             {
     // get warnings
    uint get_warnings_count()
    {
        uint res = mysqlpl_warning_count(_db);

        if (res == -1)
            throw new MSqlException(_db);

        return res;
    }

    char[] get_info()
    {
        char* info = mysqlpl_info(_db);

        if (!info)
            throw new MSqlException(_db);

        return info[0 .. info?strlen(info):0];
    }

    void print_warnings(Stream o)
    {
        while(get_warnings_count())
            o.writeString(get_info() ~ '\n');
    }
  } else { // version(MYSQLPL_PREP_STMT)

Member Data Documentation

Definition at line 565 of file mysqlpl.d.

Definition at line 562 of file mysqlpl.d.


The documentation for this class was generated from the following file: