~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_load.cc

Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs

Show diffs side-by-side

added added

removed removed

Lines of Context:
162
162
  ulong skip_lines= ex->skip_lines;
163
163
  bool transactional_table;
164
164
  THD::killed_state killed_status= THD::NOT_KILLED;
165
 
  DBUG_ENTER("mysql_load");
166
165
 
167
166
  if (escaped->length() > 1 || enclosed->length() > 1)
168
167
  {
169
168
    my_message(ER_WRONG_FIELD_TERMINATORS,ER(ER_WRONG_FIELD_TERMINATORS),
170
169
               MYF(0));
171
 
    DBUG_RETURN(TRUE);
 
170
    return(TRUE);
172
171
  }
173
172
  if (open_and_lock_tables(thd, table_list))
174
 
    DBUG_RETURN(TRUE);
 
173
    return(TRUE);
175
174
  if (setup_tables_and_check_access(thd, &thd->lex->select_lex.context,
176
175
                                    &thd->lex->select_lex.top_join_list,
177
176
                                    table_list,
178
177
                                    &thd->lex->select_lex.leaf_tables, true))
179
 
     DBUG_RETURN(-1);
 
178
     return(-1);
180
179
 
181
180
  /*
182
181
    Let us emit an error if we are loading data to table which is used
189
188
  if (unique_table(thd, table_list, table_list->next_global, 0))
190
189
  {
191
190
    my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->table_name);
192
 
    DBUG_RETURN(TRUE);
 
191
    return(TRUE);
193
192
  }
194
193
 
195
194
  table= table_list->table;
208
207
    */
209
208
    if (setup_fields(thd, 0, set_fields, MARK_COLUMNS_WRITE, 0, 0) ||
210
209
        setup_fields(thd, 0, set_values, MARK_COLUMNS_READ, 0, 0))
211
 
      DBUG_RETURN(TRUE);
 
210
      return(TRUE);
212
211
  }
213
212
  else
214
213
  {                                             // Part field list
216
215
    if (setup_fields(thd, 0, fields_vars, MARK_COLUMNS_WRITE, 0, 0) ||
217
216
        setup_fields(thd, 0, set_fields, MARK_COLUMNS_WRITE, 0, 0) ||
218
217
        check_that_all_fields_are_given_values(thd, table, table_list))
219
 
      DBUG_RETURN(TRUE);
 
218
      return(TRUE);
220
219
    /*
221
220
      Check whenever TIMESTAMP field with auto-set feature specified
222
221
      explicitly.
234
233
    }
235
234
    /* Fix the expressions in SET clause */
236
235
    if (setup_fields(thd, 0, set_values, MARK_COLUMNS_READ, 0, 0))
237
 
      DBUG_RETURN(TRUE);
 
236
      return(TRUE);
238
237
  }
239
238
 
240
239
  table->mark_columns_needed_for_insert();
266
265
  {
267
266
    my_message(ER_BLOBS_AND_NO_TERMINATED,ER(ER_BLOBS_AND_NO_TERMINATED),
268
267
               MYF(0));
269
 
    DBUG_RETURN(TRUE);
 
268
    return(TRUE);
270
269
  }
271
270
  if (use_vars && !field_term->length() && !enclosed->length())
272
271
  {
273
272
    my_error(ER_LOAD_FROM_FIXED_SIZE_ROWS_TO_VAR, MYF(0));
274
 
    DBUG_RETURN(TRUE);
 
273
    return(TRUE);
275
274
  }
276
275
 
277
276
  /* We can't give an error in the middle when using LOCAL files */
304
303
      {
305
304
        /* Read only allowed from within dir specified by secure_file_priv */
306
305
        my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");
307
 
        DBUG_RETURN(TRUE);
 
306
        return(TRUE);
308
307
      }
309
308
 
310
309
      struct stat stat_info;
311
310
      if (stat(name,&stat_info))
312
 
        DBUG_RETURN(TRUE);
 
311
        return(TRUE);
313
312
 
314
313
      // if we are not in slave thread, the file must be:
315
314
      if (!thd->slave_thread &&
319
318
             (stat_info.st_mode & S_IFIFO) == S_IFIFO)))
320
319
      {
321
320
        my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), name);
322
 
        DBUG_RETURN(TRUE);
 
321
        return(TRUE);
323
322
      }
324
323
      if ((stat_info.st_mode & S_IFIFO) == S_IFIFO)
325
324
        is_fifo = 1;
326
325
    }
327
326
    if ((file=my_open(name,O_RDONLY,MYF(MY_WME))) < 0)
328
 
      DBUG_RETURN(TRUE);
 
327
      return(TRUE);
329
328
  }
330
329
 
331
330
  COPY_INFO info;
342
341
  {
343
342
    if  (file >= 0)
344
343
      my_close(file,MYF(0));                    // no files in net reading
345
 
    DBUG_RETURN(TRUE);                          // Can't allocate buffers
 
344
    return(TRUE);                               // Can't allocate buffers
346
345
  }
347
346
 
348
347
  if (mysql_bin_log.is_open())
514
513
  table->file->ha_release_auto_increment();
515
514
  table->auto_increment_field_not_null= FALSE;
516
515
  thd->abort_on_warning= 0;
517
 
  DBUG_RETURN(error);
 
516
  return(error);
518
517
}
519
518
 
520
519
 
551
550
  TABLE *table= table_list->table;
552
551
  ulonglong id;
553
552
  bool err;
554
 
  DBUG_ENTER("read_fixed_length");
555
553
 
556
554
  id= 0;
557
555
 
560
558
    if (thd->killed)
561
559
    {
562
560
      thd->send_kill_message();
563
 
      DBUG_RETURN(1);
 
561
      return(1);
564
562
    }
565
563
    if (skip_lines)
566
564
    {
630
628
    if (thd->killed ||
631
629
        fill_record(thd, set_fields, set_values,
632
630
                    ignore_check_option_errors))
633
 
      DBUG_RETURN(1);
 
631
      return(1);
634
632
 
635
633
    err= write_record(thd, table, &info);
636
634
    table->auto_increment_field_not_null= FALSE;
637
635
    if (err)
638
 
      DBUG_RETURN(1);
 
636
      return(1);
639
637
   
640
638
    /*
641
639
      We don't need to reset auto-increment field since we are restoring
652
650
    }
653
651
    thd->row_count++;
654
652
  }
655
 
  DBUG_RETURN(test(read_info.error));
 
653
  return(test(read_info.error));
656
654
}
657
655
 
658
656
 
670
668
  uint enclosed_length;
671
669
  ulonglong id;
672
670
  bool err;
673
 
  DBUG_ENTER("read_sep_field");
674
671
 
675
672
  enclosed_length=enclosed.length();
676
673
  id= 0;
680
677
    if (thd->killed)
681
678
    {
682
679
      thd->send_kill_message();
683
 
      DBUG_RETURN(1);
 
680
      return(1);
684
681
    }
685
682
 
686
683
    restore_record(table, s->default_values);
714
711
          {
715
712
            my_error(ER_WARN_NULL_TO_NOTNULL, MYF(0), field->field_name,
716
713
                     thd->row_count);
717
 
            DBUG_RETURN(1);
 
714
            return(1);
718
715
          }
719
716
          field->set_null();
720
717
          if (!field->maybe_null())
734
731
        else
735
732
        {
736
733
          my_error(ER_LOAD_DATA_INVALID_COLUMN, MYF(0), item->full_name());
737
 
          DBUG_RETURN(1);
 
734
          return(1);
738
735
        }
739
736
 
740
737
        continue;
757
754
      else
758
755
      {
759
756
        my_error(ER_LOAD_DATA_INVALID_COLUMN, MYF(0), item->full_name());
760
 
        DBUG_RETURN(1);
 
757
        return(1);
761
758
      }
762
759
    }
763
760
    if (read_info.error)
782
779
          {
783
780
            my_error(ER_WARN_NULL_TO_NOTNULL, MYF(0),field->field_name,
784
781
                     thd->row_count);
785
 
            DBUG_RETURN(1);
 
782
            return(1);
786
783
          }
787
784
          if (!field->maybe_null() && field->type() == FIELD_TYPE_TIMESTAMP)
788
785
              ((Field_timestamp*) field)->set_time();
805
802
        else
806
803
        {
807
804
          my_error(ER_LOAD_DATA_INVALID_COLUMN, MYF(0), item->full_name());
808
 
          DBUG_RETURN(1);
 
805
          return(1);
809
806
        }
810
807
      }
811
808
    }
813
810
    if (thd->killed ||
814
811
        fill_record(thd, set_fields, set_values,
815
812
                    ignore_check_option_errors))
816
 
      DBUG_RETURN(1);
 
813
      return(1);
817
814
 
818
815
    err= write_record(thd, table, &info);
819
816
    table->auto_increment_field_not_null= FALSE;
820
817
    if (err)
821
 
      DBUG_RETURN(1);
 
818
      return(1);
822
819
    /*
823
820
      We don't need to reset auto-increment field since we are restoring
824
821
      its default value at the beginning of each loop iteration.
832
829
                          ER_WARN_TOO_MANY_RECORDS, ER(ER_WARN_TOO_MANY_RECORDS), 
833
830
                          thd->row_count);   
834
831
      if (thd->killed)
835
 
        DBUG_RETURN(1);
 
832
        return(1);
836
833
    }
837
834
    thd->row_count++;
838
835
  }
839
 
  DBUG_RETURN(test(read_info.error));
 
836
  return(test(read_info.error));
840
837
}
841
838
 
842
839
 
855
852
  TABLE *table= table_list->table;
856
853
  bool no_trans_update_stmt;
857
854
  CHARSET_INFO *cs= read_info.read_charset;
858
 
  DBUG_ENTER("read_xml_field");
859
855
  
860
856
  no_trans_update_stmt= !table->file->has_transactions();
861
857
  
864
860
    if (thd->killed)
865
861
    {
866
862
      thd->send_kill_message();
867
 
      DBUG_RETURN(1);
 
863
      return(1);
868
864
    }
869
865
    
870
866
    // read row tag and save values into tag list
875
871
    xmlit.rewind();
876
872
    XML_TAG *tag= NULL;
877
873
    
878
 
#ifndef DBUG_OFF
879
 
    DBUG_PRINT("read_xml_field", ("skip_lines=%d", (int) skip_lines));
880
 
    while ((tag= xmlit++))
881
 
    {
882
 
      DBUG_PRINT("read_xml_field", ("got tag:%i '%s' '%s'",
883
 
                                    tag->level, tag->field.c_ptr(),
884
 
                                    tag->value.c_ptr()));
885
 
    }
886
 
#endif
887
874
    
888
875
    restore_record(table, s->default_values);
889
876
    
975
962
 
976
963
    if (thd->killed || fill_record(thd, set_fields, set_values,
977
964
                    ignore_check_option_errors))
978
 
      DBUG_RETURN(1);
 
965
      return(1);
979
966
 
980
967
    if (write_record(thd, table, &info))
981
 
      DBUG_RETURN(1);
 
968
      return(1);
982
969
    
983
970
    /*
984
971
      We don't need to reset auto-increment field since we are restoring
987
974
    thd->transaction.stmt.modified_non_trans_table= no_trans_update_stmt;
988
975
    thd->row_count++;
989
976
  }
990
 
  DBUG_RETURN(test(read_info.error));
 
977
  return(test(read_info.error));
991
978
} /* load xml end */
992
979
 
993
980
 
1445
1432
*/
1446
1433
int READ_INFO::clear_level(int level)
1447
1434
{
1448
 
  DBUG_ENTER("READ_INFO::read_xml clear_level");
1449
1435
  List_iterator<XML_TAG> xmlit(taglist);
1450
1436
  xmlit.rewind();
1451
1437
  XML_TAG *tag;
1458
1444
       delete tag;
1459
1445
     }
1460
1446
  }
1461
 
  DBUG_RETURN(0);
 
1447
  return(0);
1462
1448
}
1463
1449
 
1464
1450
 
1522
1508
#ifdef USE_MB
1523
1509
    if (my_mbcharlen(read_charset, chr) > 1)
1524
1510
    {
1525
 
      DBUG_PRINT("read_xml",("multi byte"));
1526
1511
      int i, ml= my_mbcharlen(read_charset, chr);
1527
1512
      for (i= 1; i < ml; i++) 
1528
1513
      {
1570
1555
*/
1571
1556
int READ_INFO::read_xml()
1572
1557
{
1573
 
  DBUG_ENTER("READ_INFO::read_xml");
1574
1558
  int chr, chr2, chr3;
1575
1559
  int delim= 0;
1576
1560
  String tag, attribute, value;
1625
1609
        chr= my_tospace(GET);
1626
1610
      }
1627
1611
      
1628
 
      // row tag should be in ROWS IDENTIFIED BY '<row>' - stored in line_term 
1629
 
      if((tag.length() == line_term_length -2) &&
1630
 
         (strncmp(tag.c_ptr_safe(), line_term_ptr + 1, tag.length()) == 0))
1631
 
      {
1632
 
        DBUG_PRINT("read_xml", ("start-of-row: %i %s %s", 
1633
 
                                level,tag.c_ptr_safe(), line_term_ptr));
1634
 
      }
1635
 
      
1636
1612
      if(chr == ' ' || chr == '>')
1637
1613
      {
1638
1614
        level++;
1667
1643
      
1668
1644
      /* save value to list */
1669
1645
      if(tag.length() > 0 && value.length() > 0)
1670
 
      {
1671
 
        DBUG_PRINT("read_xml", ("lev:%i tag:%s val:%s",
1672
 
                                level,tag.c_ptr_safe(), value.c_ptr_safe()));
1673
1646
        taglist.push_front( new XML_TAG(level, tag, value));
1674
 
      }
 
1647
 
1675
1648
      tag.length(0);
1676
1649
      value.length(0);
1677
1650
      attribute.length(0);
1690
1663
      
1691
1664
      if((tag.length() == line_term_length -2) &&
1692
1665
         (strncmp(tag.c_ptr_safe(), line_term_ptr + 1, tag.length()) == 0))
1693
 
      {
1694
 
         DBUG_PRINT("read_xml", ("found end-of-row %i %s", 
1695
 
                                 level, tag.c_ptr_safe()));
1696
 
         DBUG_RETURN(0); //normal return
1697
 
      }
 
1666
         return(0); //normal return
 
1667
 
1698
1668
      chr= my_tospace(GET);
1699
1669
      break;   
1700
1670
      
1731
1701
      
1732
1702
      chr= read_value(delim, &value);
1733
1703
      if(attribute.length() > 0 && value.length() > 0)
1734
 
      {
1735
 
        DBUG_PRINT("read_xml", ("lev:%i att:%s val:%s\n",
1736
 
                                level + 1,
1737
 
                                attribute.c_ptr_safe(),
1738
 
                                value.c_ptr_safe()));
1739
1704
        taglist.push_front(new XML_TAG(level + 1, attribute, value));
1740
 
      }
 
1705
 
1741
1706
      attribute.length(0);
1742
1707
      value.length(0);
1743
1708
      if (chr != ' ')
1750
1715
  } /* end while */
1751
1716
  
1752
1717
found_eof:
1753
 
  DBUG_PRINT("read_xml",("Found eof"));
1754
1718
  eof= 1;
1755
 
  DBUG_RETURN(1);
 
1719
  return(1);
1756
1720
}