1
/* Copyright (C) 2000-2004 DRIZZLE AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation.
7
There are special exceptions to the terms and conditions of the GPL as it
8
is applied to this software. View the full text of the exception in file
9
EXCEPTIONS-CLIENT in the directory of this software distribution.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
21
#include <drizzled/global.h>
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
22
#include "libdrizzle.h"
23
#include "libdrizzle_priv.h"
23
24
#include "errmsg.h"
24
25
#include <sys/stat.h>
25
26
#include <signal.h>
52
56
#include <sql_common.h>
53
57
#include "local_infile.h"
58
#include <libdrizzle/gettext.h>
60
#define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1))
57
62
bool handle_local_infile(DRIZZLE *drizzle, const char *net_filename)
77
82
/* copy filename into local memory and allocate read buffer */
78
83
if (!(buf=malloc(packet_length)))
80
set_drizzle_error(drizzle, CR_OUT_OF_MEMORY, unknown_sqlstate);
85
drizzle_set_error(drizzle, CR_OUT_OF_MEMORY, sqlstate_get_unknown());
85
90
if ((*options->local_infile_init)(&li_ptr, net_filename,
86
91
options->local_infile_userdata))
88
VOID(my_net_write(net,(const uchar*) "",0)); /* Server needs one packet */
93
(void)my_net_write(net,(const unsigned char*) "",0); /* Server needs one packet */
90
strcpy(net->sqlstate, unknown_sqlstate);
95
strcpy(net->sqlstate, sqlstate_get_unknown());
92
97
(*options->local_infile_error)(li_ptr,
100
105
(*options->local_infile_read)(li_ptr, buf,
101
106
packet_length)) > 0)
103
if (my_net_write(net, (uchar*) buf, readcount))
108
if (my_net_write(net, (unsigned char*) buf, readcount))
109
114
/* Send empty packet to mark end of file */
110
if (my_net_write(net, (const uchar*) "", 0) || net_flush(net))
115
if (my_net_write(net, (const unsigned char*) "", 0) || net_flush(net))
112
set_drizzle_error(drizzle, CR_SERVER_LOST, unknown_sqlstate);
117
drizzle_set_error(drizzle, CR_SERVER_LOST, sqlstate_get_unknown());
210
215
default_local_infile_data*data = (default_local_infile_data *) ptr;
212
if ((count= (int) read(data->fd, (uchar *) buf, buf_len)) < 0)
217
if ((count= (int) read(data->fd, (unsigned char *) buf, buf_len)) < 0)
214
219
data->error_num= 2; /* the errmsg for not entire file read */
215
220
snprintf(data->error_msg, sizeof(data->error_msg)-1,