Commit b82dede5 authored by unknown's avatar unknown

ndb: set column type sets column defaults

parent 4f5bbc54
...@@ -46,9 +46,9 @@ ...@@ -46,9 +46,9 @@
* *
* NdbDictionary::Column * NdbDictionary::Column
* setName() * setName()
* setPrimaryKey()
* setType() * setType()
* setLength() * setLength()
* setPrimaryKey()
* setNullable() * setNullable()
* *
* NdbDictionary::Table * NdbDictionary::Table
...@@ -234,9 +234,9 @@ int create_table(Ndb * myNdb) ...@@ -234,9 +234,9 @@ int create_table(Ndb * myNdb)
* Column REG_NO * Column REG_NO
*/ */
myColumn.setName("REG_NO"); myColumn.setName("REG_NO");
myColumn.setPrimaryKey(true);
myColumn.setType(NdbDictionary::Column::Unsigned); myColumn.setType(NdbDictionary::Column::Unsigned);
myColumn.setLength(1); myColumn.setLength(1);
myColumn.setPrimaryKey(true);
myColumn.setNullable(false); myColumn.setNullable(false);
myTable.addColumn(myColumn); myTable.addColumn(myColumn);
...@@ -244,9 +244,9 @@ int create_table(Ndb * myNdb) ...@@ -244,9 +244,9 @@ int create_table(Ndb * myNdb)
* Column BRAND * Column BRAND
*/ */
myColumn.setName("BRAND"); myColumn.setName("BRAND");
myColumn.setPrimaryKey(false);
myColumn.setType(NdbDictionary::Column::Char); myColumn.setType(NdbDictionary::Column::Char);
myColumn.setLength(20); myColumn.setLength(20);
myColumn.setPrimaryKey(false);
myColumn.setNullable(false); myColumn.setNullable(false);
myTable.addColumn(myColumn); myTable.addColumn(myColumn);
...@@ -254,9 +254,9 @@ int create_table(Ndb * myNdb) ...@@ -254,9 +254,9 @@ int create_table(Ndb * myNdb)
* Column COLOR * Column COLOR
*/ */
myColumn.setName("COLOR"); myColumn.setName("COLOR");
myColumn.setPrimaryKey(false);
myColumn.setType(NdbDictionary::Column::Char); myColumn.setType(NdbDictionary::Column::Char);
myColumn.setLength(20); myColumn.setLength(20);
myColumn.setPrimaryKey(false);
myColumn.setNullable(false); myColumn.setNullable(false);
myTable.addColumn(myColumn); myTable.addColumn(myColumn);
...@@ -494,5 +494,3 @@ int main() ...@@ -494,5 +494,3 @@ int main()
std::cout << "Number of temporary errors: " << tempErrors << std::endl; std::cout << "Number of temporary errors: " << tempErrors << std::endl;
delete myNdb; delete myNdb;
} }
...@@ -79,16 +79,16 @@ int main() ...@@ -79,16 +79,16 @@ int main()
myTable.setName("MYTABLENAME"); myTable.setName("MYTABLENAME");
myColumn.setName("ATTR1"); myColumn.setName("ATTR1");
myColumn.setPrimaryKey(true);
myColumn.setType(NdbDictionary::Column::Unsigned); myColumn.setType(NdbDictionary::Column::Unsigned);
myColumn.setLength(1); myColumn.setLength(1);
myColumn.setPrimaryKey(true);
myColumn.setNullable(false); myColumn.setNullable(false);
myTable.addColumn(myColumn); myTable.addColumn(myColumn);
myColumn.setName("ATTR2"); myColumn.setName("ATTR2");
myColumn.setPrimaryKey(false);
myColumn.setType(NdbDictionary::Column::Unsigned); myColumn.setType(NdbDictionary::Column::Unsigned);
myColumn.setLength(1); myColumn.setLength(1);
myColumn.setPrimaryKey(false);
myColumn.setNullable(false); myColumn.setNullable(false);
myTable.addColumn(myColumn); myTable.addColumn(myColumn);
......
...@@ -80,16 +80,16 @@ int main() ...@@ -80,16 +80,16 @@ int main()
myTable.setName("MYTABLENAME"); myTable.setName("MYTABLENAME");
myColumn.setName("ATTR1"); myColumn.setName("ATTR1");
myColumn.setPrimaryKey(true);
myColumn.setType(NdbDictionary::Column::Unsigned); myColumn.setType(NdbDictionary::Column::Unsigned);
myColumn.setLength(1); myColumn.setLength(1);
myColumn.setPrimaryKey(true);
myColumn.setNullable(false); myColumn.setNullable(false);
myTable.addColumn(myColumn); myTable.addColumn(myColumn);
myColumn.setName("ATTR2"); myColumn.setName("ATTR2");
myColumn.setPrimaryKey(false);
myColumn.setType(NdbDictionary::Column::Unsigned); myColumn.setType(NdbDictionary::Column::Unsigned);
myColumn.setLength(1); myColumn.setLength(1);
myColumn.setPrimaryKey(false);
myColumn.setNullable(false); myColumn.setNullable(false);
myTable.addColumn(myColumn); myTable.addColumn(myColumn);
......
...@@ -47,9 +47,9 @@ ...@@ -47,9 +47,9 @@
* *
* NdbDictionary::Column * NdbDictionary::Column
* setName() * setName()
* setPrimaryKey()
* setType() * setType()
* setLength() * setLength()
* setPrimaryKey()
* setNullable() * setNullable()
* *
* NdbDictionary::Table * NdbDictionary::Table
...@@ -165,24 +165,24 @@ int create_table(Ndb * myNdb) ...@@ -165,24 +165,24 @@ int create_table(Ndb * myNdb)
myTable.setName("GARAGE"); myTable.setName("GARAGE");
myColumn.setName("REG_NO"); myColumn.setName("REG_NO");
myColumn.setPrimaryKey(true);
myColumn.setType(NdbDictionary::Column::Unsigned); myColumn.setType(NdbDictionary::Column::Unsigned);
myColumn.setLength(1); myColumn.setLength(1);
myColumn.setPrimaryKey(true);
myColumn.setNullable(false); myColumn.setNullable(false);
myTable.addColumn(myColumn); myTable.addColumn(myColumn);
myColumn.setName("BRAND"); myColumn.setName("BRAND");
myColumn.setPrimaryKey(false);
myColumn.setType(NdbDictionary::Column::Char); myColumn.setType(NdbDictionary::Column::Char);
myColumn.setLength(20); myColumn.setLength(20);
myColumn.setPrimaryKey(false);
myColumn.setNullable(false); myColumn.setNullable(false);
myTable.addColumn(myColumn); myTable.addColumn(myColumn);
myColumn.setName("COLOR"); myColumn.setName("COLOR");
myColumn.setPrimaryKey(false);
myColumn.setType(NdbDictionary::Column::Char); myColumn.setType(NdbDictionary::Column::Char);
myColumn.setLength(20); myColumn.setLength(20);
myColumn.setPrimaryKey(false);
myColumn.setNullable(false); myColumn.setNullable(false);
myTable.addColumn(myColumn); myTable.addColumn(myColumn);
...@@ -814,4 +814,3 @@ int main() ...@@ -814,4 +814,3 @@ int main()
delete myNdb; delete myNdb;
} }
...@@ -257,6 +257,10 @@ public: ...@@ -257,6 +257,10 @@ public:
/** /**
* Set type of column * Set type of column
* @param type Type of column * @param type Type of column
*
* @note setType resets <em>all</em> column attributes
* to (type dependent) defaults and should be the first
* method to call. Default type is Unsigned.
*/ */
void setType(Type type); void setType(Type type);
...@@ -306,23 +310,23 @@ public: ...@@ -306,23 +310,23 @@ public:
* to store in table's blob attribute. This part is normally in * to store in table's blob attribute. This part is normally in
* main memory and can be indexed and interpreted. * main memory and can be indexed and interpreted.
*/ */
void setInlineSize(int size) { setPrecision(size); } void setInlineSize(int size);
int getInlineSize() const { return getPrecision(); } int getInlineSize() const;
/** /**
* For blob, set or get "part size" i.e. number of bytes to store in * For blob, set or get "part size" i.e. number of bytes to store in
* each tuple of the "blob table". Can be set to zero to omit parts * each tuple of the "blob table". Can be set to zero to omit parts
* and to allow only inline bytes ("tinyblob"). * and to allow only inline bytes ("tinyblob").
*/ */
void setPartSize(int size) { setScale(size); } void setPartSize(int size);
int getPartSize() const { return getScale(); } int getPartSize() const;
/** /**
* For blob, set or get "stripe size" i.e. number of consecutive * For blob, set or get "stripe size" i.e. number of consecutive
* <em>parts</em> to store in each node group. * <em>parts</em> to store in each node group.
*/ */
void setStripeSize(int size) { setLength(size); } void setStripeSize(int size);
int getStripeSize() const { return getLength(); } int getStripeSize() const;
/** /**
* Get size of element * Get size of element
......
...@@ -65,7 +65,7 @@ NdbDictionary::Column::getName() const { ...@@ -65,7 +65,7 @@ NdbDictionary::Column::getName() const {
void void
NdbDictionary::Column::setType(Type t){ NdbDictionary::Column::setType(Type t){
m_impl.m_type = t; m_impl.init(t);
} }
NdbDictionary::Column::Type NdbDictionary::Column::Type
...@@ -103,6 +103,42 @@ NdbDictionary::Column::getLength() const{ ...@@ -103,6 +103,42 @@ NdbDictionary::Column::getLength() const{
return m_impl.m_length; return m_impl.m_length;
} }
void
NdbDictionary::Column::setInlineSize(int size)
{
m_impl.m_precision = size;
}
int
NdbDictionary::Column::getInlineSize() const
{
return m_impl.m_precision;
}
void
NdbDictionary::Column::setPartSize(int size)
{
m_impl.m_scale = size;
}
int
NdbDictionary::Column::getPartSize() const
{
return m_impl.m_scale;
}
void
NdbDictionary::Column::setStripeSize(int size)
{
m_impl.m_length = size;
}
int
NdbDictionary::Column::getStripeSize() const
{
return m_impl.m_length;
}
int int
NdbDictionary::Column::getSize() const{ NdbDictionary::Column::getSize() const{
return m_impl.m_attrSize; return m_impl.m_attrSize;
......
...@@ -87,10 +87,57 @@ NdbColumnImpl::operator=(const NdbColumnImpl& col) ...@@ -87,10 +87,57 @@ NdbColumnImpl::operator=(const NdbColumnImpl& col)
} }
void void
NdbColumnImpl::init() NdbColumnImpl::init(Type t)
{ {
m_attrId = -1; m_attrId = -1;
m_type = NdbDictionary::Column::Unsigned; m_type = t;
switch (m_type) {
case Tinyint:
case Tinyunsigned:
case Smallint:
case Smallunsigned:
case Mediumint:
case Mediumunsigned:
case Int:
case Unsigned:
case Bigint:
case Bigunsigned:
case Float:
case Double:
m_precision = 0;
m_scale = 0;
m_length = 1;
break;
case Decimal:
m_precision = 10;
m_scale = 0;
m_length = 1;
break;
case Char:
case Varchar:
m_precision = 0;
m_scale = 0;
m_length = 1;
break;
case Binary:
case Varbinary:
case Datetime:
case Timespec:
m_precision = 0;
m_scale = 0;
m_length = 1;
break;
case Blob:
m_precision = 256;
m_scale = 8000;
m_length = 4;
break;
case Text:
m_precision = 256;
m_scale = 8000;
m_length = 4;
break;
}
m_pk = false; m_pk = false;
m_nullable = false; m_nullable = false;
m_tupleKey = false; m_tupleKey = false;
...@@ -98,12 +145,10 @@ NdbColumnImpl::init() ...@@ -98,12 +145,10 @@ NdbColumnImpl::init()
m_distributionKey = false; m_distributionKey = false;
m_distributionGroup = false; m_distributionGroup = false;
m_distributionGroupBits = 8; m_distributionGroupBits = 8;
m_length = 1;
m_scale = 5;
m_precision = 5;
m_keyInfoPos = 0; m_keyInfoPos = 0;
m_attrSize = 4, // next 2 are set at run time
m_arraySize = 1, m_attrSize = 0;
m_arraySize = 0;
m_autoIncrement = false; m_autoIncrement = false;
m_autoIncrementInitialValue = 1; m_autoIncrementInitialValue = 1;
m_blobTable = NULL; m_blobTable = NULL;
...@@ -209,14 +254,18 @@ NdbColumnImpl::create_psuedo(const char * name){ ...@@ -209,14 +254,18 @@ NdbColumnImpl::create_psuedo(const char * name){
if(!strcmp(name, "NDB$FRAGMENT")){ if(!strcmp(name, "NDB$FRAGMENT")){
col->setType(NdbDictionary::Column::Unsigned); col->setType(NdbDictionary::Column::Unsigned);
col->m_impl.m_attrId = AttributeHeader::FRAGMENT; col->m_impl.m_attrId = AttributeHeader::FRAGMENT;
col->m_impl.m_attrSize = 4;
col->m_impl.m_arraySize = 1;
} else if(!strcmp(name, "NDB$ROW_COUNT")){ } else if(!strcmp(name, "NDB$ROW_COUNT")){
col->setType(NdbDictionary::Column::Bigunsigned); col->setType(NdbDictionary::Column::Bigunsigned);
col->m_impl.m_attrId = AttributeHeader::ROW_COUNT; col->m_impl.m_attrId = AttributeHeader::ROW_COUNT;
col->m_impl.m_attrSize = 8; col->m_impl.m_attrSize = 8;
col->m_impl.m_arraySize = 1;
} else if(!strcmp(name, "NDB$COMMIT_COUNT")){ } else if(!strcmp(name, "NDB$COMMIT_COUNT")){
col->setType(NdbDictionary::Column::Bigunsigned); col->setType(NdbDictionary::Column::Bigunsigned);
col->m_impl.m_attrId = AttributeHeader::COMMIT_COUNT; col->m_impl.m_attrId = AttributeHeader::COMMIT_COUNT;
col->m_impl.m_attrSize = 8; col->m_impl.m_attrSize = 8;
col->m_impl.m_arraySize = 1;
} else { } else {
abort(); abort();
} }
......
...@@ -52,7 +52,7 @@ public: ...@@ -52,7 +52,7 @@ public:
NdbColumnImpl(NdbDictionary::Column &); // This is not a copy constructor NdbColumnImpl(NdbDictionary::Column &); // This is not a copy constructor
~NdbColumnImpl(); ~NdbColumnImpl();
NdbColumnImpl& operator=(const NdbColumnImpl&); NdbColumnImpl& operator=(const NdbColumnImpl&);
void init(); void init(Type t = Unsigned);
int m_attrId; int m_attrId;
BaseString m_name; BaseString m_name;
......
...@@ -33,10 +33,10 @@ public: ...@@ -33,10 +33,10 @@ public:
{ {
assert(_name != 0); assert(_name != 0);
setType(_type);
setLength(_length);
setNullable(_nullable); setNullable(_nullable);
setPrimaryKey(_pk); setPrimaryKey(_pk);
setLength(_length);
setType(_type);
} }
}; };
......
...@@ -81,63 +81,63 @@ static void createTable(Ndb &myNdb, bool storeInACC, bool twoKey, bool longKey) ...@@ -81,63 +81,63 @@ static void createTable(Ndb &myNdb, bool storeInACC, bool twoKey, bool longKey)
int res; int res;
column.setName("NAME"); column.setName("NAME");
column.setPrimaryKey(true);
column.setType(NdbDictionary::Column::Char); column.setType(NdbDictionary::Column::Char);
column.setLength((longKey)? column.setLength((longKey)?
1024 // 1KB => long key 1024 // 1KB => long key
:12); :12);
column.setPrimaryKey(true);
column.setNullable(false); column.setNullable(false);
table.addColumn(column); table.addColumn(column);
if (twoKey) { if (twoKey) {
column.setName("KEY2"); column.setName("KEY2");
column.setPrimaryKey(true);
column.setType(NdbDictionary::Column::Unsigned); column.setType(NdbDictionary::Column::Unsigned);
column.setLength(1); column.setLength(1);
column.setPrimaryKey(true);
column.setNullable(false); column.setNullable(false);
table.addColumn(column); table.addColumn(column);
} }
column.setName("PNUM1"); column.setName("PNUM1");
column.setPrimaryKey(false);
column.setType(NdbDictionary::Column::Unsigned); column.setType(NdbDictionary::Column::Unsigned);
column.setLength(1); column.setLength(1);
column.setPrimaryKey(false);
column.setNullable(false); column.setNullable(false);
table.addColumn(column); table.addColumn(column);
column.setName("PNUM2"); column.setName("PNUM2");
column.setPrimaryKey(false);
column.setType(NdbDictionary::Column::Unsigned); column.setType(NdbDictionary::Column::Unsigned);
column.setLength(1); column.setLength(1);
column.setPrimaryKey(false);
column.setNullable(false); column.setNullable(false);
table.addColumn(column); table.addColumn(column);
column.setName("PNUM3"); column.setName("PNUM3");
column.setPrimaryKey(false);
column.setType(NdbDictionary::Column::Unsigned); column.setType(NdbDictionary::Column::Unsigned);
column.setLength(1); column.setLength(1);
column.setPrimaryKey(false);
column.setNullable(false); column.setNullable(false);
table.addColumn(column); table.addColumn(column);
column.setName("PNUM4"); column.setName("PNUM4");
column.setPrimaryKey(false);
column.setType(NdbDictionary::Column::Unsigned); column.setType(NdbDictionary::Column::Unsigned);
column.setLength(1); column.setLength(1);
column.setPrimaryKey(false);
column.setNullable(false); column.setNullable(false);
table.addColumn(column); table.addColumn(column);
column.setName("AGE"); column.setName("AGE");
column.setPrimaryKey(false);
column.setType(NdbDictionary::Column::Unsigned); column.setType(NdbDictionary::Column::Unsigned);
column.setLength(1); column.setLength(1);
column.setPrimaryKey(false);
column.setNullable(false); column.setNullable(false);
table.addColumn(column); table.addColumn(column);
column.setName("STRING_AGE"); column.setName("STRING_AGE");
column.setPrimaryKey(false);
column.setType(NdbDictionary::Column::Char); column.setType(NdbDictionary::Column::Char);
column.setLength(1); column.setLength(1);
column.setLength(256); column.setLength(256);
column.setPrimaryKey(false);
column.setNullable(false); column.setNullable(false);
table.addColumn(column); table.addColumn(column);
......
...@@ -81,16 +81,16 @@ static void createTable(Ndb &myNdb, bool storeInACC, bool twoKey, bool longKey) ...@@ -81,16 +81,16 @@ static void createTable(Ndb &myNdb, bool storeInACC, bool twoKey, bool longKey)
int res; int res;
column.setName("X"); column.setName("X");
column.setPrimaryKey(true);
column.setType(NdbDictionary::Column::Unsigned); column.setType(NdbDictionary::Column::Unsigned);
column.setLength(1); column.setLength(1);
column.setPrimaryKey(true);
column.setNullable(false); column.setNullable(false);
table.addColumn(column); table.addColumn(column);
column.setName("Y"); column.setName("Y");
column.setPrimaryKey(false);
column.setType(NdbDictionary::Column::Unsigned); column.setType(NdbDictionary::Column::Unsigned);
column.setLength(1); column.setLength(1);
column.setPrimaryKey(false);
column.setNullable(false); column.setNullable(false);
table.addColumn(column); table.addColumn(column);
......
...@@ -1128,9 +1128,9 @@ runCreateAutoincrementTable(NDBT_Context* ctx, NDBT_Step* step){ ...@@ -1128,9 +1128,9 @@ runCreateAutoincrementTable(NDBT_Context* ctx, NDBT_Step* step){
myTable.setName(tabname); myTable.setName(tabname);
myColumn.setName("ATTR1"); myColumn.setName("ATTR1");
myColumn.setPrimaryKey(true);
myColumn.setType(NdbDictionary::Column::Unsigned); myColumn.setType(NdbDictionary::Column::Unsigned);
myColumn.setLength(1); myColumn.setLength(1);
myColumn.setPrimaryKey(true);
myColumn.setNullable(false); myColumn.setNullable(false);
myColumn.setAutoIncrement(true); myColumn.setAutoIncrement(true);
if (startvalue != ~0) // check that default value starts with 1 if (startvalue != ~0) // check that default value starts with 1
......
...@@ -979,9 +979,9 @@ createtable(Par par) ...@@ -979,9 +979,9 @@ createtable(Par par)
for (unsigned k = 0; k < tab.m_cols; k++) { for (unsigned k = 0; k < tab.m_cols; k++) {
const Col& col = tab.m_col[k]; const Col& col = tab.m_col[k];
NdbDictionary::Column c(col.m_name); NdbDictionary::Column c(col.m_name);
c.setPrimaryKey(col.m_pk);
c.setType(col.m_type); c.setType(col.m_type);
c.setLength(col.m_length); c.setLength(col.m_length);
c.setPrimaryKey(col.m_pk);
c.setNullable(col.m_nullable); c.setNullable(col.m_nullable);
t.addColumn(c); t.addColumn(c);
} }
...@@ -2236,9 +2236,8 @@ pkreadfast(Par par, unsigned count) ...@@ -2236,9 +2236,8 @@ pkreadfast(Par par, unsigned count)
keyrow.calc(par, i); keyrow.calc(par, i);
CHK(keyrow.selrow(par) == 0); CHK(keyrow.selrow(par) == 0);
NdbRecAttr* rec; NdbRecAttr* rec;
CHK(con.getValue((Uint32)0, rec) == 0);
CHK(con.executeScan() == 0);
// get 1st column // get 1st column
CHK(con.getValue((Uint32)0, rec) == 0);
CHK(con.execute(Commit) == 0); CHK(con.execute(Commit) == 0);
con.closeTransaction(); con.closeTransaction();
} }
......
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