4
4
* DBD::drizzle - DBI driver for the drizzle database
6
* Copyright (c) 2008 Patrick Galbraith
6
* Copyright (c) 2009 Patrick Galbraith
7
7
* Copyright 2009 Clint Byrum
9
9
* You may distribute this under the terms of either the GNU General Public
1002
// XXX commented out until this is better understood
1003
// XXX according to eday, LOCAL INFILE is not going to be supported -cb
1005
if ((svp = hv_fetch( hv, "drizzle_local_infile", 18, FALSE)) && *svp)
1007
unsigned int flag = SvTRUE(*svp);
1008
if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)
1009
PerlIO_printf(DBILOGFP,
1010
"imp_dbh->drizzle_dr_connect: Using" \
1011
" local infile %u.\n", flag);
1012
drizzleclient_options(con, DRIZZLE_OPT_LOCAL_INFILE, (const char *) &flag);
1018
1005
//client_flag|= CLIENT_MULTI_RESULTS;
1020
//result = drizzleclient_connect(con, host, user, password, dbname,
1021
// portNr, drizzle_socket, client_flag);
1022
// XXX handle options later
1023
// Everything here is already allocated, return is ok to ignore
1024
// XXX this is not smooth.. there's no host with UDS
1025
// XXX UDS isn't in drizzle, only mysql.. duh
1026
//if ( strcmp(host, "localhost") ) { } else
1027
//{ (void)drizzle_con_add_uds(drizzle, con, drizzle_socket, user,
1028
//password, dbname, DRIZZLE_CON_NONE); }
1006
// XXX not sure about this logic...
1029
1007
if (imp_dbh->con != NULL)
1031
1009
imp_dbh->con= drizzle_con_add_tcp(drizzle, NULL, host, portNr,
1434
1412
else if (kl == 20 && strEQ(key,"drizzle_auto_reconnect"))
1435
1413
imp_dbh->auto_reconnect = bool_value;
1437
else if (kl == 31 && strEQ(key,"drizzle_unsafe_bind_type_guessing"))
1415
else if (kl == 24 && strEQ(key,"drizzle_bind_type_guessing"))
1438
1416
imp_dbh->bind_type_guessing = SvIV(valuesv);
1440
1418
#if defined(sv_utf8_decode)
1510
1488
result= sv_2mortal(newSViv(imp_dbh->auto_reconnect));
1513
if (kl == strlen("unsafe_bind_type_guessing") &&
1514
strEQ(key, "unsafe_bind_type_guessing"))
1491
if (kl == strlen("bind_type_guessing") &&
1492
strEQ(key, "bind_type_guessing"))
1515
1493
result = sv_2mortal(newSViv(imp_dbh->bind_type_guessing));
1631
1607
Clean-up previous result set(s) for sth to prevent
1632
1608
'Commands out of sync' error
1634
// XXX drizzle_con_ready() for conn pooling would be awesome
1610
// TODO drizzle_con_ready() for conn pooling would be awesome
1635
1611
drizzle_st_free_result_sets(sth, imp_sth);
1636
1612
// (void)drizzle_result_create(imp_dbh->con, imp_sth->result);
1668
1644
if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)
1669
1645
PerlIO_printf(DBILOGFP, "\t>- dbd_st_free_result_sets\n");
1671
// XXX the goal is to flush out the connection
1673
if (imp_sth->result) {
1674
// returns 0 when there's no row
1675
while (row = drizzle_row_buffer(imp_sth->result, &ret)) {
1676
if (ret != DRIZZLE_RETURN_OK) {
1677
do_error(sth, drizzle_result_error_code(imp_sth->result), drizzle_result_error(imp_sth->result),
1678
drizzle_result_sqlstate(imp_sth->result));
1680
drizzle_row_free(imp_sth->result, row);
1683
if (imp_sth->result)
1685
drizzle_result_free(imp_sth->result);
1686
imp_sth->result= NULL;
1693
if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)
1694
PerlIO_printf(DBILOGFP, "\t<- dbd_st_free_result_sets RC %d\n", next_result_rc);
1696
if (next_result_rc == 0)
1698
if (!(imp_sth->result = drizzleclient_use_result(imp_dbh->pdrizzle)))
1700
// Check for possible error
1701
if (drizzleclient_field_count(imp_dbh->pdrizzle))
1703
if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)
1704
PerlIO_printf(DBILOGFP, "\t<- dbd_st_free_result_sets ERROR: %s\n",
1705
drizzleclient_error(imp_dbh->pdrizzle));
1707
do_error(sth, drizzleclient_errno(imp_dbh->pdrizzle), drizzleclient_error(imp_dbh->pdrizzle),
1708
drizzleclient_sqlstate(imp_dbh->pdrizzle));
1713
if (imp_sth->result)
1715
drizzleclient_free_result(imp_sth->result);
1716
imp_sth->result=NULL;
1718
} while ((next_result_rc= drizzleclient_next_result(imp_dbh->pdrizzle))==0);
1720
if (next_result_rc > 0)
1722
if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)
1723
PerlIO_printf(DBILOGFP, "\t<- dbd_st_free_result_sets: Error while processing multi-result set: %s\n",
1724
drizzleclient_error(imp_dbh->pdrizzle));
1726
do_error(sth, drizzleclient_errno(imp_dbh->pdrizzle), drizzleclient_error(imp_dbh->pdrizzle),
1727
drizzleclient_sqlstate(imp_dbh->pdrizzle));
1647
/* Nice and simple , thanks Eric */
1648
if (imp_sth->result)
1650
drizzle_result_free(imp_sth->result);
1651
imp_sth->result= NULL;
1731
if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)
1732
PerlIO_printf(DBILOGFP, "\t<- dbd_st_free_result_sets\n");
1808
1727
if (imp_sth->row) {
1809
1728
/* We have a new rowset */
1812
1729
/* delete cached handle attributes */
1813
1730
/* XXX should be driven by a list to ease maintenance */
1814
1731
hv_delete((HV*)SvRV(sth), "NAME", 4, G_DISCARD);
1963
if (!(query= malloc(strlen("SHOW COLUMNS FROM ``")+1+strlen(table)))) {
1880
if (!(query= malloc(strlen("SHOW COLUMNS FROM ``") + 1 + strlen(table)))) {
1964
1881
do_error(h, JW_ERR_MEM, "Out of memory", NULL);
1967
sprintf(query,"SHOW COLUMNS FROM `%s`", table);
1884
sprintf(query,"SHOW COLUMNS FROM `%s`", table);
1968
1885
*result= drizzle_query_str(con, NULL, query, &ret);
2005
1922
,drizzle_result_sqlstate(*result));
2008
// XXX this is *really* shady.. not sure how to differentiate yet
1925
/* Best way to be sure we return the right number if possible */
2009
1926
rows = drizzle_result_row_count(*result);
2011
1928
rows = drizzle_result_affected_rows(*result);
2193
2110
drizzle_result_row_count(imp_sth->result));
2194
2111
PerlIO_printf(DBILOGFP, "\tdrizzle_result_affected_rows=%llu\n",
2195
2112
drizzle_result_affected_rows(imp_sth->result));
2196
PerlIO_printf(DBILOGFP, "\tdbd_st_fetch for %08lx, currow= %d\n",
2197
(u_long) sth,imp_sth->currow);
2200
2115
if ( imp_sth->row) {
2204
2119
if (imp_sth->unbuffered_result) {
2205
2120
// We dont buffer result, but we will buffer each row
2206
row= drizzle_row_buffer(imp_sth->result, &ret);
2121
row= drizzle_row_buffer(imp_sth->result, &ret);
2208
2123
row= drizzle_row_next(imp_sth->result);
2220
2135
drizzle_result_error(imp_sth->result),
2221
2136
drizzle_result_sqlstate(imp_sth->result));
2223
// XXX when would this ever be true?
2224
//if (!drizzleclient_more_results(con))
2225
2138
dbd_st_finish(sth, imp_sth);
2229
2142
num_fields= drizzle_result_column_count(imp_sth->result);
2230
//fields= drizzleclient_fetch_fields(imp_sth->result);
2231
//lengths= drizzleclient_fetch_lengths(imp_sth->result);
2232
2143
lengths= (size_t *)drizzle_row_field_sizes(imp_sth->result);
2234
2145
if ((av= DBIc_FIELDS_AV(imp_sth)) != Nullav)
2687
2598
if (strEQ(key, "TYPE"))
2688
2599
retsv= ST_FETCH_AV(AV_ATTRIB_SQL_TYPE);
2693
2604
if (strEQ(key, "drizzle_type"))
2694
2605
retsv= ST_FETCH_AV(AV_ATTRIB_TYPE);
2697
2608
if (strEQ(key, "drizzle_table"))
2698
2609
retsv= ST_FETCH_AV(AV_ATTRIB_TABLE);
2701
2612
if ( strEQ(key, "drizzle_is_key"))
2702
2613
retsv= ST_FETCH_AV(AV_ATTRIB_IS_KEY);
2703
2614
else if (strEQ(key, "drizzle_is_num"))
2707
2618
else if (strEQ(key, "drizzle_result"))
2708
2619
retsv= sv_2mortal(newSViv((IV) imp_sth->result));
2711
2622
if (strEQ(key, "drizzle_is_blob"))
2712
2623
retsv= ST_FETCH_AV(AV_ATTRIB_IS_BLOB);
2715
2626
if (strEQ(key, "drizzle_insertid"))
2717
2628
/* We cannot return an IV, because the insertid is a long. */
2721
2632
return sv_2mortal(my_ulonglong2str(imp_dbh->insert_id));
2725
2636
if (strEQ(key, "drizzle_type_name"))
2726
2637
retsv = ST_FETCH_AV(AV_ATTRIB_TYPE_NAME);
2729
2640
if ( strEQ(key, "drizzle_is_pri_key"))
2730
2641
retsv= ST_FETCH_AV(AV_ATTRIB_IS_PRI_KEY);
2731
2642
else if (strEQ(key, "drizzle_max_length"))
2733
2644
else if (strEQ(key, "drizzle_unbuffered_result"))
2734
2645
retsv= boolSV(imp_sth->unbuffered_result);
2737
2648
if (strEQ(key, "drizzle_warning_count"))
2738
2649
retsv= sv_2mortal(newSViv((IV) imp_sth->warning_count));
2741
2652
if (strEQ(key, "drizzle_is_auto_increment"))
2742
2653
retsv = ST_FETCH_AV(AV_ATTRIB_IS_AUTO_INCREMENT);
2915
2826
* the execute, so next time $dbh->quote() gets called, instant SIGSEGV!
2918
// XXX pretty sure this one always allocates RAM so being careful
2829
/* this one always allocates RAM so being careful */
2919
2830
conres= drizzle_con_clone(imp_dbh->drizzle, &con, imp_dbh->con);
2921
2832
if (!my_login(h, imp_dbh))