summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <ingo@mysql.com>2004-06-25 12:59:47 +0200
committerunknown <ingo@mysql.com>2004-06-25 12:59:47 +0200
commitfb987c8907c55d974b189ccd5e9c891f8dee7a14 (patch)
tree1d74a4c02a5562fbb2989c5a7d17269c1f40161d /sql
parent098a1e3afa7a911c39dca37bad084f6c171f7c44 (diff)
parentafe29967e03d5c936c378fff9ea4e4bcf7e9251e (diff)
downloadmariadb-git-fb987c8907c55d974b189ccd5e9c891f8dee7a14.tar.gz
Merge
sql/ha_berkeley.cc: Auto merged mysql-test/r/bdb.result: SCCS merged mysql-test/t/bdb.test: SCCS merged
Diffstat (limited to 'sql')
-rw-r--r--sql/field.cc80
-rw-r--r--sql/field.h6
-rw-r--r--sql/ha_berkeley.cc4
3 files changed, 88 insertions, 2 deletions
diff --git a/sql/field.cc b/sql/field.cc
index 7273c9036c4..e3bdf78e718 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -4167,6 +4167,42 @@ uint32 Field_blob::get_length(const char *pos)
}
+/*
+ Put a blob length field into a record buffer.
+
+ SYNOPSIS
+ Field_blob::put_length()
+ pos Pointer into the record buffer.
+ length The length value to put.
+
+ DESCRIPTION
+ Depending on the maximum length of a blob, its length field is
+ put into 1 to 4 bytes. This is a property of the blob object,
+ described by 'packlength'.
+
+ RETURN
+ nothing
+*/
+
+void Field_blob::put_length(char *pos, uint32 length)
+{
+ switch (packlength) {
+ case 1:
+ *pos= (char) length;
+ break;
+ case 2:
+ int2store(pos, length);
+ break;
+ case 3:
+ int3store(pos, length);
+ break;
+ case 4:
+ int4store(pos, length);
+ break;
+ }
+}
+
+
void Field_blob::store(const char *from,uint len)
{
if (!len)
@@ -4525,6 +4561,50 @@ char *Field_blob::pack_key(char *to, const char *from, uint max_length)
return to+length;
}
+
+/*
+ Unpack a blob key into a record buffer.
+
+ SYNOPSIS
+ Field_blob::unpack_key()
+ to Pointer into the record buffer.
+ from Pointer to the packed key.
+ max_length Key length limit from key description.
+
+ DESCRIPTION
+ A blob key has a maximum size of 64K-1.
+ In its packed form, the length field is one or two bytes long,
+ depending on 'max_length'.
+ Depending on the maximum length of a blob, its length field is
+ put into 1 to 4 bytes. This is a property of the blob object,
+ described by 'packlength'.
+ Blobs are internally stored apart from the record buffer, which
+ contains a pointer to the blob buffer.
+
+ RETURN
+ Pointer into 'from' past the last byte copied from packed key.
+*/
+
+const char *Field_blob::unpack_key(char *to, const char *from, uint max_length)
+{
+ /* get length of the blob key */
+ uint32 length= *((uchar*) from++);
+ if (max_length > 255)
+ length+= (*((uchar*) from++)) << 8;
+
+ /* put the length into the record buffer */
+ put_length(to, length);
+
+ /* put the address of the blob buffer or NULL */
+ if (length)
+ memcpy_fixed(to + packlength, &from, sizeof(from));
+ else
+ bzero(to + packlength, sizeof(from));
+
+ /* point to first byte of next field in 'from' */
+ return from + length;
+}
+
/* Create a packed key that will be used for storage from a MySQL key */
char *Field_blob::pack_key_from_key_image(char *to, const char *from,
diff --git a/sql/field.h b/sql/field.h
index 5a1ab163266..d93ed1db9b5 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -189,6 +189,10 @@ public:
{
return pack(to,from,max_length);
}
+ virtual const char *unpack_key(char* to, const char *from, uint max_length)
+ {
+ return unpack(to,from);
+ }
virtual uint packed_col_length(const char *to, uint length)
{ return length;}
virtual uint max_packed_col_length(uint max_length)
@@ -890,6 +894,7 @@ public:
inline uint32 get_length(uint row_offset=0)
{ return get_length(ptr+row_offset); }
uint32 get_length(const char *ptr);
+ void put_length(char *pos, uint32 length);
bool binary() const { return binary_flag; }
inline void get_ptr(char **str)
{
@@ -923,6 +928,7 @@ public:
const char *unpack(char *to, const char *from);
char *pack_key(char *to, const char *from, uint max_length);
char *pack_key_from_key_image(char* to, const char *from, uint max_length);
+ const char *unpack_key(char* to, const char *from, uint max_length);
int pack_cmp(const char *a, const char *b, uint key_length);
int pack_cmp(const char *b, uint key_length);
uint packed_col_length(const char *col_ptr, uint length);
diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc
index 18af688d07c..b307b3a4b75 100644
--- a/sql/ha_berkeley.cc
+++ b/sql/ha_berkeley.cc
@@ -720,8 +720,8 @@ void ha_berkeley::unpack_key(char *record, DBT *key, uint index)
}
record[key_part->null_offset]&= ~key_part->null_bit;
}
- pos= (char*) key_part->field->unpack(record + key_part->field->offset(),
- pos);
+ pos= (char*) key_part->field->unpack_key(record + key_part->field->offset(),
+ pos, key_part->length);
}
}