//creates a DBTable and DBColumn from table being accessed and populates DBTable dictionary public string GetReaderSchema(SqliteDataReader reader) { var builder = new StringBuilder(); var schemaTable = reader.GetSchemaTable(); foreach (DataRow column in schemaTable.Rows) { if ((bool)column[SchemaTableColumn.IsExpression]) { builder.Append("(expression)"); } else { builder.Append(column[SchemaTableColumn.BaseTableName]) .Append(".") .Append(column[SchemaTableColumn.BaseColumnName]); if (!DatabaseInfo.ContainsKey(column[SchemaTableColumn.BaseTableName].ToString())) { DatabaseInfo.Add(column[SchemaTableColumn.BaseTableName].ToString(), new DBTable(column[SchemaTableColumn.BaseTableName].ToString())); } } DBTable t = DatabaseInfo[column[SchemaTableColumn.BaseTableName].ToString()]; DBColumn dBColumn; if (!t.Columns.ContainsKey(column[SchemaTableColumn.ColumnName].ToString())) { dBColumn = new DBColumn(column[SchemaTableColumn.ColumnName].ToString()); t.Columns.Add(column[SchemaTableColumn.ColumnName].ToString(), dBColumn); } else { dBColumn = t.Columns[column[SchemaTableColumn.ColumnName].ToString()]; } builder.Append(" "); builder.Append(setColumnInfoToDict(column, dBColumn)); } var debugString = builder.ToString(); return(debugString); }
//Sets the information in DBColumn public StringBuilder setColumnInfoToDict(DataRow column, DBColumn dBColumn) { var builder = new StringBuilder(); if ((bool)column[SchemaTableColumn.IsAliased]) { dBColumn.isAliased = true; builder.Append("AS ") .Append(column[SchemaTableColumn.ColumnName]) .Append(" "); } builder.Append(column["DataTypeName"]) .Append(" "); dBColumn.DataType = column["DataTypeName"].ToString(); if (column[SchemaTableColumn.AllowDBNull] as bool? == false) { dBColumn.isNotNull = true; builder.Append("NOT NULL "); } if (column[SchemaTableColumn.IsKey] as bool? == true) { dBColumn.isPrimaryKey = true; builder.Append("PRIMARY KEY "); } if (column[SchemaTableOptionalColumn.IsAutoIncrement] as bool? == true) { dBColumn.isAutoIncrement = true; builder.Append("AUTOINCREMENT "); } if (column[SchemaTableColumn.IsUnique] as bool? == true) { dBColumn.isUnique = true; builder.Append("UNIQUE "); } builder.AppendLine(); return(builder); }