Пример #1
0
        public void MirrorUpdate(IList <FieldValue> fieldValues, IList <List <FieldValue> > docValues, IList <Hubble.Core.Query.DocumentResultForSort> docs)
        {
            StringBuilder sql = new StringBuilder();

            for (int index = 0; index < docs.Count; index++)
            {
                sql.AppendFormat("update {0} set ", Table.DBTableName);

                for (int i = 0; i < fieldValues.Count; i++)
                {
                    Data.FieldValue fvFieldName = fieldValues[i];

                    Data.FieldValue fv = docValues[index][i];

                    string value;

                    if (fv.Value == null)
                    {
                        value = "NULL";
                    }
                    else
                    {
                        value = fv.Type == Data.DataType.Varchar || fv.Type == Data.DataType.NVarchar ||
                                fv.Type == Data.DataType.NChar || fv.Type == Data.DataType.Char ||
                                fv.Type == Data.DataType.Date || fv.Type == Data.DataType.DateTime ||
                                fv.Type == Data.DataType.SmallDateTime || fv.Type == Data.DataType.Data ?
                                string.Format("'{0}'", fv.Value.Replace("'", "''")) : fv.Value;
                    }

                    if (i == 0)
                    {
                        sql.AppendFormat("`{0}`={1}", fvFieldName.FieldName, value);
                    }
                    else
                    {
                        sql.AppendFormat(",`{0}`={1}", fvFieldName.FieldName, value);
                    }
                }

                int docid = docs[index].DocId;

                if (DocIdReplaceField == null)
                {
                    sql.AppendFormat(" where docId = {0}; \r\n", docid);
                }
                else
                {
                    long replaceFieldValue = this.DBProvider.GetDocIdReplaceFieldValue(docid);
                    sql.AppendFormat(" where {0} = {1}; \r\n", DocIdReplaceField, replaceFieldValue);
                }
            }

            using (MysqlDataProvider sqlData = new MysqlDataProvider())
            {
                sqlData.Connect(Table.ConnectionString);
                sqlData.ExcuteSql(sql.ToString());
            }
        }
Пример #2
0
        public void MirrorUpdate(IList <FieldValue> fieldValues, IList <List <FieldValue> > docValues, IList <Hubble.Core.Query.DocumentResultForSort> docs)
        {
            StringBuilder sql = new StringBuilder();

            using (SQLiteDataProvider sqlData = new SQLiteDataProvider())
            {
                sqlData.Connect(Table.ConnectionString);
                sqlData.Connect(Table.ConnectionString);
                System.Data.Common.DbTransaction tran;
                System.Data.Common.DbCommand     cmd = sqlData.GetCommand(out tran);

                try
                {
                    for (int index = 0; index < docs.Count; index++)
                    {
                        sql.AppendFormat("update {0} set ", Table.DBTableName);

                        for (int i = 0; i < fieldValues.Count; i++)
                        {
                            Data.FieldValue fvFieldName = fieldValues[i];

                            Data.FieldValue fv = docValues[index][i];

                            string value;

                            if (fv.Value == null)
                            {
                                value = "NULL";
                            }
                            else
                            {
                                switch (fv.Type)
                                {
                                case Hubble.Core.Data.DataType.Varchar:
                                case Hubble.Core.Data.DataType.NVarchar:
                                case Hubble.Core.Data.DataType.Char:
                                case Hubble.Core.Data.DataType.NChar:
                                case Hubble.Core.Data.DataType.Data:
                                    value = string.Format("'{0}'", fv.Value.Replace("'", "''"));
                                    break;

                                case Hubble.Core.Data.DataType.DateTime:
                                case Hubble.Core.Data.DataType.Date:
                                case Hubble.Core.Data.DataType.SmallDateTime:
                                    DateTime dTime = DateTime.Parse(fv.Value);
                                    value = string.Format("'{0}'", dTime.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                                    break;

                                case DataType.Float:
                                    value = fv.Value;
                                    //insertString.AppendFormat(",{0:E}", double.Parse(fv.Value)); //We can change it like this in furture.
                                    break;

                                default:
                                    value = fv.Value;
                                    break;
                                }
                            }

                            if (i == 0)
                            {
                                sql.AppendFormat("[{0}]={1}", fvFieldName.FieldName, value);
                            }
                            else
                            {
                                sql.AppendFormat(",[{0}]={1}", fvFieldName.FieldName, value);
                            }
                        }

                        int docid = docs[index].DocId;

                        if (DocIdReplaceField == null)
                        {
                            sql.AppendFormat(" where docId = {0}; \r\n", docid);
                        }
                        else
                        {
                            long replaceFieldValue = this.DBProvider.GetDocIdReplaceFieldValue(docid);
                            sql.AppendFormat(" where {0} = {1}; \r\n", DocIdReplaceField, replaceFieldValue);
                        }

                        sqlData.ExecuteNonQuery(sql.ToString());
                        sql.Length = 0;
                    }

                    tran.Commit();
                }
                catch (Exception e)
                {
                    tran.Rollback();
                    throw e;
                }
            }
        }