hacker_j99 has asked for the wisdom of the Perl Monks concerning the following question:
the perl error/* Script writen my Harry Franks taken as example from FreeTDS using FreeTDS as the backbone. */ #include <stdio.h> #include <tds.h> static char software_version[] = "$Id: t0005.c,v 1.1 2000/11/04 01: +35:51 mark Exp $"; static void *no_unused_var_warn[] = {software_version, no_unused_var_w +arn}; // Sets up the Socket and char/int to use with the SQl int run_query(TDSSOCKET *tds, char *query); char *value_as_string(TDSSOCKET *tds, int col_idx); int main() { // the login and socket is setup by some files setup by FreeTDS TDSLOGIN *login; TDSSOCKET *tds; int verbose = 0; int rc; int i; // Some arbitrary stup set up to test the quality of the server // (ability to handel large numbers) char *len200 = "012345678901234567890123456789012345678901234567890 +123456789012345678901234567890123456789012345678901234567890123456789 +012345678901234567890123456789012345678901234567890123456789012345678 +90123456789"; char large_sql[1000]; // print out a header to show its starting fprintf(stdout, "%s: Test show tables replies\n", __FILE__); // login rc = try_tds_login(&login, &tds, __FILE__, verbose); if (rc != TDS_SUCCEED) { fprintf(stderr, "try_tds_login() failed\n"); return 1; } // drop the old test_table so we dont get old values rc = run_query(tds, "DROP TABLE test_table"); if (rc != TDS_SUCCEED) { return 1; } // create the clean test table rc = run_query(tds, "CREATE TABLE test_table (id int, name varchar( +255))"); if (rc != TDS_SUCCEED) { return 1; } // insert large values and stuff into the table so we can check it sprintf(large_sql, "INSERT test_table (id, name) VALUES (0, 'A%s')" +, len200); rc = run_query(tds, large_sql); if (rc != TDS_SUCCEED) { return 1; } sprintf(large_sql, "INSERT test_table (id, name) VALUES (1, 'B%s')" +, len200); rc = run_query(tds, large_sql); if (rc != TDS_SUCCEED) { return 1; } sprintf(large_sql, "INSERT test_table (id, name) VALUES (2, 'C%s')" +, len200); rc = run_query(tds, large_sql); if (rc != TDS_SUCCEED) { return 1; } sprintf(large_sql, "INSERT test_table (id, name) VALUES (3, 'This i +s a test.. Greg I broke it')", len200); rc = run_query(tds, large_sql); if (rc != TDS_SUCCEED) { return 1; } /* * The heart of the test the SELECT statement */ rc = tds_submit_query(tds, "SELECT * FROM sysusers"); // while everything went fine print them out while ((rc=tds_process_result_tokens(tds))==TDS_SUCCEED) { while ((rc=tds_process_row_tokens(tds))==TDS_SUCCEED) { for (i=0; i<tds->res_info->num_cols; i++) { if (verbose == 0) { // print out the data printf("col %i is %s\n", i, value_as_string(tds, i)); } } } // the test failed.... Why? if (rc == TDS_FAIL) { fprintf(stderr, "tds_process_row_tokens() returned TDS_FAIL\n +"); return 1; } else if (rc != TDS_NO_MORE_ROWS) { fprintf(stderr, "tds_process_row_tokens() unexpected return\n +"); return 1; } } if (rc == TDS_FAIL) { fprintf(stderr, "tds_process_result_tokens() returned TDS_FAIL f +or SELECT\n"); return 1; } else if (rc != TDS_NO_MORE_RESULTS) { fprintf(stderr, "tds_process_result_tokens() unexpected return\n +"); } // logout of the database try_tds_logout(login, tds, verbose); return 0; } /* Run query for which there should be no return results */ int run_query(TDSSOCKET *tds, char *query) { int rc; rc = tds_submit_query(tds, query); if (rc != TDS_SUCCEED) { fprintf(stderr, "tds_submit_query() failed for query '%s'\n", qu +ery); return TDS_FAIL; } while ((rc=tds_process_result_tokens(tds))==TDS_SUCCEED) { if (tds->res_info->rows_exist) { fprintf(stderr, "Error: query should not return results\n"); return TDS_FAIL; } } if (rc == TDS_FAIL) { /* probably okay - DROP TABLE might cause this */ /* fprintf(stderr, "tds_process_result_tokens() returned TDS_FAI +L for '%s'\n", query); */ } else if (rc != TDS_NO_MORE_RESULTS) { fprintf(stderr, "tds_process_result_tokens() unexpected return\n +"); return TDS_FAIL; } return TDS_SUCCEED; } // the types that this expects or wants in a sql statement // varchar and int are only excepted at this time char *value_as_string( TDSSOCKET *tds, int col_idx) { static char result[256]; const int type = tds->res_info->columns[col_idx]->column_type +; const char *row = tds->res_info->current_row; const int offset = tds->res_info->columns[col_idx]->column_offs +et; const void *value = (row+offset); switch(type) { case SYBVARCHAR: strncpy(result, (char *)value, sizeof(result)-1); result[sizeof(result)-1] = '\0'; break; case SYBINT4: sprintf(result, "%d", *(int *)value); break; default: sprintf(result, "Unexpected column_type %d", type); break; } return result; }
install_driver(Sybase) failed: Can't load '/var/tmp/hfranks/lib/perl5/site_perl/ 5.6.1/sun4-solaris/auto/DBD/Sybase/Sybase.so' for module DBD::Sybase: ld.so.1: / var/tmp/hfranks/bin/perl: fatal: relocation error: file /home/top/hfranks/hfrank s2/hfranks2/lib/libct.so.0: symbol g_tds_err_handler: referenced symbo +l not foun d at /var/tmp/hfranks/lib/perl5/5.6.1/sun4-solaris/DynaLoader.pm line +206. at (eval 4) line 3 Compilation failed in require at (eval 4) line 3. Perhaps a required shared library or dll isn't installed where expecte +d at newest.pl line 8
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Ms SQL Server and perl.
by Moonie (Friar) on Jul 28, 2001 at 11:03 UTC | |
by scain (Curate) on Jul 29, 2001 at 00:07 UTC | |
by Moonie (Friar) on Jul 29, 2001 at 00:44 UTC | |
by hacker_j99 (Beadle) on Jul 29, 2001 at 23:43 UTC | |
by Moonie (Friar) on Jul 30, 2001 at 00:01 UTC | |
|
Re: Ms SQL Server and perl.
by aquacade (Scribe) on Jul 28, 2001 at 07:12 UTC | |
by hacker_j99 (Beadle) on Jul 29, 2001 at 23:49 UTC | |
|
Re: Ms SQL Server and perl.
by scain (Curate) on Jul 28, 2001 at 19:51 UTC | |
by hacker_j99 (Beadle) on Jul 29, 2001 at 23:52 UTC |