sdk/dotnet/src/Microsoft.Datasync.Client.SQLiteStore/Utils/SqlStatements.cs
/// <summary>
/// Creates a <c>INSERT INTO {table}</c> SQL statement.
/// </summary>
/// <param name="tableName">The name of the table.</param>
/// <param name="items">The items to insert.</param>
/// <param name="parameters">On completion, a list of parameters for the SQL statement.</param>
/// <returns>The SQL statement.</returns>
Creates a INSERT INTO {table}
Creates a INSERT INTO { table }
internal static string BatchInsert(string tableName, List<ColumnDefinition> columns, IEnumerable<JObject> items, out Dictionary<string, object> parameters)
        {
            var columnDefns = string.Join(", ", columns.Select(c => FormatColumnName(c.Name)));
            var insertParams = new Dictionary<string, object>();
            StringBuilder sql = new($"INSERT OR IGNORE INTO {FormatTableName(tableName)} ({columnDefns}) VALUES ");
            foreach (JObject item in items)
            {
                var itemColumns = columns.Select(c => AddParameter(item, c, insertParams));
                sql.Append('(').Append(string.Join(", ", itemColumns)).Append("),");
            }
            if (insertParams.Count > 0)
            {
                sql.Remove(sql.Length - 1, 1); 
                parameters = insertParams;
                return sql.ToString();
            }
            parameters = null;
            return null;
        }
internal static string BatchInsert ( string tableName , List < ColumnDefinition > columns , IEnumerable < JObject > items , out Dictionary < string , object > parameters ) { var columnDefns = string . Join ( " " , columns . Select ( c => FormatColumnName ( c . Name ) ) ) ; var insertParams = new Dictionary < string , object > ( ) ; StringBuilder sql = new ( $" INSERT OR IGNORE INTO  { FormatTableName ( tableName ) }  ( { columnDefns } ) VALUES  " ) ; foreach ( JObject item in items ) { var itemColumns = columns . Select ( c => AddParameter ( item , c , insertParams ) ) ; sql . Append ( ' ' ) . Append ( string . Join ( " " , itemColumns ) ) . Append ( " " ) ; } if ( insertParams . Count > 0 ) { sql . Remove ( sql . Length - 1 , 1 ) ; parameters = insertParams ; return sql . ToString ( ) ; } parameters = null ; return null ; }
Creates a INSERT INTO {table}
Creates a INSERT INTO { table }
// Remove the trailing comma
The SQL statement.
The SQL statement .
tableName
string
The name of the table.
The name of the table .
columns
List<ColumnDefinition>
items
IEnumerable<JObject>
The items to insert.
The items to insert .
Dictionary<string, object>
out
parameters
On completion, a list of parameters for the SQL statement.
On completion a list of parameters for the SQL statement .