Skip to content

Commit f576de1

Browse files
author
Michael Meskes
committed
Improved ECPG warning as suggested by Michael Paquier and removed test case
that triggers the warning during regression tests.
1 parent 31f860a commit f576de1

File tree

5 files changed

+118
-263
lines changed

5 files changed

+118
-263
lines changed

src/interfaces/ecpg/preproc/ecpg.header

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,8 @@ check_declared_list(const char *name)
595595
if (strcmp(name, ptr -> name) == 0)
596596
{
597597
if (connection)
598-
mmerror(PARSE_ERROR, ET_WARNING, "connection %s is overwritten to %s.", connection, ptr->connection);
598+
if (connection && strcmp(ptr->connection, connection) != 0)
599+
mmerror(PARSE_ERROR, ET_WARNING, "connection %s is overwritten with %s by declare statement %s.", connection, ptr->connection, name);
599600
connection = mm_strdup(ptr -> connection);
600601
return true;
601602
}

src/interfaces/ecpg/test/expected/sql-declare.c

Lines changed: 58 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -366,103 +366,71 @@ if (sqlca.sqlcode < 0) sqlprint();}
366366
printResult("testcase2", 2);
367367

368368
/*
369-
* testcase3. using DECLARE STATEMENT at con1,
370-
* using PREPARE and CURSOR statement at con2
369+
* testcase3. using DECLARE STATEMENT without using AT clause,
370+
* using PREPARE and EXECUTE statement without using AT clause
371371
*/
372372
reset();
373373

374374
/* declare \"stmt_3\" as an SQL identifier */
375375
#line 122 "declare.pgc"
376376

377-
{ ECPGprepare(__LINE__, "con1", 0, "stmt_3", selectString);
377+
{ ECPGprepare(__LINE__, NULL, 0, "stmt_3", selectString);
378378
#line 123 "declare.pgc"
379379

380380
if (sqlca.sqlcode < 0) sqlprint();}
381381
#line 123 "declare.pgc"
382382

383-
/* declare cur_3 cursor for $1 */
384-
#line 124 "declare.pgc"
385-
386-
{ ECPGdo(__LINE__, 0, 1, "con1", 0, ECPGst_normal, "declare cur_3 cursor for $1",
387-
ECPGt_char_variable,(ECPGprepared_statement("con1", "stmt_3", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
388-
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
389-
#line 125 "declare.pgc"
390-
391-
if (sqlca.sqlcode < 0) sqlprint();}
392-
#line 125 "declare.pgc"
393-
394-
395-
/* exec sql whenever not found break ; */
396-
#line 127 "declare.pgc"
397-
398-
i = 0;
399-
while (1)
400-
{
401-
{ ECPGdo(__LINE__, 0, 1, "con1", 0, ECPGst_normal, "fetch cur_3", ECPGt_EOIT,
402-
ECPGt_int,&(f1[i]),(long)1,(long)1,sizeof(int),
383+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "stmt_3", ECPGt_EOIT,
384+
ECPGt_int,(f1),(long)1,(long)ARRAY_SIZE,sizeof(int),
403385
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
404-
ECPGt_int,&(f2[i]),(long)1,(long)1,sizeof(int),
386+
ECPGt_int,(f2),(long)1,(long)ARRAY_SIZE,sizeof(int),
405387
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
406-
ECPGt_char,(f3[i]),(long)20,(long)1,(20)*sizeof(char),
388+
ECPGt_char,(f3),(long)20,(long)ARRAY_SIZE,(20)*sizeof(char),
407389
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
408-
#line 131 "declare.pgc"
409-
410-
if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
411-
#line 131 "declare.pgc"
390+
#line 124 "declare.pgc"
412391

413392
if (sqlca.sqlcode < 0) sqlprint();}
414-
#line 131 "declare.pgc"
415-
416-
i++;
417-
}
418-
{ ECPGdo(__LINE__, 0, 1, "con1", 0, ECPGst_normal, "close cur_3", ECPGt_EOIT, ECPGt_EORT);
419-
#line 134 "declare.pgc"
393+
#line 124 "declare.pgc"
420394

421-
if (sqlca.sqlcode < 0) sqlprint();}
422-
#line 134 "declare.pgc"
423395

424-
{ ECPGdeallocate(__LINE__, 0, "con1", "stmt_3");
425-
#line 135 "declare.pgc"
396+
{ ECPGdeallocate(__LINE__, 0, NULL, "stmt_3");
397+
#line 126 "declare.pgc"
426398

427399
if (sqlca.sqlcode < 0) sqlprint();}
428-
#line 135 "declare.pgc"
429-
430-
/* exec sql whenever not found continue ; */
431-
#line 136 "declare.pgc"
400+
#line 126 "declare.pgc"
432401

433402

434403
printResult("testcase3", 2);
435404

436-
437405
/*
438406
* testcase4. using DECLARE STATEMENT without using AT clause,
439407
* using PREPARE and CURSOR statement at con2
440408
*/
441409
reset();
442410

443411
/* declare \"stmt_4\" as an SQL identifier */
444-
#line 147 "declare.pgc"
412+
#line 136 "declare.pgc"
445413

446414
{ ECPGprepare(__LINE__, "con2", 0, "stmt_4", selectString);
447-
#line 148 "declare.pgc"
415+
#line 137 "declare.pgc"
448416

449417
if (sqlca.sqlcode < 0) sqlprint();}
450-
#line 148 "declare.pgc"
418+
#line 137 "declare.pgc"
451419

452420
/* declare cur_4 cursor for $1 */
453-
#line 149 "declare.pgc"
421+
#line 138 "declare.pgc"
454422

455423
{ ECPGdo(__LINE__, 0, 1, "con2", 0, ECPGst_normal, "declare cur_4 cursor for $1",
456424
ECPGt_char_variable,(ECPGprepared_statement("con2", "stmt_4", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
457425
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
458-
#line 150 "declare.pgc"
426+
#line 139 "declare.pgc"
459427

460428
if (sqlca.sqlcode < 0) sqlprint();}
461-
#line 150 "declare.pgc"
429+
#line 139 "declare.pgc"
462430

463431

464432
/* exec sql whenever not found break ; */
465-
#line 152 "declare.pgc"
433+
#line 141 "declare.pgc"
466434

467435
i = 0;
468436
while (1)
@@ -474,173 +442,136 @@ if (sqlca.sqlcode < 0) sqlprint();}
474442
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
475443
ECPGt_char,(f3[i]),(long)20,(long)1,(20)*sizeof(char),
476444
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
477-
#line 156 "declare.pgc"
445+
#line 145 "declare.pgc"
478446

479447
if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
480-
#line 156 "declare.pgc"
448+
#line 145 "declare.pgc"
481449

482450
if (sqlca.sqlcode < 0) sqlprint();}
483-
#line 156 "declare.pgc"
451+
#line 145 "declare.pgc"
484452

485453
i++;
486454
}
487455
{ ECPGdo(__LINE__, 0, 1, "con2", 0, ECPGst_normal, "close cur_4", ECPGt_EOIT, ECPGt_EORT);
488-
#line 159 "declare.pgc"
456+
#line 148 "declare.pgc"
489457

490458
if (sqlca.sqlcode < 0) sqlprint();}
491-
#line 159 "declare.pgc"
459+
#line 148 "declare.pgc"
492460

493461
{ ECPGdeallocate(__LINE__, 0, "con2", "stmt_4");
494-
#line 160 "declare.pgc"
462+
#line 149 "declare.pgc"
495463

496464
if (sqlca.sqlcode < 0) sqlprint();}
497-
#line 160 "declare.pgc"
465+
#line 149 "declare.pgc"
498466

499467
/* exec sql whenever not found continue ; */
500-
#line 161 "declare.pgc"
468+
#line 150 "declare.pgc"
501469

502470

503471
printResult("testcase4", 2);
504472

505-
/*
506-
* testcase5. using DECLARE STATEMENT without using AT clause,
507-
* using PREPARE and EXECUTE statement without using AT clause
508-
*/
509-
reset();
510-
511-
/* declare \"stmt_5\" as an SQL identifier */
512-
#line 171 "declare.pgc"
513-
514-
{ ECPGprepare(__LINE__, NULL, 0, "stmt_5", selectString);
515-
#line 172 "declare.pgc"
516-
517-
if (sqlca.sqlcode < 0) sqlprint();}
518-
#line 172 "declare.pgc"
519-
520-
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "stmt_5", ECPGt_EOIT,
521-
ECPGt_int,(f1),(long)1,(long)ARRAY_SIZE,sizeof(int),
522-
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
523-
ECPGt_int,(f2),(long)1,(long)ARRAY_SIZE,sizeof(int),
524-
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
525-
ECPGt_char,(f3),(long)20,(long)ARRAY_SIZE,(20)*sizeof(char),
526-
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
527-
#line 173 "declare.pgc"
528-
529-
if (sqlca.sqlcode < 0) sqlprint();}
530-
#line 173 "declare.pgc"
531-
532-
533-
{ ECPGdeallocate(__LINE__, 0, NULL, "stmt_5");
534-
#line 175 "declare.pgc"
535-
536-
if (sqlca.sqlcode < 0) sqlprint();}
537-
#line 175 "declare.pgc"
538-
539-
540-
printResult("testcase5", 2);
541-
542473
/*
543474
* DESCRIBE statement is also supported.
544475
*/
545476
/* declare \"stmt_desc\" as an SQL identifier */
546-
#line 182 "declare.pgc"
477+
#line 157 "declare.pgc"
547478

548479
{ ECPGprepare(__LINE__, "con1", 0, "stmt_desc", selectString);
549-
#line 183 "declare.pgc"
480+
#line 158 "declare.pgc"
550481

551482
if (sqlca.sqlcode < 0) sqlprint();}
552-
#line 183 "declare.pgc"
483+
#line 158 "declare.pgc"
553484

554485
/* declare cur_desc cursor for $1 */
555-
#line 184 "declare.pgc"
486+
#line 159 "declare.pgc"
556487

557488
{ ECPGdo(__LINE__, 0, 1, "con1", 0, ECPGst_normal, "declare cur_desc cursor for $1",
558489
ECPGt_char_variable,(ECPGprepared_statement("con1", "stmt_desc", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
559490
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
560-
#line 185 "declare.pgc"
491+
#line 160 "declare.pgc"
561492

562493
if (sqlca.sqlcode < 0) sqlprint();}
563-
#line 185 "declare.pgc"
494+
#line 160 "declare.pgc"
564495

565496

566497
/* descriptor can be used for describe statement */
567498
ECPGallocate_desc(__LINE__, "desc_for_describe");
568-
#line 188 "declare.pgc"
499+
#line 163 "declare.pgc"
569500

570501
if (sqlca.sqlcode < 0) sqlprint();
571-
#line 188 "declare.pgc"
502+
#line 163 "declare.pgc"
572503

573504
{ ECPGdescribe(__LINE__, 0, 0, "con1", "stmt_desc",
574505
ECPGt_descriptor, "desc_for_describe", 1L, 1L, 1L,
575506
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
576-
#line 189 "declare.pgc"
507+
#line 164 "declare.pgc"
577508

578509

579510
{ ECPGget_desc_header(__LINE__, "desc_for_describe", &(count));
580511

581-
#line 191 "declare.pgc"
512+
#line 166 "declare.pgc"
582513

583514
if (sqlca.sqlcode < 0) sqlprint();}
584-
#line 191 "declare.pgc"
515+
#line 166 "declare.pgc"
585516

586517
{ ECPGget_desc(__LINE__, "desc_for_describe", 3,ECPGd_length,
587518
ECPGt_int,&(length),(long)1,(long)1,sizeof(int), ECPGd_EODT);
588519

589-
#line 192 "declare.pgc"
520+
#line 167 "declare.pgc"
590521

591522
if (sqlca.sqlcode < 0) sqlprint();}
592-
#line 192 "declare.pgc"
523+
#line 167 "declare.pgc"
593524

594525

595526
ECPGdeallocate_desc(__LINE__, "desc_for_describe");
596-
#line 194 "declare.pgc"
527+
#line 169 "declare.pgc"
597528

598529
if (sqlca.sqlcode < 0) sqlprint();
599-
#line 194 "declare.pgc"
530+
#line 169 "declare.pgc"
600531

601532

602533
/* for fetch statement */
603534
ECPGallocate_desc(__LINE__, "desc_for_fetch");
604-
#line 197 "declare.pgc"
535+
#line 172 "declare.pgc"
605536

606537
if (sqlca.sqlcode < 0) sqlprint();
607-
#line 197 "declare.pgc"
538+
#line 172 "declare.pgc"
608539

609540
{ ECPGdo(__LINE__, 0, 1, "con1", 0, ECPGst_normal, "fetch cur_desc", ECPGt_EOIT,
610541
ECPGt_descriptor, "desc_for_fetch", 1L, 1L, 1L,
611542
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
612-
#line 198 "declare.pgc"
543+
#line 173 "declare.pgc"
613544

614545
if (sqlca.sqlcode < 0) sqlprint();}
615-
#line 198 "declare.pgc"
546+
#line 173 "declare.pgc"
616547

617548

618549
{ ECPGget_desc(__LINE__, "desc_for_fetch", 3,ECPGd_data,
619550
ECPGt_char,(f3[0]),(long)20,(long)1,(20)*sizeof(char), ECPGd_EODT);
620551

621-
#line 200 "declare.pgc"
552+
#line 175 "declare.pgc"
622553

623554
if (sqlca.sqlcode < 0) sqlprint();}
624-
#line 200 "declare.pgc"
555+
#line 175 "declare.pgc"
625556

626557

627558
ECPGdeallocate_desc(__LINE__, "desc_for_fetch");
628-
#line 202 "declare.pgc"
559+
#line 177 "declare.pgc"
629560

630561
if (sqlca.sqlcode < 0) sqlprint();
631-
#line 202 "declare.pgc"
562+
#line 177 "declare.pgc"
632563

633564
{ ECPGdo(__LINE__, 0, 1, "con1", 0, ECPGst_normal, "close cur_desc", ECPGt_EOIT, ECPGt_EORT);
634-
#line 203 "declare.pgc"
565+
#line 178 "declare.pgc"
635566

636567
if (sqlca.sqlcode < 0) sqlprint();}
637-
#line 203 "declare.pgc"
568+
#line 178 "declare.pgc"
638569

639570
{ ECPGdeallocate(__LINE__, 0, "con1", "stmt_desc");
640-
#line 204 "declare.pgc"
571+
#line 179 "declare.pgc"
641572

642573
if (sqlca.sqlcode < 0) sqlprint();}
643-
#line 204 "declare.pgc"
574+
#line 179 "declare.pgc"
644575

645576

646577
printf("****descriptor results****\n");
@@ -650,16 +581,16 @@ if (sqlca.sqlcode < 0) sqlprint();}
650581
void commitTable()
651582
{
652583
{ ECPGtrans(__LINE__, "con1", "commit");
653-
#line 212 "declare.pgc"
584+
#line 187 "declare.pgc"
654585

655586
if (sqlca.sqlcode < 0) sqlprint();}
656-
#line 212 "declare.pgc"
587+
#line 187 "declare.pgc"
657588

658589
{ ECPGtrans(__LINE__, "con2", "commit");
659-
#line 213 "declare.pgc"
590+
#line 188 "declare.pgc"
660591

661592
if (sqlca.sqlcode < 0) sqlprint();}
662-
#line 213 "declare.pgc"
593+
#line 188 "declare.pgc"
663594

664595
}
665596

0 commit comments

Comments
 (0)