public static void Convert(string filename, string outFilename) { Trace.WriteLine("Opening " + filename); sqlite3 handle; SQLite3.Result result = SQLite3.Open(filename, out handle); try { if (result != SQLite3.Result.OK) { string msg = SQLite3.GetErrmsg(handle); throw new Exception(msg); } Trace.WriteLine("Opened"); List <string> tableNames = new List <string>(); var writer = new LiteWriter(); GetTableNames(handle, tableNames); // build the table definitions, add the data CreateTables(handle, tableNames, writer); writer.Write(outFilename); } finally { if (handle != null) { SQLite3.Close(handle); handle = null; } } }
private static void CreateTables(sqlite3 handle, List <string> tableNames, LiteWriter writer) { foreach (var tableName in tableNames) { var stmt = SQLite3.Prepare2(handle, "pragma table_info(" + tableName + ")"); try { int offset = 0; List <Column> columns = new List <Column>(); while (SQLite3.Step(stmt) == SQLite3.Result.Row) { string name = SQLite3.ColumnString(stmt, 1); string type = SQLite3.ColumnString(stmt, 2); int notNull = SQLite3.ColumnInt(stmt, 3); var ct = GetType(type); var column = new Column(name, ct, offset); columns.Add(column); offset += LiteData.GetLength(ct); } var columnArray = new Column[columns.Count]; columns.CopyTo(columnArray); var table = writer.AddTable(tableName, columnArray, offset); AddRows(handle, table); } finally { SQLite3.Finalize(stmt); } } }
public LiteTableBuilder(LiteWriter writer, string name, Column[] columns, int rowLength) { Name = name; this.Columns = columns; this.rowLength = rowLength; Writer = writer; }