void print_consumer_info(FILE* f, consumer_info_t* info) { fprintf(f, "queue name: %s\n", info->queue_name); fprintf(f, "consumer name: %s\n", info->consumer_name); fprintf(f, "lag: %s\n", PGTYPESinterval_to_asc(&info->lag)); fprintf(f, "last_seen: %s\n", PGTYPESinterval_to_asc(&info->last_seen)); fprintf(f, "last_tick: %ld\n", info->last_tick); fprintf(f, "current_batch: %ld\n", info->current_batch); fprintf(f, "next_tick: %ld\n", info->next_tick); fprintf(f, "pending_events: %ld\n", info->pending_events); }
void print_queue_info(FILE* f, queue_info_t* info) { char temp[256]; fprintf(f, "queue name: %s\n", info->name); fprintf(f, "ntables: %d\n", info->ntables); fprintf(f, "cur_table: %d\n", info->cur_table); fprintf(f, "rotation_period: %s\n", PGTYPESinterval_to_asc(&info->rotation_period)); PGTYPEStimestamp_fmt_asc(&info->switch_time, temp, ARRAY_SIZE(temp), "%Y-%m-%d %T"); fprintf(f, "switch_time: %s\n", temp); fprintf(f, "external_ticker: %d\n", info->external_ticker); fprintf(f, "ticker_paused: %d\n", info->ticker_paused); fprintf(f, "ticker_max_count: %d\n", info->ticker_max_count); fprintf(f, "ticker_max_lag: %s\n", PGTYPESinterval_to_asc(&info->ticker_max_lag)); fprintf(f, "ticker_idle_period: %s\n", PGTYPESinterval_to_asc(&info->ticker_idle_period)); fprintf(f, "ticker_lag: %s\n", PGTYPESinterval_to_asc(&info->ticker_lag)); fprintf(f, "ev_per_sec: %f\n", info->ev_per_sec); fprintf(f, "ev_new: %ld\n", info->ev_new); fprintf(f, "last_tick_id: %ld\n", info->last_tick_id); }
void print_batch_info(FILE* f, batch_info_t* info) { char temp[256]; fprintf(f, "queue name: %s\n", info->queue_name); fprintf(f, "consumer name: %s\n", info->consumer_name); PGTYPEStimestamp_fmt_asc(&info->batch_start, temp, ARRAY_SIZE(temp), "%Y-%m-%d %T"); fprintf(f, "batch_start: %s\n", temp); PGTYPEStimestamp_fmt_asc(&info->batch_end, temp, ARRAY_SIZE(temp), "%Y-%m-%d %T"); fprintf(f, "batch_end: %s\n", temp); fprintf(f, "prev_tick_id: %ld\n", info->prev_tick_id); fprintf(f, "tick_id: %ld\n", info->tick_id); fprintf(f, "lag: %s\n", PGTYPESinterval_to_asc(&info->lag)); fprintf(f, "seq_start: %ld\n", info->seq_start); fprintf(f, "seq_end: %ld\n", info->seq_end); }
int main (void) { /* exec sql begin declare section */ #line 19 "array.pgc" int i = 1 , j ; #line 20 "array.pgc" int * did = & i ; #line 21 "array.pgc" short a [ 10 ] = { 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 } ; #line 22 "array.pgc" timestamp ts [ 10 ] ; #line 23 "array.pgc" date d [ 10 ] ; #line 24 "array.pgc" interval in [ 10 ] ; #line 25 "array.pgc" numeric n [ 10 ] ; #line 26 "array.pgc" char text [ 25 ] = "klmnopqrst" ; #line 27 "array.pgc" char * t = ( char * ) malloc ( 11 ) ; #line 28 "array.pgc" double f ; /* exec sql end declare section */ #line 29 "array.pgc" strcpy(t, "0123456789"); setlocale(LC_ALL, "C"); ECPGdebug(1, stderr); for (j = 0; j < 10; j++) { char str[20]; numeric *value; interval *inter; sprintf(str, "2000-1-1 0%d:00:00", j); ts[j] = PGTYPEStimestamp_from_asc(str, NULL); sprintf(str, "2000-1-1%d\n", j); d[j] = PGTYPESdate_from_asc(str, NULL); sprintf(str, "%d hours", j+10); inter = PGTYPESinterval_from_asc(str, NULL); in[j] = *inter; value = PGTYPESnumeric_new(); PGTYPESnumeric_from_int(j, value); n[j] = *value; } { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0); #line 53 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 53 "array.pgc" { ECPGsetcommit(__LINE__, "on", NULL); #line 55 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 55 "array.pgc" { ECPGtrans(__LINE__, NULL, "begin work"); #line 57 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 57 "array.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( f float , i int , a int [ 10 ] , text char ( 10 ) , ts timestamp [ 10 ] , n numeric [ 10 ] , d date [ 10 ] , inter interval [ 10 ] )", ECPGt_EOIT, ECPGt_EORT); #line 59 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 59 "array.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text , ts , n , d , inter ) values ( 404.90 , 3 , '{0,1,2,3,4,5,6,7,8,9}' , 'abcdefghij' , $1 , $2 , $3 , $4 )", ECPGt_timestamp,&(ts),(long)1,(long)10,sizeof(timestamp), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_numeric,&(n),(long)1,(long)10,sizeof(numeric), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_date,&(d),(long)1,(long)10,sizeof(date), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_interval,&(in),(long)1,(long)10,sizeof(interval), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT); #line 61 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 61 "array.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text , ts , n , d , inter ) values ( 140787.0 , 2 , $1 , $2 , $3 , $4 , $5 , $6 )", ECPGt_short,(a),(long)1,(long)10,sizeof(short), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_timestamp,&(ts),(long)1,(long)10,sizeof(timestamp), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_numeric,&(n),(long)1,(long)10,sizeof(numeric), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_date,&(d),(long)1,(long)10,sizeof(date), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_interval,&(in),(long)1,(long)10,sizeof(interval), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT); #line 63 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 63 "array.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( f , i , a , text , ts , n , d , inter ) values ( 14.07 , $1 , $2 , $3 , $4 , $5 , $6 , $7 )", ECPGt_int,&(did),(long)1,(long)0,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_short,(a),(long)1,(long)10,sizeof(short), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_char,&(t),(long)0,(long)1,(1)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_timestamp,&(ts),(long)1,(long)10,sizeof(timestamp), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_numeric,&(n),(long)1,(long)10,sizeof(numeric), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_date,&(d),(long)1,(long)10,sizeof(date), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_interval,&(in),(long)1,(long)10,sizeof(interval), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT); #line 65 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 65 "array.pgc" { ECPGtrans(__LINE__, NULL, "commit"); #line 67 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 67 "array.pgc" for (j = 0; j < 10; j++) { ts[j] = PGTYPEStimestamp_from_asc("1900-01-01 00:00:00", NULL); d[j] = PGTYPESdate_from_asc("1900-01-01", NULL); in[j] = *PGTYPESinterval_new(); n[j] = *PGTYPESnumeric_new(); } { ECPGtrans(__LINE__, NULL, "begin work"); #line 75 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 75 "array.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select f , text from test where i = 1", ECPGt_EOIT, ECPGt_double,&(f),(long)1,(long)1,sizeof(double), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); #line 80 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 80 "array.pgc" printf("Found f=%f text=%10.10s\n", f, text); f=140787; { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select a , text , ts , n , d , inter from test where f = $1 ", ECPGt_double,&(f),(long)1,(long)1,sizeof(double), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_short,(a),(long)1,(long)10,sizeof(short), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_char,&(t),(long)0,(long)1,(1)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_timestamp,&(ts),(long)1,(long)10,sizeof(timestamp), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_numeric,&(n),(long)1,(long)10,sizeof(numeric), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_date,&(d),(long)1,(long)10,sizeof(date), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_interval,&(in),(long)1,(long)10,sizeof(interval), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); #line 88 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 88 "array.pgc" for (i = 0; i < 10; i++) printf("Found a[%d] = %d ts[%d] = %s n[%d] = %s d[%d] = %s in[%d] = %s\n", i, a[i], i, PGTYPEStimestamp_to_asc(ts[i]), i, PGTYPESnumeric_to_asc(&(n[i]), -1), i, PGTYPESdate_to_asc(d[i]), i, PGTYPESinterval_to_asc(&(in[i]))); printf("Found text=%10.10s\n", t); { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select a from test where f = $1 ", ECPGt_double,&(f),(long)1,(long)1,sizeof(double), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); #line 98 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 98 "array.pgc" printf("Found text=%s\n", text); { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT); #line 102 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 102 "array.pgc" { ECPGtrans(__LINE__, NULL, "commit"); #line 104 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 104 "array.pgc" { ECPGdisconnect(__LINE__, "CURRENT"); #line 106 "array.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 106 "array.pgc" free(t); return 0; }
int main(void) { /* exec sql begin declare section */ #line 62 "dt_test2.pgc" date date1 ; #line 63 "dt_test2.pgc" timestamp ts1 , ts2 ; #line 64 "dt_test2.pgc" char * text ; #line 65 "dt_test2.pgc" interval * i1 ; #line 66 "dt_test2.pgc" date * dc ; /* exec sql end declare section */ #line 67 "dt_test2.pgc" int i, j; char *endptr; ECPGdebug(1, stderr); ts1 = PGTYPEStimestamp_from_asc("2003-12-04 17:34:29", NULL); text = PGTYPEStimestamp_to_asc(ts1); printf("timestamp: %s\n", text); free(text); date1 = PGTYPESdate_from_timestamp(ts1); dc = PGTYPESdate_new(); *dc = date1; text = PGTYPESdate_to_asc(*dc); printf("Date of timestamp: %s\n", text); free(text); PGTYPESdate_free(dc); for (i = 0; dates[i]; i++) { bool err = false; date1 = PGTYPESdate_from_asc(dates[i], &endptr); if (date1 == INT_MIN) { err = true; } text = PGTYPESdate_to_asc(date1); printf("Date[%d]: %s (%c - %c)\n", i, err ? "-" : text, endptr ? 'N' : 'Y', err ? 'T' : 'F'); free(text); if (!err) { for (j = 0; times[j]; j++) { int length = strlen(dates[i]) + 1 + strlen(times[j]) + 1; char* t = malloc(length); sprintf(t, "%s %s", dates[i], times[j]); ts1 = PGTYPEStimestamp_from_asc(t, NULL); text = PGTYPEStimestamp_to_asc(ts1); printf("TS[%d,%d]: %s\n", i, j, errno ? "-" : text); free(text); free(t); } } } ts1 = PGTYPEStimestamp_from_asc("2004-04-04 23:23:23", NULL); for (i = 0; intervals[i]; i++) { interval *ic; i1 = PGTYPESinterval_from_asc(intervals[i], &endptr); if (*endptr) printf("endptr set to %s\n", endptr); if (!i1) { printf("Error parsing interval %d\n", i); continue; } j = PGTYPEStimestamp_add_interval(&ts1, i1, &ts2); if (j < 0) continue; text = PGTYPESinterval_to_asc(i1); printf("interval[%d]: %s\n", i, text ? text : "-"); free(text); ic = PGTYPESinterval_new(); PGTYPESinterval_copy(i1, ic); text = PGTYPESinterval_to_asc(i1); printf("interval_copy[%d]: %s\n", i, text ? text : "-"); free(text); PGTYPESinterval_free(ic); PGTYPESinterval_free(i1); } return 0; }