pg 0.8.0-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,180 @@
1
+
2
+ #ifndef __compat_h
3
+ #define __compat_h
4
+
5
+ #include <stdlib.h>
6
+
7
+ #include "libpq-fe.h"
8
+ #include "libpq/libpq-fs.h" /* large-object interface */
9
+
10
+ #include "ruby.h"
11
+
12
+ /* pg_config.h does not exist in older versions of
13
+ * PostgreSQL, so I can't effectively use PG_VERSION_NUM
14
+ * Instead, I create some #defines to help organization.
15
+ */
16
+ #ifndef HAVE_PQCONNECTIONUSEDPASSWORD
17
+ #define PG_BEFORE_080300
18
+ #endif
19
+
20
+ #ifndef HAVE_PQISTHREADSAFE
21
+ #define PG_BEFORE_080200
22
+ #endif
23
+
24
+ #ifndef HAVE_LO_CREATE
25
+ #define PG_BEFORE_080100
26
+ #endif
27
+
28
+ #ifndef HAVE_PQPREPARE
29
+ #define PG_BEFORE_080000
30
+ #endif
31
+
32
+ #ifndef HAVE_PQEXECPARAMS
33
+ #define PG_BEFORE_070400
34
+ #endif
35
+
36
+ #ifndef HAVE_PQESCAPESTRINGCONN
37
+ #define PG_BEFORE_070300
38
+ #error PostgreSQL client version too old, requires 7.3 or later.
39
+ #endif
40
+
41
+ /* This is necessary because NAMEDATALEN is defined in
42
+ * pg_config_manual.h in 8.3, and that include file doesn't
43
+ * exist before 7.4
44
+ */
45
+ #ifndef PG_BEFORE_070400
46
+ #include "pg_config_manual.h"
47
+ #endif
48
+
49
+ #ifndef PG_DIAG_INTERNAL_POSITION
50
+ #define PG_DIAG_INTERNAL_POSITION 'p'
51
+ #endif /* PG_DIAG_INTERNAL_POSITION */
52
+
53
+ #ifndef PG_DIAG_INTERNAL_QUERY
54
+ #define PG_DIAG_INTERNAL_QUERY 'q'
55
+ #endif /* PG_DIAG_INTERNAL_QUERY */
56
+
57
+ #ifdef PG_BEFORE_080300
58
+
59
+ #ifndef HAVE_PG_ENCODING_TO_CHAR
60
+ #define pg_encoding_to_char(x) "SQL_ASCII"
61
+ #else
62
+ /* Some versions ofPostgreSQL prior to 8.3 define pg_encoding_to_char
63
+ * but do not declare it in a header file, so this declaration will
64
+ * eliminate an unecessary warning
65
+ */
66
+ extern char* pg_encoding_to_char(int);
67
+ #endif /* HAVE_PG_ENCODING_TO_CHAR */
68
+
69
+ int PQconnectionNeedsPassword(PGconn *conn);
70
+ int PQconnectionUsedPassword(PGconn *conn);
71
+ int lo_truncate(PGconn *conn, int fd, size_t len);
72
+
73
+ #endif /* PG_BEFORE_080300 */
74
+
75
+ #ifdef PG_BEFORE_080200
76
+ int PQisthreadsafe(void);
77
+ int PQnparams(const PGresult *res);
78
+ Oid PQparamtype(const PGresult *res, int param_number);
79
+ PGresult * PQdescribePrepared(PGconn *conn, const char *stmtName);
80
+ PGresult * PQdescribePortal(PGconn *conn, const char *portalName);
81
+ int PQsendDescribePrepared(PGconn *conn, const char *stmtName);
82
+ int PQsendDescribePortal(PGconn *conn, const char *portalName);
83
+ char *PQencryptPassword(const char *passwd, const char *user);
84
+ #endif /* PG_BEFORE_080200 */
85
+
86
+ #ifdef PG_BEFORE_080100
87
+ Oid lo_create(PGconn *conn, Oid lobjId);
88
+ #endif /* PG_BEFORE_080100 */
89
+
90
+ #ifdef PG_BEFORE_080000
91
+ PGresult *PQprepare(PGconn *conn, const char *stmtName, const char *query,
92
+ int nParams, const Oid *paramTypes);
93
+ int PQsendPrepare(PGconn *conn, const char *stmtName, const char *query,
94
+ int nParams, const Oid *paramTypes);
95
+ int PQserverVersion(const PGconn* conn);
96
+ #endif /* PG_BEFORE_080000 */
97
+
98
+ #ifdef PG_BEFORE_070400
99
+
100
+ #define PG_DIAG_SEVERITY 'S'
101
+ #define PG_DIAG_SQLSTATE 'C'
102
+ #define PG_DIAG_MESSAGE_PRIMARY 'M'
103
+ #define PG_DIAG_MESSAGE_DETAIL 'D'
104
+ #define PG_DIAG_MESSAGE_HINT 'H'
105
+ #define PG_DIAG_STATEMENT_POSITION 'P'
106
+ #define PG_DIAG_CONTEXT 'W'
107
+ #define PG_DIAG_SOURCE_FILE 'F'
108
+ #define PG_DIAG_SOURCE_LINE 'L'
109
+ #define PG_DIAG_SOURCE_FUNCTION 'R'
110
+
111
+ #define PQfreemem(ptr) free(ptr)
112
+ #define PGNOTIFY_EXTRA(notify) ""
113
+
114
+ /* CONNECTION_SSL_STARTUP was added to an enum type
115
+ * after 7.3. For 7.3 in order to compile, we just need
116
+ * it to evaluate to something that is not present in that
117
+ * enum.
118
+ */
119
+ #define CONNECTION_SSL_STARTUP 1000000
120
+
121
+ typedef void (*PQnoticeReceiver) (void *arg, const PGresult *res);
122
+
123
+ typedef enum
124
+ {
125
+ PQERRORS_TERSE, /* single-line error messages */
126
+ PQERRORS_DEFAULT, /* recommended style */
127
+ PQERRORS_VERBOSE /* all the facts, ma'am */
128
+ } PGVerbosity;
129
+
130
+ typedef enum
131
+ {
132
+ PQTRANS_IDLE, /* connection idle */
133
+ PQTRANS_ACTIVE, /* command in progress */
134
+ PQTRANS_INTRANS, /* idle, within transaction block */
135
+ PQTRANS_INERROR, /* idle, within failed transaction */
136
+ PQTRANS_UNKNOWN /* cannot determine status */
137
+ } PGTransactionStatusType;
138
+
139
+ PGresult *PQexecParams(PGconn *conn, const char *command, int nParams,
140
+ const Oid *paramTypes, const char * const * paramValues, const int *paramLengths,
141
+ const int *paramFormats, int resultFormat);
142
+ PGTransactionStatusType PQtransactionStatus(const PGconn *conn);
143
+ char *PQparameterStatus(const PGconn *conn, const char *paramName);
144
+ int PQprotocolVersion(const PGconn *conn);
145
+ PGresult *PQexecPrepared(PGconn *conn, const char *stmtName, int nParams,
146
+ const char * const *ParamValues, const int *paramLengths, const int *paramFormats,
147
+ int resultFormat);
148
+ int PQsendQueryParams(PGconn *conn, const char *command, int nParams,
149
+ const Oid *paramTypes, const char * const * paramValues, const int *paramLengths,
150
+ const int *paramFormats, int resultFormat);
151
+ int PQsendQueryPrepared(PGconn *conn, const char *stmtName, int nParams,
152
+ const char * const *ParamValues, const int *paramLengths, const int *paramFormats,
153
+ int resultFormat);
154
+ int PQputCopyData(PGconn *conn, const char *buffer, int nbytes);
155
+ int PQputCopyEnd(PGconn *conn, const char *errormsg);
156
+ int PQgetCopyData(PGconn *conn, char **buffer, int async);
157
+ PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity);
158
+ Oid PQftable(const PGresult *res, int column_number);
159
+ int PQftablecol(const PGresult *res, int column_number);
160
+ int PQfformat(const PGresult *res, int column_number);
161
+ char *PQresultErrorField(const PGresult *res, int fieldcode);
162
+ PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn, PQnoticeReceiver proc, void *arg);
163
+
164
+ #else
165
+ #define PGNOTIFY_EXTRA(notify) ((notify)->extra)
166
+ #endif /* PG_BEFORE_070400 */
167
+
168
+ #ifdef PG_BEFORE_070300
169
+ #error unsupported postgresql version, requires 7.3 or later.
170
+ int PQsetClientEncoding(PGconn *conn, const char *encoding)
171
+ size_t PQescapeString(char *to, const char *from, size_t length);
172
+ unsigned char * PQescapeBytea(const unsigned char *bintext, size_t binlen, size_t *bytealen);
173
+ unsigned char * PQunescapeBytea(const unsigned char *strtext, size_t *retbuflen);
174
+ size_t PQescapeStringConn(PGconn *conn, char *to, const char *from,
175
+ size_t length, int *error);
176
+ unsigned char *PQescapeByteaConn(PGconn *conn, const unsigned char *from,
177
+ size_t from_length, size_t *to_length);
178
+ #endif /* PG_BEFORE_070300 */
179
+
180
+ #endif /* __compat_h */
@@ -0,0 +1,87 @@
1
+ require 'mkmf'
2
+
3
+ begin
4
+ IO.popen("pg_config --version").readline.chomp
5
+ rescue
6
+ $stderr.write("ERROR: can't find pg_config.\n")
7
+ $stderr.write("HINT: Make sure pg_config is in your PATH\n")
8
+ exit 1
9
+ end
10
+
11
+ # OS X compatibility
12
+ if(RUBY_PLATFORM =~ /darwin/) then
13
+ # test if postgresql is probably universal
14
+ bindir = (IO.popen("pg_config --bindir").readline.chomp rescue nil)
15
+ filetype = (IO.popen("file #{bindir}/pg_config").
16
+ readline.chomp rescue nil)
17
+ # if it's not universal, ARCHFLAGS should be set
18
+ if((filetype !~ /universal binary/) && ENV['ARCHFLAGS'].nil?) then
19
+ arch_tmp = (IO.popen("uname -p").readline.chomp rescue nil)
20
+ if(arch_tmp == 'powerpc')
21
+ arch = 'ppc'
22
+ else
23
+ arch = 'i386'
24
+ end
25
+ $stderr.write %{
26
+ =========== WARNING ===========
27
+
28
+ You are building this extension on OS X without setting the
29
+ ARCHFLAGS environment variable, and PostgreSQL does not appear
30
+ to have been built as a universal binary. If you are seeing this
31
+ message, that means that the build will probably fail.
32
+
33
+ Try setting the environment variable ARCHFLAGS
34
+ to '-arch #{arch}' before building.
35
+
36
+ For example:
37
+ (in bash) $ export ARCHFLAGS='-arch #{arch}'
38
+ (in tcsh) % setenv ARCHFLAGS '-arch #{arch}'
39
+
40
+ Then try building again.
41
+
42
+ ===================================
43
+ }
44
+ # We don't exit here. Who knows? It might build.
45
+ end
46
+ end
47
+
48
+ if RUBY_VERSION < '1.8'
49
+ puts 'This library is for ruby-1.8 or higher.'
50
+ exit 1
51
+ end
52
+
53
+ def config_value(type)
54
+ ENV["POSTGRES_#{type.upcase}"] || pg_config(type)
55
+ end
56
+
57
+ def pg_config(type)
58
+ IO.popen("pg_config --#{type}dir").readline.chomp rescue nil
59
+ end
60
+
61
+ def have_build_env
62
+ (have_library('pq') || have_library('libpq') || have_library('ms/libpq')) &&
63
+ have_header('libpq-fe.h') && have_header('libpq/libpq-fs.h')
64
+ end
65
+
66
+ dir_config('pg', config_value('include'), config_value('lib'))
67
+
68
+ desired_functions = %w(
69
+ PQconnectionUsedPassword
70
+ PQisthreadsafe
71
+ PQprepare
72
+ PQexecParams
73
+ PQescapeString
74
+ PQescapeStringConn
75
+ lo_create
76
+ pg_encoding_to_char
77
+ PQsetClientEncoding
78
+ )
79
+
80
+ if have_build_env
81
+ desired_functions.each(&method(:have_func))
82
+ $OBJS = ['pg.o','compat.o']
83
+ create_makefile("pg")
84
+ else
85
+ puts 'Could not find PostgreSQL build environment (libraries & headers): Makefile not created'
86
+ end
87
+
@@ -0,0 +1,24 @@
1
+ # We can't use Ruby's standard build procedures
2
+ # on Windows because the Ruby executable is
3
+ # built with VC++ while here we want to build
4
+ # with MingW. So just roll our own...
5
+
6
+ require 'fileutils'
7
+ require 'rbconfig'
8
+
9
+ EXTENSION_NAME = "pg.#{Config::CONFIG["DLEXT"]}"
10
+
11
+ # This is called when the Windows GEM is installed!
12
+ task :install do
13
+ # Gems will pass these two environment variables:
14
+ # RUBYARCHDIR=#{dest_path}
15
+ # RUBYLIBDIR=#{dest_path}
16
+
17
+ dest_path = ENV['RUBYLIBDIR']
18
+ mkdir_p(dest_path)
19
+
20
+ # Copy the extension
21
+ cp(EXTENSION_NAME, dest_path)
22
+ end
23
+
24
+ task :default => :install
@@ -0,0 +1,40 @@
1
+ # We can't use Ruby's standard build procedures
2
+ # on Windows because the Ruby executable is
3
+ # built with VC++ while here we want to build
4
+ # with MingW. So just roll our own...
5
+
6
+ require 'rake/clean'
7
+ require 'rbconfig'
8
+
9
+ RUBY_INCLUDE_DIR = Config::CONFIG["archdir"]
10
+ RUBY_BIN_DIR = Config::CONFIG["bindir"]
11
+ RUBY_LIB_DIR = Config::CONFIG["libdir"]
12
+ RUBY_SHARED_LIB = Config::CONFIG["LIBRUBY"]
13
+ RUBY_SHARED_DLL = RUBY_SHARED_LIB.gsub(/lib$/, 'dll')
14
+
15
+ EXTENSION_NAME = "pg.#{Config::CONFIG["DLEXT"]}"
16
+
17
+ CLEAN.include('*.o')
18
+ CLOBBER.include(EXTENSION_NAME)
19
+
20
+ task :default => "pg"
21
+
22
+ DEFINES = "-DHAVE_LIBPQ_FE_H -DHAVE_LIBPQ_LIBPQ_FS_H -DHAVE_PQCONNECTIONUSEDPASSWORD -DHAVE_PQISTHREADSAFE -DHAVE_LO_CREATE -DHAVE_PQPREPARE -DHAVE_PQEXECPARAMS -DHAVE_PQESCAPESTRING -DHAVE_PQESCAPESTRINGCONN -DHAVE_PG_ENCODING_TO_CHAR -DHAVE_PQSETCLIENTENCODING"
23
+ LIBS = "-lpq -lm"
24
+ SRC = FileList['../*.c']
25
+ OBJ = SRC.collect do |file_name|
26
+ File.basename(file_name).ext('o')
27
+ end
28
+
29
+ SRC.each do |srcfile|
30
+ objfile = File.basename(srcfile).ext('o')
31
+ file objfile => srcfile do
32
+ command = "gcc -c -O2 -Wall #{DEFINES} -o #{objfile} -I/usr/local/include #{srcfile} -I#{RUBY_INCLUDE_DIR}"
33
+ sh "sh -c '#{command}'"
34
+ end
35
+ end
36
+
37
+ file "pg" => OBJ do
38
+ command = "gcc -shared -o #{EXTENSION_NAME} #{OBJ} -L/usr/local/lib #{LIBS} #{RUBY_BIN_DIR}/#{RUBY_SHARED_DLL}"
39
+ sh "sh -c '#{command}'"
40
+ end
Binary file
@@ -0,0 +1,138 @@
1
+ require 'rubygems'
2
+ require 'mkrf'
3
+
4
+ pg_config_command =
5
+ if RUBY_PLATFORM.match(/win32/)
6
+ "pg_config --bindir > nul"
7
+ else
8
+ "pg_config --bindir > /dev/null"
9
+ end
10
+
11
+ unless system(pg_config_command)
12
+ $stderr.write("ERROR: can't find pg_config.\n")
13
+ $stderr.write("HINT: Make sure pg_config is in your PATH\n")
14
+ exit 1
15
+ end
16
+
17
+ $functions = %w[
18
+ lo_create
19
+ PQconnectionUsedPassword
20
+ PQisthreadsafe
21
+ PQprepare
22
+ PQexecParams
23
+ PQescapeString
24
+ PQescapeStringConn
25
+ lo_create
26
+ pg_encoding_to_char
27
+ PQsetClientEncoding
28
+ ]
29
+
30
+ # OS X compatibility
31
+ if(PLATFORM =~ /darwin/) then
32
+ # test if postgresql is probably universal
33
+ bindir = escape_path(IO.popen("pg_config --bindir").readline.chomp)
34
+ Open3.popen3('file',"#{bindir}/pg_config") do |the_in, the_out, the_err|
35
+ filetype = the_out.readline.chomp
36
+ end
37
+ # if it's not universal, ARCHFLAGS should be set
38
+ if((filetype !~ /universal binary/) && ENV['ARCHFLAGS'].nil?) then
39
+ arch_tmp = (IO.popen("uname -p").readline.chomp rescue nil)
40
+ if(arch_tmp == 'powerpc')
41
+ arch = 'ppc'
42
+ else
43
+ arch = 'i386'
44
+ end
45
+ $stderr.write %{
46
+ =========== WARNING ===========
47
+
48
+ You are building this extension on OS X without setting the
49
+ ARCHFLAGS environment variable, and PostgreSQL does not appear
50
+ to have been built as a universal binary. If you are seeing this
51
+ message, that means that the build will probably fail.
52
+
53
+ Try setting the environment variable ARCHFLAGS
54
+ to '-arch #{arch}' before building.
55
+
56
+ For example:
57
+ (in bash) $ export ARCHFLAGS='-arch #{arch}'
58
+ (in tcsh) % setenv ARCHFLAGS '-arch #{arch}'
59
+
60
+ Then try building again.
61
+
62
+ ===================================
63
+ }
64
+ # We don't exit here. Who knows? It might build.
65
+ end
66
+ end
67
+
68
+ if RUBY_VERSION < '1.8'
69
+ puts 'This library is for ruby-1.8 or higher.'
70
+ exit 1
71
+ end
72
+
73
+ def escape_path(path)
74
+ if(PLATFORM =~ /mswin|mingw/) then
75
+ '"' + path + '"'
76
+ else
77
+ path.gsub(%r{([^a-zA-Z0-9/._-])}, "\\\\\\1")
78
+ end
79
+ end
80
+
81
+ def pg_config(type)
82
+ IO.popen("pg_config --#{type}dir").readline.chomp
83
+ end
84
+
85
+ def config_value(type)
86
+ escape_path(ENV["POSTGRES_#{type.upcase}"] || pg_config(type))
87
+ end
88
+
89
+ Mkrf::Generator.new('pg', '*.c',
90
+ {
91
+ :includes => [config_value('include'), Config::CONFIG['includedir'],
92
+ Config::CONFIG["archdir"], Config::CONFIG['sitelibdir'], "."],
93
+ :library_paths => [config_value('lib')],
94
+ # must set loaded_libs to work around a mkrf bug on some platforms
95
+ :loaded_libs => []
96
+ }
97
+ ) do |g|
98
+
99
+ $stdout.write("checking for libpq-fe.h... ")
100
+ if g.include_header('libpq-fe.h') &&
101
+ g.include_header('libpq/libpq-fs.h')
102
+ then
103
+ puts 'yes'
104
+ else
105
+ puts 'no'
106
+ puts 'Could not find PostgreSQL headers: ' +
107
+ 'Rakefile not created'
108
+ exit 1
109
+ end
110
+
111
+ $stdout.write("checking for libpq... ")
112
+ # we have to check a few possible names to account
113
+ # for building on windows
114
+ if g.include_library('pq') ||
115
+ g.include_library('libpq') ||
116
+ g.include_library('ms/libpq')
117
+ then
118
+ puts 'yes'
119
+ else
120
+ puts 'no'
121
+ puts 'Could not find PostgreSQL client library: ' +
122
+ 'Rakefile not created'
123
+ exit 1
124
+ end
125
+
126
+ $functions.each do |func|
127
+ $stdout.write("checking for #{func}()... ")
128
+ if(g.has_function?(func)) then
129
+ g.add_define("HAVE_#{func.upcase}")
130
+ puts 'yes'
131
+ else
132
+ puts 'no'
133
+ end
134
+ end
135
+
136
+ puts "creating Rakefile"
137
+ end
138
+