public static Task <TKey> InsertAsync <TElement, TKey>(this QueryExpressionBuilder.xSelect <TKey, TElement> source, TElement value) { //Console.WriteLine("enter InsertAsync"); // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestXMySQL\Program.cs // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestWebInsert\Application.cs var z = new TaskCompletionSource <TKey>(); // was it manually set? //QueryExpressionBuilder.WithConnectionAsync( QueryExpressionBuilder.WithConnection( (IDbConnection cc) => { InsertAsync(source, cc, value).ContinueWith( task => { //Console.WriteLine("after InsertAsync"); z.SetResult(task.Result); } ); } ); //Console.WriteLine("exit InsertAsync"); return(z.Task); }
public static Task <TKey> InsertAsync <TElement, TKey>(this QueryExpressionBuilder.xSelect <TKey, TElement> source, IDbConnection cc, TElement value) { // in CLR and in browser this would work. var xDbCommand = QueryExpressionBuilder.GetInsertCommand(source, cc, value) as DbCommand; // why ExecuteNonQueryAsync is not part of CLR, now we need to link in SQLite and PHP! if (xDbCommand != null) { //Console.WriteLine("before ExecuteNonQueryAsync"); var n = xDbCommand.ExecuteNonQueryAsync(); // n = Id = 0x00000001, Status = RanToCompletion, Method = "{null}", Result = "1" var c = new TaskCompletionSource <TKey>(); n.ContinueWith( task => { // jsc makes all Keys of long, yet data layer seems to talk int? long LastInsertRowId = IDbConnectionExtensions.GetLastInsertRowId(cc); //Console.WriteLine("InsertAsync " + new { LastInsertRowId }); c.SetResult( (TKey)(object)LastInsertRowId ); } ); return(c.Task); } // how would this work in the browser if scriptcorelib does not yet provide the implementation? //var xMySQLCommand = c as System.Data.MySQL.MySQLCommand; //if (xMySQLCommand != null) //{ // var n = xMySQLCommand.ExecuteNonQueryAsync(); // return n; //} // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestXMySQL\Program.cs // should we report back the new key? throw new NotSupportedException(); }
// X:\jsc.svn\examples\javascript\Test\TestSQLiteConnection\TestSQLiteConnection\Application.cs // X:\jsc.svn\core\ScriptCoreLib.Extensions\ScriptCoreLib.Extensions\Query\Experimental\QueryExpressionBuilder.IDbConnection.Insert.cs public static Task <TKey[]> InsertAsync <TElement, TKey>(this QueryExpressionBuilder.xSelect <TKey, TElement> source, params TElement[] collection) { // used by // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestSelectAverage\Program.cs // x:\jsc.svn\examples\javascript\linq\test\auto\testselect\testweborderbythengroupby\application.cs //Console.WriteLine("enter InsertAsync"); // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestXMySQL\Program.cs var z = new TaskCompletionSource <TKey[]>(); // was it manually set? //QueryExpressionBuilder.WithConnectionAsync( QueryExpressionBuilder.WithConnection( (IDbConnection cc) => { var i = from c in collection select InsertAsync(source, cc, c); //Task.Factory.ContinueWhenAll( // X:\jsc.svn\core\ScriptCoreLib\JavaScript\BCLImplementation\System\Threading\Tasks\Task\Task.WhenAll.cs // X:\jsc.svn\examples\java\hybrid\test\JVMCLRWhenAll\JVMCLRWhenAll\Program.cs Task.WhenAll(i.ToArray()).ContinueWith( delegate { //Console.WriteLine("after InsertAsync"); z.SetResult( i.Select(x => x.Result).ToArray() ); } ); } ); //Console.WriteLine("exit InsertAsync"); return(z.Task); }
// https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150911/mysql // ! to track down jvm issues, lets name generics with method name public static Task <TInsertAsync1Key[]> InsertAsync <TElement, TInsertAsync1Key>(this QueryExpressionBuilder.xSelect <TInsertAsync1Key, TElement> source, params TElement[] collection) { // tested by? // used by // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestSelectAverage\Program.cs // x:\jsc.svn\examples\javascript\linq\test\auto\testselect\testweborderbythengroupby\application.cs //Console.WriteLine("enter InsertAsync"); // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestXMySQL\Program.cs var v = new __InsertAsync <TElement, TInsertAsync1Key> { source = source, collection = collection }; //v.Invoke(); QueryExpressionBuilder.WithConnection(v.Invoke); return(v.z.Task); }