~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_insert.cc

merged with up to date trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <drizzled/probes.h>
26
26
#include <drizzled/sql_base.h>
27
27
#include <drizzled/sql_load.h>
28
 
#include <drizzled/field/timestamp.h>
 
28
#include <drizzled/field/epoch.h>
29
29
#include <drizzled/lock.h>
30
30
#include "drizzled/sql_table.h"
31
31
#include "drizzled/pthread_globals.h"
129
129
      }
130
130
      else
131
131
      {
132
 
        table->setWriteSet(table->timestamp_field->field_index);
 
132
        table->setWriteSet(table->timestamp_field->position());
133
133
      }
134
134
    }
135
135
  }
170
170
      Unmark the timestamp field so that we can check if this is modified
171
171
      by update_fields
172
172
    */
173
 
    timestamp_mark= table->write_set->test(table->timestamp_field->field_index);
174
 
    table->write_set->reset(table->timestamp_field->field_index);
 
173
    timestamp_mark= table->write_set->test(table->timestamp_field->position());
 
174
    table->write_set->reset(table->timestamp_field->position());
175
175
  }
176
176
 
177
177
  /* Check the fields we are going to modify */
189
189
 
190
190
    if (timestamp_mark)
191
191
    {
192
 
      table->setWriteSet(table->timestamp_field->field_index);
 
192
      table->setWriteSet(table->timestamp_field->position());
193
193
    }
194
194
  }
195
195
  return 0;
227
227
  end of dispatch_command().
228
228
*/
229
229
 
230
 
bool mysql_insert(Session *session,TableList *table_list,
 
230
bool insert_query(Session *session,TableList *table_list,
231
231
                  List<Item> &fields,
232
232
                  List<List_item> &values_list,
233
233
                  List<Item> &update_fields,
271
271
  values= its++;
272
272
  value_count= values->elements;
273
273
 
274
 
  if (mysql_prepare_insert(session, table_list, table, fields, values,
 
274
  if (prepare_insert(session, table_list, table, fields, values,
275
275
                           update_fields, update_values, duplic, &unused_conds,
276
276
                           false,
277
277
                           (fields.elements || !value_count ||
520
520
  Check if table can be updated
521
521
 
522
522
  SYNOPSIS
523
 
     mysql_prepare_insert_check_table()
 
523
     prepare_insert_check_table()
524
524
     session            Thread handle
525
525
     table_list         Table list
526
526
     fields             List of fields to be updated
532
532
     true  ERROR
533
533
*/
534
534
 
535
 
static bool mysql_prepare_insert_check_table(Session *session, TableList *table_list,
 
535
static bool prepare_insert_check_table(Session *session, TableList *table_list,
536
536
                                             List<Item> &,
537
537
                                             bool select_insert)
538
538
{
560
560
  Prepare items in INSERT statement
561
561
 
562
562
  SYNOPSIS
563
 
    mysql_prepare_insert()
 
563
    prepare_insert()
564
564
    session                     Thread handler
565
565
    table_list          Global/local table list
566
566
    table               Table to insert into (can be NULL if table should
587
587
    true  error
588
588
*/
589
589
 
590
 
bool mysql_prepare_insert(Session *session, TableList *table_list,
 
590
bool prepare_insert(Session *session, TableList *table_list,
591
591
                          Table *table, List<Item> &fields, List_item *values,
592
592
                          List<Item> &update_fields, List<Item> &update_values,
593
593
                          enum_duplicates duplic,
632
632
      return(true);
633
633
  }
634
634
 
635
 
  if (mysql_prepare_insert_check_table(session, table_list, fields, select_insert))
 
635
  if (prepare_insert_check_table(session, table_list, fields, select_insert))
636
636
    return(true);
637
637
 
638
638
 
868
868
          /*
869
869
            If ON DUP KEY UPDATE updates a row instead of inserting one, it's
870
870
            like a regular UPDATE statement: it should not affect the value of a
871
 
            next SELECT LAST_INSERT_ID() or mysql_insert_id().
 
871
            next SELECT LAST_INSERT_ID() or insert_id().
872
872
            Except if LAST_INSERT_ID(#) was in the INSERT query, which is
873
873
            handled separately by Session::arg_of_last_insert_id_function.
874
874
          */
1026
1026
  make insert specific preparation and checks after opening tables
1027
1027
 
1028
1028
  SYNOPSIS
1029
 
    mysql_insert_select_prepare()
 
1029
    insert_select_prepare()
1030
1030
    session         thread handler
1031
1031
 
1032
1032
  RETURN
1034
1034
    true  Error
1035
1035
*/
1036
1036
 
1037
 
bool mysql_insert_select_prepare(Session *session)
 
1037
bool insert_select_prepare(Session *session)
1038
1038
{
1039
1039
  LEX *lex= session->lex;
1040
1040
  Select_Lex *select_lex= &lex->select_lex;
1044
1044
    clause if table is VIEW
1045
1045
  */
1046
1046
 
1047
 
  if (mysql_prepare_insert(session, lex->query_tables,
 
1047
  if (prepare_insert(session, lex->query_tables,
1048
1048
                           lex->query_tables->table, lex->field_list, 0,
1049
1049
                           lex->update_list, lex->value_list,
1050
1050
                           lex->duplicates,
1576
1576
  */
1577
1577
  Table *table= 0;
1578
1578
  {
1579
 
    if (not mysql_create_table_no_lock(session,
 
1579
    if (not create_table_no_lock(session,
1580
1580
                                       identifier,
1581
1581
                                       create_info,
1582
1582
                                       table_proto,
1704
1704
 
1705
1705
  /* Mark all fields that are given values */
1706
1706
  for (Field **f= field ; *f ; f++)
1707
 
    table->setWriteSet((*f)->field_index);
 
1707
  {
 
1708
    table->setWriteSet((*f)->position());
 
1709
  }
1708
1710
 
1709
1711
  /* Don't set timestamp if used */
1710
1712
  table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;