// String and Binary handling. These are represented as a long, which is an offset into a file.
 
  public long EncodeString( string s ) 
  { 
    if ( s == "" ) return 0;
    // See if it is in SysStringIndex
    try
    {
      var start = new StringStart( s );
      foreach( IndexFileRecord ixr in SysStringIndex.From( start.Compare, false ) )
      {
        if ( (string)(ixr.Col[0]._O) == s ) return ixr.Col[0].L;
        break;
      }
    }
    catch ( System.Exception x )
    {
      SysStringIndex.Dump();
      throw x;
    }

    // Save to file.
    long sid = SysString.Length;
    SysString.Position = sid;
    SysStringWriter.Write( s );

    // Insert into the index
    IndexFileRecord r = new IndexFileRecord( 1 );
    r.Col[ 0 ].L = sid + 1;
    r.Col[ 0 ]._O = s;
    SysStringIndex.Insert( ref r );

    return sid + 1; // + 1 because zero indicates the encoding has not yet been done.
  }
 int ReadSchemaId( string schemaName )
 {
   if ( schemaName == "sys" ) return 1;
   var start = new StringStart( schemaName );
   foreach( IndexFileRecord ixr in SysSchemaByName.From( start.Compare, false ) )
   {
     if ( (string)(ixr.Col[0]._O) == schemaName ) return (int)ixr.Col[1].L;
     break;
   }
   return -1;
 }
 long ReadTableId( Schema schema, string name, out bool isView, out string definition )
 {
   var r = new RowCursor( SysTable );
   var start = new StringStart( name );
   foreach( IndexFileRecord ixr in SysTableByName.From( start.Compare, false ) )
   {
     if ( (string)(ixr.Col[0]._O) == name )
     {
       long id = ixr.Col[1].L;
       r.Get( id );
       if ( r.V[1].L == schema.Id ) 
       {
         isView = r.V[3].L != 0;
         definition = (string)r.V[4]._O;
         return id;
       }
     }
   }
   isView = false; definition = null;
   return -1;
 }