Пример #1
0
        private void ProcessSave(QueryInfo query_info)
        {
            //先收集数据
            List <List <string> > list_result = new List <List <string> >();

            for (int row = 0; row < m_find_result.Rows.Count; ++row)
            {
                List <string> list = new List <string>();
                for (int col = 0; col < m_find_result.Columns.Count; col++)
                {
                    string value = m_find_result.Rows[row].Cells[col].Value as string;
                    list.Add(value);
                }
                list_result.Add(list);
            }

            //序列化
            ByteArray by = new ByteArray(1024 * 8, int.MaxValue);

            for (int row = 0; row < list_result.Count; ++row)
            {
                int           start_pos       = by.Tail;
                List <string> list_row_result = list_result[row];
                for (int col = 0; col < m_list_bin_header.Count; ++col)
                {
                    BinHeader header_info = m_list_bin_header[col];
                    string    value       = list_row_result[col];
                    switch (header_info.type)
                    {
                    case "int":
                        if (value.Length == 0)
                        {
                            value = "0";
                        }
                        long   l = long.Parse(value);
                        byte[] b = BitConverter.GetBytes(l);
                        by.Write(b, header_info.length);
                        break;

                    case "uint":
                        if (value.Length == 0)
                        {
                            value = "0";
                        }
                        ulong ul = ulong.Parse(value);
                        b = BitConverter.GetBytes(ul);
                        by.Write(b, header_info.length);
                        break;

                    case "float":
                        if (value.Length == 0)
                        {
                            value = "0";
                        }
                        float f = float.Parse(value);
                        b = BitConverter.GetBytes(f);
                        by.Write(b, header_info.length);
                        break;

                    case "double":
                        if (value.Length == 0)
                        {
                            value = "0";
                        }
                        double d = double.Parse(value);
                        b = BitConverter.GetBytes(d);
                        by.Write(b, header_info.length);
                        break;

                    case "string":
                        by.WriteString(value);
                        break;

                    default: continue;
                    }
                }
                if (query_info.fixed_length > 0)
                {
                    by.WriteEmpty(query_info.fixed_length - (by.Tail - start_pos));
                }
            }

            //保存到db
            string key_sql = query_info.sql_key_value;

            if (query_info.sql_key_type == 1)
            {
                key_sql = "'" + key_sql + "'";
            }

            string sql = "replace into `" + query_info.table_name + "`" +
                         "(`" + query_info.sql_key_name + "`,`" + query_info.field_name + "`) " +
                         "values (" +
                         key_sql + "," +
                         "@bin_data)";

            List <MySqlParameter> param = new List <MySqlParameter>();
            MySqlParameter        p     = Database.MakeMysqlParam("@bin_data", query_info.bin_type, by.GetBuffer(), by.Available);

            param.Add(p);
            DatabaseManager.Instance.GetDB(query_info.db_type).Execute(sql, param);
        }
Пример #2
0
 public override void Write(ByteArray by)
 {
     base.Write(by);
     by.Write(data.GetBuffer(), data.Available);
 }