   if nextQuery?
     queueInProgress = true
     result = []
-
+    console.log nextQuery.query
     request = new tedious.Request nextQuery.query, (err, rowCount) ->
       if err
-        nextQuery.promise.reject err
+        nextQuery.cb err
       else
         if nextQuery.returnArray
-          nextQuery.promise.resolve result
+          nextQuery.cb null, result
         else
-          nextQuery.promise.resolve result[0]
+          nextQuery.cb null, result[0]
       #recursive call to process anything else on the queue
       processQueryQueue()
 


runQuery = (query, returnArray, conn, cb) ->

  console.log 'running query ' + query
  #pop query on the queue
  deferred = Q.defer()

  obj =
    query: query
    returnArray: returnArray
    conn: conn
    promise: deferred

  queryQueue.push obj
  
  if !queueInProgress
    processQueryQueue()

  deferred.promise.nodeify cb

module.exports =
  runQuery: runQuery

tedious = require 'tedious'
queryQueue = []
queueInProgress = false
