Sha256: 76af95fd2757a341f7d48cfc888c6c316f44b350adfffb01fdaa41b23b1fce7e

Contents?: true

Size: 1.23 KB

Versions: 68

Compression:

Stored size: 1.23 KB

Contents

#!/usr/bin/env ruby

def camelize(lower_case_and_underscored_word)
	lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
end

ec_txt, ec_def = *ARGV

File.open(ec_def, 'w') do |fd_def|
	fd_def.puts <<EOCODE
/*
 * #{ec_def} - Definition of error classes.
 *
 * WARNING: This file is autogenerated. Please edit #{__FILE__} !
 *
 */


EOCODE

	File.read(ec_txt).lines.each do |line|
		# The format of this file is one error code per line, with the following
		# whitespace-separated fields:
		#
		#      sqlstate    E/W/S    errcode_macro_name    spec_name

		if line =~ /^(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+/i
			sqlstate, ews, errcode_macro_name = $1, $2, $3
			next unless ews=='E'

			is_sqlclass = sqlstate[2..-1] == '000'
			class_code = sqlstate[0,2]
			baseclass_code = is_sqlclass ? 'NULL' : class_code.inspect
			class_name = camelize(errcode_macro_name.sub('ERRCODE_', '').downcase)

			fd_def.puts "{"
			fd_def.puts "  VALUE klass = define_error_class( #{class_name.inspect}, #{baseclass_code} );"
			fd_def.puts "  register_error_class( #{sqlstate.inspect}, klass );"
			if is_sqlclass
				fd_def.puts "  register_error_class( #{class_code.inspect}, klass );"
			end
			fd_def.puts "}"
		end
	end
end

Version data entries

68 entries across 68 versions & 4 rubygems

Version Path
pg-1.0.0-x64-mingw32 ext/errorcodes.rb
pg-1.0.0-x86-mingw32 ext/errorcodes.rb
pg-1.0.0 ext/errorcodes.rb
pg-0.21.0-x64-mingw32 ext/errorcodes.rb
pg-0.21.0-x86-mingw32 ext/errorcodes.rb
pg-0.21.0 ext/errorcodes.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/pg-0.20.0/ext/errorcodes.rb
pg-0.20.0-x86-mingw32 ext/errorcodes.rb
pg-0.20.0-x64-mingw32 ext/errorcodes.rb
pg-0.20.0 ext/errorcodes.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/errorcodes.rb
pg-0.19.1.pre20170124220800-x64-mingw32 ext/errorcodes.rb
pg-0.19.1.pre20170124220800-x86-mingw32 ext/errorcodes.rb
pg-0.19.1.pre20170124220800 ext/errorcodes.rb
pg-0.19.1.pre20170115074000-x64-mingw32 ext/errorcodes.rb
pg-0.19.1.pre20170115074000-x86-mingw32 ext/errorcodes.rb
pg-0.19.1.pre20170115074000 ext/errorcodes.rb
pg-0.19.0.pre20170115074000 ext/errorcodes.rb
pg-0.19.0-x86-mingw32 ext/errorcodes.rb
pg-0.19.0-x64-mingw32 ext/errorcodes.rb