25
25
int _dbd_real_connect(dbi_conn_t *conn, char *enc)
27
char dpb_buffer[256], *dpb;
27
char dpb_buffer[256], *dpb, *p, *fb_encoding;
31
31
char db_fullpath[PATH_MAX];
33
isc_db_handle db = NULL; /* database handle */
34
isc_tr_handle trans = NULL; /* transaction handle */
33
isc_db_handle db = 0L; /* database handle */
34
isc_tr_handle trans = 0L; /* transaction handle */
35
35
ibase_conn_t *iconn = (ibase_conn_t * ) malloc(sizeof(ibase_conn_t));
36
ISC_STATUS status_vector[ISC_STATUS_LENGTH];
37
38
const char *dbname = dbi_conn_get_option(conn, "dbname");
38
39
const char *host = dbi_conn_get_option(conn, "host");
48
49
*dpb++ = isc_dpb_num_buffers;
53
*dpb++ = isc_dpb_user_name;
54
*dpb++ = strlen(username);
55
for (p = (char*)username; *p; *dpb++ = *p++);
57
*dpb++ = isc_dpb_password;
58
*dpb++ = strlen(password);
59
for (p = (char*)password; *p; *dpb++ = *p++);
61
*dpb++ = isc_dpb_lc_ctype;
62
fb_encoding = (char*)dbd_encoding_from_iana(encoding);
63
*dpb++ = strlen(fb_encoding);
64
for (p = fb_encoding; *p; *dpb++ = *p++);
51
66
dpb_length = dpb - dpb_buffer;
54
isc_expand_dpb(&dpb, &dpb_length,
55
isc_dpb_user_name, username,
56
isc_dpb_password, password,
57
isc_dpb_lc_ctype, dbd_encoding_from_iana(encoding),
69
/* could be used here, but is tagged deprecated */
70
/* isc_expand_dpb(&dpb, &dpb_length, */
71
/* isc_dpb_user_name, username, */
72
/* isc_dpb_password, password, */
73
/* isc_dpb_lc_ctype, dbd_encoding_from_iana(encoding), */
61
_dbd_internal_error_handler(conn, "no database specified", 0);
78
_dbd_internal_error_handler(conn, "no database specified", DBI_ERROR_DBD);
65
82
_firebird_populate_db_string( conn, dbname, db_fullpath );
66
snprintf(dbase, 256, "%s:%s", ( (host == NULL || *host == '\0')
67
? "localhost" : host) , db_fullpath);
69
if ( isc_attach_database(iconn->status, strlen(dbase), dbase, &db, dpb_length, dpb_buffer) ||
70
isc_start_transaction(iconn->status, &trans, 1, &db, 0, NULL)) {
84
if (host == NULL || !*host) {
85
snprintf(dbase, 256, "%s", db_fullpath);
88
snprintf(dbase, 256, "%s:%s", host, db_fullpath);
91
/* printf("dbase went to: %s<<; host: %s, username: %s, passwd: %s, encoding: %s; dbp:%s<<\n", dbase, host, username, password, encoding, dpb); */
93
isc_attach_database(status_vector, strlen(dbase), dbase, &db, dpb_length, dpb);
94
if (status_vector[0] == 1 && status_vector[1]) {
96
long* pvector = status_vector;
71
97
dealocate_iconn( iconn );
98
isc_interprete(msg, &pvector);
99
_dbd_internal_error_handler(conn, msg, DBI_ERROR_DBD);
103
isc_start_transaction(status_vector, &trans, 1, &db, 0, NULL);
75
106
iconn->trans = trans;
265
296
case DBI_TYPE_DATETIME:
266
297
sizeattrib = _isolate_attrib(result->field_attribs[curfield], DBI_DATETIME_DATE, DBI_DATETIME_TIME);
269
case DBI_DATETIME_TIME:
299
if (sizeattrib&DBI_DATETIME_TIME
300
&& sizeattrib&DBI_DATETIME_DATE) {
301
isc_decode_timestamp((ISC_TIMESTAMP *)var.sqldata, ×);
302
sprintf(date_s, "%04d-%02d-%02d %02d:%02d:%02d",
303
times.tm_year + 1900,
310
else if (sizeattrib&DBI_DATETIME_TIME) {
270
311
isc_decode_sql_time((ISC_TIME *)var.sqldata, ×);
271
/* sprintf(date_s, "%02d:%02d:%02d.%04d", */
275
/* (*((ISC_TIME *)var.sqldata)) % 10000); */
276
312
sprintf(date_s, "%02d:%02d:%02d",
282
case DBI_DATETIME_DATE:
283
318
isc_decode_sql_date((ISC_DATE *)var.sqldata, ×);
284
319
sprintf(date_s, "%04d-%02d-%02d",
285
320
times.tm_year + 1900,
290
isc_decode_timestamp((ISC_TIMESTAMP *)var.sqldata, ×);
291
/* sprintf(date_s, "%04d-%02d-%02d %02d:%02d:%02d.%04d", */
292
/* times.tm_year + 1900, */
293
/* times.tm_mon+1, */
298
/* ((ISC_TIMESTAMP *)var.sqldata)->timestamp_time % 10000); */
299
sprintf(date_s, "%04d-%02d-%02d %02d:%02d:%02d",
300
times.tm_year + 1900,
308
324
data->d_datetime = _dbd_parse_datetime(date_s, sizeattrib);
311
327
case DBI_TYPE_BINARY:
312
328
bid = *(ISC_QUAD *) var.sqldata;
314
isc_open_blob2( iconn->status, &(iconn->db), &(iconn->trans), &blob_handle, &bid, 0, NULL );
315
blob_stat = isc_get_segment( iconn->status, &blob_handle, &actual_seg_len,
330
isc_open_blob2( iconn->status_vector, &(iconn->db), &(iconn->trans), &blob_handle, &bid, 0, NULL );
331
blob_stat = isc_get_segment( iconn->status_vector, &blob_handle, &actual_seg_len,
316
332
sizeof(blob_segment), blob_segment );
318
334
data->d_string = malloc(sizeof(actual_seg_len));
319
335
memcpy(data->d_string, blob_segment, actual_seg_len);
320
336
row->field_sizes[curfield] = actual_seg_len;
322
while (blob_stat == 0 || iconn->status[1] == isc_segment) {
323
blob_stat = isc_get_segment(iconn->status, &blob_handle,
338
while (blob_stat == 0 || iconn->status_vector[1] == isc_segment) {
339
blob_stat = isc_get_segment(iconn->status_vector, &blob_handle,
325
341
sizeof(blob_segment), blob_segment);