Skip to content

Commit eb40f73

Browse files
committed
Bug #62489: dba_insert not working as expected
1 parent 6dc80f0 commit eb40f73

17 files changed

+83
-22
lines changed

NEWS

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ PHP NEWS
2727

2828
- DateTime
2929
. Added DateTimeImmutable - a variant of DateTime that only returns the
30-
modified state instead of changing itself. (Derick)
30+
modified state instead of changing itself. (Derick)
3131

3232
- pgsql:
3333
. Bug #46408: Locale number format settings can cause pg_query_params to
3434
break with numerics. (asmecher, Lars)
3535

36+
- dba:
37+
. Bug #62489: dba_insert not working as expected.
38+
(marc-bennewitz at arcor dot de, Lars)
39+
3640
18 Dec 2012, PHP 5.5.0 Alpha 2
3741

3842
- General improvements:

ext/dba/dba_flatfile.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,16 @@ DBA_UPDATE_FUNC(flatfile)
8888
gval.dsize = vallen;
8989

9090
switch(flatfile_store(dba, gkey, gval, mode==1 ? FLATFILE_INSERT : FLATFILE_REPLACE TSRMLS_CC)) {
91-
case -1:
92-
php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Operation not possible");
93-
return FAILURE;
94-
default:
95-
case 0:
96-
return SUCCESS;
97-
case 1:
98-
php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Key already exists");
99-
return FAILURE;
91+
case 0:
92+
return SUCCESS;
93+
case 1:
94+
return FAILURE;
95+
case -1:
96+
php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Operation not possible");
97+
return FAILURE;
98+
default:
99+
php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "Unknown return value");
100+
return FAILURE;
100101
}
101102
}
102103

ext/dba/dba_gdbm.c

+12-5
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,18 @@ DBA_UPDATE_FUNC(gdbm)
104104
gval.dptr = (char *) val;
105105
gval.dsize = vallen;
106106

107-
if(gdbm_store(dba->dbf, gkey, gval,
108-
mode == 1 ? GDBM_INSERT : GDBM_REPLACE) == 0)
109-
return SUCCESS;
110-
php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "%s", gdbm_strerror(gdbm_errno));
111-
return FAILURE;
107+
switch (gdbm_store(dba->dbf, gkey, gval, mode == 1 ? GDBM_INSERT : GDBM_REPLACE)) {
108+
case 0:
109+
return SUCCESS;
110+
case 1:
111+
return FAILURE;
112+
case -1:
113+
php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "%s", gdbm_strerror(gdbm_errno));
114+
return FAILURE;
115+
default:
116+
php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "Unknown return value");
117+
return FAILURE;
118+
}
112119
}
113120

114121
DBA_EXISTS_FUNC(gdbm)

ext/dba/dba_inifile.c

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ DBA_UPDATE_FUNC(inifile)
101101
case 0:
102102
return SUCCESS;
103103
case 1:
104-
php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Key already exists");
105104
return FAILURE;
106105
}
107106
}

ext/dba/dba_qdbm.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,15 @@ DBA_FETCH_FUNC(qdbm)
9696
DBA_UPDATE_FUNC(qdbm)
9797
{
9898
QDBM_DATA;
99-
int result;
10099

101-
result = dpput(dba->dbf, key, keylen, val, vallen, mode == 1 ? DP_DKEEP : DP_DOVER);
102-
if (result)
100+
if (dpput(dba->dbf, key, keylen, val, vallen, mode == 1 ? DP_DKEEP : DP_DOVER)) {
103101
return SUCCESS;
102+
}
103+
104+
if (dpecode != DP_EKEEP) {
105+
php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "%s", dperrmsg(dpecode));
106+
}
104107

105-
php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "%s", dperrmsg(dpecode));
106108
return FAILURE;
107109
}
108110

ext/dba/tests/dba_db1.phpt

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ database handler: db1
1818
Content String 2
1919
Content 2 replaced
2020
Read during write: not allowed
21+
"key number 6" written
22+
Failed to write "key number 6" 2nd time
2123
Content 2 replaced 2nd time
2224
The 6th value
2325
array(3) {
@@ -33,6 +35,8 @@ array(3) {
3335
Content String 2
3436
Content 2 replaced
3537
Read during write: not allowed
38+
"key number 6" written
39+
Failed to write "key number 6" 2nd time
3640
Content 2 replaced 2nd time
3741
The 6th value
3842
array(3) {

ext/dba/tests/dba_db2.phpt

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ database handler: db2
1818
Content String 2
1919
Content 2 replaced
2020
Read during write: not allowed
21+
"key number 6" written
22+
Failed to write "key number 6" 2nd time
2123
Content 2 replaced 2nd time
2224
The 6th value
2325
array(3) {
@@ -33,6 +35,8 @@ array(3) {
3335
Content String 2
3436
Content 2 replaced
3537
Read during write: not allowed
38+
"key number 6" written
39+
Failed to write "key number 6" 2nd time
3640
Content 2 replaced 2nd time
3741
The 6th value
3842
array(3) {

ext/dba/tests/dba_db3.phpt

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ database handler: db3
1818
Content String 2
1919
Content 2 replaced
2020
Read during write: not allowed
21+
"key number 6" written
22+
Failed to write "key number 6" 2nd time
2123
Content 2 replaced 2nd time
2224
The 6th value
2325
array(3) {
@@ -33,6 +35,8 @@ array(3) {
3335
Content String 2
3436
Content 2 replaced
3537
Read during write: not allowed
38+
"key number 6" written
39+
Failed to write "key number 6" 2nd time
3640
Content 2 replaced 2nd time
3741
The 6th value
3842
array(3) {

ext/dba/tests/dba_db4_000.phpt

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ database handler: db4
2222
Content String 2
2323
Content 2 replaced
2424
Read during write: not allowed
25+
"key number 6" written
26+
Failed to write "key number 6" 2nd time
2527
Content 2 replaced 2nd time
2628
The 6th value
2729
array(3) {
@@ -37,6 +39,8 @@ array(3) {
3739
Content String 2
3840
Content 2 replaced
3941
Read during write: not allowed
42+
"key number 6" written
43+
Failed to write "key number 6" 2nd time
4044
Content 2 replaced 2nd time
4145
The 6th value
4246
array(3) {

ext/dba/tests/dba_dbm.phpt

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ database handler: dbm
1818
Content String 2
1919
Content 2 replaced
2020
Read during write: not allowed
21+
"key number 6" written
22+
Failed to write "key number 6" 2nd time
2123
Content 2 replaced 2nd time
2224
The 6th value
2325
array(3) {
@@ -33,6 +35,8 @@ array(3) {
3335
Content String 2
3436
Content 2 replaced
3537
Read during write: not allowed
38+
"key number 6" written
39+
Failed to write "key number 6" 2nd time
3640
Content 2 replaced 2nd time
3741
The 6th value
3842
array(3) {

ext/dba/tests/dba_flatfile.phpt

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ database handler: flatfile
2222
Content String 2
2323
Content 2 replaced
2424
Read during write: not allowed
25+
"key number 6" written
26+
Failed to write "key number 6" 2nd time
2527
Content 2 replaced 2nd time
2628
The 6th value
2729
array(3) {
@@ -37,6 +39,8 @@ array(3) {
3739
Content String 2
3840
Content 2 replaced
3941
Read during write: not allowed
42+
"key number 6" written
43+
Failed to write "key number 6" 2nd time
4044
Content 2 replaced 2nd time
4145
The 6th value
4246
array(3) {

ext/dba/tests/dba_gdbm.phpt

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ database handler: gdbm
2121
Content String 2
2222
Content 2 replaced
2323
Read during write:%sallowed
24+
"key number 6" written
25+
Failed to write "key number 6" 2nd time
2426
Content 2 replaced 2nd time
2527
The 6th value
2628
array(3) {

ext/dba/tests/dba_handler.inc

+10-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ do {
4646
echo "Read during write: allowed\n";
4747
}
4848
if ($db_writer!==FALSE) {
49-
dba_insert("key number 6", "The 6th value", $db_writer);
50-
@dba_insert("key number 6", "The 6th value inserted again would be an error", $db_writer);
49+
if (dba_insert("key number 6", "The 6th value", $db_writer)) {
50+
echo '"key number 6" written' . "\n";
51+
} else {
52+
echo 'Failed to write "key number 6"' . "\n";
53+
}
54+
if (dba_insert("key number 6", "The 6th value inserted again would be an error", $db_writer)) {
55+
echo '"key number 6" written 2nd time' . "\n";
56+
} else {
57+
echo 'Failed to write "key number 6" 2nd time' . "\n";
58+
}
5159
dba_replace("key2", "Content 2 replaced 2nd time", $db_writer);
5260
dba_delete("key4", $db_writer);
5361
echo dba_fetch("key2", $db_writer)."\n";

ext/dba/tests/dba_inifile.phpt

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ database handler: inifile
1818
Content String 2
1919
Content 2 replaced
2020
Read during write: not allowed
21+
"key number 6" written
22+
Failed to write "key number 6" 2nd time
2123
Content 2 replaced 2nd time
2224
The 6th value
2325
array(3) {
@@ -33,6 +35,8 @@ array(3) {
3335
Content String 2
3436
Content 2 replaced
3537
Read during write: not allowed
38+
"key number 6" written
39+
Failed to write "key number 6" 2nd time
3640
Content 2 replaced 2nd time
3741
The 6th value
3842
array(3) {

ext/dba/tests/dba_ndbm.phpt

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ database handler: ndbm
1818
Content String 2
1919
Content 2 replaced
2020
Read during write: not allowed
21+
"key number 6" written
22+
Failed to write "key number 6" 2nd time
2123
Content 2 replaced 2nd time
2224
The 6th value
2325
array(3) {
@@ -33,6 +35,8 @@ array(3) {
3335
Content String 2
3436
Content 2 replaced
3537
Read during write: not allowed
38+
"key number 6" written
39+
Failed to write "key number 6" 2nd time
3640
Content 2 replaced 2nd time
3741
The 6th value
3842
array(3) {

ext/dba/tests/dba_qdbm.phpt

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ database handler: qdbm
1919
Content String 2
2020
Content 2 replaced
2121
Read during write:%sallowed
22+
"key number 6" written
23+
Failed to write "key number 6" 2nd time
2224
Content 2 replaced 2nd time
2325
The 6th value
2426
array(3) {

ext/dba/tests/dba_tcadb.phpt

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ database handler: tcadb
2222
Content String 2
2323
Content 2 replaced
2424
Read during write: not allowed
25+
"key number 6" written
26+
Failed to write "key number 6" 2nd time
2527
Content 2 replaced 2nd time
2628
The 6th value
2729
array(3) {
@@ -37,6 +39,8 @@ array(3) {
3739
Content String 2
3840
Content 2 replaced
3941
Read during write: not allowed
42+
"key number 6" written
43+
Failed to write "key number 6" 2nd time
4044
Content 2 replaced 2nd time
4145
The 6th value
4246
array(3) {

0 commit comments

Comments
 (0)