lib/QuickBaseClient.rb in quickbase_client-1.0.8 vs lib/QuickBaseClient.rb in quickbase_client-1.0.9

- old
+ new

@@ -1233,10 +1233,12 @@ if query and query.elements["qyclst"] clistForQuery = query.elements["qyclst"].text.dup end clistForQuery end + + alias getColumnListForReport getColumnListForQuery # Returns the slist associated with a query. def getSortListForQuery( id, name ) slistForQuery = nil if id @@ -1247,11 +1249,29 @@ if query and query.elements["qyslst"] slistForQuery = query.elements["qyslst"].text.dup end slistForQuery end + + alias getSortListForReport getSortListForQuery + # Returns the criteria associated with a query. + def getCriteriaForQuery( id, name ) + criteriaForQuery = nil + if id + query = lookupQuery( id ) + elsif name + query = lookupQueryByName( name ) + end + if query and query.elements["qycrit"] + criteriaForQuery = query.elements["qycrit"].text.dup + end + criteriaForQuery + end + + alias getCriteriaForReport getCriteriaForQuery + # Returns a valid query operator. def verifyQueryOperator( operator, fieldType ) queryOperator = "" if @queryOperators.nil? @@ -2009,19 +2029,19 @@ # API_DoQuery 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 - - xmlRequestData = getQueryRequestXML( query, qid, qname ) @clist ||= getColumnListForQuery(qid, qname) + @slist ||= getSortListForQuery(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 + 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" ) @@ -2140,10 +2160,13 @@ # Download a file's contents from a file attachment field in QuickBase. # You must write the contents to disk before a local file exists. # Uses the active table id. def _downLoadFile( rid, fid, vid = "0" ) downLoadFile( @dbid, rid, fid, vid ) end + alias downloadFile downLoadFile + alias _downloadFile _downLoadFile + # API_EditRecord def editRecord( dbid, rid, fvlist, disprec = nil, fform = nil, ignoreError = nil, update_id = nil, msInUTC =nil ) @dbid, @rid, @fvlist, @disprec, @fform, @ignoreError, @update_id, @msInUTC = dbid, rid, fvlist, disprec, fform, ignoreError, update_id, msInUTC setFieldValues( fvlist, false ) if fvlist.is_a?(Hash) @@ -2273,16 +2296,18 @@ # API_GenAddRecordForm, using the active table id. def _genAddRecordForm( fvlist = nil ) genAddRecordForm( @dbid, fvlist ) end # API_GenResultsTable - def genResultsTable( dbid, query = nil, clist = nil, slist = nil, jht = nil, jsa = nil, options = nil ) + def genResultsTable( dbid, query = nil, clist = nil, slist = nil, jht = nil, jsa = nil, options = nil, qid = nil, qname = nil ) @dbid, @query, @clist, @slist, @jht, @jsa, @options = dbid, query, clist, slist, jht, jsa, options - @query = "{'0'.CT.''}" if @query.nil? - xmlRequestData = toXML( :query, @query ) + @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( :jht, @jht ) if @jht xmlRequestData << toXML( :jsa, @jsa ) if @jsa xmlRequestData << toXML( :options, @options ) if @options @@ -4420,9 +4445,20 @@ output = "" end end } end + + # Create a CSV file using the records for a Report. + def makeCSVFileForReport(filename,dbid=@dbid,query=nil,qid=nil,qname=nil) + csv = getCSVForReport(dbid,query,qid,qname) + File.open(filename,"w"){|f|f.write(csv || "")} + end + + # Get the CSV data for a Report. + def getCSVForReport(dbid,query=nil,qid=nil,qname=nil) + genResultsTable(dbid,query,nil,nil,nil,nil,"csv",qid,qname) + end # Upload a file into a new record in a table. # Additional field values can optionally be set. # e.g. uploadFile( "dhnju5y7", "contacts.txt", "Contacts File", { "Notes" => "#{Time.now}" } def uploadFile( dbid, filename, fileAttachmentFieldName, additionalFieldsToSet = nil )