//public static void Insert<TElement>(this IQueryStrategy<TElement> source, IDbConnection cc, TElement value) public static TKey Insert <TElement, TKey>(this xSelect <TKey, TElement> source, IDbConnection cc, TElement value) { if (cc == null) { if (Debugger.IsAttached) { Debugger.Break(); } } // X:\jsc.svn\core\ScriptCoreLib.Async\ScriptCoreLib.Async\Query\Experimental\QueryExpressionBuilderAsync.IDbConnection.Insert.cs // tested by // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestSQLiteCLRInsert\Program.cs var c = GetInsertCommand(source, cc, value) as DbCommand; var n = c.ExecuteNonQuery(); // jsc makes all Keys of long, yet data layer seems to talk int? long LastInsertRowId = IDbConnectionExtensions.GetLastInsertRowId(cc); //Console.WriteLine("Insert " + new { LastInsertRowId }); // Additional information: Invalid cast from 'System.Int32' to 'TestSQLiteCLRInsert.PerformanceResourceTimingData2ApplicationPerformanceRow'. // Additional information: Specified cast is not valid. return((TKey)(object)LastInsertRowId); //var __value = (TKey)Convert.ChangeType(LastInsertRowId, source.keySelector.Parameters[0].Type); //return __value; //var nKey = cc. // public const string CreateCommandText = @"create table // if not exists `PerformanceResourceTimingData2.ApplicationPerformance` ( // `Key` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, // `connectStart` BIGINT NOT NULL, // `connectEnd` BIGINT NOT NULL, // `requestStart` BIGINT NOT NULL, // `responseStart` BIGINT NOT NULL, // `responseEnd` BIGINT NOT NULL, // `domLoading` BIGINT NOT NULL, // `domComplete` BIGINT NOT NULL, // `loadEventStart` BIGINT NOT NULL, // `loadEventEnd` BIGINT NOT NULL, // `EventTime` BIGINT NOT NULL, // `Tag` TEXT, // `Timestamp` BIGINT NOT NULL)"; }
public static Task <TInsertAsync3Key> InsertAsync <TElement, TInsertAsync3Key>(this QueryExpressionBuilder.xSelect <TInsertAsync3Key, 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 <TInsertAsync3Key>(); 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( (TInsertAsync3Key)(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(); }