public OrderByClause(TableColumn column, bool descending)
 {
     Column    = column;
     Desending = descending;
 }
Exemple #2
0
        public static TableMeta ToMeta(string tableName)
        {
            // Parse a string like;
            // CREATE TABLE SimpleTable ([Id] long not null,[Test] nvarchar(300) ,[When] date , PRIMARY KEY ([Id] ))

            TableMeta meta = new TableMeta {
                ParameterizedTableName = tableName
            };

            string schema = GetDbSchemaFor(tableName);

            if (string.IsNullOrEmpty(schema))
            {
                return(null);
            }

            StringParse parse = new StringParse(schema);

            if (!parse.Read("CREATE TABLE " + tableName + " ("))
            {
                return(null);
            }

            while (!parse.Peek(")") && !parse.IsEmpty)
            {
                parse.SkipWhitespace();


                if (parse.Peek("[") || parse.Contains(' '))
                {
                    string fieldName;
                    if (parse.Peek("["))
                    {
                        fieldName = parse.ReadBetween('[', ']');
                    }
                    else
                    {
                        if (parse.Peek("PRIMARY KEY"))
                        {
                            break;
                        }

                        fieldName = parse.ReadTo(' ');
                    }

                    parse.SkipWhitespace();

                    TableColumn tc = new TableColumn
                    {
                        Name = fieldName,
                        Get  = (t, inst) => ((AnonmousTable)inst)[t.RawName],
                        Set  = (t, inst, val) => ((AnonmousTable)inst)[t.RawName] = val
                    };

                    parse.While(KeywordTriggerDefinitions, tc);

                    meta.Columns.Add(tc);
                }

                if (parse.Peek(","))
                {
                    parse.Read(",");
                    continue;
                }

                if (parse.Peek(")"))
                {
                    break;
                }

                if (parse.Peek("PRIMARY KEY"))
                {
                    break;
                }

                throw new NotImplementedException("Incomplete parsing of " + tableName);
            }

            return(meta);
        }