Jump to content

jordanwb

Members
  • Posts

    560
  • Joined

  • Last visited

Everything posted by jordanwb

  1. TBH I have no idea which subforum this should go under so I'm putting it here. I'm working on a cross platform C application that uses among other things the MySQL C connector. MySQL doesn't give an installer that I can use with mingw so I have to compile it myself which isn't a problem. However I can't get cmake to configure it since every test fails. This is my configure log: http://pastebin.com/uAz4PbXv I don't know what kind of info is needed to help solve the issue so let me know. Thanks in advance
  2. Vuze? I think that's the name of it
  3. I'm going to cut straight to the chase, this is my function: void client_job_results (client *c, json_object *obj) { char *tripcode_insert_query = "INSERT INTO tah_tripcodes VALUES ('', ?, ?, ?, ?)"; int job_id, results_count; unsigned long tripcode_len = 10; MYSQL_STMT *tripcode_stmt = mysql_stmt_init(conn); MYSQL_BIND tripcode_params[4]; mysql_stmt_prepare(tripcode_stmt, tripcode_insert_query, strlen(tripcode_insert_query)); memset (tripcode_params, 0, sizeof (tripcode_params)); json_object *jobs_array = json_object_object_get (obj, "jobs"), *job, *results_array, *result_pair; char *password, *tripcode, *utf8_password_orig, *salt = alloca(3), *c_password = alloca (9), *des_result = alloca (14), *utf8_password = alloca (20); // is 20 enough? memset (utf8_password, 0, 20); size_t sjis_pass_len; size_t utf8_pass_len; if (jobs_array == NULL) return; iconv_t cd = iconv_open ("UTF8", "SHIFT_JIS"); for (int i = 0; i < json_object_array_length (jobs_array); i++) { job = json_object_array_get_idx (jobs_array, i); if (job == NULL) { continue; } results_array = json_object_object_get (job, "results"); results_count = json_object_array_length (results_array); if (results_count == 0) continue; job_id = json_object_get_int (json_object_object_get (job, "job-id")); if (job_id == 0) { continue; } for (int j = 0; j < results_count; j++) { result_pair = json_object_array_get_idx (results_array, j); password = json_object_get_string (json_object_object_get (result_pair, "password")); tripcode = json_object_get_string (json_object_object_get (result_pair, "tripcode")); // check to make sure password is correct make_correct_password (password, c_password); make_salt (c_password, salt); DES_fcrypt (c_password, salt, des_result); if (strcmp (des_result + 3, tripcode) != 0) { printf ("Client gave invalid password/tripcode pair; claimed \"%s\" gave \"%s\", but got \"%s\" as a result.\n", password, tripcode, des_result + 3); continue; } // // convert to unicode sjis_pass_len = strlen (password); utf8_pass_len = sjis_pass_len * 2; utf8_password_orig = utf8_password; if (iconv (cd, &password, &sjis_pass_len, &utf8_password, &utf8_pass_len) == -1) { printf ("iconv could not convert password. Error is: %s\n", strerror(errno)); continue; } utf8_pass_len = strlen(utf8_password_orig); // tripcode_params[0].buffer_type = MYSQL_TYPE_LONG; tripcode_params[0].buffer = (void*)&job_id; tripcode_params[1].buffer_type = MYSQL_TYPE_STRING; tripcode_params[1].buffer = (void*)utf8_password_orig; tripcode_params[1].length = &utf8_pass_len; // this param is the number of bytes used in the buffer (# of single byte chars) tripcode_params[2].buffer_type = MYSQL_TYPE_STRING; tripcode_params[2].buffer = (void*)tripcode; tripcode_params[2].length = &tripcode_len; tripcode_params[3].buffer_type = MYSQL_TYPE_LONG; tripcode_params[3].buffer = (void*)&(c->user_id); mysql_stmt_bind_param(tripcode_stmt, (MYSQL_BIND *)&tripcode_params); mysql_stmt_execute (tripcode_stmt); } } iconv_close (cd); mysql_stmt_free_result (tripcode_stmt); } When the program reaches mysql_stmt_bind_param the program crashes and I don't know why. iconv does properly convert the shift_jis strings to UTF8 and the program crashes only when I try to insert unicode characters into the table.
  4. I'm writing a program in C which requires MySQL. I wrote a little test program to make sure I know how to use the API. The problem is a keep getting a segmentation fault when I call mysql_num_fields on line 23: #include <stdio.h> #include <mysql/mysql.h> int main (int argc, char **argv) { mysql_library_init(0, NULL, NULL); MYSQL *database = mysql_init (NULL); if (mysql_real_connect (database, "127.0.0.1", "root", "", "my_database", 0, NULL, 0) == NULL) { return 1; } char *query = "SELECT * FROM my_table"; int result = mysql_query (database, query); MYSQL_RES *res = mysql_store_result (database); // do stuff with result unsigned int num_fields = mysql_num_fields(res); MYSQL_ROW row; while (row = mysql_fetch_row(res)) { unsigned long *lengths; lengths = mysql_fetch_lengths(res); for(int i = 0; i < num_fields; i++) { printf("[%.*s] ", (int) lengths[i], row[i] ? row[i] : "NULL"); } printf("\n"); } mysql_free_result(res); mysql_close (database); mysql_library_end(); return 0; }
  5. That'll work, thanks. On a related note, where does "c" and "i" come from?
  6. Yes I did, see picture of results: http://img405.imageshack.us/img405/8157/27243565.png The query returns every record in gd_gallery_images and lists the same single record in gd_gallery_categories twice. There should be only one result, the single row from gd_gallery_categories and either one of the two records in gd_gallery_images.
  7. For each record in gd_gallery_categories there will be one or more records in gd_gallery_images associated with that record in gd_gallery_categories. For each record I read from gd_gallery_categories, I want to get one random record from gd_gallery_images associated with that record.
  8. Thanks for replying, No that won't work. I want to get each record from gd_gallery_categories and also get one random record from gd_gallery_images in the category. The records returned from gd_gallery_categories would be ordered by gallery_cat_id in descending order.
  9. I have the following two tables: gd_gallery_categories, CREATE TABLE `gd_gallery_categories` ( `gallery_cat_id` int(11) NOT NULL AUTO_INCREMENT, `gallery_name` varchar(64) DEFAULT NULL, `gallery_description` varchar(45) DEFAULT NULL, PRIMARY KEY (`gallery_cat_id`) ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 gd_gallery_images, CREATE TABLE `gd_gallery_images` ( `gallery_image_id` int(11) NOT NULL AUTO_INCREMENT, `gallery_cat_id` int(11) DEFAULT NULL, `gallery_image_name` varchar(64) DEFAULT NULL, `gallery_image_path` varchar(64) DEFAULT NULL, PRIMARY KEY (`gallery_image_id`) ) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 What I want to do is get all the categories in gd_gallery_categories and for each category also retrieve a random image associated with that category in the same row. The value stored in gd_gallery_images.gallery_cat_id is the category id stored in gd_gallery_categories.gallery_cat_id
  10. I'd like to add that I've being charged for a site that I canceled over a year ago.
  11. I've sent ober an pm to remove EMaxHosting, here's why: apache version emax uses: 1.3.39 Latest version (for gentoo): 2.2.9-r1 MySQL version emax uses: 4.1.22 Latest version (for gentoo): mysql-5.0.60-r1 Kernel version emax uses: 2.6.9 Latest version: 2.6.26.5 Also their home pages sucks and their Customer Management Interface is horrible
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.