[firebase-br] Linguagem C
Valdir Marcos
valdir.marcos em ig.com.br
Sex Out 14 13:46:01 -03 2005
------------
C/C++
-----------
#include "ibase.h"
#include <cstdlib>
#include <iostream>
using namespace std;
/*
* Name: getConnectedUsers.c
*
*
* It then uses the isc_database_info call to fetch the number
* of users connected to that database
*
* Brett Bandy, June 1998
*/
void usage()
{
printf("Syntax Error:n");
printf("t getConnectedUsers n");
return;
}
int main(int argc, char **argv)
{
ISC_STATUS isc_status[20];
isc_db_handle db;
char dbname[128];
char infoBuffer[] = {isc_info_user_names};
char result_buffer[512];
char *p;
char userName[32];
int length;
char item;
int i;
int userNameSize;
int totalUsers;
/* init dbhandle */
db = 0L;
switch(argc)
{
case 1:
/* get dbname from user */
printf("Enter Database to check for connections: ");
gets(dbname);
break;
case 2:
/* dbname is passed in */
strcpy(dbname, argv[1]);
break;
default:
usage();
return 0 ;
}
printf("nAttempting to attach to database:nt%snn", dbname);
isc_attach_database(isc_status, strlen(dbname), dbname,
&db, 0, NULL);
if(isc_status[0] == 1 && isc_status[1])
{
isc_print_status(isc_status);
exit(1);
}
/* now fetch the number of cache buffers database is using */
isc_database_info(isc_status,
&db, /* ptr to db handle */
sizeof(infoBuffer), /* size of items buffer */
infoBuffer, /* array of items to retrieve */
sizeof(result_buffer),
result_buffer); /* results will be written */
if(isc_status[0] == 1 && isc_status[1])
{
isc_print_status(isc_status);
exit(1);
}
/* initialize totalUsers */
totalUsers = 0;
/*
* Format for this call is:
*
* 1 byte: type of info item (isc_info_user_names)
* 2 bytes: length of next item (must use isc_vax_integer
* to get correct byte order)
* x bytes: next item which consists of...
* 1 byte: length of username
* x bytes: username
*
*/
/* extract the info from result_buffer */
/* loop because there can be more that one user */
for(p = result_buffer; *p != isc_info_end;)
{
item = *p++; /* item return type */
if(item != isc_info_user_names)
{
printf("Error retrieving user namesn");
return 0;
}
/* this will return the length of the */
/* item in bytes (length is 2 byte) */
length = isc_vax_integer(p, 2);
/* increment pointer so points to next username */
p+=2;
/* username items are stored in pascal style
<1 byte for length> */
/* get length of username */
userNameSize = isc_vax_integer(p,1);
p+=1;
/* copy username from result_buffer to userName char array */
memcpy(userName, p, length);
userName[userNameSize] = '0';
/* advance p to point to start of next item */
p+=userNameSize;
printf("User [%s] is connectedn", userName);
totalUsers++;
}
printf("nTotal Connected User Count is %dn", totalUsers);
isc_detach_database(isc_status, &db);
if(isc_status[0] == 1 && isc_status[1])
{
isc_print_status(isc_status);
exit(1);
}
}
-----------
----- Original Message -----
From: "janderson cardoso" <jandersonc em yahoo.com.br>
To: "FireBase" <lista em firebase.com.br>
Sent: Friday, October 14, 2005 10:38 AM
Subject: [firebase-br] Linguagem C
> Bom dia!
> Alguem da lista pode me enviar um exemplo de programa
> feito em C acessando o banco de dados Firebird?
>
>
> Janderson Cardoso
>
>
>
>
>
>
>
>
> _______________________________________________________
> Promoção Yahoo! Acesso Grátis: a cada hora navegada você acumula cupons e
> concorre a mais de 500 prêmios! Participe! http://yahoo.fbiz.com.br/
>
> ______________________________________________
> FireBase-BR (www.firebase.com.br) - Hospedado em www.bavs.com.br
> Para editar sua configuração na lista, use o endereço
> http://mail.firebase.com.br/mailman/listinfo/lista_firebase.com.br
> Para consultar mensagens antigas: http://firebase.com.br/pesquisa
>
>
Mais detalhes sobre a lista de discussão lista