Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0d559d1

Browse files
committed
Initial support for SQLite (90% approx).
Initial support for Firebird (30% approx). Initial support for Access (10% approx). Shared libraries code/installation scripts ported to 64bit, directory structure adapted. Minor code adjustments.
1 parent f1fde2e commit 0d559d1

61 files changed

Lines changed: 3769 additions & 670 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
File renamed without changes.
File renamed without changes.

extra/udfhack/linux/lib_mysqludf_sys/lib_mysqludf_sys.c renamed to extra/udfhack/linux/32/lib_mysqludf_sys/lib_mysqludf_sys.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,11 @@ char* sys_eval(
435435
, char *error
436436
){
437437
FILE *pipe;
438-
char line[1024];
438+
char *line;
439439
unsigned long outlen, linelen;
440440

441-
result = malloc(1);
441+
line = (char *)malloc(1024);
442+
result = (char *)malloc(1);
442443
outlen = 0;
443444

444445
pipe = popen(args->args[0], "r");
@@ -548,4 +549,4 @@ DWORD WINAPI exec_payload(LPVOID lpParameter)
548549
}
549550
#endif
550551

551-
#endif /* HAVE_DLOPEN */
552+
#endif /* HAVE_DLOPEN */

extra/udfhack/linux/lib_mysqludf_sys/lib_mysqludf_sys.sql renamed to extra/udfhack/linux/32/lib_mysqludf_sys/lib_mysqludf_sys.sql

File renamed without changes.
File renamed without changes.

extra/udfhack/linux/lib_postgresqludf_sys/install.sh renamed to extra/udfhack/linux/32/lib_postgresqludf_sys/install.sh

File renamed without changes.

extra/udfhack/windows/lib_postgresqludf_sys/lib_postgresqludf_sys/lib_postgresqludf_sys.c renamed to extra/udfhack/linux/32/lib_postgresqludf_sys/lib_postgresqludf_sys.c

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,44 @@ DWORD WINAPI exec_payload(LPVOID lpParameter);
4646
PG_MODULE_MAGIC;
4747
#endif
4848

49+
char *text_ptr_to_char_ptr(text *arg)
50+
{
51+
char *retVal;
52+
int arg_size = VARSIZE(arg) - VARHDRSZ;
53+
retVal = (char *)malloc(arg_size + 1);
54+
55+
memcpy(retVal, VARDATA(arg), arg_size);
56+
retVal[arg_size] = '\0';
57+
58+
return retVal;
59+
}
60+
61+
text *chr_ptr_to_text_ptr(char *arg)
62+
{
63+
text *retVal;
64+
65+
retVal = (text *)malloc(VARHDRSZ + strlen(arg));
66+
#ifdef SET_VARSIZE
67+
SET_VARSIZE(retVal, VARHDRSZ + strlen(arg));
68+
#else
69+
VARATT_SIZEP(retVal) = strlen(arg) + VARHDRSZ;
70+
#endif
71+
memcpy(VARDATA(retVal), arg, strlen(arg));
72+
73+
return retVal;
74+
}
75+
4976
PG_FUNCTION_INFO_V1(sys_exec);
5077
#ifdef PGDLLIMPORT
5178
extern PGDLLIMPORT Datum sys_exec(PG_FUNCTION_ARGS) {
5279
#else
5380
extern DLLIMPORT Datum sys_exec(PG_FUNCTION_ARGS) {
5481
#endif
5582
text *argv0 = PG_GETARG_TEXT_P(0);
56-
int32 argv0_size;
5783
int32 result = 0;
5884
char *command;
5985

60-
argv0_size = VARSIZE(argv0) - VARHDRSZ;
61-
command = (char *)malloc(argv0_size + 1);
62-
63-
memcpy(command, VARDATA(argv0), argv0_size);
64-
command[argv0_size] = '\0';
86+
command = text_ptr_to_char_ptr(argv0);
6587

6688
/*
6789
Only if you want to log
@@ -83,24 +105,20 @@ extern DLLIMPORT Datum sys_eval(PG_FUNCTION_ARGS) {
83105
#endif
84106
text *argv0 = PG_GETARG_TEXT_P(0);
85107
text *result_text;
86-
int32 argv0_size;
87108
char *command;
88109
char *result;
89110
FILE *pipe;
90-
char line[1024];
111+
char *line;
91112
int32 outlen, linelen;
92113

93-
argv0_size = VARSIZE(argv0) - VARHDRSZ;
94-
command = (char *)malloc(argv0_size + 1);
95-
96-
memcpy(command, VARDATA(argv0), argv0_size);
97-
command[argv0_size] = '\0';
114+
command = text_ptr_to_char_ptr(argv0);
98115

99116
/*
100117
Only if you want to log
101118
elog(NOTICE, "Command evaluated: %s", command);
102119
*/
103120

121+
line = (char *)malloc(1024);
104122
result = (char *)malloc(1);
105123
outlen = 0;
106124

@@ -119,13 +137,7 @@ extern DLLIMPORT Datum sys_eval(PG_FUNCTION_ARGS) {
119137
result[outlen-1] = 0x00;
120138
}
121139

122-
result_text = (text *)malloc(VARHDRSZ + strlen(result));
123-
#ifdef SET_VARSIZE
124-
SET_VARSIZE(result_text, VARHDRSZ + strlen(result));
125-
#else
126-
VARATT_SIZEP(result_text) = strlen(result) + VARHDRSZ;
127-
#endif
128-
memcpy(VARDATA(result_text), result, strlen(result));
140+
result_text = chr_ptr_to_text_ptr(result);
129141

130142
PG_RETURN_POINTER(result_text);
131143
}
@@ -216,7 +228,6 @@ extern DLLIMPORT Datum sys_fileread(PG_FUNCTION_ARGS) {
216228
#endif
217229
text *argv0 = PG_GETARG_TEXT_P(0);
218230
text *result_text;
219-
int32 argv0_size;
220231
int32 len;
221232
int32 i, j;
222233
char *filename;
@@ -225,11 +236,7 @@ extern DLLIMPORT Datum sys_fileread(PG_FUNCTION_ARGS) {
225236
char table[] = "0123456789ABCDEF";
226237
FILE *file;
227238

228-
argv0_size = VARSIZE(argv0) - VARHDRSZ;
229-
filename = (char *)malloc(argv0_size + 1);
230-
231-
memcpy(filename, VARDATA(argv0), argv0_size);
232-
filename[argv0_size] = '\0';
239+
filename = text_ptr_to_char_ptr(argv0);
233240

234241
file = fopen(filename, "rb");
235242
if (!file)
@@ -258,13 +265,7 @@ extern DLLIMPORT Datum sys_fileread(PG_FUNCTION_ARGS) {
258265
}
259266
result[j] = '\0';
260267

261-
result_text = (text *)malloc(VARHDRSZ + strlen(result));
262-
#ifdef SET_VARSIZE
263-
SET_VARSIZE(result_text, VARHDRSZ + strlen(result));
264-
#else
265-
VARATT_SIZEP(result_text) = strlen(result) + VARHDRSZ;
266-
#endif
267-
memcpy(VARDATA(result_text), result, strlen(result));
268+
result_text = chr_ptr_to_text_ptr(result);
268269

269270
free(result);
270271
free(buffer);

extra/udfhack/linux/lib_postgresqludf_sys/lib_postgresqludf_sys.sql renamed to extra/udfhack/linux/32/lib_postgresqludf_sys/lib_postgresqludf_sys.sql

File renamed without changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# For MySQL < 5.1
2+
LIBDIR=/usr/lib
3+
# For MySQL >= 5.1
4+
#LIBDIR=/usr/lib/mysql/plugin
5+
6+
install:
7+
gcc-4.2 -Wall -I/usr/include/mysql -Os -shared lib_mysqludf_sys.c -fPIC -o lib_mysqludf_sys.so
8+
strip -sx lib_mysqludf_sys.so
9+
cp -f lib_mysqludf_sys.so $(LIBDIR)/lib_mysqludf_sys.so
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
# lib_mysqludf_sys - a library with miscellaneous (operating) system level functions
3+
# Copyright (C) 2007 Roland Bouman
4+
# Copyright (C) 2008-2010 Roland Bouman and Bernardo Damele A. G.
5+
# web: http://www.mysqludf.org/
6+
7+
#
8+
# This library is free software; you can redistribute it and/or
9+
# modify it under the terms of the GNU Lesser General Public
10+
# License as published by the Free Software Foundation; either
11+
# version 2.1 of the License, or (at your option) any later version.
12+
#
13+
# This library is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
# Lesser General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU Lesser General Public
19+
# License along with this library; if not, write to the Free Software
20+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21+
22+
# Adapt the following settings to your environment
23+
USER="root"
24+
PORT="3306"
25+
26+
echo "Compiling the MySQL UDF"
27+
make
28+
29+
if test $? -ne 0; then
30+
echo "ERROR: You need libmysqlclient development software installed"
31+
echo "to be able to compile this UDF, on Debian/Ubuntu just run:"
32+
echo "apt-get install libmysqlclient-dev"
33+
exit 1
34+
else
35+
echo "MySQL UDF compiled successfully"
36+
fi
37+
38+
echo -e "\nPlease provide your MySQL root password"
39+
40+
mysql -u ${USER} -P ${PORT} -p mysql < lib_mysqludf_sys.sql
41+
42+
if test $? -ne 0; then
43+
echo "ERROR: unable to install the UDF"
44+
exit 1
45+
else
46+
echo "MySQL UDF installed successfully"
47+
fi

0 commit comments

Comments
 (0)