Hello,

  I develop threaded mysql client in c++ that uses connection
pool.

  The program coredumps during vio_read (called from my_net_read).
I'm using libmysqlclient_r and keep all rules from "How to make
threaded client" section. Thread-pool is implemented with
CommonC++ class Thread.
  my_thread_init() and my_thread_end() are called when the new thread
is created/deleted. my_init() is called in pool object constructor.

Could anyone email me working threaded client (preferably in c++) ?

The main query method is below. Does anyone have idea why it doesn't
work ? (I can post the rest of methods if needed)
All notes are welcome :)
Thanks.

--
//getFreeHandle() and disposeHandle() are mutexed and track which
//connections are in use (bool isBusy[MAX_CONN]).

int SQLPool::query(SQLResult &res, string sql)
{
        int i, ret;
        res.free(); res.init();

        int h = getFreeHandle();
        if (h < 0) return -1;

        int rh = mysql_query(handles[h], sql.c_str());

        if (rh < 0) {
                res.error = mysql_error(handles[h]);
                LogMsg(str("\'")+sql+"': "+res.error, L_GRP, LL_ALERT);
                disposeHandle(h);
                return -1;
        }

        MYSQL_RES *table = mysql_store_result(handles[h]);
        ret = mysql_affected_rows(handles[h]);
        if (! table || ! table->data) {
                res.nRows = 0;
                res.resetSeq();
                res.isBusy = true;
                //if (table) mysql_free_result(table);
                disposeHandle(h);
                return 0;
        }

        MYSQL_ROWS *row;
        MYSQL_FIELD *field;
        SQLRow *sqlrow;

        res.nRows = mysql_num_rows(table);
        res.nFields = mysql_num_fields(table);
        if (res.nRows > 0) res.rows = new SQLRow*[res.nRows];
        if (res.nFields >0 ) res.fieldNames = new char*[res.nFields];

// Copy field names
        for(i=0; i < res.nFields; i++) {
                res.fieldNames[i] = new char[xstrlen(table->fields[i].name)+1];
                xstrcpy(res.fieldNames[i], table->fields[i].name);
        }

// Copy data row-by-row
        for(i=0, row = table->data->data; row && i < res.nRows; i++, row = row->next) {
                sqlrow = new SQLRow(res.nFields);
                for(int j=0; j<res.nFields; j++) {
                        int len = xstrlen(row->data[j]);
                        sqlrow->data[j] = new char[len+1];
                        xstrcpy(sqlrow->data[j], row->data[j]);
                }
                sqlrow->parent = &res;
                res.rows[i] = sqlrow;
        }
        mysql_free_result(table);
        disposeHandle(h);
        return ret;
}

-- 
Best regards,
 Anatoliy                          mailto:[EMAIL PROTECTED]



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to