Sample Code for isc_action_svc_delete_db_alias

From InterBase
Jump to: navigation, search

Go Up to Overview of Task Identifiers

/*
* db_alias_del: delete database alias from the server
*
* Copyright 1986-2010 Embarcadero Technologies, Inc.
* All rights reserved.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ibase.h>
#include "example.h"
#define RESPBUF 2048
void main (argc, argv)
int argc;
char *argv[];
{
char *user = "sysdba", *pass = "masterkey";
char alias_name[64];
ISC_STATUS status [20];
isc_svc_handle *svc_handle = NULL;
char svc_name[RESPBUF], spb_buff[RESPBUF], thd_buff[RESPBUF];
char respbuf[RESPBUF], *p = respbuf, *spb = spb_buff, *thd = thd_buff,*x;
short spblen, thdlen;
int i = 0, cnt=0;
short finished = ISC_FALSE;
if (argc > 1)
sprintf (alias_name, "%s", argv[1]);
else
strcpy (alias_name, "empdb");
*spb++ = isc_spb_version;
*spb++ = isc_spb_current_version;
*spb++ = isc_spb_user_name;
*spb++ = strlen (user);
for (x = user; *x;)
*spb++ = *x++;
*spb++ = isc_spb_password;
*spb++ = strlen (pass);
for (x = pass; *x;)
*spb++ = *x++;
sprintf (svc_name, "service_mgr");
spblen = spb - spb_buff;
if (isc_service_attach (status, 0, svc_name, &svc_handle, spblen, spb_buff))
{
isc_print_status (status);
exit (1);
}
*thd++ = isc_action_svc_delete_db_alias;
*thd++ = isc_spb_sec_db_alias_name;
ADD_SPB_LENGTH (thd, strlen(alias_name));
for (x = alias_name; *x;)
*thd++ = *x++;
thdlen = thd - thd_buff;
printf ("Attach succeed\n");
if (isc_service_start(status, &svc_handle, NULL, thdlen, thd_buff))
{
ISC_STATUS *vector = status;
printf ("Unable to start service:\n");
while (isc_interprete (respbuf, &vector))
printf ("ERROR: %s\n", respbuf);
printf ("End of errors\n");
isc_service_detach (status, &svc_handle);
exit(1);
}
printf ("Start succeed\n");
do
{
char sendbuf[] = {isc_info_svc_line};
ISC_STATUS loc_status[20], *stat = loc_status;
if (isc_service_query (status, &svc_handle, NULL, 0, NULL, sizeof (sendbuf), sendbuf, RESPBUF, respbuf))
{
isc_print_status (status);
isc_service_detach (status, &svc_handle);
exit(1);
}
x = p = respbuf;
if (*p++ == isc_info_svc_line)
{
ISC_USHORT len = 0, chTmp = 0;
len = (ISC_USHORT)isc_vax_integer(p, sizeof(ISC_USHORT));
p += sizeof (ISC_USHORT);
if (!len)
if (*p == isc_info_data_not_ready)
{
printf ("no data available at this moment\n");
continue;
}
else
{
if (*p != isc_info_end)
printf ("Format error ... <%d>\n", *p);
break;
}
for (chTmp = 0; chTmp < len; chTmp++)
printf("%c",p[chTmp]);
p += len;
if (*p != isc_info_truncated && *p != isc_info_end)
{
printf ("Format error ... encountered <%d>\n", *p);
break;
}
else
{
// printf ("\nisc_info_truncated || isc_info_end\n");
}
}
else
printf ("not a isc_info_svc_line, but %d\n", *x);
}
while (*x == isc_info_svc_line);
isc_service_detach (status, &svc_handle);
}

See the following sections for descriptions of tasks and examples of starting them.

Advance To: