postgres 0.7.9.2008.01.28 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE DELETED
@@ -1,58 +0,0 @@
1
- Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.co.jp>.
2
- You can redistribute it and/or modify it under either the terms of the GPL
3
- (see COPYING.txt file), or the conditions below:
4
-
5
- 1. You may make and give away verbatim copies of the source form of the
6
- software without restriction, provided that you duplicate all of the
7
- original copyright notices and associated disclaimers.
8
-
9
- 2. You may modify your copy of the software in any way, provided that
10
- you do at least ONE of the following:
11
-
12
- a) place your modifications in the Public Domain or otherwise
13
- make them Freely Available, such as by posting said
14
- modifications to Usenet or an equivalent medium, or by allowing
15
- the author to include your modifications in the software.
16
-
17
- b) use the modified software only within your corporation or
18
- organization.
19
-
20
- c) rename any non-standard executables so the names do not conflict
21
- with standard executables, which must also be provided.
22
-
23
- d) make other distribution arrangements with the author.
24
-
25
- 3. You may distribute the software in object code or executable
26
- form, provided that you do at least ONE of the following:
27
-
28
- a) distribute the executables and library files of the software,
29
- together with instructions (in the manual page or equivalent)
30
- on where to get the original distribution.
31
-
32
- b) accompany the distribution with the machine-readable source of
33
- the software.
34
-
35
- c) give non-standard executables non-standard names, with
36
- instructions on where to get the original software distribution.
37
-
38
- d) make other distribution arrangements with the author.
39
-
40
- 4. You may modify and include the part of the software into any other
41
- software (possibly commercial). But some files in the distribution
42
- are not written by the author, so that they are not under this terms.
43
-
44
- They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
45
- files under the ./missing directory. See each file for the copying
46
- condition.
47
-
48
- 5. The scripts and library files supplied as input to or produced as
49
- output from the software do not automatically fall under the
50
- copyright of the software, but belong to whomever generated them,
51
- and may be sold commercially, and may be aggregated with this
52
- software.
53
-
54
- 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
55
- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
56
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57
- PURPOSE.
58
-
data/README DELETED
@@ -1,125 +0,0 @@
1
- ================================================================================
2
- ruby-pg: Ruby interface to PostgreSQL RDBMS
3
- ================================================================================
4
-
5
- This library is copyrighted by the authors.
6
-
7
- Authors:
8
- * Yukihiro Matsumoto <matz@ruby-lang.org>
9
- Author of Ruby.
10
- * Eiji Matsumoto <usagi@ruby.club.or.jp>
11
- One of users who loves Ruby.
12
- * Jeff Davis <ruby-pg@j-davis.com>
13
-
14
- Thanks to:
15
- * Noboru Saitou <noborus@netlab.jp>
16
- Past maintainer.
17
- * Dave Lee
18
- Past maintainer.
19
- * Guy Decoux ts <decoux@moulon.inra.fr>
20
-
21
- Maintainer:
22
- Jeff Davis <ruby-pg@j-davis.com>
23
-
24
- Copying:
25
- You may redistribute this software under the terms of the GPL,
26
- included in the file named GPL; or under the same terms as Ruby,
27
- included in the file name LICENSE.
28
-
29
- - Summary
30
-
31
- This is the extension library to access a PostgreSQL database from Ruby.
32
- This library works with PostgreSQL 7.4 and later.
33
-
34
- - Requirements
35
-
36
- Ruby 1.8 or later.
37
- PostgreSQL 7.4 or later installed.
38
-
39
- It may work with earlier versions as well, but those are
40
- not regularly tested.
41
-
42
- - How to install ?
43
-
44
- Follow the instructions below to compile and install:
45
-
46
- ruby extconf.rb
47
- make
48
- su (if necessary)
49
- make install
50
-
51
- You may need to specify the directory name for the include files and the
52
- -lpq library by using
53
-
54
- --with-pgsql-include=<include file directory>
55
- --with-pgsql-lib=<library directory>
56
-
57
- For example:
58
-
59
- ruby extconf.rb --with-pgsql-include=/usr/local/pgsql/include \
60
- --with-pgsql-lib=/usr/local/pgsql/lib
61
-
62
- - Modules
63
-
64
- 'pg': The 'pg' module is the newer module, that has been greatly improved, and
65
- is almost a complete rewrite. It is not backwards compatible. Use this module
66
- for newly written code. It should be more stable, less buggy, and has more
67
- features.
68
-
69
- 'postgres': Older module, maintained for backwards compatibility. It
70
- has known flaws that aren't reasonably fixable without breaking backwards
71
- compatibility. Use this module if you have code that already works, and
72
- you just want the fixes that I've committed to this module (for instance,
73
- this module is compatible with PostgreSQL 8.3).
74
-
75
- - How to use ?
76
-
77
- This gem builds and installs two PostgreSQL database adapters, 'postgres'
78
- and 'pg'. 'postgres' is currently (Jan 2008) the recommended PostgreSQL
79
- adapter for use with Rails.
80
-
81
- The standard way to download and install the most current stable
82
- version of the postgres gem (from http://gems.rubyforge.org) is to use
83
- the RubyGem package manager. You may need to supply RubyGem with the
84
- location of the libpq library and the libpq.h and libpq/libpq-fs.h
85
- files, and may need to run as root.
86
- If you installed from source on a Unix system you can locate these
87
- libpq files with:
88
- find <path to install directory> -name "libpq-fe.h" -print
89
- With binary distributions, you may need to install additional
90
- PostgreSQL development libraries to get these files.
91
-
92
- Then run:
93
- sudo gem install postgres -- --with-pgsql-include-dir=<location of
94
- Postgresql>/include --with-pgsql-lib-dir=<location of Postgresql/lib
95
-
96
- Example:
97
- on Mac OS X with PostgreSQL in /Library/PostgreSQL8 use
98
- --with-pgsql-include-dir=/Library/PostgreSQL8/include --with-pgsql-lib-
99
- dir=/Library/PostgreSQL8/lib
100
-
101
- To use the postgres adapter with Rails:
102
- refer to it as
103
- adapter: postgresql
104
- in your database:yaml file
105
-
106
- The pg adapter cannot be used with Rails yet and is available for
107
- testing and developer use.
108
-
109
- To use these modules in Ruby directly (not Rails), refer to the RDoc
110
- documentation.
111
-
112
- - Acknowledgments
113
-
114
- We are thankful to the people at the ruby-list and ruby-dev mailing lists.
115
- And to the people who developed PostgreSQL.
116
-
117
- - Copying
118
-
119
- This library is copyrighted by its authors; Yukihiro Matsumoto, and Eiji
120
- Matsumoto.
121
-
122
- Portions copyright Laika, Inc.
123
-
124
-
125
-
@@ -1,73 +0,0 @@
1
-
2
-
3
- # windows compatibility, need different library name
4
- if(PLATFORM =~ /mingw|mswin/) then
5
- $libname = '/ms/libpq'
6
- else
7
- $libname = 'pq'
8
- end
9
-
10
- if(PLATFORM =~ /darwin/) then
11
- # test if postgresql is probably universal
12
- bindir = (IO.popen("pg_config --bindir").readline.chomp rescue nil)
13
- filetype = (IO.popen("file #{bindir}/pg_config").
14
- readline.chomp rescue nil)
15
- # if it's not universal, ARCHFLAGS should be set
16
- if((filetype !~ /universal binary/) && ENV['ARCHFLAGS'].nil?) then
17
- arch = (IO.popen("uname -m").readline.chomp rescue nil)
18
- $stderr.write %{
19
- =========== WARNING ===========
20
-
21
- You are building this extension on OS X without setting the
22
- ARCHFLAGS environment variable, and PostgreSQL does not appear
23
- to have been built as a universal binary. If you are seeing this
24
- message, that means that the build will probably fail.
25
-
26
- Try setting the environment variable ARCHFLAGS
27
- to '-arch #{arch}' before building.
28
-
29
- For example:
30
- (in bash) $ export ARCHFLAGS='-arch #{arch}'
31
- (in tcsh) $ setenv ARCHFLAGS '-arch #{arch}'
32
-
33
- Then try building again.
34
-
35
- ===================================
36
- }
37
- # We don't exit here. Who knows? It might build.
38
- end
39
- end
40
-
41
- if RUBY_VERSION < '1.8'
42
- puts 'This library is for ruby-1.8 or higher.'
43
- exit 1
44
- end
45
-
46
- require 'mkmf'
47
-
48
- def config_value(type)
49
- ENV["POSTGRES_#{type.upcase}"] || pg_config(type)
50
- end
51
-
52
- def pg_config(type)
53
- IO.popen("pg_config --#{type}dir").readline.chomp rescue nil
54
- end
55
-
56
- def have_build_env
57
- have_library($libname) && have_header('libpq-fe.h') && have_header('libpq/libpq-fs.h')
58
- end
59
-
60
- dir_config('pgsql', config_value('include'), config_value('lib'))
61
-
62
- required_libraries = []
63
- desired_functions = %w(PQsetClientEncoding pg_encoding_to_char PQfreemem PQserverVersion)
64
- compat_functions = %w(PQescapeString PQexecParams)
65
-
66
- if have_build_env
67
- required_libraries.each(&method(:have_library))
68
- desired_functions.each(&method(:have_func))
69
- $objs = ['postgres.o','libpq-compat.o'] if compat_functions.all?(&method(:have_func))
70
- create_makefile("postgres")
71
- else
72
- puts 'Could not find PostgreSQL build environment (libraries & headers): Makefile not created'
73
- end
@@ -1,253 +0,0 @@
1
- #include <stdlib.h>
2
-
3
- #ifndef HAVE_PQESCAPESTRING
4
- /*
5
- * Escaping arbitrary strings to get valid SQL literal strings.
6
- *
7
- * Replaces "\\" with "\\\\" and "'" with "''".
8
- *
9
- * length is the length of the source string. (Note: if a terminating NUL
10
- * is encountered sooner, PQescapeString stops short of "length"; the behavior
11
- * is thus rather like strncpy.)
12
- *
13
- * For safety the buffer at "to" must be at least 2*length + 1 bytes long.
14
- * A terminating NUL character is added to the output string, whether the
15
- * input is NUL-terminated or not.
16
- *
17
- * Returns the actual length of the output (not counting the terminating NUL).
18
- */
19
- size_t
20
- PQescapeString(char *to, const char *from, size_t length)
21
- {
22
- const char *source = from;
23
- char *target = to;
24
- size_t remaining = length;
25
-
26
- while (remaining > 0 && *source != '\0')
27
- {
28
- switch (*source)
29
- {
30
- case '\\':
31
- *target++ = '\\';
32
- *target++ = '\\';
33
- break;
34
-
35
- case '\'':
36
- *target++ = '\'';
37
- *target++ = '\'';
38
- break;
39
-
40
- default:
41
- *target++ = *source;
42
- break;
43
- }
44
- source++;
45
- remaining--;
46
- }
47
-
48
- /* Write the terminating NUL character. */
49
- *target = '\0';
50
-
51
- return target - to;
52
- }
53
-
54
- /*
55
- * PQescapeBytea - converts from binary string to the
56
- * minimal encoding necessary to include the string in an SQL
57
- * INSERT statement with a bytea type column as the target.
58
- *
59
- * The following transformations are applied
60
- * '\0' == ASCII 0 == \\000
61
- * '\'' == ASCII 39 == \'
62
- * '\\' == ASCII 92 == \\\\
63
- * anything < 0x20, or > 0x7e ---> \\ooo
64
- * (where ooo is an octal expression)
65
- */
66
- unsigned char *
67
- PQescapeBytea(const unsigned char *bintext, size_t binlen, size_t *bytealen)
68
- {
69
- const unsigned char *vp;
70
- unsigned char *rp;
71
- unsigned char *result;
72
- size_t i;
73
- size_t len;
74
-
75
- /*
76
- * empty string has 1 char ('\0')
77
- */
78
- len = 1;
79
-
80
- vp = bintext;
81
- for (i = binlen; i > 0; i--, vp++)
82
- {
83
- if (*vp < 0x20 || *vp > 0x7e)
84
- len += 5; /* '5' is for '\\ooo' */
85
- else if (*vp == '\'')
86
- len += 2;
87
- else if (*vp == '\\')
88
- len += 4;
89
- else
90
- len++;
91
- }
92
-
93
- rp = result = (unsigned char *) malloc(len);
94
- if (rp == NULL)
95
- return NULL;
96
-
97
- vp = bintext;
98
- *bytealen = len;
99
-
100
- for (i = binlen; i > 0; i--, vp++)
101
- {
102
- if (*vp < 0x20 || *vp > 0x7e)
103
- {
104
- (void) sprintf(rp, "\\\\%03o", *vp);
105
- rp += 5;
106
- }
107
- else if (*vp == '\'')
108
- {
109
- rp[0] = '\\';
110
- rp[1] = '\'';
111
- rp += 2;
112
- }
113
- else if (*vp == '\\')
114
- {
115
- rp[0] = '\\';
116
- rp[1] = '\\';
117
- rp[2] = '\\';
118
- rp[3] = '\\';
119
- rp += 4;
120
- }
121
- else
122
- *rp++ = *vp;
123
- }
124
- *rp = '\0';
125
-
126
- return result;
127
- }
128
-
129
- #define ISFIRSTOCTDIGIT(CH) ((CH) >= '0' && (CH) <= '3')
130
- #define ISOCTDIGIT(CH) ((CH) >= '0' && (CH) <= '7')
131
- #define OCTVAL(CH) ((CH) - '0')
132
-
133
- /*
134
- * PQunescapeBytea - converts the null terminated string representation
135
- * of a bytea, strtext, into binary, filling a buffer. It returns a
136
- * pointer to the buffer (or NULL on error), and the size of the
137
- * buffer in retbuflen. The pointer may subsequently be used as an
138
- * argument to the function free(3). It is the reverse of PQescapeBytea.
139
- *
140
- * The following transformations are made:
141
- * \\ == ASCII 92 == \
142
- * \ooo == a byte whose value = ooo (ooo is an octal number)
143
- * \x == x (x is any character not matched by the above transformations)
144
- */
145
- unsigned char *
146
- PQunescapeBytea(const unsigned char *strtext, size_t *retbuflen)
147
- {
148
- size_t strtextlen,
149
- buflen;
150
- unsigned char *buffer,
151
- *tmpbuf;
152
- size_t i,
153
- j;
154
-
155
- if (strtext == NULL)
156
- return NULL;
157
-
158
- strtextlen = strlen(strtext);
159
-
160
- /*
161
- * Length of input is max length of output, but add one to avoid
162
- * unportable malloc(0) if input is zero-length.
163
- */
164
- buffer = (unsigned char *) malloc(strtextlen + 1);
165
- if (buffer == NULL)
166
- return NULL;
167
-
168
- for (i = j = 0; i < strtextlen;)
169
- {
170
- switch (strtext[i])
171
- {
172
- case '\\':
173
- i++;
174
- if (strtext[i] == '\\')
175
- buffer[j++] = strtext[i++];
176
- else
177
- {
178
- if ((ISFIRSTOCTDIGIT(strtext[i])) &&
179
- (ISOCTDIGIT(strtext[i + 1])) &&
180
- (ISOCTDIGIT(strtext[i + 2])))
181
- {
182
- int byte;
183
-
184
- byte = OCTVAL(strtext[i++]);
185
- byte = (byte << 3) + OCTVAL(strtext[i++]);
186
- byte = (byte << 3) + OCTVAL(strtext[i++]);
187
- buffer[j++] = byte;
188
- }
189
- }
190
-
191
- /*
192
- * Note: if we see '\' followed by something that isn't a
193
- * recognized escape sequence, we loop around having done
194
- * nothing except advance i. Therefore the something will
195
- * be emitted as ordinary data on the next cycle. Corner
196
- * case: '\' at end of string will just be discarded.
197
- */
198
- break;
199
-
200
- default:
201
- buffer[j++] = strtext[i++];
202
- break;
203
- }
204
- }
205
- buflen = j; /* buflen is the length of the dequoted
206
- * data */
207
-
208
- /* Shrink the buffer to be no larger than necessary */
209
- /* +1 avoids unportable behavior when buflen==0 */
210
- tmpbuf = realloc(buffer, buflen + 1);
211
-
212
- /* It would only be a very brain-dead realloc that could fail, but... */
213
- if (!tmpbuf)
214
- {
215
- free(buffer);
216
- return NULL;
217
- }
218
-
219
- *retbuflen = buflen;
220
- return tmpbuf;
221
- }
222
- #endif
223
-
224
- #ifndef HAVE_PQEXECPARAMS
225
- #include <ruby.h>
226
- #include <re.h>
227
- #include <libpq-fe.h>
228
-
229
- #define BIND_PARAM_PATTERN "\\$(\\d+)"
230
- #define BindParamNumber(match) (FIX2INT(rb_str_to_inum(rb_reg_nth_match(1, match), 10, 0))-1)
231
-
232
- PGresult *PQexecParams_compat(PGconn *conn, VALUE command, VALUE values)
233
- {
234
- VALUE bind_param_re = rb_reg_new(BIND_PARAM_PATTERN, 7, 0);
235
- VALUE result = rb_str_buf_new(RSTRING(command)->len);
236
- char* ptr = RSTRING(command)->ptr;
237
- int scan = 0;
238
- while ((scan = rb_reg_search(bind_param_re, command, scan, 0)) > 0) {
239
- VALUE match = rb_backref_get();
240
- int pos = BindParamNumber(match);
241
- if (pos < RARRAY(values)->len) {
242
- rb_str_buf_cat(result, ptr, scan - (ptr - RSTRING(command)->ptr));
243
- ptr = RSTRING(command)->ptr + scan;
244
- rb_str_buf_append(result, RARRAY(values)->ptr[pos]);
245
- }
246
- scan += RSTRING(rb_reg_nth_match(0, match))->len;
247
- ptr += RSTRING(rb_reg_nth_match(0, match))->len;
248
- }
249
- rb_str_buf_cat(result, ptr, RSTRING(command)->len - (ptr - RSTRING(command)->ptr));
250
-
251
- return PQexec(conn, StringValuePtr(result));
252
- }
253
- #endif