@@ -2455,7 +2455,7 @@ static int add_partition_values(String *str, partition_info *part_info,
2455
2455
@retval != 0 Failure
2456
2456
*/
2457
2457
2458
- static int add_key_with_algorithm (String *str, partition_info *part_info)
2458
+ static int add_key_with_algorithm (String *str, const partition_info *part_info)
2459
2459
{
2460
2460
int err= 0 ;
2461
2461
err+= str->append (STRING_WITH_LEN (" KEY " ));
@@ -2484,6 +2484,78 @@ char *generate_partition_syntax_for_frm(THD *thd, partition_info *part_info,
2484
2484
return res;
2485
2485
}
2486
2486
2487
+
2488
+ /*
2489
+ Generate the partition type syntax from the partition data structure.
2490
+
2491
+ @return Operation status.
2492
+ @retval 0 Success
2493
+ @retval > 0 Failure
2494
+ @retval -1 Fatal error
2495
+ */
2496
+
2497
+ int partition_info::gen_part_type (THD *thd, String *str) const
2498
+ {
2499
+ int err= 0 ;
2500
+ switch (part_type)
2501
+ {
2502
+ case RANGE_PARTITION:
2503
+ err+= str->append (STRING_WITH_LEN (" RANGE " ));
2504
+ break ;
2505
+ case LIST_PARTITION:
2506
+ err+= str->append (STRING_WITH_LEN (" LIST " ));
2507
+ break ;
2508
+ case HASH_PARTITION:
2509
+ if (linear_hash_ind)
2510
+ err+= str->append (STRING_WITH_LEN (" LINEAR " ));
2511
+ if (list_of_part_fields)
2512
+ {
2513
+ err+= add_key_with_algorithm (str, this );
2514
+ err+= add_part_field_list (thd, str, part_field_list);
2515
+ }
2516
+ else
2517
+ err+= str->append (STRING_WITH_LEN (" HASH " ));
2518
+ break ;
2519
+ case VERSIONING_PARTITION:
2520
+ err+= str->append (STRING_WITH_LEN (" SYSTEM_TIME " ));
2521
+ break ;
2522
+ default :
2523
+ DBUG_ASSERT (0 );
2524
+ /* We really shouldn't get here, no use in continuing from here */
2525
+ my_error (ER_OUT_OF_RESOURCES, MYF (ME_FATAL));
2526
+ return -1 ;
2527
+ }
2528
+ return err;
2529
+ }
2530
+
2531
+
2532
+ void part_type_error (THD *thd, partition_info *work_part_info,
2533
+ const char *part_type,
2534
+ partition_info *tab_part_info)
2535
+ {
2536
+ StringBuffer<256 > tab_part_type;
2537
+ if (tab_part_info->gen_part_type (thd, &tab_part_type) < 0 )
2538
+ return ;
2539
+ tab_part_type.length (tab_part_type.length () - 1 );
2540
+ if (work_part_info)
2541
+ {
2542
+ DBUG_ASSERT (!part_type);
2543
+ StringBuffer<256 > work_part_type;
2544
+ if (work_part_info->gen_part_type (thd, &work_part_type) < 0 )
2545
+ return ;
2546
+ work_part_type.length (work_part_type.length () - 1 );
2547
+ my_error (ER_PARTITION_WRONG_TYPE, MYF (0 ), work_part_type.c_ptr (),
2548
+ tab_part_type.c_ptr ());
2549
+ }
2550
+ else
2551
+ {
2552
+ DBUG_ASSERT (part_type);
2553
+ my_error (ER_PARTITION_WRONG_TYPE, MYF (0 ), part_type,
2554
+ tab_part_type.c_ptr ());
2555
+ }
2556
+ }
2557
+
2558
+
2487
2559
/*
2488
2560
Generate the partition syntax from the partition data structure.
2489
2561
Useful for support of generating defaults, SHOW CREATE TABLES
@@ -2527,34 +2599,10 @@ char *generate_partition_syntax(THD *thd, partition_info *part_info,
2527
2599
DBUG_ENTER (" generate_partition_syntax" );
2528
2600
2529
2601
err+= str.append (STRING_WITH_LEN (" PARTITION BY " ));
2530
- switch (part_info->part_type )
2531
- {
2532
- case RANGE_PARTITION:
2533
- err+= str.append (STRING_WITH_LEN (" RANGE " ));
2534
- break ;
2535
- case LIST_PARTITION:
2536
- err+= str.append (STRING_WITH_LEN (" LIST " ));
2537
- break ;
2538
- case HASH_PARTITION:
2539
- if (part_info->linear_hash_ind )
2540
- err+= str.append (STRING_WITH_LEN (" LINEAR " ));
2541
- if (part_info->list_of_part_fields )
2542
- {
2543
- err+= add_key_with_algorithm (&str, part_info);
2544
- err+= add_part_field_list (thd, &str, part_info->part_field_list );
2545
- }
2546
- else
2547
- err+= str.append (STRING_WITH_LEN (" HASH " ));
2548
- break ;
2549
- case VERSIONING_PARTITION:
2550
- err+= str.append (STRING_WITH_LEN (" SYSTEM_TIME " ));
2551
- break ;
2552
- default :
2553
- DBUG_ASSERT (0 );
2554
- /* We really shouldn't get here, no use in continuing from here */
2555
- my_error (ER_OUT_OF_RESOURCES, MYF (ME_FATAL));
2556
- DBUG_RETURN (NULL );
2557
- }
2602
+ int err2= part_info->gen_part_type (thd, &str);
2603
+ if (err2 < 0 )
2604
+ DBUG_RETURN (NULL );
2605
+ err+= err2;
2558
2606
if (part_info->part_type == VERSIONING_PARTITION)
2559
2607
{
2560
2608
Vers_part_info *vers_info= part_info->vers_info ;
@@ -5044,7 +5092,7 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
5044
5092
else if (thd->work_part_info ->part_type == VERSIONING_PARTITION ||
5045
5093
tab_part_info->part_type == VERSIONING_PARTITION)
5046
5094
{
5047
- my_error (ER_PARTITION_WRONG_TYPE, MYF ( 0 ), " SYSTEM_TIME " );
5095
+ part_type_error (thd, thd-> work_part_info , NULL , tab_part_info );
5048
5096
}
5049
5097
else
5050
5098
{
0 commit comments