summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMichael Widenius <monty@askmonty.org>2011-05-12 14:30:34 +0300
committerMichael Widenius <monty@askmonty.org>2011-05-12 14:30:34 +0300
commitf09f1c7c7da344d0078b2c13edc9249c4c61c6b9 (patch)
tree1b707c9edf2d159102019147a5dbca390e1aac83 /include
parentf34be1893892745b5b1a7a099eab4ad8e9ac8641 (diff)
parent4c81cef75d7871e2c77d6723813ac328c34603b5 (diff)
downloadmariadb-git-f09f1c7c7da344d0078b2c13edc9249c4c61c6b9.tar.gz
Merge with dynamic column code
Diffstat (limited to 'include')
-rw-r--r--include/Makefile.am1
-rw-r--r--include/decimal.h12
-rw-r--r--include/ma_dyncol.h147
-rw-r--r--include/my_decimal_limits.h31
-rw-r--r--include/my_sys.h2
-rw-r--r--include/my_time.h5
6 files changed, 191 insertions, 7 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index e23fd94a7fc..99a21d686a3 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -30,6 +30,7 @@ pkginclude_HEADERS = $(HEADERS_ABI) my_dbug.h m_string.h my_sys.h \
my_getopt.h sslopt-longopts.h my_dir.h \
sslopt-vars.h sslopt-case.h sql_common.h keycache.h \
m_ctype.h my_attribute.h my_compiler.h \
+ my_decimal_limits.h ma_dyncol.h \
$(HEADERS_GEN_CONFIGURE) \
$(HEADERS_GEN_MAKE)
diff --git a/include/decimal.h b/include/decimal.h
index 530ed9e1757..aad9db9a1b8 100644
--- a/include/decimal.h
+++ b/include/decimal.h
@@ -29,17 +29,17 @@ typedef struct st_decimal_t {
int internal_str2dec(const char *from, decimal_t *to, char **end,
my_bool fixed);
-int decimal2string(decimal_t *from, char *to, int *to_len,
+int decimal2string(const decimal_t *from, char *to, int *to_len,
int fixed_precision, int fixed_decimals,
char filler);
-int decimal2ulonglong(decimal_t *from, ulonglong *to);
+int decimal2ulonglong(const decimal_t *from, ulonglong *to);
int ulonglong2decimal(ulonglong from, decimal_t *to);
-int decimal2longlong(decimal_t *from, longlong *to);
+int decimal2longlong(const decimal_t *from, longlong *to);
int longlong2decimal(longlong from, decimal_t *to);
-int decimal2double(decimal_t *from, double *to);
+int decimal2double(const decimal_t *from, double *to);
int double2decimal(double from, decimal_t *to);
int decimal_actual_fraction(decimal_t *from);
-int decimal2bin(decimal_t *from, uchar *to, int precision, int scale);
+int decimal2bin(const decimal_t *from, uchar *to, int precision, int scale);
int bin2decimal(const uchar *from, decimal_t *to, int precision, int scale);
int decimal_size(int precision, int scale);
@@ -55,7 +55,7 @@ int decimal_mul(decimal_t *from1, decimal_t *from2, decimal_t *to);
int decimal_div(decimal_t *from1, decimal_t *from2, decimal_t *to,
int scale_incr);
int decimal_mod(decimal_t *from1, decimal_t *from2, decimal_t *to);
-int decimal_round(decimal_t *from, decimal_t *to, int new_scale,
+int decimal_round(const decimal_t *from, decimal_t *to, int new_scale,
decimal_round_mode mode);
int decimal_is_zero(decimal_t *from);
void max_decimal(int precision, int frac, decimal_t *to);
diff --git a/include/ma_dyncol.h b/include/ma_dyncol.h
new file mode 100644
index 00000000000..687823a4e73
--- /dev/null
+++ b/include/ma_dyncol.h
@@ -0,0 +1,147 @@
+/* Copyright (c) 2011, Monty Program Ab
+ Copyright (c) 2011, Oleksandr Byelkin
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND ANY
+ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+*/
+
+#ifndef ma_dyncol_h
+#define ma_dyncol_h
+
+#include <decimal.h>
+#include <my_decimal_limits.h>
+#include <mysql_time.h>
+
+/*
+ Max length for data in a dynamic colums. This comes from how the
+ how the offset are stored.
+*/
+#define MAX_DYNAMIC_COLUMN_LENGTH 0X1FFFFFFFL
+
+/* NO and OK is the same used just to show semantics */
+#define ER_DYNCOL_NO ER_DYNCOL_OK
+
+enum enum_dyncol_func_result
+{
+ ER_DYNCOL_OK= 0,
+ ER_DYNCOL_YES= 1, /* For functions returning 0/1 */
+ ER_DYNCOL_FORMAT= -1, /* Wrong format of the encoded string */
+ ER_DYNCOL_LIMIT= -2, /* Some limit reached */
+ ER_DYNCOL_RESOURCE= -3, /* Out of resourses */
+ ER_DYNCOL_DATA= -4, /* Incorrect input data */
+ ER_DYNCOL_UNKNOWN_CHARSET= -5 /* Unknown character set */
+};
+
+typedef DYNAMIC_STRING DYNAMIC_COLUMN;
+
+enum enum_dynamic_column_type
+{
+ DYN_COL_NULL= 0,
+ DYN_COL_INT,
+ DYN_COL_UINT,
+ DYN_COL_DOUBLE,
+ DYN_COL_STRING,
+ DYN_COL_DECIMAL,
+ DYN_COL_DATETIME,
+ DYN_COL_DATE,
+ DYN_COL_TIME
+};
+
+typedef enum enum_dynamic_column_type DYNAMIC_COLUMN_TYPE;
+
+struct st_dynamic_column_value
+{
+ DYNAMIC_COLUMN_TYPE type;
+ union
+ {
+ long long long_value;
+ unsigned long long ulong_value;
+ double double_value;
+ struct {
+ LEX_STRING string_value;
+ CHARSET_INFO *charset;
+ };
+ struct {
+ decimal_digit_t decimal_buffer[DECIMAL_BUFF_LENGTH];
+ decimal_t decimal_value;
+ };
+ MYSQL_TIME time_value;
+ };
+};
+
+typedef struct st_dynamic_column_value DYNAMIC_COLUMN_VALUE;
+
+enum enum_dyncol_func_result
+dynamic_column_create(DYNAMIC_COLUMN *str,
+ uint column_nr, DYNAMIC_COLUMN_VALUE *value);
+
+enum enum_dyncol_func_result
+dynamic_column_create_many(DYNAMIC_COLUMN *str,
+ uint column_count,
+ uint *column_numbers,
+ DYNAMIC_COLUMN_VALUE *values);
+
+enum enum_dyncol_func_result
+dynamic_column_update(DYNAMIC_COLUMN *org, uint column_nr,
+ DYNAMIC_COLUMN_VALUE *value);
+enum enum_dyncol_func_result
+dynamic_column_update_many(DYNAMIC_COLUMN *str,
+ uint add_column_count,
+ uint *column_numbers,
+ DYNAMIC_COLUMN_VALUE *values);
+
+enum enum_dyncol_func_result
+dynamic_column_delete(DYNAMIC_COLUMN *org, uint column_nr);
+
+enum enum_dyncol_func_result
+dynamic_column_exists(DYNAMIC_COLUMN *org, uint column_nr);
+
+/* List of not NULL columns */
+enum enum_dyncol_func_result
+dynamic_column_list(DYNAMIC_COLUMN *org, DYNAMIC_ARRAY *array_of_uint);
+
+/*
+ if the column do not exists it is NULL
+*/
+enum enum_dyncol_func_result
+dynamic_column_get(DYNAMIC_COLUMN *org, uint column_nr,
+ DYNAMIC_COLUMN_VALUE *store_it_here);
+
+#define dynamic_column_initialize(A) memset((A), 0, sizeof(*(A)))
+#define dynamic_column_column_free(V) dynstr_free(V)
+
+/***************************************************************************
+ Internal functions, don't use if you don't know what you are doing...
+***************************************************************************/
+
+#define dynamic_column_reassociate(V,P,L, A) dynstr_reassociate((V),(P),(L),(A))
+
+#define dynamic_column_value_init(V) (V)->type= DYN_COL_NULL
+
+/*
+ Prepare value for using as decimal
+*/
+void dynamic_column_prepare_decimal(DYNAMIC_COLUMN_VALUE *value);
+
+#endif
diff --git a/include/my_decimal_limits.h b/include/my_decimal_limits.h
new file mode 100644
index 00000000000..d9dabe92373
--- /dev/null
+++ b/include/my_decimal_limits.h
@@ -0,0 +1,31 @@
+#ifndef my_decimal_limits_h
+#define my_decimal_limits_h
+
+#define DECIMAL_LONGLONG_DIGITS 22
+#define DECIMAL_LONG_DIGITS 10
+#define DECIMAL_LONG3_DIGITS 8
+
+/** maximum length of buffer in our big digits (uint32). */
+#define DECIMAL_BUFF_LENGTH 9
+
+/* the number of digits that my_decimal can possibly contain */
+#define DECIMAL_MAX_POSSIBLE_PRECISION (DECIMAL_BUFF_LENGTH * 9)
+
+
+/**
+ maximum guaranteed precision of number in decimal digits (number of our
+ digits * number of decimal digits in one our big digit - number of decimal
+ digits in one our big digit decreased by 1 (because we always put decimal
+ point on the border of our big digits))
+*/
+#define DECIMAL_MAX_PRECISION (DECIMAL_MAX_POSSIBLE_PRECISION - 8*2)
+#define DECIMAL_MAX_SCALE 30
+#define DECIMAL_NOT_SPECIFIED 31
+
+/**
+ maximum length of string representation (number of maximum decimal
+ digits + 1 position for sign + 1 position for decimal point)
+*/
+#define DECIMAL_MAX_STR_LENGTH (DECIMAL_MAX_POSSIBLE_PRECISION + 2)
+
+#endif
diff --git a/include/my_sys.h b/include/my_sys.h
index 65455990b04..f891ee7e065 100644
--- a/include/my_sys.h
+++ b/include/my_sys.h
@@ -863,6 +863,8 @@ extern my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str);
extern my_bool dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size);
extern my_bool dynstr_trunc(DYNAMIC_STRING *str, size_t n);
extern void dynstr_free(DYNAMIC_STRING *str);
+extern void dynstr_reassociate(DYNAMIC_STRING *str, char **res, size_t *length,
+ size_t *alloc_length);
#ifdef HAVE_MLOCK
extern void *my_malloc_lock(size_t length,myf flags);
extern void my_free_lock(void *ptr,myf flags);
diff --git a/include/my_time.h b/include/my_time.h
index 0bbb83b78b7..1269cd649ee 100644
--- a/include/my_time.h
+++ b/include/my_time.h
@@ -85,6 +85,7 @@ typedef long my_time_t;
TIME_MAX_SECOND)
#define TIME_MAX_VALUE_SECONDS (TIME_MAX_HOUR * 3600L + \
TIME_MAX_MINUTE * 60L + TIME_MAX_SECOND)
+#define TIME_SUBSECOND_RANGE 1000000
my_bool check_date(const MYSQL_TIME *ltime, my_bool not_zero_date,
ulong flags, int *was_cut);
@@ -93,6 +94,8 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time,
uint flags, int *was_cut);
longlong number_to_datetime(longlong nr, MYSQL_TIME *time_res,
uint flags, int *was_cut);
+my_bool double_to_datetime(double nr, MYSQL_TIME *time_res,
+ uint flags);
ulonglong TIME_to_ulonglong_datetime(const MYSQL_TIME *);
ulonglong TIME_to_ulonglong_date(const MYSQL_TIME *);
ulonglong TIME_to_ulonglong_time(const MYSQL_TIME *);
@@ -100,7 +103,7 @@ ulonglong TIME_to_ulonglong(const MYSQL_TIME *);
my_bool str_to_time(const char *str,uint length, MYSQL_TIME *l_time,
- int *warning);
+ ulong flag,int *warning);
int check_time_range(struct st_mysql_time *, int *warning);