/* * /// <summary> * /// Determines the data type of a column in a statement * /// </summary> * /// <param name="stmt">The statement to retrieve information for</param> * /// <param name="i">The column to retrieve type information on</param> * /// <param name="typ">The SQLiteType to receive the affinity for the given column</param> * internal static void ColumnToType(SharpHsqlStatement stmt, int i, SQLiteType typ) * { * typ.Type = TypeNameToDbType(stmt._sql.ColumnType(stmt, i, out typ.Affinity)); * } */ /// <summary> /// Converts a SQLiteType to a .NET Type object /// </summary> /// <param name="t">The SQLiteType to convert</param> /// <returns>Returns a .NET Type object</returns> internal static Type SQLiteTypeToType(SQLiteType t) { if (t.Type == DbType.Object) { return(_affinitytotype[(int)t.Affinity]); } else { return(SharpHsqlConvert.DbTypeToType(t.Type)); } }
/// <summary> /// Turn a datatable into a table in the temporary database for the connection /// </summary> /// <param name="cnn">The connection to make the temporary table in</param> /// <param name="table">The table to write out</param> /// <param name="dest">The temporary table name to write to</param> private void DataTableToTable(SharpHsqlConnection cnn, DataTable table, string dest) { StringBuilder sql = new StringBuilder(); SharpHsqlCommandBuilder builder = new SharpHsqlCommandBuilder(); using (SharpHsqlCommand cmd = cnn.CreateCommand()) using (DataTable source = new DataTable()) { sql.AppendFormat(CultureInfo.InvariantCulture, "CREATE TEMP TABLE {0} (", builder.QuoteIdentifier(dest)); string separator = String.Empty; foreach (DataColumn dc in table.Columns) { DbType dbtypeName = SharpHsqlConvert.TypeToDbType(dc.DataType); string typeName = SharpHsqlConvert.DbTypeToTypeName(dbtypeName); sql.AppendFormat(CultureInfo.InvariantCulture, "{2}{0} {1} COLLATE NOCASE", builder.QuoteIdentifier(dc.ColumnName), typeName, separator); separator = ", "; } sql.Append(")"); cmd.CommandText = sql.ToString(); cmd.ExecuteNonQuery(); cmd.CommandText = String.Format("SELECT * FROM TEMP.{0} WHERE 1=2", builder.QuoteIdentifier(dest)); using (SharpHsqlDataAdapter adp = new SharpHsqlDataAdapter(cmd)) { builder.DataAdapter = adp; adp.Fill(source); foreach (DataRow row in table.Rows) { object[] arr = row.ItemArray; source.Rows.Add(arr); } adp.Update(source); } } }