def doQuery( dbid, query = nil, qid = nil, qname = nil, clist = nil, slist = nil, fmt = "structured", options = nil  )

      @dbid, @clist, @slist, @fmt, @options = dbid, clist, slist, fmt, options
      
      @clist ||= getColumnListForQuery(qid, qname)
      @slist ||= getSortListForQuery(qid, qname)
      
      xmlRequestData = getQueryRequestXML( query, qid, qname )
      xmlRequestData << toXML( :clist, @clist ) if @clist
      xmlRequestData << toXML( :slist, @slist ) if @slist
      xmlRequestData << toXML( :fmt, @fmt ) if @fmt
      xmlRequestData << toXML( :options, @options ) if @options

      sendRequest( :doQuery, xmlRequestData )

      if @fmt and @fmt == "structured"
         @records = getResponseElement( "table/records" )
         @fields = getResponseElement( "table/fields" )
         @chdbids = getResponseElement( "table/chdbids" )
         @queries = getResponseElement( "table/queries" )
         @variables = getResponseElement( "table/variables" )
      else
         @records = getResponseElements( "qdbapi/record" )
         @fields = getResponseElements( "qdbapi/field" )
         @chdbids = getResponseElements( "qdbapi/chdbid" )
         @queries = getResponseElements( "qdbapi/query" )
         @variables = getResponseElements( "qdbapi/variable" )
      end

      return self if @chainAPIcalls

      if block_given?
         if @records 
            @records.each { |element|  yield element }
         else
             yield nil
         end  
      else
         @records
      end

   end
def doQuery( dbid, query = nil, qid = nil, qname = nil, clist = nil, slist = nil, fmt = "structured", options = nil  )

      @dbid, @clist, @slist, @fmt, @options = dbid, clist, slist, fmt, options
      
      @clist ||= getColumnListForQuery(qid, qname)
      @slist ||= getSortListForQuery(qid, qname)
      
      xmlRequestData = getQueryRequestXML( query, qid, qname )
      xmlRequestData << toXML( :clist, @clist ) if @clist
      xmlRequestData << toXML( :slist, @slist ) if @slist
      xmlRequestData << toXML( :fmt, @fmt ) if @fmt
      xmlRequestData << toXML( :options, @options ) if @options

      sendRequest( :doQuery, xmlRequestData )

      if @fmt and @fmt == "structured"
         @records = getResponseElement( "table/records" )
         @fields = getResponseElement( "table/fields" )
         @chdbids = getResponseElement( "table/chdbids" )
         @queries = getResponseElement( "table/queries" )
         @variables = getResponseElement( "table/variables" )
      else
         @records = getResponseElements( "qdbapi/record" )
         @fields = getResponseElements( "qdbapi/field" )
         @chdbids = getResponseElements( "qdbapi/chdbid" )
         @queries = getResponseElements( "qdbapi/query" )
         @variables = getResponseElements( "qdbapi/variable" )
      end

      return self if @chainAPIcalls

      if block_given?
         if @records 
            @records.each { |element|  yield element }
         else
             yield nil
         end  
      else
         @records
      end

   end
API_DoQuery