Sha256: c738accd574d871933a46b643eab6af16dc6fd2c0409ec10ba1b9cc2feb9d83b

Contents?: true

Size: 1.96 KB

Versions: 9

Compression:

Stored size: 1.96 KB

Contents

########    #######    ########    #######    ########    ########
##     / / / /    License    \ \ \ \ 
##    Copyleft culture, Copyright (C) is prohibited here
##    This work is licensed under a CC BY-SA 4.0
##    Creative Commons Attribution-ShareAlike 4.0 License
##    Refer to the http://creativecommons.org/licenses/by-sa/4.0/
########    #######    ########    #######    ########    ########
##    / / / /    Code Climate    \ \ \ \ 
##    Language = ruby
##    Indent = space;    4 chars;
########    #######    ########    #######    ########    ########
module ArchestryLookup
  module Sql
    class << self
      
      def sqlQuery(state, sql)
        
#         p "##SQL:: #{sql}"
        res = {}

        case state[:dbtype]
        when :sqlite
          res = sqliteAnswerMap(state[:db][:handler].execute2(sql))
        when :pg
          res = pgAnswerMap(state[:db][:handler].exec(sql))
        end
          
#         p "## SQL_RES:: #{res}"        
        res        
      end
      
      def sqliteAnswerMap(answer)
        res = {}
        m = {}
        n = 0
        j = 0
        answer.each do |result|
          if n == 0
#             puts "##keys::#{result}"
            i = 0
            result.each do |v|
              m[i] = v.to_sym
              i += 1
            end 
          else
#             puts  "##values::#{result}"
            i = 0
            result.each do |v|
              res[j] ||= {}
              res[j][m[i]] = v
              i += 1               
            end 
            j += 1            
          end
          n += 1
        end   
        
        res
      end
      
      def pgAnswerMap(answer)
        res = {}
        m = {}
        i = 0
        answer.each do |result|
#           puts "##values::#{result}"
          result.each do |k, v|
            res[i] ||= {}
            res[i][k.to_sym] = v
          end
          i += 1          
        end   
        
        res
      end      
    
 
      
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
archestry_lookup-0.0.19 lib/sql/dbhandlers.rb
archestry_lookup-0.0.18 lib/sql/dbhandlers.rb
archestry_lookup-0.0.17 lib/sql/dbhandlers.rb
archestry_lookup-0.0.16 lib/sql/dbhandlers.rb
archestry_lookup-0.0.15 lib/sql/dbhandlers.rb
archestry_lookup-0.0.14 lib/sql/dbhandlers.rb
archestry_lookup-0.0.13 lib/sql/dbhandlers.rb
archestry_lookup-0.0.12 lib/sql/dbhandlers.rb
archestry_lookup-0.0.11 lib/sql/dbhandlers.rb