Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 512a3ae

Browse files
author
Barry Lind
committed
fixed change in behavior introduced in bytea / getBytes changes. This patch reverts back unintentional change in behavior to return raw value even when not bytea column
1 parent c41b6b1 commit 512a3ae

File tree

2 files changed

+62
-38
lines changed

2 files changed

+62
-38
lines changed

src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -391,31 +391,43 @@ public byte[] getBytes(int columnIndex) throws SQLException
391391
if (columnIndex < 1 || columnIndex > fields.length)
392392
throw new PSQLException("postgresql.res.colrange");
393393

394-
//If the data is already binary then just return it
395-
if (binaryCursor)
396-
return this_row[columnIndex - 1];
397-
398-
if (connection.haveMinimumCompatibleVersion("7.2"))
394+
wasNullFlag = (this_row[columnIndex - 1] == null);
395+
if (!wasNullFlag)
399396
{
397+
if (binaryCursor)
398+
{
399+
//If the data is already binary then just return it
400+
return this_row[columnIndex - 1];
401+
}
402+
else if (connection.haveMinimumCompatibleVersion("7.2"))
403+
{
400404
//Version 7.2 supports the bytea datatype for byte arrays
401-
return PGbytea.toBytes(getString(columnIndex));
402-
}
403-
else
404-
{
405+
if (fields[columnIndex - 1].getPGType().equals("bytea"))
406+
{
407+
return PGbytea.toBytes(getString(columnIndex));
408+
}
409+
else
410+
{
411+
return this_row[columnIndex - 1];
412+
}
413+
}
414+
else
415+
{
405416
//Version 7.1 and earlier supports LargeObjects for byte arrays
406-
wasNullFlag = (this_row[columnIndex - 1] == null);
407417
// Handle OID's as BLOBS
408-
if (!wasNullFlag)
418+
if ( fields[columnIndex - 1].getOID() == 26)
409419
{
410-
if ( fields[columnIndex - 1].getOID() == 26)
411-
{
412-
LargeObjectManager lom = connection.getLargeObjectAPI();
413-
LargeObject lob = lom.open(getInt(columnIndex));
414-
byte buf[] = lob.read(lob.size());
415-
lob.close();
416-
return buf;
417-
}
420+
LargeObjectManager lom = connection.getLargeObjectAPI();
421+
LargeObject lob = lom.open(getInt(columnIndex));
422+
byte buf[] = lob.read(lob.size());
423+
lob.close();
424+
return buf;
425+
}
426+
else
427+
{
428+
return this_row[columnIndex - 1];
418429
}
430+
}
419431
}
420432
return null;
421433
}

src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -318,31 +318,43 @@ public byte[] getBytes(int columnIndex) throws SQLException
318318
if (columnIndex < 1 || columnIndex > fields.length)
319319
throw new PSQLException("postgresql.res.colrange");
320320

321-
//If the data is already binary then just return it
322-
if (binaryCursor)
323-
return this_row[columnIndex - 1];
324-
325-
if (connection.haveMinimumCompatibleVersion("7.2"))
321+
wasNullFlag = (this_row[columnIndex - 1] == null);
322+
if (!wasNullFlag)
326323
{
324+
if (binaryCursor)
325+
{
326+
//If the data is already binary then just return it
327+
return this_row[columnIndex - 1];
328+
}
329+
else if (connection.haveMinimumCompatibleVersion("7.2"))
330+
{
327331
//Version 7.2 supports the bytea datatype for byte arrays
328-
return PGbytea.toBytes(getString(columnIndex));
329-
}
330-
else
331-
{
332+
if (fields[columnIndex - 1].getPGType().equals("bytea"))
333+
{
334+
return PGbytea.toBytes(getString(columnIndex));
335+
}
336+
else
337+
{
338+
return this_row[columnIndex - 1];
339+
}
340+
}
341+
else
342+
{
332343
//Version 7.1 and earlier supports LargeObjects for byte arrays
333-
wasNullFlag = (this_row[columnIndex - 1] == null);
334344
// Handle OID's as BLOBS
335-
if (!wasNullFlag)
345+
if ( fields[columnIndex - 1].getOID() == 26)
336346
{
337-
if ( fields[columnIndex - 1].getOID() == 26)
338-
{
339-
LargeObjectManager lom = connection.getLargeObjectAPI();
340-
LargeObject lob = lom.open(getInt(columnIndex));
341-
byte buf[] = lob.read(lob.size());
342-
lob.close();
343-
return buf;
344-
}
347+
LargeObjectManager lom = connection.getLargeObjectAPI();
348+
LargeObject lob = lom.open(getInt(columnIndex));
349+
byte buf[] = lob.read(lob.size());
350+
lob.close();
351+
return buf;
352+
}
353+
else
354+
{
355+
return this_row[columnIndex - 1];
345356
}
357+
}
346358
}
347359
return null;
348360
}

0 commit comments

Comments
 (0)