// ruby interface:
// MysqlBlobStreaming.stream(mysql2_client, query, buffer_length, &block)
static VALUE stmt_fetch_and_write(int argc, VALUE *argv, VALUE self)
{
    VALUE rb_mysql2_client;
    VALUE rb_query;
    VALUE rb_buffer_length;
    VALUE rb_block;
    rb_scan_args(argc, argv, "3&", &rb_mysql2_client, &rb_query, &rb_buffer_length, &rb_block);

    int buffer_length = FIX2INT(rb_buffer_length);

    if (buffer_length == 0) {
        return 0;
    }
    if (buffer_length < 0) {
        rb_raise(rb_eRuntimeError, "buffer size must be integer >= 0");
    }

    char *query = RSTRING_PTR(rb_query);

    MYSQL *conn = mysql_connection(rb_mysql2_client);
    MYSQL_STMT *stmt = prepare_and_execute_stmt_with_query(conn, query);
    MYSQL_BIND *bind = build_result_bind(stmt, buffer_length);

    int total_blob_length = determine_blob_length(stmt, bind);
    loop_store_buffer(stmt, bind, total_blob_length, rb_block, self);

    mysql_stmt_close(stmt);
    free_result_bind(bind);
    return Qnil;
}
Exemplo n.º 2
0
int main(int argc, const char *argv[])
{

    MYSQL *conn;
    conn = mysql_init(NULL);

    if (mysql_connection(conn) == 1) {
        exit(1);
    }

    dbread(conn);
    mysql_close(conn);

    exit(0);
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{

if ( argc < 2 ) /* argc should be 2 for correct execution */
{
	printf( "Missing config file path argument \n" );
}
   
if(read_config_file(argv[1]))
{
	printf("Error Loading Configuration File\n");
	printf("Exiting Mydombox .... By !\n");
	exit(1);
}


log_INFO("--------- Starting Mydombox Server ---------");
log_INFO("MySQL client version: %s", mysql_get_client_info());
log_INFO("Loglevel: %s",LOG_LEVEL);
log_INFO("Learn Mode: %d",RECORD);

	conn = mysql_connection();
	result = mysql_select(conn,"SELECT * FROM devices;");
	mysql_free_result(result);
	mysql_close(conn);


if ( file_exists(PORT_RFXTRX433) ){
    // On crée un thread
    pthread_t thread_rfxtrx433;
    // Permet d'exécuter le fonction thread_rfxtrx433 en parallèle
    pthread_create(&thread_rfxtrx433, NULL, rfxtrx433, NULL);
	log_INFO("Module RFXTRX433 Detected & Started");
}

sleep(5);

if ( file_exists(PORT_ENOUSB300) ){
    // On crée un thread
    pthread_t thread_enusb300;
    // Permet d'exécuter le fonction thread_enusb300 en parallèle
    pthread_create(&thread_enusb300, NULL, enusb300, NULL);
    log_INFO("Module USB300 Detected & Started");
}
    
    
sleep(10);

if ( MODULE_SOAP == 1){
    // On crée un thread
    pthread_t thread_soapserver;
    // Permet d'exécuter le fonction thread_soapserver en parallèle
    pthread_create(&thread_soapserver, NULL, soapserver, NULL);
	log_INFO("Module SOAP Started");
}

sleep(5);
if ( MODULE_RPIDOM == 1){
    // On crée un thread
    pthread_t thread_rpidom;
    // Permet d'exécuter le fonction thread_rpidom en parallèle
    pthread_create(&thread_rpidom, NULL, rpidom, NULL);
	log_INFO("Module RPIDOM Started");
}

while(1){
	read_config_file(argv[1]);
    scheduler();
	thermostat();
	sleep (60);
}

return 0;
}
EnDevice GetEnDevice(char* data){
    
    EnDevice device;
    device.dc_id = 0;
    
    unsigned char		packettype = data[0];
    unsigned char		id1 = "";
    unsigned char		id2 = "";
    unsigned char		id3 = "";
    unsigned char		id4 = "";
    
    switch (packettype)
    {
    case 0xD5:
        id1 = data[2];
        id2 = data[3];
        id3 = data[4];
        id4 = data[5];
        break;
    case 0xF6:
        id1 = data[2];
        id2 = data[3];
        id3 = data[4];
        id4 = data[5];
        break;
    case 0xA5:
        id1 = data[5];
        id2 = data[6];
        id3 = data[7];
        id4 = data[8];
        break;
    case 0xD2:
        id1 = data[7];
        id2 = data[8];
        id3 = data[9];
        id4 = data[10];
        break;
    default:
        log_DEBUG("[EnOcean] TYPE: Not Supported");
        break;
    }

    MYSQL *conn;
    MYSQL_RES *result;
    MYSQL_ROW row;
    
    conn = mysql_connection();
    result = mysql_select(conn,"SELECT dc_id,packettype,subtype,type,id1,id2,id3,id4,enable FROM devices \
                          WHERE int_id=%d AND id1='%02hhX'AND id2='%02hhX'AND id3='%02hhX'AND id4='%02hhX';",4,id1,id2,id3,id4);
    
    int num_fields = mysql_num_fields(result);
    if (num_fields != 0) {
        
        while ((row = mysql_fetch_row(result))){
            
            device.dc_id = atoi(row[0]);
            device.rorg = stringtohex(row[1]);
            device.func = stringtohex(row[2]);
            device.type = stringtohex(row[3]);
            device.id1 = stringtohex(row[4]);
            device.id2 = stringtohex(row[5]);
            device.id3 = stringtohex(row[6]);
            device.id4 = stringtohex(row[7]);
            device.enable=(bool)row[8];
        }
    }
    return device;
}