public static DatabaseTableStructure GetDatabaseTableStructure(string tableDescriptor)
        {
            if (String.IsNullOrEmpty(tableDescriptor))
            {
                return(null);
            }
            //table_descriptor = table_descriptor.ToUpper();

            var tableName = tableDescriptor.Substring("CREATE TABLE ", " (");

            if (tableName.IndexOf('[') == 0 && tableName.IndexOf(']') == tableName.Length - 1)
            {
                tableName = tableName.Substring(1, tableName.Length - 2);
            }

            var columns = new List <DatabaseColumnStructure>();

            var primaryKeys = tableDescriptor.Substring("PRIMARY KEY(", ")").Split(',');

            for (var i = 0; i < primaryKeys.Length; i++)
            {
                primaryKeys[i] = primaryKeys[i].Trim();
            }

            var index = tableDescriptor.IndexOf('(') + 1;
            var end   = false;

            while (!end)
            {
                var index2 = tableDescriptor.IndexOf(", ", index + 1);
                if (index2 == NotFound)
                {
                    end    = true;
                    index2 = tableDescriptor.IndexOf(" PRIMARY KEY", index + 1);
                }

                if (index2 != NotFound)
                {
                    var columnDescriptor = tableDescriptor.Substring(index, index2 - index);
                    if (columnDescriptor.IndexOf(", ") == 0)
                    {
                        columnDescriptor = columnDescriptor.Substring(2);
                    }
                    var cs = DatabaseColumnStructure.GetDatabaseColumnStructure(columnDescriptor, primaryKeys);
                    columns.Add(cs);
                }
                index = index2;
            }

            //var columnsArray = (DatabaseColumnStructure[])columns.ToArray(typeof(DatabaseColumnStructure));
            var id = DatabaseColumnStructure.GetPrimaryId(columns);

            if (!id.Any())
            {
                var ids = tableDescriptor.Substring("PRIMARY KEY(", ")").Split(',');
                for (var i = 0; i < ids.Length; i++)
                {
                    for (var j = 0; j < columns.Count; j++)
                    {
                        if (!String.Equals(columns[j].ColumnName, ids[i].Trim(), StringComparison.CurrentCultureIgnoreCase))
                        {
                            continue;
                        }
                        id.Add(columns[j]); // TODO: Why has only one key?
                        break;
                    }
                }
            }

            return(new DatabaseTableStructure(tableName, columns, id));
        }
 public IEnumerable <DatabaseColumnStructure> GetPrimaryId()
 {
     return(DatabaseColumnStructure.GetPrimaryId(Columns));
 }