/// <summary>
        /// Check if selected columns of source and destination are compatible or not.
        /// </summary>
        /// <returns></returns>
        private bool AreTypesCompatible(List <FieldDef> sourceVarList, List <DBField> destinationColumnList)
        {
            bool isTypeCompatible = false;

            for (int fieldIndex = 0; fieldIndex < destinationColumnList.Count; fieldIndex++)
            {
                isTypeCompatible = StorageAttributeCheck.IsTypeCompatibile(sourceVarList[fieldIndex].getType(), (StorageAttribute)destinationColumnList[fieldIndex].Attr);
                if (!isTypeCompatible)
                {
                    break;
                }
            }

            return(isTypeCompatible);
        }
Esempio n. 2
0
        /// <summary>
        /// Convert fields according to the storage attribute. For newly created field assign default value to that field.
        /// </summary>
        /// <param name="sourceDataSourceDefinition"></param>
        /// <param name="destinationDataSourceDefinition"></param>
        /// <param name="sourceValues"></param>
        /// <param name="destinationValues"></param>
        private void ConvertFields(DataSourceDefinition sourceDataSourceDefinition, DataSourceDefinition destinationDataSourceDefinition,
                                   FieldValues sourceValues, FieldValues destinationValues)
        {
            FieldsMap  fieldsMap   = new FieldsMap(sourceDataSourceDefinition.Fields, destinationDataSourceDefinition.Fields);
            DBField    sourceField = null;
            FieldValue sourceValue = null;

            for (int destinationFieldIndex = 0; destinationFieldIndex < destinationDataSourceDefinition.Fields.Count; destinationFieldIndex++)
            {
                int sourceFieldIndex = fieldsMap.GetSourceFieldIndex(destinationFieldIndex);

                DBField    destinationField = destinationDataSourceDefinition.Fields[destinationFieldIndex];
                FieldValue destinationValue = destinationValues[destinationFieldIndex];

                // If source field exists and source and destination types are comapatible then convert field values.
                // Else assign default value to destination field.
                if (sourceFieldIndex != -1)
                {
                    sourceField = sourceDataSourceDefinition.Fields[sourceFieldIndex];
                    sourceValue = sourceValues[sourceFieldIndex];

                    if (StorageAttributeCheck.IsTypeCompatibile((StorageAttribute)sourceField.Attr, (StorageAttribute)destinationField.Attr))
                    {
                        ConvertFieldValue(sourceField, destinationField, sourceValue, destinationValue);
                    }
                    else
                    {
                        destinationValue.Value  = destinationField.DefaultValue;
                        destinationValue.IsNull = destinationField.DefaultNull;
                    }
                }
                else
                {
                    destinationValue.Value  = destinationField.DefaultValue;
                    destinationValue.IsNull = destinationField.DefaultNull;
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// converts Alpha/Unicode values to Blob and vice versa.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="srcAttr"></param>
        /// <param name="expectedType"></param>
        /// <returns></returns>
        internal static String convertArgs(String value, StorageAttribute srcAttr, StorageAttribute expectedType)
        {
            int    key;
            object dotNetObj  = null;
            bool   invalidArg = false;

            if (srcAttr != StorageAttribute.DOTNET &&
                expectedType == StorageAttribute.DOTNET)
            {
                //Convert Magic To DotNet
                key       = _tempTableKey;
                dotNetObj = DNConvert.convertMagicToDotNet(value, srcAttr,
                                                           DNConvert.getDefaultDotNetTypeForMagicType(value, srcAttr));

                DNManager.getInstance().DNObjectsCollection.Update(key, dotNetObj);
                value = BlobType.createDotNetBlobPrefix(key);
            }
            else if (srcAttr == StorageAttribute.DOTNET &&
                     expectedType != StorageAttribute.DOTNET &&
                     expectedType != StorageAttribute.NONE)
            {
                //Convert DotNet to Magic
                key = BlobType.getKey(value);

                if (key != 0)
                {
                    dotNetObj = DNManager.getInstance().DNObjectsCollection.GetDNObj(key);
                    value     = DNConvert.convertDotNetToMagic(dotNetObj, expectedType);
                }
            }
            else
            {
                switch (expectedType)
                {
                case StorageAttribute.ALPHA:
                case StorageAttribute.UNICODE:
                    if (srcAttr == StorageAttribute.BLOB)
                    {
                        if (BlobType.isValidBlob(value))
                        {
                            value = BlobType.getString(value);
                        }
                    }
                    else if (!StorageAttributeCheck.IsTypeAlphaOrUnicode(srcAttr))
                    {
                        invalidArg = true;
                    }
                    break;

                case StorageAttribute.NUMERIC:
                case StorageAttribute.DATE:
                case StorageAttribute.TIME:
                    if (!StorageAttributeCheck.isTypeNumeric(srcAttr))
                    {
                        invalidArg = true;
                    }
                    break;

                case StorageAttribute.BLOB:
                    if (StorageAttributeCheck.IsTypeAlphaOrUnicode(srcAttr))
                    {
                        char contentType = srcAttr == StorageAttribute.ALPHA
                                           ? BlobType.CONTENT_TYPE_ANSI
                                           : BlobType.CONTENT_TYPE_UNICODE;
                        value = BlobType.createFromString(value, contentType);
                    }
                    else if (!StorageAttributeCheck.isTypeBlob(srcAttr))
                    {
                        invalidArg = true;
                    }
                    break;
                }

                //If there is mismatch in attribute, take default value of expectd argument.
                if (invalidArg)
                {
                    value = FieldDef.getMagicDefaultValue(expectedType);
                }
            }

            return(value);
        }
Esempio n. 4
0
        /// <summary>
        /// Fill the fields data.
        /// </summary>
        /// <param name="fldValInBytes"></param>
        /// <param name="recFlags"></param>
        /// <param name="isCurrRec"></param>
        protected override void fillFieldsData(byte[] fldValInBytes, String recFlags)
        {
            Object           val = null;
            String           tmp = null;
            int              parsedLen = 0;
            int              i, j, from, size;
            StorageAttribute currType;
            bool             useHex;
            FieldDef         fld = null;
            bool             valueNotPassed;

            from = getFromFldIdx(false);
            size = getSizeFld(false);
            int destinationFieldIndex = 0;

            for (i = from, j = 0; j < size; i++, j++)
            {
                fld      = getFieldsTab().getField(i);
                currType = fld.getType();

                useHex = (ClientManager.Instance.getEnvironment().GetDebugLevel() > 1 ||
                          currType == StorageAttribute.ALPHA ||
                          currType == StorageAttribute.UNICODE ||
                          StorageAttributeCheck.isTypeLogical(currType));

                // Qcr #940443 : Old fashion flags are still being used by resident table. So check them 1st coz we  might get exception otherwise.
                // The flags for resident are very simple, only 2 options. '.' = false, '/' = true.
                // We keep using it for resident, since in the server side we do not know if we are creating the xml for richclient or for BC at the creation stage.
                // Since we couldn't create different flags for rich, we will use the old flags here.
                if ((byte)(recFlags[j]) == '.')
                {
                    _flags[i] = 0;
                }
                else if ((byte)(recFlags[j]) == '/')
                {
                    _flags[i] = 1;
                }
                else // New flags style. For the view.
                {
                    // Each flag will appear in the xml in 2 chars representing hex value ("42" for 0x42).
                    tmp       = recFlags.Substring(j * 2, 2);
                    _flags[i] = Convert.ToByte(tmp, 16);
                }

                // save the ind that the value was not passed from the server.
                valueNotPassed = (FLAG_VALUE_NOT_PASSED == (byte)(_flags[i] & FLAG_VALUE_NOT_PASSED));
                _flags[i]      = (byte)(_flags[i] & ~FLAG_VALUE_NOT_PASSED);

                _flagsHistory[i] = _flags[i];

                if (valueNotPassed)
                {
                    if (FLAG_NULL == (byte)(_flags[i] & FLAG_NULL))
                    {
                        // null ind is on, just put any value in the field.
                        val = fld.getDefaultValue();
                    }
                    else
                    {
                        // copy the existing value from the existing curr rec.
                        val = ((Record)_dataview.getCurrRec()).GetFieldValue(i);
                    }
                }
                else
                {
                    DBField dbField = destinationColumnList[destinationFieldIndex++];
                    val = RecordUtils.deSerializeItemVal(fldValInBytes, (StorageAttribute)dbField.Attr, dbField.Length, dbField.Storage, ref parsedLen);
                }

                _fieldsData[i] = val;
            }
            setInitialFldVals(false, false);
        }