D vs MySQL5

el.gato forward_ua at ukr.net
Mon Feb 25 02:42:52 PST 2008


nobody Wrote:

> el.gato Wrote:
> 
> > KUV Wrote:
> > 
> > > When using existing MySQL binding with version 5, I get "segmentation fault"
> > > error. Does anyone have module for working with this version?
> > > 
> > > 
> > 
> > i have the same problem :( but only when using threads and running about 10-20 concurrent connections (each thread with it's own connection to mysql) :(
> 
> Are you using DDBI or the mysql_binding from www.steinmole.de/d  ?
> Have you an example for get the "segmentation fault" ?

I use DDBI, because mysql_binding works only with Phobos.

This might work as an example:

import  tango.core.Thread;

import  tango.net.http.HttpConst;

import  tango.util.log.Configurator;

import  mango.net.http.server.HttpServer,
        mango.net.http.server.HttpRequest,
        mango.net.http.server.HttpResponse,
        mango.net.http.server.HttpProvider;

import dbi.sqlite.SqliteDatabase;
import dbi.Row;

/*******************************************************************************

        Create a simple HttpServer, that responds with a trivial HTML page.
        The server listens on localhost:8080

*******************************************************************************/

void main ()
{
        // our simple http hander
        class Provider : HttpProvider
        {
                override void service (HttpRequest request, HttpResponse response)
                {
                        MysqlDatabase db = new MysqlDatabase();
                        db.connect("dbname=mysql;host=localhost;port=3306","root","");
                        db.close();
                        response.getOutputBuffer.append("<html>Hi :-)</html>").flush;
                }
        }

        // bind server to port 8080 on a local address
        auto addr = new InternetAddress (8080);

        // create a (1 thread) server using the ServiceProvider to service requests
        auto server = new HttpServer (new Provider, addr, 100, 100);

        // start listening for requests (but this thread does not listen)
        server.start;
}

This will start server on 8080 port, 100 threads, each thread connects and disconnects from mysql, even nothing getting from it. Then run for example: ab -c 100 -n 100 'http://localhost:8080/'
and you'll get segfault..

PS: dont have dmd compiler here, so the code might work, but i'm not sure:) sorry



More information about the Digitalmars-d mailing list