Dynamic SQL with PROC/C++ problem

From: Fredrik Lindstrom <invalid_at_invalid.com>
Date: Wed, 3 Dec 2003 13:49:08 +0100
Message-ID: <3fcddbc7$1_2_at_news.Usenet.com>


Hi folks,

First I would like to know if there is a better forum regarding Oracle issues. I have heard that this forum is obsolete so if that is true please redirect me.

I also want to admit that I am very new to PROC and oracle.

I want to count the rows in a table using the following:

unsigned int db_count(char *table_name, char *server_id) {
  EXEC SQL BEGIN DECLARE SECTION;
   unsigned int cnt = 0;
   char sqlstmt[MAX_SQLSTMT_LENGTH];
  EXEC SQL END DECLARE SECTION;   sprintf(sqlstmt, "SELECT COUNT(*) INTO :cnt FROM %s", table_name);

  printf("sqlstmt = %s\n", sqlstmt);
  EXEC SQL WHENEVER SQLERROR DO return(sql_error(server_id, "Error counting rows in table %s.", table_name));
  EXEC SQL AT :server_id EXECUTE IMMEDIATE :sqlstmt;

  return(cnt);
}

Well this does not work cause I will always get 0 as an answer.

Any hints?

Regards
Fredrik Lindstrom

----== Posted via Usenet.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.Usenet.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--- Received on Wed Dec 03 2003 - 13:49:08 CET

Original text of this message