~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/array.cc

  • Committer: Jay Pipes
  • Date: 2009-01-30 04:01:12 UTC
  • mto: This revision was merged to the branch mainline in revision 830.
  • Revision ID: jpipes@serialcoder-20090130040112-svbn774guj98pwi4
To remain in compatibility with MySQL, added ability to interpret
decimal arguments as datetime strings for temporal functions.

Fixed YEAR(), MONTH(), DAYOFMONTH(), DAYOFYEAR(), HOUR(), MINUTE(), SECOND(), and MICROSECOND()
to accept decimal parameters and interpret them the same way as MySQL.

Fixed an issue with the TemporalFormat::matches() method which was 
incorrectly assuming all microsecond arguments were specified as 6 digits.
Added power of 10 multiplier to usecond calculation. This fixes issues with
failures in type_date and func_sapdb test cases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/* Handling of arrays that can grow dynamicly. */
17
17
 
18
 
#include "config.h"
19
 
#include "drizzled/internal/my_sys.h"
20
 
#include "drizzled/internal/m_string.h"
21
 
 
22
 
#include <algorithm>
23
 
 
24
 
using namespace std;
25
 
 
26
 
namespace drizzled
27
 
{
28
 
 
29
 
static bool allocate_dynamic(DYNAMIC_ARRAY *array, uint32_t max_elements);
 
18
#include "mysys_priv.h"
 
19
#include <mystrings/m_string.h>
30
20
 
31
21
/*
32
22
  Initiate dynamic array
56
46
{
57
47
  if (!alloc_increment)
58
48
  {
59
 
    alloc_increment=max((8192-MALLOC_OVERHEAD)/element_size,16U);
 
49
    alloc_increment=cmax((8192-MALLOC_OVERHEAD)/element_size,16);
60
50
    if (init_alloc > 8 && alloc_increment > init_alloc * 2)
61
51
      alloc_increment=init_alloc*2;
62
52
  }
80
70
  return(false);
81
71
}
82
72
 
 
73
bool init_dynamic_array(DYNAMIC_ARRAY *array, uint32_t element_size,
 
74
                           uint32_t init_alloc,
 
75
                           uint32_t alloc_increment)
 
76
{
 
77
  /* placeholder to preserve ABI */
 
78
  return my_init_dynamic_array_ci(array, element_size, init_alloc,
 
79
                                  alloc_increment);
 
80
}
83
81
/*
84
82
  Insert element at the end of array. Allocate memory if needed.
85
83
 
227
225
    true        Allocation of new memory failed
228
226
*/
229
227
 
230
 
static bool allocate_dynamic(DYNAMIC_ARRAY *array, uint32_t max_elements)
 
228
bool allocate_dynamic(DYNAMIC_ARRAY *array, uint32_t max_elements)
231
229
{
232
230
  if (max_elements >= array->max_element)
233
231
  {
306
304
  }
307
305
}
308
306
 
309
 
} /* namespace drizzled */
 
307
/*
 
308
  Delete element by given index
 
309
 
 
310
  SYNOPSIS
 
311
    delete_dynamic_element()
 
312
      array
 
313
      idx        Index of element to be deleted
 
314
*/
 
315
 
 
316
void delete_dynamic_element(DYNAMIC_ARRAY *array, uint32_t idx)
 
317
{
 
318
  char *ptr= (char*) array->buffer+array->size_of_element*idx;
 
319
  array->elements--;
 
320
  memmove(ptr,ptr+array->size_of_element,
 
321
          (array->elements-idx)*array->size_of_element);
 
322
}
 
323
 
 
324
 
 
325
/*
 
326
  Free unused memory
 
327
 
 
328
  SYNOPSIS
 
329
    freeze_size()
 
330
      array     Array to be freed
 
331
 
 
332
*/
 
333
 
 
334
void freeze_size(DYNAMIC_ARRAY *array)
 
335
{
 
336
  uint32_t elements=cmax(array->elements,1);
 
337
 
 
338
  /*
 
339
    Do nothing if we are using a static buffer
 
340
  */
 
341
  if (array->buffer == (unsigned char *)(array + 1))
 
342
    return;
 
343
 
 
344
  if (array->buffer && array->max_element != elements)
 
345
  {
 
346
    array->buffer=(unsigned char*) realloc(array->buffer,
 
347
                                     elements*array->size_of_element);
 
348
    array->max_element=elements;
 
349
  }
 
350
}
 
351
 
 
352
 
 
353
/*
 
354
  Get the index of a dynamic element
 
355
 
 
356
  SYNOPSIS
 
357
    get_index_dynamic()
 
358
     array      Array
 
359
     element Whose element index
 
360
 
 
361
*/
 
362
 
 
363
int get_index_dynamic(DYNAMIC_ARRAY *array, unsigned char* element)
 
364
{
 
365
  uint32_t ret;
 
366
  if (array->buffer > element)
 
367
    return -1;
 
368
 
 
369
  ret= (element - array->buffer) /  array->size_of_element;
 
370
  if (ret > array->elements)
 
371
    return -1;
 
372
 
 
373
  return ret;
 
374
 
 
375
}