Commit b82dede5 authored by unknown's avatar unknown

ndb: set column type sets column defaults

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