---
drizzled/message/table.proto | 2 -
drizzled/sql_table.cc | 17 ++++++++++-
drizzled/sql_yacc.yy | 64 ++++++++++++++++++++++++++++++++++++++++--
drizzled/table.cc | 4 +-
drizzled/table_proto_write.cc | 23 ++++++++++-----
5 files changed, 96 insertions(+), 14 deletions(-)
Index: drizzled/message/table.proto
===================================================================
--- drizzled/message/table.proto.orig 2009-11-04 15:20:41.774165708 +1100
+++ drizzled/message/table.proto 2009-11-04 15:20:45.204172804 +1100
@@ -107,7 +107,7 @@ message Table {
}
message FieldConstraints {
- required bool is_nullable = 1 [default = false];
+ required bool is_nullable = 1 [default = true];
optional bool is_unsigned = 2 [default = false];
repeated string expression = 16; /* Reserve 0-15 for frequenty accessed
attributes */
}
Index: drizzled/sql_table.cc
===================================================================
--- drizzled/sql_table.cc.orig 2009-11-04 15:20:39.854172168 +1100
+++ drizzled/sql_table.cc 2009-11-04 15:20:45.204172804 +1100
@@ -1272,15 +1272,18 @@ int mysql_prepare_create_table(Session *
key_info->comment.str= key->key_create_info.comment.str;
}
+ message::Table::Field *protofield= NULL;
+
List_iterator<Key_part_spec> cols(key->columns), cols2(key->columns);
for (uint32_t column_nr=0 ; (column=cols++) ; column_nr++)
{
uint32_t length;
Key_part_spec *dup_column;
+ int proto_field_nr= 0;
it.rewind();
field=0;
- while ((sql_field=it++) &&
+ while ((sql_field=it++) && ++proto_field_nr &&
my_strcasecmp(system_charset_info,
column->field_name.str,
sql_field->field_name))
@@ -1302,6 +1305,10 @@ int mysql_prepare_create_table(Session *
}
}
cols2.rewind();
+
+ if (create_proto->field_size() > 0)
+ protofield= create_proto->mutable_field(proto_field_nr - 1);
+
{
column->length*= sql_field->charset->mbmaxlen;
@@ -1325,6 +1332,14 @@ int mysql_prepare_create_table(Session *
/* Implicitly set primary key fields to NOT NULL for ISO conf. */
sql_field->flags|= NOT_NULL_FLAG;
null_fields--;
+
+ if (protofield)
+ {
+ message::Table::Field::FieldConstraints *constraints;
+ constraints= protofield->mutable_constraints();
+ constraints->set_is_nullable(false);
+ }
+
}
else
{
Index: drizzled/sql_yacc.yy
===================================================================
--- drizzled/sql_yacc.yy.orig 2009-11-04 15:20:41.824167400 +1100
+++ drizzled/sql_yacc.yy 2009-11-04 15:20:45.244173082 +1100
@@ -1626,6 +1626,14 @@ type:
{
$$=DRIZZLE_TYPE_LONGLONG;
Lex->type|= (AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG);
+
+ statement::CreateTable *statement= (statement::CreateTable
*)Lex->statement;
+ if (statement->current_proto_field)
+ {
+ message::Table::Field::FieldConstraints *constraints;
+ constraints=
statement->current_proto_field->mutable_constraints();
+ constraints->set_is_nullable(false);
+ }
}
;
@@ -1693,7 +1701,18 @@ opt_attribute_list:
;
attribute:
- NULL_SYM { Lex->type&= ~ NOT_NULL_FLAG; }
+ NULL_SYM
+ {
+ statement::AlterTable *statement= (statement::AlterTable
*)Lex->statement;
+ Lex->type&= ~ NOT_NULL_FLAG;
+
+ if (statement->current_proto_field)
+ {
+ message::Table::Field::FieldConstraints *constraints;
+ constraints=
statement->current_proto_field->mutable_constraints();
+ constraints->set_is_nullable(true);
+ }
+ }
| COLUMN_FORMAT_SYM column_format_types
{
statement::AlterTable *statement= (statement::AlterTable
*)Lex->statement;
@@ -1701,7 +1720,18 @@ attribute:
statement->column_format= $2;
statement->alter_info.flags.set(ALTER_COLUMN_FORMAT);
}
- | not NULL_SYM { Lex->type|= NOT_NULL_FLAG; }
+ | not NULL_SYM
+ {
+ statement::AlterTable *statement= (statement::AlterTable
*)Lex->statement;
+ Lex->type|= NOT_NULL_FLAG;
+
+ if (statement->current_proto_field)
+ {
+ message::Table::Field::FieldConstraints *constraints;
+ constraints=
statement->current_proto_field->mutable_constraints();
+ constraints->set_is_nullable(false);
+ }
+ }
| DEFAULT now_or_signed_literal
{
statement::AlterTable *statement= (statement::AlterTable
*)Lex->statement;
@@ -1711,7 +1741,19 @@ attribute:
}
| ON UPDATE_SYM NOW_SYM optional_braces
{ ((statement::AlterTable *)Lex->statement)->on_update_value= new
Item_func_now_local(); }
- | AUTO_INC { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
+ | AUTO_INC
+ {
+ Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG;
+
+ statement::AlterTable *statement= (statement::AlterTable
*)Lex->statement;
+ if (statement->current_proto_field)
+ {
+ message::Table::Field::FieldConstraints *constraints;
+
+ constraints=
statement->current_proto_field->mutable_constraints();
+ constraints->set_is_nullable(false);
+ }
+ }
| SERIAL_SYM DEFAULT VALUE_SYM
{
LEX *lex=Lex;
@@ -1719,6 +1761,13 @@ attribute:
lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG | UNIQUE_FLAG;
statement->alter_info.flags.set(ALTER_ADD_INDEX);
+
+ if (statement->current_proto_field)
+ {
+ message::Table::Field::FieldConstraints *constraints;
+ constraints=
statement->current_proto_field->mutable_constraints();
+ constraints->set_is_nullable(false);
+ }
}
| opt_primary KEY_SYM
{
@@ -1727,6 +1776,13 @@ attribute:
lex->type|= PRI_KEY_FLAG | NOT_NULL_FLAG;
statement->alter_info.flags.set(ALTER_ADD_INDEX);
+
+ if (statement->current_proto_field)
+ {
+ message::Table::Field::FieldConstraints *constraints;
+ constraints=
statement->current_proto_field->mutable_constraints();
+ constraints->set_is_nullable(false);
+ }
}
| UNIQUE_SYM
{
@@ -2182,6 +2238,8 @@ alter_list_item:
lex->charset= NULL;
statement->alter_info.flags.set(ALTER_CHANGE_COLUMN);
statement->column_format= COLUMN_FORMAT_TYPE_DEFAULT;
+
+ statement->current_proto_field= NULL;
}
field_def
{
Index: drizzled/table.cc
===================================================================
--- drizzled/table.cc.orig 2009-11-04 15:20:39.934170285 +1100
+++ drizzled/table.cc 2009-11-04 15:20:45.284198435 +1100
@@ -515,7 +515,7 @@ int drizzled::parse_table_proto(Session
for (unsigned int fieldnr= 0; fieldnr < share->fields; fieldnr++)
{
message::Table::Field pfield= table.field(fieldnr);
- if (pfield.has_constraints() && pfield.constraints().is_nullable())
+ if (pfield.constraints().is_nullable())
null_fields++;
enum_field_types drizzle_field_type=
@@ -854,7 +854,7 @@ int drizzled::parse_table_proto(Session
&share->mem_root,
record + field_offsets[fieldnr] + data_offset,
pfield.options().length(),
- pfield.has_constraints() &&
pfield.constraints().is_nullable() ? true : false,
+ pfield.constraints().is_nullable(),
null_pos,
null_bit_pos,
decimals,
Index: drizzled/table_proto_write.cc
===================================================================
--- drizzled/table_proto_write.cc.orig 2009-11-04 15:20:41.954171401 +1100
+++ drizzled/table_proto_write.cc 2009-11-04 15:20:45.304191975 +1100
@@ -60,21 +60,30 @@ int fill_table_proto(message::Table *tab
{
message::Table::Field *attribute;
+ /* some (one) code path for CREATE TABLE fills the proto
+ out more than the others, so we already have partially
+ filled out Field messages */
+
if (use_existing_fields)
attribute= table_proto->mutable_field(field_number++);
else
+ {
+ /* Other code paths still have to fill out the proto */
attribute= table_proto->add_field();
- attribute->set_name(field_arg->field_name);
-
- if(! (field_arg->flags & NOT_NULL_FLAG))
- {
- message::Table::Field::FieldConstraints *constraints;
+ if(field_arg->flags & NOT_NULL_FLAG)
+ {
+ message::Table::Field::FieldConstraints *constraints;
- constraints= attribute->mutable_constraints();
- constraints->set_is_nullable(true);
+ constraints= attribute->mutable_constraints();
+ constraints->set_is_nullable(false);
+ }
}
+ assert((!(field_arg->flags & NOT_NULL_FLAG)) ==
attribute->constraints().is_nullable());
+
+ attribute->set_name(field_arg->field_name);
+
switch (field_arg->sql_type) {
case DRIZZLE_TYPE_LONG:
attribute->set_type(message::Table::Field::INTEGER);
--
Stewart Smith
_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help : https://help.launchpad.net/ListHelp