MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / insert_records_with_bind_params

Function insert_records_with_bind_params

tests/tools/cdb2api_caller.cpp:88–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86
87
88void insert_records_with_bind_params(cdb2_hndl_tp *db, std::string table)
89{
90 // insert records with bind index
91 for (int j = 2000; j < 3000; j++) {
92 std::ostringstream ss;
93 time_t rawtime;
94 struct tm * timeinfo;
95 char buffer [80];
96
97 time (&rawtime);
98 timeinfo = localtime (&rawtime);
99 std::vector<int> types;
100
101 strftime (buffer,80,"'%FT%T'",timeinfo);
102
103 short palltypes_short = (1-2*(j%2))*j;
104 int palltypes_int = (1-2*(j%2))*j;
105 unsigned short palltypes_u_short = j;
106 float palltypes_float = (1-2*(j%2)) * (100.0 + ((float) j)/1000.0);
107 double palltypes_double = (1-2*(j%2)) * (100000.0 + ((double) j)/1000000.0);
108 unsigned char palltypes_byte[17] = "1234567890123456";
109 unsigned char palltypes_cstring[16] = "123456789012345";
110 unsigned char palltypes_pstring[16] = "123456789012345";
111 unsigned char palltypes_blob[1025];
112 {
113 for(unsigned int i = 0 ; i < sizeof(palltypes_blob) - 1; i++)
114 palltypes_blob[i] = 'a' + (i % 26);
115 palltypes_blob[sizeof(palltypes_blob)-1] = '\0';
116 }
117 time_t t = 1386783296; //2013-12-11T123456
118 cdb2_client_datetime_t datetime = {0};
119 gmtime_r(&t, (struct tm *)&datetime.tm); //corrupts memory past the tm member
120 datetime.msec = 123; // should not be larger than 999
121 datetime.tzname[0] = '\0';
122
123 cdb2_client_datetimeus_t datetimeus = {0};
124 gmtime_r(&t, (struct tm *)&datetimeus.tm);
125 datetimeus.usec = 123456; // should not be larger than 999999
126 datetimeus.tzname[0] = '\0'; // gmtime_r corrupts past member tm
127 cdb2_client_intv_ym_t ym = {1, 5, 2};
128
129 cdb2_client_intv_ds_t ci = {1, 12, 23, 34, 45, 456 };
130
131 cdb2_client_intv_dsus_t cidsus = {1, 12, 23, 34, 45, 456789 };
132
133 if(cdb2_bind_param(db, "palltypes_short", CDB2_INTEGER, &palltypes_short, sizeof(palltypes_short)) )
134 fprintf(stderr, "Error binding palltypes_short.\n");
135 if(cdb2_bind_param(db, "palltypes_u_short", CDB2_INTEGER, &palltypes_u_short, sizeof(palltypes_u_short)) )
136 fprintf(stderr, "Error binding palltypes_short.\n");
137 if(cdb2_bind_param(db, "palltypes_int", CDB2_INTEGER, &palltypes_int, sizeof(palltypes_int)) )
138 fprintf(stderr, "Error binding palltypes_short.\n");
139 if(cdb2_bind_param(db, "palltypes_float", CDB2_REAL, &palltypes_float, sizeof(palltypes_float)) )
140 fprintf(stderr, "Error binding palltypes_float.\n");
141 if(cdb2_bind_param(db, "palltypes_double", CDB2_REAL, &palltypes_double, sizeof(palltypes_double)) )
142 fprintf(stderr, "Error binding palltypes_double.\n");
143 if(cdb2_bind_param(db, "palltypes_byte", CDB2_BLOB, palltypes_byte, sizeof(palltypes_byte)-1))
144 fprintf(stderr, "Error binding palltypes_byte.\n");
145 if(j == 2000) {

Callers 1

mainFunction · 0.85

Calls 5

localtimeFunction · 0.85
cdb2_bind_paramFunction · 0.85
exitFunction · 0.85
cdb2_clearbindingsFunction · 0.85
runtagFunction · 0.70

Tested by

no test coverage detected