Commit 46d7ae75 authored by Bruce Momjian's avatar Bruce Momjian

Add intended Array.java file that accidentally was patched into the

wrong directory.
parent d39ec83c
...@@ -24,10 +24,6 @@ ...@@ -24,10 +24,6 @@
* PRIVATE FUNCTIONS * PRIVATE FUNCTIONS
*/ */
typedef unsigned char unsigned8;
typedef unsigned int unsigned32;
typedef unsigned long unsigned64;
#ifdef FRONTEND #ifdef FRONTEND
#undef palloc #undef palloc
#define palloc malloc #define palloc malloc
...@@ -39,13 +35,13 @@ typedef unsigned long unsigned64; ...@@ -39,13 +35,13 @@ typedef unsigned long unsigned64;
* The returned array is allocated using malloc. the caller should free it * The returned array is allocated using malloc. the caller should free it
* when it is no longer needed. * when it is no longer needed.
*/ */
static unsigned8 * static uint8 *
createPaddedCopyWithLength(unsigned8 *b, unsigned32 *l) createPaddedCopyWithLength(uint8 *b, uint32 *l)
{ {
unsigned8 *ret; uint8 *ret;
unsigned32 q; uint32 q;
unsigned32 len, newLen448; uint32 len, newLen448;
unsigned64 len64; uint32 len_high, len_low; /* 64-bit value split into 32-bit sections */
len = ((b == NULL) ? 0 : *l); len = ((b == NULL) ? 0 : *l);
newLen448 = len + 64 - (len % 64) - 8; newLen448 = len + 64 - (len % 64) - 8;
...@@ -53,11 +49,11 @@ createPaddedCopyWithLength(unsigned8 *b, unsigned32 *l) ...@@ -53,11 +49,11 @@ createPaddedCopyWithLength(unsigned8 *b, unsigned32 *l)
newLen448 += 64; newLen448 += 64;
*l = newLen448 + 8; *l = newLen448 + 8;
if ((ret = (unsigned8 *) malloc(sizeof(unsigned8) * *l)) == NULL) if ((ret = (uint8 *) malloc(sizeof(uint8) * *l)) == NULL)
return NULL; return NULL;
if (b != NULL) if (b != NULL)
memcpy(ret, b, sizeof(unsigned8) * len); memcpy(ret, b, sizeof(uint8) * len);
/* pad */ /* pad */
ret[len] = 0x80; ret[len] = 0x80;
...@@ -65,24 +61,26 @@ createPaddedCopyWithLength(unsigned8 *b, unsigned32 *l) ...@@ -65,24 +61,26 @@ createPaddedCopyWithLength(unsigned8 *b, unsigned32 *l)
ret[q] = 0x00; ret[q] = 0x00;
/* append length as a 64 bit bitcount */ /* append length as a 64 bit bitcount */
len64 = len; len_low = len;
len64 <<= 3; /* split into two 32-bit values */
/* we only look at the bottom 32-bits */
len_high = len >> 29;
len_low <<= 3;
q = newLen448; q = newLen448;
ret[q++] = (len64 & 0xFF); ret[q++] = (len_low & 0xff);
len64 >>= 8; len_low >>= 8;
ret[q++] = (len64 & 0xFF); ret[q++] = (len_low & 0xff);
len64 >>= 8; len_low >>= 8;
ret[q++] = (len64 & 0xFF); ret[q++] = (len_low & 0xff);
len64 >>= 8; len_low >>= 8;
ret[q++] = (len64 & 0xFF); ret[q++] = (len_low & 0xff);
len64 >>= 8; ret[q++] = (len_high & 0xff);
ret[q++] = (len64 & 0xFF); len_high >>= 8;
len64 >>= 8; ret[q++] = (len_high & 0xff);
ret[q++] = (len64 & 0xFF); len_high >>= 8;
len64 >>= 8; ret[q++] = (len_high & 0xff);
ret[q++] = (len64 & 0xFF); len_high >>= 8;
len64 >>= 8; ret[q] = (len_high & 0xff);
ret[q] = (len64 & 0xFF);
return ret; return ret;
} }
...@@ -94,9 +92,9 @@ createPaddedCopyWithLength(unsigned8 *b, unsigned32 *l) ...@@ -94,9 +92,9 @@ createPaddedCopyWithLength(unsigned8 *b, unsigned32 *l)
#define ROT_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) #define ROT_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
static void static void
doTheRounds(unsigned32 X[16], unsigned32 state[4]) doTheRounds(uint32 X[16], uint32 state[4])
{ {
unsigned32 a, b, c, d; uint32 a, b, c, d;
a = state[0]; a = state[0];
b = state[1]; b = state[1];
...@@ -182,13 +180,13 @@ doTheRounds(unsigned32 X[16], unsigned32 state[4]) ...@@ -182,13 +180,13 @@ doTheRounds(unsigned32 X[16], unsigned32 state[4])
} }
static int static int
calculateDigestFromBuffer(unsigned8 *b, unsigned32 len, unsigned8 sum[16]) calculateDigestFromBuffer(uint8 *b, uint32 len, uint8 sum[16])
{ {
register unsigned32 i, j, k, newI; register uint32 i, j, k, newI;
unsigned32 l; uint32 l;
unsigned8 *input; uint8 *input;
register unsigned32 *wbp; register uint32 *wbp;
unsigned32 workBuff[16], state[4]; uint32 workBuff[16], state[4];
l = len; l = len;
...@@ -223,19 +221,19 @@ calculateDigestFromBuffer(unsigned8 *b, unsigned32 len, unsigned8 sum[16]) ...@@ -223,19 +221,19 @@ calculateDigestFromBuffer(unsigned8 *b, unsigned32 len, unsigned8 sum[16])
j = 0; j = 0;
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
k = state[i]; k = state[i];
sum[j++] = (k & 0xFF); sum[j++] = (k & 0xff);
k >>= 8; k >>= 8;
sum[j++] = (k & 0xFF); sum[j++] = (k & 0xff);
k >>= 8; k >>= 8;
sum[j++] = (k & 0xFF); sum[j++] = (k & 0xff);
k >>= 8; k >>= 8;
sum[j++] = (k & 0xFF); sum[j++] = (k & 0xff);
} }
return 1; return 1;
} }
static void static void
bytesToHex(unsigned8 b[16], char *s) bytesToHex(uint8 b[16], char *s)
{ {
static char *hex = "0123456789abcdef"; static char *hex = "0123456789abcdef";
int q, w; int q, w;
...@@ -280,9 +278,9 @@ bytesToHex(unsigned8 b[16], char *s) ...@@ -280,9 +278,9 @@ bytesToHex(unsigned8 b[16], char *s)
bool bool
md5_hash(const void *buff, size_t len, char *hexsum) md5_hash(const void *buff, size_t len, char *hexsum)
{ {
unsigned8 sum[16]; uint8 sum[16];
if (!calculateDigestFromBuffer((unsigned8 *) buff, len, sum)) if (!calculateDigestFromBuffer((uint8 *) buff, len, sum))
return false; return false;
bytesToHex(sum, hexsum); bytesToHex(sum, hexsum);
......
...@@ -169,11 +169,11 @@ public class Array implements java.sql.Array ...@@ -169,11 +169,11 @@ public class Array implements java.sql.Array
} }
public int getBaseType() throws SQLException { public int getBaseType() throws SQLException {
return conn.getSQLType(getBaseTypeName()); return Field.getSQLType( getBaseTypeName() );
} }
public String getBaseTypeName() throws SQLException { public String getBaseTypeName() throws SQLException {
String fType = field.getPGType(); String fType = field.getTypeName();
if( fType.charAt(0) == '_' ) if( fType.charAt(0) == '_' )
fType = fType.substring(1); fType = fType.substring(1);
return fType; return fType;
...@@ -195,12 +195,12 @@ public class Array implements java.sql.Array ...@@ -195,12 +195,12 @@ public class Array implements java.sql.Array
Object array = getArray( index, count, map ); Object array = getArray( index, count, map );
Vector rows = new Vector(); Vector rows = new Vector();
Field[] fields = new Field[2]; Field[] fields = new Field[2];
fields[0] = new Field(conn, "INDEX", conn.getOID("int2"), 2); fields[0] = new Field(conn, "INDEX", field.getOID("int2"), 2);
switch ( getBaseType() ) switch ( getBaseType() )
{ {
case Types.BIT: case Types.BIT:
boolean[] booleanArray = (boolean[]) array; boolean[] booleanArray = (boolean[]) array;
fields[1] = new Field(conn, "VALUE", conn.getOID("bool"), 1); fields[1] = new Field(conn, "VALUE", field.getOID("bool"), 1);
for( int i=0; i<booleanArray.length; i++ ) { for( int i=0; i<booleanArray.length; i++ ) {
byte[][] tuple = new byte[2][0]; byte[][] tuple = new byte[2][0];
tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index
...@@ -208,11 +208,11 @@ public class Array implements java.sql.Array ...@@ -208,11 +208,11 @@ public class Array implements java.sql.Array
rows.addElement(tuple); rows.addElement(tuple);
} }
case Types.SMALLINT: case Types.SMALLINT:
fields[1] = new Field(conn, "VALUE", conn.getOID("int2"), 2); fields[1] = new Field(conn, "VALUE", field.getOID("int2"), 2);
case Types.INTEGER: case Types.INTEGER:
int[] intArray = (int[]) array; int[] intArray = (int[]) array;
if( fields[1] == null ) if( fields[1] == null )
fields[1] = new Field(conn, "VALUE", conn.getOID("int4"), 4); fields[1] = new Field(conn, "VALUE", field.getOID("int4"), 4);
for( int i=0; i<intArray.length; i++ ) { for( int i=0; i<intArray.length; i++ ) {
byte[][] tuple = new byte[2][0]; byte[][] tuple = new byte[2][0];
tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index
...@@ -222,7 +222,7 @@ public class Array implements java.sql.Array ...@@ -222,7 +222,7 @@ public class Array implements java.sql.Array
break; break;
case Types.BIGINT: case Types.BIGINT:
long[] longArray = (long[]) array; long[] longArray = (long[]) array;
fields[1] = new Field(conn, "VALUE", conn.getOID("int8"), 8); fields[1] = new Field(conn, "VALUE", field.getOID("int8"), 8);
for( int i=0; i<longArray.length; i++ ) { for( int i=0; i<longArray.length; i++ ) {
byte[][] tuple = new byte[2][0]; byte[][] tuple = new byte[2][0];
tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index
...@@ -232,7 +232,7 @@ public class Array implements java.sql.Array ...@@ -232,7 +232,7 @@ public class Array implements java.sql.Array
break; break;
case Types.NUMERIC: case Types.NUMERIC:
BigDecimal[] bdArray = (BigDecimal[]) array; BigDecimal[] bdArray = (BigDecimal[]) array;
fields[1] = new Field(conn, "VALUE", conn.getOID("numeric"), -1); fields[1] = new Field(conn, "VALUE", field.getOID("numeric"), -1);
for( int i=0; i<bdArray.length; i++ ) { for( int i=0; i<bdArray.length; i++ ) {
byte[][] tuple = new byte[2][0]; byte[][] tuple = new byte[2][0];
tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index
...@@ -242,7 +242,7 @@ public class Array implements java.sql.Array ...@@ -242,7 +242,7 @@ public class Array implements java.sql.Array
break; break;
case Types.REAL: case Types.REAL:
float[] floatArray = (float[]) array; float[] floatArray = (float[]) array;
fields[1] = new Field(conn, "VALUE", conn.getOID("float4"), 4); fields[1] = new Field(conn, "VALUE", field.getOID("float4"), 4);
for( int i=0; i<floatArray.length; i++ ) { for( int i=0; i<floatArray.length; i++ ) {
byte[][] tuple = new byte[2][0]; byte[][] tuple = new byte[2][0];
tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index
...@@ -252,7 +252,7 @@ public class Array implements java.sql.Array ...@@ -252,7 +252,7 @@ public class Array implements java.sql.Array
break; break;
case Types.DOUBLE: case Types.DOUBLE:
double[] doubleArray = (double[]) array; double[] doubleArray = (double[]) array;
fields[1] = new Field(conn, "VALUE", conn.getOID("float8"), 8); fields[1] = new Field(conn, "VALUE", field.getOID("float8"), 8);
for( int i=0; i<doubleArray.length; i++ ) { for( int i=0; i<doubleArray.length; i++ ) {
byte[][] tuple = new byte[2][0]; byte[][] tuple = new byte[2][0];
tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index
...@@ -261,11 +261,11 @@ public class Array implements java.sql.Array ...@@ -261,11 +261,11 @@ public class Array implements java.sql.Array
} }
break; break;
case Types.CHAR: case Types.CHAR:
fields[1] = new Field(conn, "VALUE", conn.getOID("char"), 1); fields[1] = new Field(conn, "VALUE", field.getOID("char"), 1);
case Types.VARCHAR: case Types.VARCHAR:
String[] strArray = (String[]) array; String[] strArray = (String[]) array;
if( fields[1] == null ) if( fields[1] == null )
fields[1] = new Field(conn, "VALUE", conn.getOID("varchar"), -1); fields[1] = new Field(conn, "VALUE", field.getOID("varchar"), -1);
for( int i=0; i<strArray.length; i++ ) { for( int i=0; i<strArray.length; i++ ) {
byte[][] tuple = new byte[2][0]; byte[][] tuple = new byte[2][0];
tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index
...@@ -275,7 +275,7 @@ public class Array implements java.sql.Array ...@@ -275,7 +275,7 @@ public class Array implements java.sql.Array
break; break;
case Types.DATE: case Types.DATE:
java.sql.Date[] dateArray = (java.sql.Date[]) array; java.sql.Date[] dateArray = (java.sql.Date[]) array;
fields[1] = new Field(conn, "VALUE", conn.getOID("date"), 4); fields[1] = new Field(conn, "VALUE", field.getOID("date"), 4);
for( int i=0; i<dateArray.length; i++ ) { for( int i=0; i<dateArray.length; i++ ) {
byte[][] tuple = new byte[2][0]; byte[][] tuple = new byte[2][0];
tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index
...@@ -285,7 +285,7 @@ public class Array implements java.sql.Array ...@@ -285,7 +285,7 @@ public class Array implements java.sql.Array
break; break;
case Types.TIME: case Types.TIME:
java.sql.Time[] timeArray = (java.sql.Time[]) array; java.sql.Time[] timeArray = (java.sql.Time[]) array;
fields[1] = new Field(conn, "VALUE", conn.getOID("time"), 8); fields[1] = new Field(conn, "VALUE", field.getOID("time"), 8);
for( int i=0; i<timeArray.length; i++ ) { for( int i=0; i<timeArray.length; i++ ) {
byte[][] tuple = new byte[2][0]; byte[][] tuple = new byte[2][0];
tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index
...@@ -295,7 +295,7 @@ public class Array implements java.sql.Array ...@@ -295,7 +295,7 @@ public class Array implements java.sql.Array
break; break;
case Types.TIMESTAMP: case Types.TIMESTAMP:
java.sql.Timestamp[] timestampArray = (java.sql.Timestamp[]) array; java.sql.Timestamp[] timestampArray = (java.sql.Timestamp[]) array;
fields[1] = new Field(conn, "VALUE", conn.getOID("timestamp"), 8); fields[1] = new Field(conn, "VALUE", field.getOID("timestamp"), 8);
for( int i=0; i<timestampArray.length; i++ ) { for( int i=0; i<timestampArray.length; i++ ) {
byte[][] tuple = new byte[2][0]; byte[][] tuple = new byte[2][0];
tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index tuple[0] = conn.getEncoding().encode( Integer.toString((int)index+i) ); // Index
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment