~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/local_infile.c

  • Committer: Stewart Smith
  • Date: 2009-01-12 05:43:13 UTC
  • mto: (784.1.4 for-brian)
  • mto: This revision was merged to the branch mainline in revision 785.
  • Revision ID: stewart@flamingspork.com-20090112054313-edk6kpf4l6kpz4j7
fix archive_basic for drizzle

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2004 DRIZZLE AB
2
 
 
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.
6
 
 
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.
10
 
 
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.
15
 
 
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 */
19
 
 
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
5
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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
 
18
 */
20
19
 
21
20
#include <drizzled/global.h>
22
 
#include "my_time.h"
23
 
#include "drizzle.h"
 
21
 
 
22
#include "libdrizzle.h"
 
23
#include "libdrizzle_priv.h"
24
24
#include "errmsg.h"
25
 
#include <vio/violite.h>
26
25
#include <sys/stat.h>
27
26
#include <signal.h>
28
27
#include <time.h>
 
28
#include <fcntl.h>
 
29
#include <stdio.h>
 
30
 
29
31
#ifdef   HAVE_PWD_H
30
32
#include <pwd.h>
31
33
#endif
51
53
#define INADDR_NONE  -1
52
54
#endif
53
55
 
54
 
#include <sql_common.h>
55
 
#include "client_settings.h"
 
56
#include "local_infile.h"
 
57
#include <drizzled/gettext.h>
56
58
 
 
59
#define MY_ALIGN(A,L)   (((A) + (L) - 1) & ~((L) - 1))
57
60
 
58
61
bool handle_local_infile(DRIZZLE *drizzle, const char *net_filename)
59
62
{
60
63
  bool result= true;
61
 
  uint packet_length=MY_ALIGN(drizzle->net.max_packet-16,IO_SIZE);
 
64
  uint32_t packet_length=MY_ALIGN(drizzle->net.max_packet-16,IO_SIZE);
62
65
  NET *net= &drizzle->net;
63
66
  int readcount;
64
67
  void *li_ptr;          /* pass state to local_infile functions */
78
81
  /* copy filename into local memory and allocate read buffer */
79
82
  if (!(buf=malloc(packet_length)))
80
83
  {
81
 
    set_drizzle_error(drizzle, CR_OUT_OF_MEMORY, unknown_sqlstate);
 
84
    drizzle_set_error(drizzle, CR_OUT_OF_MEMORY, sqlstate_get_unknown());
82
85
    return(1);
83
86
  }
84
87
 
86
89
  if ((*options->local_infile_init)(&li_ptr, net_filename,
87
90
    options->local_infile_userdata))
88
91
  {
89
 
    VOID(my_net_write(net,(const uchar*) "",0)); /* Server needs one packet */
 
92
    (void)my_net_write(net,(const unsigned char*) "",0); /* Server needs one packet */
90
93
    net_flush(net);
91
 
    strcpy(net->sqlstate, unknown_sqlstate);
 
94
    strcpy(net->sqlstate, sqlstate_get_unknown());
92
95
    net->last_errno=
93
96
      (*options->local_infile_error)(li_ptr,
94
97
                                     net->last_error,
101
104
    (*options->local_infile_read)(li_ptr, buf,
102
105
          packet_length)) > 0)
103
106
  {
104
 
    if (my_net_write(net, (uchar*) buf, readcount))
 
107
    if (my_net_write(net, (unsigned char*) buf, readcount))
105
108
    {
106
109
      goto err;
107
110
    }
108
111
  }
109
112
 
110
113
  /* Send empty packet to mark end of file */
111
 
  if (my_net_write(net, (const uchar*) "", 0) || net_flush(net))
 
114
  if (my_net_write(net, (const unsigned char*) "", 0) || net_flush(net))
112
115
  {
113
 
    set_drizzle_error(drizzle, CR_SERVER_LOST, unknown_sqlstate);
 
116
    drizzle_set_error(drizzle, CR_SERVER_LOST, sqlstate_get_unknown());
114
117
    goto err;
115
118
  }
116
119
 
205
208
    < 0    Error
206
209
*/
207
210
 
208
 
static int default_local_infile_read(void *ptr, char *buf, uint buf_len)
 
211
static int default_local_infile_read(void *ptr, char *buf, uint32_t buf_len)
209
212
{
210
213
  int count;
211
214
  default_local_infile_data*data = (default_local_infile_data *) ptr;
212
215
 
213
 
  if ((count= (int) read(data->fd, (uchar *) buf, buf_len)) < 0)
 
216
  if ((count= (int) read(data->fd, (unsigned char *) buf, buf_len)) < 0)
214
217
  {
215
218
    data->error_num= 2; /* the errmsg for not entire file read */
216
219
    snprintf(data->error_msg, sizeof(data->error_msg)-1,
259
262
*/
260
263
 
261
264
static int
262
 
default_local_infile_error(void *ptr, char *error_msg, uint error_msg_len)
 
265
default_local_infile_error(void *ptr, char *error_msg, uint32_t error_msg_len)
263
266
{
264
267
  default_local_infile_data *data = (default_local_infile_data *) ptr;
265
268
  if (data)          /* If not error on open */
277
280
drizzle_set_local_infile_handler(DRIZZLE *drizzle,
278
281
                               int (*local_infile_init)(void **, const char *,
279
282
                               void *),
280
 
                               int (*local_infile_read)(void *, char *, uint),
 
283
                               int (*local_infile_read)(void *, char *, uint32_t),
281
284
                               void (*local_infile_end)(void *),
282
 
                               int (*local_infile_error)(void *, char *, uint),
 
285
                               int (*local_infile_error)(void *, char *, uint32_t),
283
286
                               void *userdata)
284
287
{
285
288
  drizzle->options.local_infile_init=  local_infile_init;