Git Product home page Git Product logo

libmysqlnb's Introduction

MYSQL-NOBLOCK(1)					      MYSQL-NOBLOCK(1)



NAME
       query_runner_init,  query_runner_execute, query_runner_get_response_fd,
       query_runner_get_request_fd,	      query_runner_handle_all_results,
       query_runner_handle_next_result, query_runner_shutdown,

SYNOPSIS
       #include "mysql-noblock.h"

       #define RUNNER_RESULT_EAGAIN -1
       #define RUNNER_RESULT_SQL_ERROR 0
       #define RUNNER_RESULT_ROWS 1
       #define RUNNER_RESULT_NONE 2

       query_runner *query_runner_init(char *hostname, char *user,
				       char *password, char *database);

       void query_runner_execute(query_runner *runner, char *query,
				 query_runner_callback callback,
				 void *callback_data );

       int query_runner_get_response_fd(query_runner *runner);

       int query_runner_get_request_fd(query_runner *runner);

       void query_runner_shutdown(query_runner * runner);

       int query_runner_handle_next_result(query_runner *runner);

       void query_runner_handle_all_results(query_runner *runner);

       typedef void (*query_runner_callback)(int, MYSQL_RES *, void *);


DESCRIPTION
       A  simple library for integrating MySQL into non-blocking, event-driven
       applications. All queries are submitted to a separate thread which sig‐
       nals  query completion by writing to a UNIX pipe. You can find out when
       the result is ready by using the file descriptor of the	pipe  in  your
       own event loops using select(), poll(), etc.


USAGE
       First write a callback for your query:

	void sql_results_callback(int result_code,
				  MYSQL_RES *res,
				  void *user_data) {
	    if (result_code == RUNNER_RESULT_SQL_ERROR) {
		print("Query Failed!");
		return;
	    }
	    /* Now do something with res (see mysql manual) */
	}

       Next you will need to start the runner somewhere in your program:

	query_runner_init("myhost","username","password","database");

       To integrate into your I/O event loop, you will need the runner's fd:

	int runner_response_fd = query_runner_get_response_fd();

       To submit queries, use query_runner_execute():

	query_runner_execute(runner,
			     "SELECT foo FROM bar",
			     sql_results_callback,
			     my_data);

       When  the  query  is complete, runner_response_fd will become ready for
       reading.  DO NOT read directly from the fd, but instead use  query_run‐
       ner_handle_all_results() or query_runner_handle_next_result(). If there
       are no results ready these functions will do nothing.






				 23 January 10		      MYSQL-NOBLOCK(1)

libmysqlnb's People

Contributors

xtianbetz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.