community.borland.com

Article #25476: How do I create an Embedded C application to GRANT on a database

Problem:
I don't want to use the EXEC SQL GRANT ALL ON TABLE TO USER syntax.  I want to be
able to prompt the user for table_name and user_name.

Solution:
#include 
#include 
#include 

EXEC SQL
  SET DATABASE EMP_DB = "employee.gdb";

main() 
{

  char user_name[32];
  char object_name[32];
  char grant_stmt[128];

  EXEC SQL
    CONNECT EMP_DB user "SYSDBA" password "masterkey";

  if (isc_status[0] == 1 && isc_status[1]) 
  {
    isc_print_status(isc_status);
    return;
  }
  
  printf("ntEnter the table in which you want to grant on: ");
  gets(object_name);

  printf("ntEnter the user name in which you want to grant to: ");
  gets(user_name);

  EXEC SQL
    SET TRANSACTION;

  if (isc_status[0] == 1 && isc_status[1]) 
  {
    isc_print_status(isc_status);
    return;
  }

  sprintf(grant_stmt, "GRANT ALL ON %s TO %s", object_name, user_name);
  
  EXEC SQL
    EXECUTE IMMEDIATE :grant_stmt;

  if (isc_status[0] == 1 && isc_status[1]) 
  {
    isc_print_status(isc_status);
    return;
  }

  EXEC SQL
    COMMIT;

  if (isc_status[0] == 1 && isc_status[1]) 
  {
    isc_print_status(isc_status);
    return;
  }

  EXEC SQL
    DISCONNECT EMP_DB;
}

Last Modified: 26-OCT-00