예제 #1
0
        internal override GatewayResult Execute()
        {
            Record();
            GatewayResult result = new GatewayResult();

            GatewayAdapterCursor gatewayAdapterCursor = GatewayAdapter.GetCursor(RuntimeCursor);

            Debug.Assert(gatewayAdapterCursor != null);

            // clear old ranges - might contain old locates.
            gatewayAdapterCursor.Ranges.Clear();

            // TODO 1:
            // fm_crsr_cache_open ???

            // Copy ranges from runtime to gateway
            if (RuntimeCursor.RuntimeCursorData.Ranges != null)
            {
                foreach (RangeData runtimeRange in RuntimeCursor.RuntimeCursorData.Ranges)
                {
                    RangeData gatewayRange = new RangeData(runtimeRange);
                    RangeConvert(gatewayRange, runtimeRange, gatewayAdapterCursor);
                    gatewayAdapterCursor.Ranges.Add(gatewayRange);
                }
            }

            // TODO 2:
            // fm_copy_sql_ranges

            result.ErrorCode = GatewayAdapter.Gateway.CrsrOpen(gatewayAdapterCursor);
            SetErrorDetails(result);
            return(result);
        }
예제 #2
0
        /// <summary>
        /// fm_copy_ranges
        /// </summary>
        /// <param name="range"></param>
        private void RangeConvert(RangeData gatewayRange, RangeData runtimeRange, GatewayAdapterCursor gatewayAdapterCursor)
        {
            DBField field = gatewayAdapterCursor.Definition.FieldsDefinition[gatewayRange.FieldIndex];

            ConvertBoundaryToGateway(gatewayRange.Min, runtimeRange.Min, field);
            ConvertBoundaryToGateway(gatewayRange.Max, runtimeRange.Max, field);
        }
예제 #3
0
        internal override GatewayResult Execute()
        {
            Record();
            GatewayResult        result = new GatewayResult();
            GatewayAdapterCursor gatewayAdapterCursor = GatewayAdapter.GetCursor(RuntimeCursor);

            Debug.Assert(gatewayAdapterCursor != null);

            gatewayAdapterCursor.Definition.ClearFlag(CursorProperties.DummyFetch);

            // TODO 1 ???:
            //if (mg_crsr->blobs)
            //   crsr_fill_blob_info(db_crsr, mg_crsr, dbd->dbh);

            // TODO 2: for join
            //link_save_area = fm_link_crsr_buf_save(join_info->db_join_crsr);
            //retval = SQL_wrap_crsr_fetch_join(join_info->db_join_crsr,
            //            !mg_crsr->fetchSource.is_set(FETCH_BYPASS_TRANS_CACHE));
            //fm_link_crsr_buf_restore(join_info->db_join_crsr, link_save_area);

            // TODO 3: for not join
            //if (not join)
            result.ErrorCode = GatewayAdapter.Gateway.CrsrFetch(gatewayAdapterCursor);

            if (result.Success)
            {
                // TODO 4: for dummy fetch
                //   if (db_crsr->properties.is_set (DUMMY_FETCH)  && mg_crsr->dummy_fetch_buf != NULL)

                // TODO 5: check if a record that was fetched is within the ranges
                // fm_check_rngs

                // TODO 6: fetch Blobs
                // CrsrFetchBLOBs & CrsrFetchBLOBsJoin

                // TODO 7: If not DUMMY_FETCH
                // fm_flds_mg_4_db
                ConvertToRuntime(gatewayAdapterCursor);
                RecordData();
            }
            else
            // TODO: Error handling.
            // Temporary !!!
            if (result.ErrorCode != GatewayErrorCode.NoRecord)
            {
                SetErrorDetails(result);
            }

            return(result);
        }
예제 #4
0
        internal override GatewayResult Execute()
        {
            Record();
            GatewayResult        result = new GatewayResult();
            GatewayAdapterCursor gatewayAdapterCursor = GatewayAdapter.GetCursor(RuntimeCursor);

            if (gatewayAdapterCursor != null)
            {
                // TODO: for join cursor CrsrReleaseJoin
                result.ErrorCode = GatewayAdapter.Gateway.CrsrRelease(gatewayAdapterCursor);
                GatewayAdapter.RemoveCursor(RuntimeCursor);
            }
            SetErrorDetails(result);
            return(result);
        }
예제 #5
0
        /// <summary>
        /// fm_flds_mg_4_db
        /// Converts a record from gateway to magic presentation
        /// </summary>
        protected void ConvertToRuntime(GatewayAdapterCursor gatewayAdapterCursor)
        {
            FieldValues currentRecord = gatewayAdapterCursor.CurrentRecord;
            FieldValues runtimeRecord = RuntimeCursor.RuntimeCursorData.CurrentValues;

            for (int i = 0; i < currentRecord.Count; i++)
            {
                FieldValue fieldValue = runtimeRecord[i];
                fieldValue.IsNull = currentRecord.IsNull(i);
                if (!fieldValue.IsNull)
                {
                    fieldValue.Value = GatewayAdapter.StorageConvertor.ConvertGatewayToRuntimeField(gatewayAdapterCursor.Definition.FieldsDefinition[i],
                                                                                                    currentRecord[i].Value);
                }
            }
        }
예제 #6
0
        /// <summary>
        /// fm_flds_mg_2_db
        /// Converts a record from magic presentation to gateway
        /// </summary>
        protected void ConvertToGateway(GatewayAdapterCursor gatewayAdapterCursor)
        {
            FieldValues currentRecord = gatewayAdapterCursor.CurrentRecord;
            FieldValues runtimeRecord = RuntimeCursor.RuntimeCursorData.CurrentValues;


            for (int i = 0; i < currentRecord.Count; i++)
            {
                currentRecord[i].IsNull = runtimeRecord.IsNull(i);
                if (currentRecord[i].IsNull)
                {
                    currentRecord[i].Value = null;
                }
                else
                {
                    DBField dbField = gatewayAdapterCursor.Definition.FieldsDefinition[i];
                    if (ValueInGatewayFormat)
                    {
                        if (dbField.IsBlob())
                        {
                            GatewayBlob blob = new GatewayBlob();
                            blob.Blob = runtimeRecord.GetValue(i);

                            if (dbField.Storage == magicsoftware.util.FldStorage.Blob)
                            {
                                blob.BlobSize = ((Byte[])runtimeRecord.GetValue(i)).Length;
                            }
                            else
                            {
                                blob.BlobSize = ((string)runtimeRecord.GetValue(i)).Length;
                            }

                            currentRecord[i].Value = blob;
                        }
                        else
                        {
                            currentRecord[i].Value = runtimeRecord.GetValue(i);
                        }
                    }
                    else
                    {
                        string trimValue = ((string)runtimeRecord.GetValue(i)).TrimEnd();
                        currentRecord[i].Value = GatewayAdapter.StorageConvertor.ConvertRuntimeFieldToGateway(dbField, trimValue);
                    }
                }
            }
        }
        internal override GatewayResult Execute()
        {
            GatewayResult result = new GatewayResult();

            Record();
            result = CheckIsFlagSet(CursorProperties.Delete);

            if (result.Success)
            {
                GatewayAdapterCursor gatewayAdapterCursor = GatewayAdapter.GetCursor(RuntimeCursor);
                Debug.Assert(gatewayAdapterCursor != null);

                result.ErrorCode = GatewayAdapter.Gateway.CrsrDelete(gatewayAdapterCursor);
                SetErrorDetails(result);
            }
            return(result);
        }
예제 #8
0
        internal override GatewayResult Execute()
        {
            Record();
            GatewayResult result = new GatewayResult();

            GatewayAdapterCursor gatewayAdapterCursor = GatewayAdapter.GetCursor(RuntimeCursor);

            Debug.Assert(gatewayAdapterCursor != null);

            result.ErrorCode = GatewayAdapter.Gateway.CrsrGetCurr(gatewayAdapterCursor);

            ConvertToRuntime(gatewayAdapterCursor);
            RecordData();

            SetErrorDetails(result);

            return(result);
        }
예제 #9
0
        /// <summary>
        /// Returns gateway adapter cursor according to its runtime cursor
        /// </summary>
        /// <param name="runtimeCursor"></param>
        /// <returns></returns>
        internal GatewayAdapterCursor GetCursor(RuntimeCursor runtimeCursor)
        {
            if (gatewayAdapterCursors.ContainsKey(runtimeCursor))
            {
                GatewayAdapterCursor gatewayAdapterCursor = gatewayAdapterCursors[runtimeCursor];

                //This change is done to execute unit test. Because for unit test each command refers different runtime cursor.
                // So to get correct Cursor definition copy CursorDefinition from RunTimeCursor To Gateway cursor.
                if (!runtimeCursor.CursorDefinition.Equals(gatewayAdapterCursor.Definition))
                {
                    gatewayAdapterCursor.Definition = runtimeCursor.CursorDefinition;
                }

                return(gatewayAdapterCursor);
            }

            return(null);
        }
예제 #10
0
        internal override GatewayResult Execute()
        {
            GatewayResult result = new GatewayResult();

            Record();
            result = CheckIsFlagSet(CursorProperties.Update);

            if (result.Success)
            {
                GatewayAdapterCursor gatewayAdapterCursor = GatewayAdapter.GetCursor(RuntimeCursor);
                Debug.Assert(gatewayAdapterCursor != null);

                // 2. fm_flds_mg_2_db
                ConvertToGateway(gatewayAdapterCursor);

                // 3. ///*Update/Delete Stmt chngs copying update fld list from mg_crsr into db_crsr*/???

                // 4. update the record into data view

                //If partofdatetime is set and only time field is updated then before going to gateway set IsFieldUpdated of date field to true.
                for (int idx = 0; idx < (int)gatewayAdapterCursor.Definition.FieldsDefinition.Count; idx++)
                {
                    DBField fld = gatewayAdapterCursor.Definition.FieldsDefinition[idx];
                    if (fld.Storage == FldStorage.TimeString && fld.PartOfDateTime != 0 && gatewayAdapterCursor.Definition.IsFieldUpdated[idx])
                    {
                        int dateIdx = 0;
                        for (dateIdx = 0; dateIdx < gatewayAdapterCursor.Definition.FieldsDefinition.Count; dateIdx++)
                        {
                            if (DataSourceDefinition.Fields[gatewayAdapterCursor.Definition.FieldsDefinition[dateIdx].IndexInRecord].Isn == fld.PartOfDateTime)
                            {
                                break;
                            }
                        }

                        gatewayAdapterCursor.Definition.IsFieldUpdated[dateIdx] = true;
                    }
                }

                result.ErrorCode = GatewayAdapter.Gateway.CrsrUpdate(gatewayAdapterCursor);
                SetErrorDetails(result);
            }
            return(result);
        }
예제 #11
0
        internal override GatewayResult Execute()
        {
            Record();
            GatewayResult result = new GatewayResult();

            GatewayAdapterCursor gatewayAdapterCursor = GatewayAdapter.GetCursor(RuntimeCursor);

            Debug.Assert(gatewayAdapterCursor != null);

            result.ErrorCode = GatewayAdapter.Gateway.CrsrClose(gatewayAdapterCursor);

            if (result.Success)
            {
                // TODO:
                // Free Blobs
            }
            SetErrorDetails(result);

            return(result);
        }
예제 #12
0
        internal override GatewayResult Execute()
        {
            Record();
            GatewayAdapterCursor gatewayAdapterCursor = new GatewayAdapterCursor(RuntimeCursor.CursorDefinition);

            gatewayAdapterCursor.CursorType = CursorType.Regular;

            GatewayResult result = new GatewayResult();

            DatabaseDefinition dbDefinition = (DatabaseDefinition)DbDefinition.Clone();

            UpdateDataBaseLocation(dbDefinition);

            result.ErrorCode = GatewayAdapter.Gateway.CrsrPrepare(gatewayAdapterCursor, dbDefinition);

            if (result.Success)
            {
                GatewayAdapter.AddCursor(RuntimeCursor, gatewayAdapterCursor);
            }
            // db_rng_val_alloc ??
            SetErrorDetails(result);
            return(result);
        }
예제 #13
0
        //internal List<BlobInfo> BlobInfo;

        /// <summary>
        ///
        /// </summary>
        internal void CrsrInit(GatewayAdapterCursor dbCrsr, SQLiteGateway gtwyObj)
        {
            SQL3Dbd pSQL3Dbd = null;
            int     segs     = 0;

            PosKey = null;

            InUse          = true;
            XtraPoskeyCnt  = 0;
            XtraSortkeyCnt = 0;

            SQLiteGateway = gtwyObj;

            /* assign the gateway cursor id to the DB_CRSR structure */

            SQLiteGateway.DbdTbl.TryGetValue(dbCrsr.Definition.DataSourceDefinition, out pSQL3Dbd);

            Logger.Instance.WriteDevToLog(string.Format("CrsrInit(): >>>>> GTWY cursor cnt = %d", SQLiteGateway.GatewayCursorTbl.Count));

            Output = null;
            Input  = null;
            Ranges = new Sql3Sqldata(SQLiteGateway);

            StartPos = new Sql3Sqldata(SQLiteGateway);

            SearchKey = null;
            Key       = null;
            Update    = null;

            GcurrInput  = null;
            GcurrOutput = null;
            StmtRanges  = null;

            /* for cascading startpos */
            /* not direct sql */
            this.PosKey = SQLiteGateway.FindPoskey(dbCrsr.Definition.DataSourceDefinition);

            Sql3PrepareForTimeStamp(dbCrsr);

            if (pSQL3Dbd != null)
            {
                /* if there is a key */
                if (dbCrsr.Definition.Key != null)
                {
                    segs = dbCrsr.Definition.Key.Segments.Count + 1;
                }

                /*--------------------------------------------------------------*/
                /* fix bug #210900 - when no key selected - use the poskey segs */
                /*--------------------------------------------------------------*/
                else if (this.PosKey != null)
                {
                    segs = PosKey.Segments.Count;
                }
                else
                {
                    segs = 1;
                }

                Logger.Instance.WriteDevToLog(string.Format("CrsrInit(): segs in startpos = {0}", segs));
                StmtStartpos = new List <string>(segs);

                for (int i = 0; i < segs; i++)
                {
                    StmtStartpos.Add(null);
                }
            }

            StmtOrderBy     = null;
            StmtOrderByRev  = null;
            StmtInsert      = null;
            StmtDelete      = null;
            StmtUpdate      = null;
            StmtWhereKey    = null;
            StmtFields      = null;
            StmtKeyFields   = null;
            StmtExtraFields = null;
            StmtAllTables   = null;

            JoinStmtBuiltWithInnerJoin = false;
            StmtAllTablesUpdLock       = null;

            StmtAllTablesWithOtimizer = null;

            SourceDbh      = null;
            DbhPrefix      = null;
            StmtJoinCond   = null;
            StmtJoinRanges = null;
            StmtSqlRng     = null;
            /* created for optimizer hints in join tables but will be use always */
            StmtAllTablesWithOtimizer = null;


            StmtJoinCond   = null;
            StmtJoinRanges = null;
            StmtSqlRng     = null;
            OuterJoin      = false;

            if (dbCrsr.CursorType != CursorType.Join)
            {
                NullIndicator = new List <int>();
                for (int i = 0; i < dbCrsr.Definition.DataSourceDefinition.Fields.Count; i++)
                {
                    NullIndicator.Add(0);
                }
            }

            /* sql3_stmt structures */
            /* Stmt allocation will be done on demand */

            SReadA     = SqliteConstants.NULL_STMT; /*  sql3_stmt_alloc ("ReadA", crsr_hdl);  */
            sReadD     = SqliteConstants.NULL_STMT; /*  sql3_stmt_alloc ("ReadD", crsr_hdl);  */
            SRngA      = SqliteConstants.NULL_STMT; /*  sql3_stmt_alloc ("RngA", crsr_hdl);   */
            SRngD      = SqliteConstants.NULL_STMT; /*  sql3_stmt_alloc ("RngD", crsr_hdl);   */
            SStrt      = SqliteConstants.NULL_STMT; /*  sql3_stmt_alloc ("Strt", crsr_hdl);   */
            SGCurr     = SqliteConstants.NULL_STMT; /*  sql3_stmt_alloc ("Gcurr", crsr_hdl);  */
            SGCurrlock = SqliteConstants.NULL_STMT;
            SGKey      = SqliteConstants.NULL_STMT; /*  sql3_stmt_alloc ("Gkey", crsr_hdl);   */
            SInsert    = SqliteConstants.NULL_STMT; /*  sql3_stmt_alloc ("Ins", crsr_hdl);    */
            SUpdate    = SqliteConstants.NULL_STMT; /*  sql3_stmt_alloc ("Upd", crsr_hdl);    */
            SDelete    = SqliteConstants.NULL_STMT; /*  sql3_stmt_alloc ("Del", crsr_hdl);    */

            /* indexes to SQL3_CURSOR 's */
            /* Cusror allocation will also be done on demand */

            CRead   = SqliteConstants.NULL_CURSOR; /* sql3_cursor_alloc ("Read", crsr_hdl);  */
            CRange  = SqliteConstants.NULL_CURSOR; /* sql3_cursor_alloc ("Range", crsr_hdl); */
            CGcurr  = SqliteConstants.NULL_CURSOR; /* sql3_cursor_alloc ("Gcurr", crsr_hdl); */
            CGkey   = SqliteConstants.NULL_CURSOR; /* sql3_cursor_alloc ("Gkey", crsr_hdl);  */
            CInsert = SqliteConstants.NULL_CURSOR;

            LastPos = new DbPos(true);
            CurrPos = new DbPos(true);

            Logger.Instance.WriteDevToLog("CrsrInit(): <<<<< ");
        }
예제 #14
0
 /// <summary>
 ///
 /// </summary>
 internal void Sql3PrepareForTimeStamp(GatewayAdapterCursor dbCrsr)
 {
 }
예제 #15
0
 /// <summary>
 /// Adds the specific cursor to the cursors dictionary
 /// </summary>
 /// <param name="runtimeCursor"></param>
 /// <param name="gatewayAdapterCursor"></param>
 internal void AddCursor(RuntimeCursor runtimeCursor, GatewayAdapterCursor gatewayAdapterCursor)
 {
     Debug.Assert(!gatewayAdapterCursors.ContainsKey(runtimeCursor));
     gatewayAdapterCursors.Add(runtimeCursor, gatewayAdapterCursor);
 }