Example #1
0
		internal object ReadData(Database db, BinaryReader br)
		{
			const string FuncErrCode=ClassErrCode+".0006";
			try
			{
//				// dec
//				BinaryReader oldbw = bw;
//				MemoryStream ms = new MemoryStream();
//				bw = new BinaryWriter(ms);
//				// dec
				Field f = this;
				switch(f.type)
				{
					case FieldType.ftBoolean:
						return br.ReadBoolean();
					case FieldType.ftDecimal:
						return br.ReadDecimal();
					case FieldType.ftDateTime:
						return new DateTime(br.ReadInt64());
					case FieldType.ftInt32:
						return br.ReadInt32();
					case FieldType.ftInt64:
						return br.ReadInt64();
					case FieldType.ftString: //long total = 2*len+8 bytes
						long p = br.BaseStream.Position;
						byte[] bytes = new byte[br.ReadInt32()];
						bytes=br.ReadBytes(bytes.Length);
						string str =System.Text.Encoding.Unicode.GetString(bytes);
						br.BaseStream.Position = p+DataSize();
						return str;
					default:
						return null;
				}
//				// dec
//				bw = oldbw;
//				long seed = bw.BaseStream.Position;
//				byte[] bytes2 = ms.ToArray();
//				for(int n=0;n<bytes2.Length;n++)
//				{
//					int pos = ((n%7)*((n+3)%103)) % bytes2.Length;
//					bytes2[n] = (byte)(((int)bytes2[n]) ^ ((int)db.passwd[n]));
//				}
//				bw.Write(bytes2);
//				// dec
			}
			catch(Exception ex)
			{
				throw new Exception(ex.Message+"\n"+FuncErrCode+": Inner exception.");
			}
		}
Example #2
0
		internal void WriteIndexData(Database db, BinaryWriter bw)
		{
			const string FuncErrCode=ClassErrCode+".0002";
			try
			{
				lock(db.TableBlocking)
				{
					bw.Write(bUnique);
					if(bUnique)
					{
						bw.Write((int)this.ht.Keys.Count);
						foreach(object key in this.ht.Keys)
						{
							Variant v = Variant.Object2Variant(key);
							v.WriteToFieldDef(bw,false);
							long rowid = (long)this.ht[key];
							bw.Write(rowid);
						}
					}
					else
					{
						bw.Write((int)this.ht.Keys.Count);
						foreach(object key in this.ht.Keys)
						{
							Variant v = Variant.Object2Variant(key);
							v.WriteToFieldDef(bw,false);
							ArrayList al = this.ht[key] as ArrayList;
							bw.Write((int)al.Count);
							foreach(long rowid in al)
								bw.Write(rowid);
						}
					}
				}
			}
			catch(Exception ex)
			{
				throw new Exception(ex.Message+"\n"+FuncErrCode+": Inner exception.");
			}
		}
Example #3
0
		internal void WriteData(Database db, BinaryWriter bw, Variant v, bool bCommit)
		{
			const string FuncErrCode=ClassErrCode+".0005";
			try
			{
//				// enc
//				BinaryWriter oldbw = bw;
//				MemoryStream ms = new MemoryStream();
//				bw = new BinaryWriter(ms);
//				// enc
				object obj = v.obj;
				if(v.type!=type)
					throw new Exception(FuncErrCode+": Different types.");
				Field f = this;
				switch(f.type)
				{
					case FieldType.ftBoolean:
						bw.Write((bool)obj);
						break;
					case FieldType.ftDecimal:
						bw.Write((decimal)obj);
						break;
					case FieldType.ftDateTime:
						bw.Write(((DateTime)obj).Ticks);
						break;
					case FieldType.ftInt32:
						bw.Write((int)obj);
						break;
					case FieldType.ftInt64:
						bw.Write((long)obj);
						break;
					case FieldType.ftString: //long total = 2*len+8 bytes
						string str = (string)obj;
						if(str.Length>f.len) str=str.Substring(0,f.len);
						byte[] bytes = System.Text.Encoding.Unicode.GetBytes(str);
						byte[] padding = new byte[(2*f.len+8)-bytes.Length];
						bw.Write((int)bytes.Length);
						bw.Write(bytes);
						bw.Write(padding);
						break;
				}
//				// enc
//				bw = oldbw;
//				long seed = bw.BaseStream.Position;
//				byte[] bytes2 = ms.ToArray();
//				for(int n=0;n<bytes2.Length;n++)
//				{
//					int pos = ((n%7)*((n+3)%103)) % bytes2.Length;
//					bytes2[n] = (byte)(((int)bytes2[n]) ^ ((int)db.passwd[n]));
//				}
//				bw.Write(bytes2);
//				// enc
				if(bCommit)
					bw.Flush();
			}
			catch(Exception ex)
			{
				throw new Exception(ex.Message+"\n"+FuncErrCode+": Inner exception.");
			}
		}
Example #4
0
		internal static Index ReadIndexData(Database db, BinaryReader br)
		{
			const string FuncErrCode=ClassErrCode+".0001";
			try
			{
				lock(db.TableBlocking)
				{
					Index ndx = new Index();
					ndx.bUnique = br.ReadBoolean();
					if(ndx.bUnique)
					{
						int nkeys = br.ReadInt32();
						for(int k=0;k<nkeys;k++)
						{
							Variant v = Variant.ReadFromFieldDef(br);
							ndx.ht[v.obj]=br.ReadInt64();
						}
					}
					else
					{
						int nkeys = br.ReadInt32();
						for(int k=0;k<nkeys;k++)
						{
							Variant v = Variant.ReadFromFieldDef(br);
							ndx.ht[v.obj] = new ArrayList();
							int values = br.ReadInt32();
							for(int vl=0;vl<values;vl++)
							{
								long rowid=br.ReadInt64();
								(ndx.ht[v.obj] as ArrayList).Add(rowid);
							}
						}
					}
					return ndx;
				}
			}
			catch(Exception ex)
			{
				throw new Exception(ex.Message+"\n"+FuncErrCode+": Inner exception.");
			}
		}