/// <summary>
		/// [R1 is deprecated use R2] Fixes unfinished writes in a previous table grow
		/// </summary>
		/// <param name="TableName"></param>
		/// <param name="f"></param>
		unsafe internal void CheckTable_FixContent(string TableName, Field f)
		{
			const string FuncErrCode=ClassErrCode+".0013";
			try
			{
				lock(this.TableBlocking)
				{
					if(!this.TableBlocking.Contains(TableName))
						this.TableBlocking[TableName] = new SortedList();// index cache
				}
				lock(this.TableBlocking[TableName])
				{
					// Check content
					if(true)
					{
						FileStream fs = FileStream2.NewFileStream(System.IO.Path.GetDirectoryName(DatabaseFilePath)+"\\"+TableName+".hc"+f.seq.ToString(),FileMode.Open,FileAccess.ReadWrite,FileShare.None);
						BinaryReader br = new BinaryReader(fs);
						bool flag = br.ReadBoolean();
						if(flag)
						//if(true)
						{
							HFI hfi = HFI.Read(TableName,DatabaseFilePath);
							long supposedLen = (f.DataSize()*hfi.rowseq)+sizeof(bool);
							long offset=fs.Length-supposedLen;
							if(fs.Length<supposedLen)
							{
								// Recovering corrupt data
								long start = (fs.Length-sizeof(bool))/f.DataSize();
								fs.Position=start*f.DataSize()+sizeof(bool);
								BinaryWriter bw = new BinaryWriter(fs);
								for(long n=start;n<hfi.rowseq;n++)
								{
									f.WriteDefaultData(bw,false);
								}
								bw.Flush();
								bw.BaseStream.Position=0;
								bw.Write((bool)false); // edition flag
								bw.Flush();
								
								// Destroy the index
								if(f.bIndexed)
								{
									(TableBlocking[TableName] as SortedList)[f.seq]=null;
									SetDirtyIndexInDisc(TableName,f);
								}
								try
								{
									LogToFile("Warning","Recovering unfinished column.'"+TableName+"' by "+offset.ToString()+" bytes");
								}
								catch
								{
								}
							}
						}
						fs.Flush();
						fs.Close();
					}
				}
			}
			catch(Exception ex)
			{
				throw new Exception(ex.Message+"\n"+FuncErrCode+": Inner exception.");
			}
		}
		/// <summary>
		/// [R1 is deprecated use R2] Adds a table
		/// </summary>
		public void AddField(string TableName, Field f)
		{
			const string FuncErrCode=ClassErrCode+".0010";
			try
			{
				lock(this.TableBlocking)
				{
					string[] tblnames;
					GetTableNames(out tblnames);
					if(!new ArrayList(tblnames).Contains(TableName))
						throw new Exception("HyperNetDatabase error: Table not present.");

					// set entry
					if(!this.TableBlocking.Contains(TableName))
						this.TableBlocking[TableName] = new SortedList();
				}
				lock(this.TableBlocking[TableName])
				{
					string tbl = TableName;
					QueryCacheDestroy(TableName);
					Field[] flds = GetFields(TableName);
					foreach(Field i in flds)
					{
						if(f.Name==i.Name)
							throw new Exception("HyperNetDatabase error: Column already present.");
					}
					FieldsCache[TableName]=null; // cancel Field Cache
					long fatid,rownum,fseq;
					HFI hfi = HFI.Read(tbl,DatabaseFilePath);
					fatid = hfi.fatid;
					
					rownum = hfi.rowseq;

					// gets new field seq
					fseq = hfi.fieldseq;
					hfi.fieldseq++;
					hfi.Write(tbl,DatabaseFilePath); 

					fatid = (fatid + 1) % 2;

					if(true)// Fat
					{
						// Create fat file
						FileStream fs = FileStream2.NewFileStream(System.IO.Path.GetDirectoryName(DatabaseFilePath)+"\\"+tbl+".hf"+fatid.ToString(),FileMode.Create,FileAccess.Write,FileShare.None);
						BinaryWriter bw = new BinaryWriter(fs,System.Text.Encoding.UTF8);
						bw.Write(magic);
						bw.Write((long)(flds.Length+1));
	 
						for(int n=0;n<flds.Length;n++)
							flds[n].Write(bw);
						f.seq=fseq;
						f.Write(bw);
						bw.Flush();
						bw.Close();
						

//						try
//						{
//
//							string fileName = System.IO.Path.GetDirectoryName(DatabaseFilePath)+"\\"+tbl+".hf"+((fatid + 1) % 2).ToString();
////							FileStream2.CloseHandle(fileName);
//							File.Delete(fileName);
//						}
//						catch
//						{
//						}

						// Create column data
						fs = FileStream2.NewFileStream(System.IO.Path.GetDirectoryName(DatabaseFilePath)+"\\"+tbl+".hc"+fseq.ToString(),FileMode.Create,FileAccess.Write,FileShare.None);
						bw = new BinaryWriter(fs,System.Text.Encoding.UTF8);
						bw.Write((bool)true); // edition flag
						bw.Flush();
						for(int n=0;n<rownum;n++)
						{
							f.WriteDefaultData(bw,false);
						}
						bw.Flush();
						bw.BaseStream.Position=0;
						bw.Write((bool)false); // edition flag
						bw.Flush();
						bw.Close();

						// Change fat pointer
						hfi.fatid=fatid;
						hfi.Write(tbl,DatabaseFilePath);
					}

				}
			}
			catch(Exception ex)
			{
				throw new Exception(ex.Message+"\n"+FuncErrCode+": Inner exception.");
			}
		}