Ejemplo n.º 1
0
FieldSet* FieldSet::createFromDefinition(string value)
{
	std::vector<string> vec;
	listToVector(value, vec, ",");

	std::vector<Field> fields;

	for (int index = 0; index < (int)vec.size(); index++)
	{
		std::string definition = vec[index];

		if (Field* field = Field::createFromDefinition(definition))
		{
			Field f(*field);
			fields.push_back(f);
			delete field;
		} else {
			return NULL;
		}
	}

	return new FieldSet(fields);
}
Ejemplo n.º 2
0
Field* Field::createFromDefinition(string value)
{
    std::vector<string> vec;

    listToVector(value, vec, " ");

    const int count = (int)vec.size();

    string _name;

    field_use _use = FIELD_DEFAULT;
    field_type _type = type_undefined;

    int _flags = flag_none;

    //parse name
    if (count > 0)
        _name = vec[0];

    //parse type
    if (count > 1)
    {
        std::string& type = vec[1];

        if (type.compare("INTEGER") == 0)
            _type = type_int;

        if (type.compare("TEXT") == 0)
            _type = type_text;

        if (type.compare("REAL") == 0)
            _type = type_float;
    }

    //parse optional flags
    if (count > 2)
    {
        std::string flags = vec[2];

        if (count > 3)
            flags += " " + vec[3];

        if (flags.find("PRIMARY KEY") != std::string::npos)
        {
            _use = FIELD_KEY;
            _flags = flag_primary_key;
        }

        if (flags.find("NOT NULL") != std::string::npos)
        {
            _flags |= flag_not_null;
        }
    }

    Field* field = NULL;

    if (!_name.empty())
    {
        if (_type != type_undefined)
        {
            if (_use == FIELD_DEFAULT)
            {
                field = new Field(_name, _type, _flags);
            } else {
                field = new Field(_use);
            }
        }
    }

    return field;
}