Ejemplo n.º 1
0
    /// <summary>
    /// Create an <see cref="Query"/> object by reading the data from the
    /// goven <see cref="IDataReader"/>.
    /// </summary>
    /// <param name="reader">
    /// A <see cref="IDataReader"/> object where the data to create the
    /// <see cref="Query"/> object could be read from.
    /// </param>
    /// <returns>
    /// A new <see cref="Query"/> object if the specified
    /// <see cref="IDataReader"/> is readable; otherwise the value of
    /// <see cref="Query.EmptyQuery"/> property.
    /// </returns>
    protected IQuery CreateQueryFromDataReader(IDataReader reader) {
      if (reader.Read()) {
        int[] ordinals = reader
          .GetOrdinals("query_name", "query_type", "query", "query_method",
            "query_use_space_as_terminator", "query_delimiter");

        const int kQueryName = 0;
        const int kQueryType = 1;
        const int kQuery = 2;
        const int kQueryMethod = 3;
        const int kUseSpaceTerminator = 4;
        const int kQueryDelimiter = 5;

        bool use_space_terminator =
          reader.GetBoolean(ordinals[kUseSpaceTerminator]);
        string delimiter = reader.GetString(ordinals[kQueryDelimiter]);
        string name = reader.GetString(ordinals[kQueryName]);
        string type = reader.GetString(ordinals[kQueryType]);
        string query_string = reader.GetString(ordinals[kQuery]);
        int method = reader.GetInt32(ordinals[kQueryMethod]);

        var query = new Query(name, type, query_string, delimiter) {
          QueryMethod = (QueryMethod) method,
          UseSpaceAsTerminator = use_space_terminator
        };

        // get the query options
        if (reader.NextResult()) {
          SetQueryOptions(reader, query);
        }
        query.Parse();
        return query;
      }
      return Query.EmptyQuery;
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Initialize the static members.
 /// </summary>
 static Query() {
   empty_query_ = new Query(string.Empty, string.Empty, string.Empty);
 }
Ejemplo n.º 3
0
    void SetQueryOptions(IDataReader reader, Query query) {
      if (reader.Read()) {
        const int kQueryOptionName = 0;
        const int kQueryOptionValue = 1;

        int[] ordinals = reader.GetOrdinals("option_name", "option_value");
        do {
          string name = reader.GetString(ordinals[kQueryOptionName]);
          string value = reader.GetString(ordinals[kQueryOptionValue]);
          query.Options.Add(name, value);
        } while (reader.Read());
      }
    }
Ejemplo n.º 4
0
 public bool Equals(Query query) {
   return query.name_ == name_;
 }