Example #1
0
 /// <summary>
 /// Populates a SQLiteCommand parameter list with parameter names based on the column names of a table
 /// </summary>
 /// <param name="table">Table metadata to obtain column names</param>
 /// <param name="cmd">SQLite command whose parameter List will be filled</param>
 private void CreateSqlCommandParameters(TableMetaData table, SQLiteCommand cmd)
 {
     cmd.Parameters.Clear();
     foreach (ColumnMetaData column in table.columns)
     {
         cmd.Parameters.Add(new SQLiteParameter(String.Format("@{0}", SchemaTablesMetaData.HexString(column.columnName))));
     }
 }
Example #2
0
        /// <summary>
        /// Creates a SQL INSERT sentence to insert a row of data to a table in the target database.
        /// </summary>
        /// <param name="table">Table metadata from the table to copy</param>
        /// <returns>SQL Sentence of the insertion in the target database</returns>
        private string CreateInsertQuery(TableMetaData table)
        {
            string csvColumList  = string.Empty;
            string csvParamsList = string.Empty;

            foreach (ColumnMetaData column in table.columns)
            {
                csvColumList  = String.Format("{0}{1},", csvColumList, SchemaTablesMetaData.EscapeIdentifier(column.columnName));
                csvParamsList = String.Format("{0}@{1},", csvParamsList, SchemaTablesMetaData.HexString(column.columnName));
            }
            string query = String.Format("INSERT INTO {0} ({1}) VALUES ({2})", SchemaTablesMetaData.EscapeIdentifier(table.tableName), csvColumList.Remove(csvColumList.Length - 1), csvParamsList.Remove(csvParamsList.Length - 1));

            return(query);
        }
Example #3
0
        /// <summary>
        /// Sets the parameter value for a SQLite query
        /// </summary>
        /// <param name="column">Column metadata info. The parameter will be named after the column name</param>
        /// <param name="cmd">SQLite command where to set the parameter</param>
        /// <param name="value">Value to set the parameter will be obtained from a row in this OleDbDataReader whose column has the column name</param>
        private void SetSqlCommandParameterValueForColumn(ColumnMetaData column, SQLiteCommand cmd, DbDataReader value)
        {
            string parameterName = String.Format("@{0}", SchemaTablesMetaData.HexString(column.columnName));

            cmd.Parameters[parameterName].Value = value[column.columnName];
        }