summaryrefslogtreecommitdiff
path: root/ndb/src
diff options
context:
space:
mode:
authorunknown <pekka@mysql.com>2005-01-27 17:33:35 +0100
committerunknown <pekka@mysql.com>2005-01-27 17:33:35 +0100
commit1ed40339e24296a51b4e22bbb434aa2752c19601 (patch)
treef684c24c22c9b9e6b1adca165b5c94327a77ce29 /ndb/src
parent4e5a513c4dbe661788841c8d3f8c994c0e7a23d9 (diff)
downloadmariadb-git-1ed40339e24296a51b4e22bbb434aa2752c19601.tar.gz
ndb - make YEAR and TIMESTAMP into ndb types
mysql-test/r/ndb_index_ordered.result: make YEAR and TIMESTAMP into ndb types mysql-test/t/ndb_index_ordered.test: make YEAR and TIMESTAMP into ndb types ndb/include/kernel/signaldata/DictTabInfo.hpp: make YEAR and TIMESTAMP into ndb types ndb/include/ndbapi/NdbDictionary.hpp: make YEAR and TIMESTAMP into ndb types ndb/include/util/NdbSqlUtil.hpp: make YEAR and TIMESTAMP into ndb types ndb/src/common/util/NdbSqlUtil.cpp: make YEAR and TIMESTAMP into ndb types ndb/src/ndbapi/NdbDictionary.cpp: make YEAR and TIMESTAMP into ndb types ndb/src/ndbapi/NdbDictionaryImpl.cpp: make YEAR and TIMESTAMP into ndb types ndb/src/ndbapi/NdbRecAttr.cpp: make YEAR and TIMESTAMP into ndb types ndb/test/include/NdbSchemaOp.hpp: make YEAR and TIMESTAMP into ndb types sql/ha_ndbcluster.cc: make YEAR and TIMESTAMP into ndb types
Diffstat (limited to 'ndb/src')
-rw-r--r--ndb/src/common/util/NdbSqlUtil.cpp36
-rw-r--r--ndb/src/ndbapi/NdbDictionary.cpp6
-rw-r--r--ndb/src/ndbapi/NdbDictionaryImpl.cpp4
-rw-r--r--ndb/src/ndbapi/NdbRecAttr.cpp85
4 files changed, 123 insertions, 8 deletions
diff --git a/ndb/src/common/util/NdbSqlUtil.cpp b/ndb/src/common/util/NdbSqlUtil.cpp
index 233698ae52b..6b23da774af 100644
--- a/ndb/src/common/util/NdbSqlUtil.cpp
+++ b/ndb/src/common/util/NdbSqlUtil.cpp
@@ -179,6 +179,14 @@ NdbSqlUtil::m_typeList[] = {
{
Type::Time,
cmpTime
+ },
+ {
+ Type::Year,
+ cmpYear
+ },
+ {
+ Type::Timestamp,
+ cmpTimestamp
}
};
@@ -592,6 +600,34 @@ NdbSqlUtil::cmpTime(const void* info, const Uint32* p1, const Uint32* p2, Uint32
return 0;
}
+int
+NdbSqlUtil::cmpYear(const void* info, const Uint32* p1, const Uint32* p2, Uint32 full, Uint32 size)
+{
+ assert(full >= size && size > 0);
+ union { const Uint32* p; const unsigned char* v; } u1, u2;
+ u1.p = p1;
+ u2.p = p2;
+ if (u1.v[0] < u2.v[0])
+ return -1;
+ if (u1.v[0] > u2.v[0])
+ return +1;
+ return 0;
+}
+
+int
+NdbSqlUtil::cmpTimestamp(const void* info, const Uint32* p1, const Uint32* p2, Uint32 full, Uint32 size)
+{
+ assert(full >= size && size > 0);
+ union { Uint32 p[1]; Uint32 v; } u1, u2;
+ u1.v = p1[0];
+ u2.v = p2[0];
+ if (u1.v < u2.v)
+ return -1;
+ if (u1.v > u2.v)
+ return +1;
+ return 0;
+}
+
// check charset
bool
diff --git a/ndb/src/ndbapi/NdbDictionary.cpp b/ndb/src/ndbapi/NdbDictionary.cpp
index 0508d8bf277..58b35c6c306 100644
--- a/ndb/src/ndbapi/NdbDictionary.cpp
+++ b/ndb/src/ndbapi/NdbDictionary.cpp
@@ -950,6 +950,12 @@ operator<<(NdbOut& out, const NdbDictionary::Column& col)
case NdbDictionary::Column::Time:
out << "Time";
break;
+ case NdbDictionary::Column::Year:
+ out << "Year";
+ break;
+ case NdbDictionary::Column::Timestamp:
+ out << "Timestamp";
+ break;
case NdbDictionary::Column::Undefined:
out << "Undefined";
break;
diff --git a/ndb/src/ndbapi/NdbDictionaryImpl.cpp b/ndb/src/ndbapi/NdbDictionaryImpl.cpp
index 59474943f3b..9f6ed144fb0 100644
--- a/ndb/src/ndbapi/NdbDictionaryImpl.cpp
+++ b/ndb/src/ndbapi/NdbDictionaryImpl.cpp
@@ -149,6 +149,8 @@ NdbColumnImpl::init(Type t)
m_cs = default_cs;
break;
case Time:
+ case Year:
+ case Timestamp:
m_precision = 0;
m_scale = 0;
m_length = 1;
@@ -1184,6 +1186,8 @@ columnTypeMapping[] = {
{ DictTabInfo::ExtBlob, NdbDictionary::Column::Blob },
{ DictTabInfo::ExtText, NdbDictionary::Column::Text },
{ DictTabInfo::ExtTime, NdbDictionary::Column::Time },
+ { DictTabInfo::ExtYear, NdbDictionary::Column::Year },
+ { DictTabInfo::ExtTimestamp, NdbDictionary::Column::Timestamp },
{ -1, -1 }
};
diff --git a/ndb/src/ndbapi/NdbRecAttr.cpp b/ndb/src/ndbapi/NdbRecAttr.cpp
index f2427fb32e8..6749a0f04d9 100644
--- a/ndb/src/ndbapi/NdbRecAttr.cpp
+++ b/ndb/src/ndbapi/NdbRecAttr.cpp
@@ -156,10 +156,11 @@ NdbOut& operator<<(NdbOut& out, const NdbRecAttr &r)
return out;
}
- if (r.arraySize() > 1)
+ uint length = r.getColumn()->getLength();
+ if (length > 1)
out << "[";
- for (Uint32 j = 0; j < r.arraySize(); j++)
+ for (Uint32 j = 0; j < length; j++)
{
if (j > 0)
out << " ";
@@ -192,14 +193,14 @@ NdbOut& operator<<(NdbOut& out, const NdbRecAttr &r)
break;
case NdbDictionary::Column::Char:
out.print("%.*s", r.arraySize(), r.aRef());
- j = r.arraySize();
+ j = length;
break;
case NdbDictionary::Column::Varchar:
{
short len = ntohs(r.u_short_value());
out.print("%.*s", len, r.aRef()+2);
}
- j = r.arraySize();
+ j = length;
break;
case NdbDictionary::Column::Float:
out << r.float_value();
@@ -207,6 +208,74 @@ NdbOut& operator<<(NdbOut& out, const NdbRecAttr &r)
case NdbDictionary::Column::Double:
out << r.double_value();
break;
+ // for dates cut-and-paste from field.cc
+ case NdbDictionary::Column::Datetime:
+ {
+ ulonglong tmp=r.u_64_value();
+ long part1,part2,part3;
+ part1=(long) (tmp/LL(1000000));
+ part2=(long) (tmp - (ulonglong) part1*LL(1000000));
+ char buf[40];
+ char* pos=(char*) buf+19;
+ *pos--=0;
+ *pos--= (char) ('0'+(char) (part2%10)); part2/=10;
+ *pos--= (char) ('0'+(char) (part2%10)); part3= (int) (part2 / 10);
+ *pos--= ':';
+ *pos--= (char) ('0'+(char) (part3%10)); part3/=10;
+ *pos--= (char) ('0'+(char) (part3%10)); part3/=10;
+ *pos--= ':';
+ *pos--= (char) ('0'+(char) (part3%10)); part3/=10;
+ *pos--= (char) ('0'+(char) part3);
+ *pos--= '/';
+ *pos--= (char) ('0'+(char) (part1%10)); part1/=10;
+ *pos--= (char) ('0'+(char) (part1%10)); part1/=10;
+ *pos--= '-';
+ *pos--= (char) ('0'+(char) (part1%10)); part1/=10;
+ *pos--= (char) ('0'+(char) (part1%10)); part3= (int) (part1/10);
+ *pos--= '-';
+ *pos--= (char) ('0'+(char) (part3%10)); part3/=10;
+ *pos--= (char) ('0'+(char) (part3%10)); part3/=10;
+ *pos--= (char) ('0'+(char) (part3%10)); part3/=10;
+ *pos=(char) ('0'+(char) part3);
+ out << buf;
+ }
+ break;
+ case NdbDictionary::Column::Date:
+ {
+ uint tmp=uint3korr(r.aRef());
+ int year=(int) ((uint32) tmp/10000L % 10000);
+ int month=(int) ((uint32) tmp/100 % 100);
+ int day=(int) ((uint32) tmp % 100);
+ char buf[40];
+ sprintf(buf, "%04d-%02d-%02d", year, month, day);
+ out << buf;
+ }
+ break;
+ case NdbDictionary::Column::Time:
+ {
+ long tmp=(long) sint3korr(r.aRef());
+ int hour=(uint) (tmp/10000);
+ int minute=(uint) (tmp/100 % 100);
+ int second=(uint) (tmp % 100);
+ char buf[40];
+ sprintf(buf, "%02d:%02d:%02d", hour, minute, second);
+ out << buf;
+ }
+ break;
+ case NdbDictionary::Column::Year:
+ {
+ uint year = 1900 + r.u_char_value();
+ char buf[40];
+ sprintf(buf, "%04d", year);
+ out << buf;
+ }
+ break;
+ case NdbDictionary::Column::Timestamp:
+ {
+ time_t time = r.u_32_value();
+ out << (uint)time;
+ }
+ break;
case NdbDictionary::Column::Blob:
{
const NdbBlob::Head* h = (const NdbBlob::Head*)r.aRef();
@@ -215,7 +284,7 @@ NdbOut& operator<<(NdbOut& out, const NdbRecAttr &r)
unsigned n = r.arraySize() - sizeof(*h);
for (unsigned k = 0; k < n && k < h->length; k++)
out.print("%02X", (int)p[k]);
- j = r.arraySize();
+ j = length;
}
break;
case NdbDictionary::Column::Text:
@@ -226,19 +295,19 @@ NdbOut& operator<<(NdbOut& out, const NdbRecAttr &r)
unsigned n = r.arraySize() - sizeof(*h);
for (unsigned k = 0; k < n && k < h->length; k++)
out.print("%c", (int)p[k]);
- j = r.arraySize();
+ j = length;
}
break;
default: /* no print functions for the rest, just print type */
out << (int) r.getType();
- j = r.arraySize();
+ j = length;
if (j > 1)
out << " " << j << " times";
break;
}
}
- if (r.arraySize() > 1)
+ if (length > 1)
{
out << "]";
}