~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/libdrizzle.c

  • Committer: brian
  • Date: 2008-08-01 09:15:55 UTC
  • mfrom: (261.1.4 drizzle)
  • Revision ID: brian@localhost.localdomain-20080801091555-axgut9h6uvtbatei
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <mysys/my_sys.h>
22
22
#include "my_time.h"
23
23
#include <mysys/mysys_err.h>
24
 
#include <mystrings/m_string.h>
25
 
#include <mystrings/m_ctype.h>
26
24
#include "drizzle.h"
27
25
#include "errmsg.h"
28
26
#include <vio/violite.h>
106
104
  end-=5;          /* Some extra */
107
105
  if (wild && wild[0])
108
106
  {
109
 
    to=strmov(to," like '");
 
107
    to= strcpy(to," like '");
 
108
    to+= 7; /* strlen(" like '"); */
 
109
 
110
110
    while (*wild && to < end)
111
111
    {
112
112
      if (*wild == '\\' || *wild == '\'')
151
151
}
152
152
 
153
153
bool STDCALL drizzle_change_user(DRIZZLE *drizzle, const char *user,
154
 
          const char *passwd, const char *db)
 
154
                                 const char *passwd, const char *db)
155
155
{
156
156
  char buff[USERNAME_LENGTH+SCRAMBLED_PASSWORD_CHAR_LENGTH+NAME_LEN+2];
157
157
  char *end= buff;
174
174
    passwd="";
175
175
 
176
176
  /* Store user into the buffer */
177
 
  end= strmake(end, user, USERNAME_LENGTH) + 1;
 
177
  end= strncpy(end, user, USERNAME_LENGTH) + USERNAME_LENGTH + 1;
178
178
 
179
179
  /* write scrambled password according to server capabilities */
180
180
  if (passwd[0])
181
181
  {
182
182
    {
183
183
      *end++= SCRAMBLE_LENGTH;
184
 
      scramble(end, drizzle->scramble, passwd);
185
184
      end+= SCRAMBLE_LENGTH;
186
185
    }
187
186
  }
188
187
  else
189
188
    *end++= '\0';                               /* empty password */
190
189
  /* Add database if needed */
191
 
  end= strmake(end, db ? db : "", NAME_LEN) + 1;
 
190
  end= strncpy(end, db ? db : "", NAME_LEN) + NAME_LEN + 1;
192
191
 
193
192
  /* Add character set number. */
194
193
 
214
213
      free(drizzle->db);
215
214
 
216
215
    /* alloc new connect information */
217
 
    drizzle->user=  my_strdup(user,MYF(MY_WME));
218
 
    drizzle->passwd=my_strdup(passwd,MYF(MY_WME));
219
 
    drizzle->db=    db ? my_strdup(db,MYF(MY_WME)) : 0;
 
216
    drizzle->user= strdup(user);
 
217
    drizzle->passwd= strdup(passwd);
 
218
    drizzle->db= db ? strdup(db) : 0;
220
219
  }
221
220
  else
222
221
  {
226
225
  return(rc);
227
226
}
228
227
 
 
228
#if defined(HAVE_GETPWUID) && defined(NO_GETPWUID_DECL)
 
229
struct passwd *getpwuid(uid_t);
 
230
char* getlogin(void);
 
231
#endif
229
232
 
230
233
/**************************************************************************
231
234
  Do a query. If query returned rows, free old rows.
293
296
 
294
297
 
295
298
/*****************************************************************************
296
 
  List all databases
297
 
*****************************************************************************/
298
 
 
299
 
DRIZZLE_RES * STDCALL
300
 
drizzle_list_dbs(DRIZZLE *drizzle, const char *wild)
301
 
{
302
 
  char buff[255];
303
 
 
304
 
  append_wild(strmov(buff,"show databases"),buff+sizeof(buff),wild);
305
 
  if (drizzle_query(drizzle,buff))
306
 
    return(0);
307
 
  return (drizzle_store_result(drizzle));
308
 
}
309
 
 
310
 
 
311
 
/*****************************************************************************
312
299
  List all tables in a database
313
300
  If wild is given then only the tables matching wild is returned
314
301
*****************************************************************************/
317
304
drizzle_list_tables(DRIZZLE *drizzle, const char *wild)
318
305
{
319
306
  char buff[255];
 
307
  char *ptr= strcpy(buff, "show tables");
 
308
  ptr+= 11; /* strlen("show tables"); */
320
309
 
321
 
  append_wild(strmov(buff,"show tables"),buff+sizeof(buff),wild);
 
310
  append_wild(ptr,buff+sizeof(buff),wild);
322
311
  if (drizzle_query(drizzle,buff))
323
312
    return(0);
324
313
  return (drizzle_store_result(drizzle));
350
339
{
351
340
  DRIZZLE_RES   *result;
352
341
  DRIZZLE_FIELD *fields;
353
 
  char       buff[257],*end;
354
 
 
355
 
  end=strmake(strmake(buff, table,128)+1,wild ? wild : "",128);
 
342
  char buff[257], *end;
 
343
 
 
344
  end= strncpy(buff, table, 128) + 128;
 
345
  end= strncpy(end+1, wild ? wild : "", 128) + 128;
 
346
 
356
347
  free_old_query(drizzle);
357
348
  if (simple_command(drizzle, COM_FIELD_LIST, (uchar*) buff,
358
349
                     (ulong) (end-buff), 1) ||