1 | /*************************************** 2 | $Revision: 1.18 $ 3 | 4 | SQL module (sq) - this is a MySQL implementation of the SQL module. 5 | 6 | Status: NOT REVUED, NOT TESTED 7 | 8 | ******************/ /****************** 9 | Filename : mysql_driver.c 10 | Author : ottrey@ripe.net 11 | OSs Tested : Solaris 12 | ******************/ /****************** 13 | Copyright (c) 1999 RIPE NCC 14 | 15 | All Rights Reserved 16 | 17 | Permission to use, copy, modify, and distribute this software and its 18 | documentation for any purpose and without fee is hereby granted, 19 | provided that the above copyright notice appear in all copies and that 20 | both that copyright notice and this permission notice appear in 21 | supporting documentation, and that the name of the author not be 22 | used in advertising or publicity pertaining to distribution of the 23 | software without specific, written prior permission. 24 | 25 | THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 26 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL 27 | AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY 28 | DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 29 | AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 30 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 31 | ***************************************/ 32 | #include <stdlib.h> 33 | #include <stdio.h> 34 | #include <sys/timeb.h> 35 | #include <strings.h> 36 | 37 | #include "mysql_driver.h" 38 | #include "constants.h" 39 | #include "memwrap.h" 40 | 41 | /*+ String sizes +*/ 42 | #define STR_S 63 43 | #define STR_M 255 44 | #define STR_L 1023 45 | #define STR_XL 4095 46 | #define STR_XXL 16383 47 | 48 | 49 | /* log_query() */ 50 | /*++++++++++++++++++++++++++++++++++++++ 51 | Log the query. This should/will get merged with a tracing module. 52 | 53 | More: 54 | +html+ <PRE> 55 | Authors: 56 | ottrey 57 | +html+ </PRE><DL COMPACT> 58 | +html+ <DT>Online References: 59 | +html+ <DD><UL> 60 | +html+ </UL></DL> 61 | 62 | ++++++++++++++++++++++++++++++++++++++*/ 63 | static void log_query(const char *logfile, const char *query, struct timeb *start, struct timeb *stop) { 64 | FILE *logf; 65 | int seconds; 66 | int milliseconds; 67 | 68 | seconds = (int)(stop->time - start->time); 69 | milliseconds = (int)(stop->millitm - start->millitm); 70 | if (milliseconds < 0) { 71 | milliseconds += 1000; 72 | seconds--; 73 | } 74 | 75 | if (strcmp(logfile, "stdout") == 0) { 76 | printf("query=[%s] took %d sec %d msec\n", query, seconds, milliseconds); 77 | } 78 | else { 79 | logf = fopen(logfile, "a"); 80 | fprintf(logf, "query=[%s] took %d sec %d msec\n", query, seconds, milliseconds); 81 | fclose(logf); 82 | } 83 | 84 | } /* log_query() */ 85 | 86 | /* SQ_get_connection() */ 87 | /*++++++++++++++++++++++++++++++++++++++ 88 | Get a connection to the database. 89 | 90 | const char *host 91 | 92 | unsigned int port 93 | 94 | const char *db 95 | 96 | const char *user 97 | 98 | const char *password 99 | 100 | More: 101 | +html+ <PRE> 102 | Authors: 103 | ottrey 104 | +html+ </PRE><DL COMPACT> 105 | +html+ <DT>Online References: 106 | +html+ <DD><UL> 107 | +html+ <LI><A HREF="http://www.tcx.se/Manual/manual.html#mysql_init">mysql_init()</A> 108 | +html+ <LI><A HREF="http://www.tcx.se/Manual/manual.html#mysql_real_connect">mysql_real_connect()</A> 109 | +html+ </UL></DL> 110 | 111 | ++++++++++++++++++++++++++++++++++++++*/ 112 | SQ_connection_t *SQ_get_connection(const char *host, unsigned int port, const char *db, const char *user, const char *password) { 113 | 114 | SQ_connection_t *sql_connection; 115 | 116 | sql_connection = mysql_init(NULL); 117 | if (!sql_connection) { 118 | /* Check for errors */ 119 | printf("Connection init error\n"); 120 | } 121 | 122 | sql_connection = mysql_real_connect(sql_connection, host, user, password, db, port, NULL, 0); 123 | if (!sql_connection) { 124 | /* Check for errors */ 125 | printf("Connection error: Failed to connect to database.... %s\n", db); 126 | /* XXX Don't be so harsh! 127 | exit(-1); 128 | */ 129 | } 130 | 131 | return sql_connection; 132 | 133 | } /* SQ_get_connection() */ 134 | 135 | SQ_connection_t *SQ_get_connection2(void) { 136 | return SQ_get_connection(CO_get_host(), 137 | CO_get_database_port(), 138 | CO_get_database(), 139 | CO_get_user(), 140 | CO_get_password() 141 | ); 142 | } /* SQ_get_connection() */ 143 | 144 | /* SQ_execute_query() */ 145 | /*++++++++++++++++++++++++++++++++++++++ 146 | Execute the sql query. 147 | 148 | SQ_connection_t *sql_connection Connection to database. 149 | 150 | const char *query SQL query. 151 | 152 | More: 153 | +html+ <PRE> 154 | Authors: 155 | ottrey 156 | +html+ </PRE><DL COMPACT> 157 | +html+ <DT>Online References: 158 | +html+ <DD><UL> 159 | +html+ <LI><A HREF="http://www.tcx.se/Manual/manual.html#mysql_query">mysql_query()</A> 160 | +html+ <LI><A HREF="http://www.tcx.se/Manual/manual.html#mysql_use_result">mysql_use_result()</A> 161 | +html+ </UL></DL> 162 | 163 | ++++++++++++++++++++++++++++++++++++++*/ 164 | SQ_result_set_t *SQ_execute_query(int store_or_not, 165 | SQ_connection_t *sql_connection, 166 | const char *query) { 167 | struct timeb *start_time; 168 | struct timeb *stop_time; 169 | int err; 170 | SQ_result_set_t *result; 171 | 172 | /* 173 | if (CO_get_query_logging() == 1) { 174 | //start_time=(struct timeb *)calloc(1, sizeof(struct timeb)+1); 175 | //stop_time=(struct timeb *)calloc(1, sizeof(struct timeb)+1); 176 | 177 | ftime(start_time); 178 | err = mysql_query(sql_connection, query); 179 | ftime(stop_time); 180 | 181 | log_query(CO_get_query_logfile(), query, start_time, stop_time); 182 | 183 | //free(start_time); 184 | //free(stop_time); 185 | } 186 | else 187 | */ 188 | { 189 | err = mysql_query(sql_connection, query); 190 | } 191 | 192 | if (err == 0) { 193 | result = mysql_store_result(sql_connection); 194 | if(store_or_not == SQ_NOSTORE) { 195 | mysql_free_result(result); 196 | result = NULL; 197 | } 198 | } 199 | else { 200 | result = NULL; 201 | } 202 | 203 | return result; 204 | 205 | } /* SQ_execute_query() */ 206 | 207 | /* SQ_get_column_count() */ 208 | /*++++++++++++++++++++++++++++++++++++++ 209 | Get the column count. 210 | 211 | SQ_result_set_t *result The results from the query. 212 | 213 | More: 214 | +html+ <PRE> 215 | Authors: 216 | ottrey 217 | +html+ </PRE><DL COMPACT> 218 | +html+ <DT>Online References: 219 | +html+ <DD><UL> 220 | +html+ <LI><A HREF="http://www.tcx.se/Manual/manual.html#mysql_num_fields">mysql_num_fields()</A> 221 | +html+ </UL></DL> 222 | 223 | ++++++++++++++++++++++++++++++++++++++*/ 224 | int SQ_get_column_count(SQ_result_set_t *result) { 225 | int cols; 226 | 227 | cols = mysql_num_fields(result); 228 | 229 | return cols; 230 | 231 | } /* SQ_get_column_count() */ 232 | 233 | /* SQ_get_column_label() */ 234 | /*++++++++++++++++++++++++++++++++++++++ 235 | Get the column label. 236 | 237 | SQ_result_set_t *result The results from the query. 238 | 239 | unsigned int column The column index. 240 | 241 | More: 242 | +html+ <PRE> 243 | Authors: 244 | ottrey 245 | +html+ </PRE><DL COMPACT> 246 | +html+ <DT>Online References: 247 | +html+ <DD><UL> 248 | +html+ <LI><A HREF="http://www.tcx.se/Manual/manual.html#mysql_fetch_field_direct">mysql_fetch_field_direct()</A> 249 | +html+ </UL></DL> 250 | 251 | ++++++++++++++++++++++++++++++++++++++*/ 252 | char *SQ_get_column_label(SQ_result_set_t *result, unsigned int column) { 253 | char *str; 254 | /* MySQL decided to change their interface. Doh! */ 255 | #ifdef OLDMYSQL 256 | MYSQL_FIELD field; 257 | 258 | field = mysql_fetch_field_direct(result, column); 259 | 260 | //str = (char *)calloc(1, strlen(field.name)+1); 261 | dieif( wr_malloc((void **)&str, strlen(field.name)+1) != UT_OK); 262 | strcpy(str, field.name); 263 | #else 264 | MYSQL_FIELD *field; 265 | 266 | field = mysql_fetch_field_direct(result, column); 267 | 268 | //str = (char *)calloc(1, strlen(field->name)+1); 269 | dieif( wr_malloc((void **)&str, strlen(field->name)+1) != UT_OK); 270 | strcpy(str, field->name); 271 | #endif 272 | 273 | /* 274 | printf("column=%d\n", column); 275 | printf("field.name=%s\n", field.name); 276 | printf("field.table=%s\n", field.table); 277 | 278 | printf("field.def=%s\n", field.def); 279 | 280 | printf("field.type=%d\n", field.type); 281 | printf("field.length=%d\n", field.length); 282 | printf("field.max_length=%d\n", field.max_length); 283 | printf("field.flags=%d\n", field.flags); 284 | printf("field.decimals=%d\n", field.decimals); 285 | */ 286 | 287 | return str; 288 | 289 | } /* SQ_get_column_label() */ 290 | 291 | /* SQ_get_column_max_length() */ 292 | /*++++++++++++++++++++++++++++++++++++++ 293 | Get the max length of the column. 294 | 295 | SQ_result_set_t *result The results from the query. 296 | 297 | unsigned int column The column index. 298 | 299 | More: 300 | +html+ <PRE> 301 | Authors: 302 | ottrey 303 | +html+ </PRE><DL COMPACT> 304 | +html+ <DT>Online References: 305 | +html+ <DD><UL> 306 | +html+ <LI><A HREF="http://www.tcx.se/Manual/manual.html#mysql_fetch_field_direct">mysql_fetch_field_direct()</A> 307 | +html+ </UL></DL> 308 | 309 | ++++++++++++++++++++++++++++++++++++++*/ 310 | unsigned int SQ_get_column_max_length(SQ_result_set_t *result, unsigned int column) { 311 | /* MySQL decided to change their interface. Doh! */ 312 | #ifdef OLDMYSQL 313 | MYSQL_FIELD field; 314 | 315 | field = mysql_fetch_field_direct(result, column); 316 | 317 | return field.length; 318 | #else 319 | MYSQL_FIELD *field; 320 | 321 | field = mysql_fetch_field_direct(result, column); 322 | 323 | return field->length; 324 | #endif 325 | 326 | } /* SQ_get_column_max_length() */ 327 | 328 | /* SQ_row_next() */ 329 | /*++++++++++++++++++++++++++++++++++++++ 330 | Get the next row. 331 | 332 | SQ_result_set_t *result The results from the query. 333 | 334 | unsigned int column The column index. 335 | 336 | More: 337 | +html+ <PRE> 338 | Authors: 339 | ottrey 340 | +html+ </PRE><DL COMPACT> 341 | +html+ <DT>Online References: 342 | +html+ <DD><UL> 343 | +html+ <LI><A HREF="http://www.tcx.se/Manual/manual.html#mysql_fetch_row">mysql_fetch_row()</A> 344 | +html+ </UL></DL> 345 | 346 | ++++++++++++++++++++++++++++++++++++++*/ 347 | SQ_row_t *SQ_row_next(SQ_result_set_t *result) { 348 | 349 | return (SQ_row_t *)mysql_fetch_row(result); 350 | 351 | } /* SQ_row_next() */ 352 | 353 | /* SQ_get_column_string() */ 354 | /*++++++++++++++++++++++++++++++++++++++ 355 | Get the column string. 356 | 357 | SQ_row_t *current_row The current row (obtained from a SQ_row_next() ). 358 | 359 | unsigned int column The column index. 360 | 361 | More: 362 | +html+ <PRE> 363 | Authors: 364 | ottrey 365 | +html+ </PRE><DL COMPACT> 366 | +html+ <DT>Online References: 367 | +html+ <DD><UL> 368 | +html+ </UL></DL> 369 | 370 | ++++++++++++++++++++++++++++++++++++++*/ 371 | char *SQ_get_column_string(SQ_result_set_t *result, SQ_row_t *current_row, unsigned int column) { 372 | char *str=NULL; 373 | int length = mysql_fetch_lengths(result)[column]; 374 | 375 | 376 | if (current_row != NULL && current_row[column] != NULL) { 377 | //str = (char *)malloc(length + 1); 378 | dieif( wr_malloc((void **)&str, length + 1) != UT_OK); 379 | if (str != NULL) { 380 | memcpy(str, current_row[column], length ); 381 | str[length] = '\0'; 382 | } 383 | } 384 | 385 | return str; 386 | 387 | } /* SQ_get_column_string() */ 388 | 389 | /* SQ_get_column_strings() */ 390 | /*++++++++++++++++++++++++++++++++++++++ 391 | Get the all the strings in one column. 392 | 393 | SQ_result_set_t *result The results. 394 | 395 | unsigned int column The column index. 396 | 397 | More: 398 | +html+ <PRE> 399 | Authors: 400 | ottrey 401 | +html+ </PRE><DL COMPACT> 402 | +html+ <DT>Online References: 403 | +html+ <DD><UL> 404 | +html+ </UL></DL> 405 | 406 | ++++++++++++++++++++++++++++++++++++++*/ 407 | char *SQ_get_column_strings(SQ_result_set_t *result, unsigned int column) { 408 | MYSQL_ROW row; 409 | char str_buffer[STR_XXL]; 410 | char str_buffer_tmp[STR_L]; 411 | char *str; 412 | 413 | strcpy(str_buffer, ""); 414 | 415 | while ((row = mysql_fetch_row(result)) != NULL) { 416 | if (row[column] != NULL) { 417 | sprintf(str_buffer_tmp, "%s\n", row[column]); 418 | } 419 | strcat(str_buffer, str_buffer_tmp); 420 | 421 | if (strlen(str_buffer) >= (STR_XXL - STR_XL) ) { 422 | strcat(str_buffer, "And some more stuff...\n"); 423 | break; 424 | } 425 | } 426 | 427 | if (strcmp(str_buffer, "") != 0) { 428 | //str = (char *)calloc(1, strlen(str_buffer)+1); 429 | dieif( wr_malloc((void **)&str, strlen(str_buffer)+1) != UT_OK); 430 | strcpy(str, str_buffer); 431 | } 432 | else { 433 | str = NULL; 434 | } 435 | 436 | return str; 437 | 438 | } /* SQ_get_column_strings() */ 439 | 440 | /* SQ_get_column_int() */ 441 | /*++++++++++++++++++++++++++++++++++++++ 442 | Get an integer from the column. 443 | 444 | SQ_result_set_t *result The results. 445 | 446 | SQ_row_t *current_row The current row. 447 | 448 | unsigned int column The column index. 449 | 450 | This uses atoi. So it may be advisable not to use it. 451 | 452 | More: 453 | +html+ <PRE> 454 | Authors: 455 | ottrey 456 | +html+ </PRE><DL COMPACT> 457 | +html+ <DT>Online References: 458 | +html+ <DD><UL> 459 | +html+ </UL></DL> 460 | 461 | ++++++++++++++++++++++++++++++++++++++*/ 462 | int SQ_get_column_int(SQ_result_set_t *result, SQ_row_t *current_row, unsigned int column) { 463 | int ret_val=-1; 464 | 465 | if (*current_row[column] != NULL) { 466 | ret_val = atoi(*current_row[column]); 467 | } 468 | else { 469 | ; 470 | } 471 | 472 | return ret_val; 473 | 474 | } /* SQ_get_column_int() */ 475 | 476 | 477 | /* SQ_result_to_string() */ 478 | /*++++++++++++++++++++++++++++++++++++++ 479 | Convert the result set to a string. 480 | 481 | SQ_result_set_t *result The results. 482 | 483 | More: 484 | +html+ <PRE> 485 | Authors: 486 | ottrey 487 | +html+ </PRE><DL COMPACT> 488 | +html+ <DT>Online References: 489 | +html+ <DD><UL> 490 | +html+ </UL></DL> 491 | 492 | ++++++++++++++++++++++++++++++++++++++*/ 493 | char *SQ_result_to_string(SQ_result_set_t *result) { 494 | MYSQL_ROW row; 495 | unsigned int no_cols; 496 | unsigned int i, j; 497 | char str_buffer[STR_XXL]; 498 | char str_buffer_tmp[STR_L]; 499 | char border[STR_L]; 500 | char *str; 501 | 502 | char *label; 503 | 504 | unsigned int length[STR_S]; 505 | 506 | strcpy(str_buffer, ""); 507 | 508 | no_cols = mysql_num_fields(result); 509 | 510 | /* Determine the maximum column widths */ 511 | /* XXX Surely MySQL should keep note of this for me! */ 512 | strcpy(border, ""); 513 | for (i=0; i < no_cols; i++) { 514 | length[i] = SQ_get_column_max_length(result, i); 515 | /* Make sure the lenghts don't get too long */ 516 | if (length[i] > STR_M) { 517 | length[i] = STR_M; 518 | } 519 | strcat(border, "*"); 520 | for (j=0; (j <= length[i]) && (j < STR_L); j++) { 521 | strcat(border, "-"); 522 | } 523 | } 524 | strcat(border, "*\n"); 525 | /* 526 | for (i=0; i < no_cols; i++) { 527 | printf("length[%d]=%d\n", i, length[i]); 528 | } 529 | */ 530 | 531 | strcat(str_buffer, border); 532 | 533 | for (i=0; i < no_cols; i++) { 534 | label = SQ_get_column_label(result, i); 535 | if (label != NULL) { 536 | sprintf(str_buffer_tmp, "| %-*s", length[i], label); 537 | strcat(str_buffer, str_buffer_tmp); 538 | } 539 | } 540 | strcat(str_buffer, "|\n"); 541 | 542 | strcat(str_buffer, border); 543 | 544 | 545 | while ((row = mysql_fetch_row(result)) != NULL) { 546 | for (i=0; i < no_cols; i++) { 547 | if (row[i] != NULL) { 548 | sprintf(str_buffer_tmp, "| %-*s", length[i], row[i]); 549 | } 550 | else { 551 | sprintf(str_buffer_tmp, "| %-*s", length[i], "NuLL"); 552 | } 553 | strcat(str_buffer, str_buffer_tmp); 554 | } 555 | strcat(str_buffer, "|\n"); 556 | 557 | if (strlen(str_buffer) >= (STR_XXL - STR_XL) ) { 558 | strcat(str_buffer, "And some more stuff...\n"); 559 | break; 560 | } 561 | } 562 | 563 | strcat(str_buffer, border); 564 | 565 | // str = (char *)calloc(1, strlen(str_buffer)+1); 566 | dieif( wr_malloc((void **)&str, strlen(str_buffer)+1) != UT_OK); 567 | strcpy(str, str_buffer); 568 | 569 | return str; 570 | 571 | } /* SQ_result_to_string() */ 572 | 573 | /* SQ_free_result() */ 574 | /*++++++++++++++++++++++++++++++++++++++ 575 | Free the result set. 576 | 577 | SQ_result_set_t *result The results. 578 | 579 | More: 580 | +html+ <PRE> 581 | Authors: 582 | ottrey 583 | +html+ </PRE><DL COMPACT> 584 | +html+ <DT>Online References: 585 | +html+ <DD><UL> 586 | +html+ <LI><A HREF="http://www.tcx.se/Manual/manual.html#mysql_free_result">mysql_free_result()</A> 587 | +html+ </UL></DL> 588 | 589 | ++++++++++++++++++++++++++++++++++++++*/ 590 | void SQ_free_result(SQ_result_set_t *result) { 591 | mysql_free_result(result); 592 | } /* SQ_free_result() */ 593 | 594 | 595 | /* SQ_close_connection() */ 596 | /*++++++++++++++++++++++++++++++++++++++ 597 | Call this function to close a connection to the server 598 | 599 | SQ_connection_t *sql_connection The connection to the database. 600 | 601 | More: 602 | +html+ <PRE> 603 | Authors: 604 | ottrey 605 | +html+ </PRE><DL COMPACT> 606 | +html+ <DT>Online References: 607 | +html+ <DD><UL> 608 | +html+ <LI><A HREF="http://www.tcx.se/Manual/manual.html#mysql_close">mysql_close()</A> 609 | +html+ </UL></DL> 610 | 611 | ++++++++++++++++++++++++++++++++++++++*/ 612 | void SQ_close_connection(SQ_connection_t *sql_connection) { 613 | 614 | mysql_close(sql_connection); 615 | 616 | } 617 | 618 | /* SQ_num_rows() */ 619 | /*++++++++++++++++++++++++++++++++++++++ 620 | Call this function to find out how many rows are in a query result 621 | 622 | SQ_result_set_t *result The results. 623 | 624 | More: 625 | +html+ <PRE> 626 | Authors: 627 | ottrey 628 | +html+ </PRE><DL COMPACT> 629 | +html+ <DT>Online References: 630 | +html+ <DD><UL> 631 | +html+ <LI><A HREF="http://www.tcx.se/Manual/manual.html#mysql_num_rows">mysql_num_rows()</A> 632 | +html+ </UL></DL> 633 | 634 | ++++++++++++++++++++++++++++++++++++++*/ 635 | int SQ_num_rows(SQ_result_set_t *result) { 636 | int rows=-1; 637 | 638 | if (result != NULL) { 639 | rows = mysql_num_rows(result); 640 | } 641 | 642 | return rows; 643 | } 644 | 645 | /* SQ_info_to_string() */ 646 | /*++++++++++++++++++++++++++++++++++++++ 647 | Convert all available information about the sql server into a string. 648 | 649 | SQ_connection_t *sql_connection The connection to the database. 650 | 651 | More: 652 | +html+ <PRE> 653 | Authors: 654 | ottrey 655 | +html+ </PRE><DL COMPACT> 656 | +html+ <DT>Online References: 657 | +html+ <DD><UL> 658 | +html+ </UL></DL> 659 | 660 | ++++++++++++++++++++++++++++++++++++++*/ 661 | char *SQ_info_to_string(SQ_connection_t *sql_connection) { 662 | char str_buffer[STR_XXL]; 663 | char str_buffer_tmp[STR_L]; 664 | char *str; 665 | char *str_tmp; 666 | 667 | strcpy(str_buffer, ""); 668 | 669 | /* Makes the server dump debug information to the log. */ 670 | sprintf(str_buffer_tmp, "mysql_dump_debug_info()=%d\n", mysql_dump_debug_info(sql_connection)); 671 | strcat(str_buffer, str_buffer_tmp); 672 | 673 | /* Returns the error number from the last MySQL function. */ 674 | sprintf(str_buffer_tmp, "mysql_errno()=%d\n", mysql_errno(sql_connection)); 675 | strcat(str_buffer, str_buffer_tmp); 676 | 677 | /* Returns the error message from the last MySQL function. */ 678 | sprintf(str_buffer_tmp, "mysql_error()=%s\n", mysql_error(sql_connection)); 679 | strcat(str_buffer, str_buffer_tmp); 680 | 681 | /* Returns client version information. */ 682 | sprintf(str_buffer_tmp, "mysql_get_client_info()=%s\n", mysql_get_client_info() ); 683 | strcat(str_buffer, str_buffer_tmp); 684 | 685 | /* Returns a string describing the connection. */ 686 | sprintf(str_buffer_tmp, "mysql_get_host_info()=%s\n", mysql_get_host_info(sql_connection)); 687 | strcat(str_buffer, str_buffer_tmp); 688 | 689 | /* Returns the protocol version used by the connection. */ 690 | sprintf(str_buffer_tmp, "mysql_get_proto_info()=%d\n", mysql_get_proto_info(sql_connection)); 691 | strcat(str_buffer, str_buffer_tmp); 692 | 693 | /* Returns the server version number. */ 694 | sprintf(str_buffer_tmp, "mysql_get_server_info()=%s\n", mysql_get_server_info(sql_connection)); 695 | strcat(str_buffer, str_buffer_tmp); 696 | 697 | /* Information about the most recently executed query. */ 698 | /* XXX Check for NULL */ 699 | str_tmp = mysql_info(sql_connection); 700 | if (str_tmp != NULL) { 701 | sprintf(str_buffer_tmp, "mysql_info()=%s\n", str_tmp); 702 | } 703 | else { 704 | sprintf(str_buffer_tmp, "mysql_info()=%s\n", "NulL"); 705 | } 706 | strcat(str_buffer, str_buffer_tmp); 707 | 708 | 709 | /* Returns a list of the current server threads. */ 710 | sprintf(str_buffer_tmp, "mysql_list_processes()=%d\n", mysql_list_processes(sql_connection)); 711 | strcat(str_buffer, str_buffer_tmp); 712 | 713 | /* Checks if the connection to the server is working. */ 714 | sprintf(str_buffer_tmp, "mysql_ping()=%d\n", mysql_ping(sql_connection)); 715 | strcat(str_buffer, str_buffer_tmp); 716 | 717 | /* Returns the server status as a string. */ 718 | sprintf(str_buffer_tmp, "mysql_stat()=%s\n", mysql_stat(sql_connection)); 719 | strcat(str_buffer, str_buffer_tmp); 720 | 721 | /* Returns the current thread id. */ 722 | sprintf(str_buffer_tmp, "mysql_thread_id()=%d\n", mysql_thread_id(sql_connection)); 723 | strcat(str_buffer, str_buffer_tmp); 724 | 725 | 726 | //str = (char *)calloc(1, strlen(str_buffer)+1); 727 | dieif( wr_malloc((void **)&str, strlen(str_buffer)+1) != UT_OK); 728 | strcpy(str, str_buffer); 729 | 730 | return str; 731 | 732 | } /* SQ_info_to_string() */ 733 | 734 | /* SQ_error() */ 735 | /*++++++++++++++++++++++++++++++++++++++ 736 | Get the error string for the last error. 737 | 738 | SQ_connection_t *sql_connection The connection to the database. 739 | 740 | More: 741 | +html+ <PRE> 742 | Authors: 743 | ottrey 744 | +html+ </PRE><DL COMPACT> 745 | +html+ <DT>Online References: 746 | +html+ <DD><UL> 747 | +html+ <LI><A HREF="http://www.tcx.se/Manual/manual.html#mysql_error">mysql_error()</A> 748 | +html+ </UL></DL> 749 | 750 | ++++++++++++++++++++++++++++++++++++++*/ 751 | char *SQ_error(SQ_connection_t *sql_connection) { 752 | 753 | return mysql_error(sql_connection); 754 | 755 | } /* SQ_error() */ 756 | 757 | /* SQ_errno() */ 758 | /*++++++++++++++++++++++++++++++++++++++ 759 | Get the error number for the last error. 760 | 761 | SQ_connection_t *sql_connection The connection to the database. 762 | 763 | More: 764 | +html+ <PRE> 765 | Authors: 766 | ottrey 767 | +html+ </PRE><DL COMPACT> 768 | +html+ <DT>Online References: 769 | +html+ <DD><UL> 770 | +html+ <LI><A HREF="http://www.tcx.se/Manual/manual.html#mysql_free_result">mysql_free_result()</A> 771 | +html+ </UL></DL> 772 | 773 | ++++++++++++++++++++++++++++++++++++++*/ 774 | int SQ_errno(SQ_connection_t *sql_connection) { 775 | 776 | return mysql_errno(sql_connection); 777 | 778 | } /* SQ_errno() */ 779 |