示例#1
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.");
			}
		}
示例#2
0
		/// <summary>
		/// [R1 is deprecated use R2] Reads or regenerates an index for a field in a table
		/// </summary>
		/// <param name="TableName"></param>
		/// <param name="f"></param>
		/// <param name="bForceRegen"></param>
		/// <value></value>
		Index GetIndex(string TableName, Field f, bool bForceRegen)
		{
			const string FuncErrCode=ClassErrCode+".0015";
			try
			{
				lock(this.TableBlocking)
				{
					if(!this.TableBlocking.Contains(TableName))
						this.TableBlocking[TableName] = new SortedList();// index cache
				}
				lock(this.TableBlocking[TableName])
				{
					if((this.TableBlocking[TableName] as SortedList)[f.seq]!=null)
						return (this.TableBlocking[TableName] as SortedList)[f.seq] as Index;
					bool bRegen=true;
					if(!bForceRegen)
					{
						string indexname = TableName+".hi"+f.seq.ToString();
						if(IndexFileExists(indexname))
						{
							FileStream fs = FileStream2.NewFileStream(System.IO.Path.GetDirectoryName(DatabaseFilePath)+"\\"+indexname,FileMode.Open,FileAccess.ReadWrite,FileShare.None);
							BinaryReader br = new BinaryReader(fs);
							bool flag = br.ReadBoolean();
							if(flag)
							{
								bRegen=true;
							}
							else
							{
								bRegen=false;
//								SoapFormatter formatter = new SoapFormatter();
//								Index ndx = (Index)formatter.Deserialize(fs);
								Index ndx = Index.ReadIndexData(this,new BinaryReader(fs));
								(this.TableBlocking[TableName] as SortedList)[f.seq]=ndx;
							}
							fs.Close();
						}
					}
					if(bRegen)
					{// unique key
						if(!f.bIndexed) throw new Exception("Not indexed field");
						
						if(f.bUnique)
						{
							Index ndx = new Index();
							ndx.bUnique=true;
							CheckTable_FixContent(TableName,f); // por si las moscas
							FileStream fs = FileStream2.NewFileStream(System.IO.Path.GetDirectoryName(DatabaseFilePath)+"\\"+TableName+".hc"+f.seq.ToString(),FileMode.Open,FileAccess.Read,FileShare.None);
							BinaryReader br = new BinaryReader(fs);
							bool flag = br.ReadBoolean();
							if(flag)
							{
								throw new Exception("Database corruption");
							}
							else
							{
								HFI hfi = HFI.Read(TableName,DatabaseFilePath);
								for(long n=0;n<hfi.rowseq;n++)
								{
									object o = f.ReadData(this,br);
									ndx.ht[o]=n;
								}
								(this.TableBlocking[TableName] as SortedList)[f.seq]=ndx;
							}
							br.Close();
						}
						else
						{// not unique key
							Index ndx = new Index();
							ndx.bUnique=false;
							CheckTable_FixContent(TableName,f); // por si las moscas
							FileStream fs = FileStream2.NewFileStream(System.IO.Path.GetDirectoryName(DatabaseFilePath)+"\\"+TableName+".hc"+f.seq.ToString(),FileMode.Open,FileAccess.Read,FileShare.None);
							BinaryReader br = new BinaryReader(fs);
							bool flag = br.ReadBoolean();
							if(flag)
							{
								throw new Exception("Database corruption");
							}
							else
							{
								HFI hfi = HFI.Read(TableName,DatabaseFilePath);
								for(long n=0;n<hfi.rowseq;n++)
								{
									object o = f.ReadData(this,br);
									if(ndx.ht[o]==null)
										ndx.ht[o]=new ArrayList();
									(ndx.ht[o] as ArrayList).Add(n);
								}
								(this.TableBlocking[TableName] as SortedList)[f.seq]=ndx;
							}
							br.Close();
						}
					}
					return (this.TableBlocking[TableName] as SortedList)[f.seq] as Index;
				}
			}
			catch(Exception ex)
			{
				throw new Exception(ex.Message+"\n"+FuncErrCode+": Inner exception.");
			}
		}