We need a simple utility written in "C" that performs the following steps:
(I need this task performed immediately )
1. reads records from a binary file one at a time. Each record will consist of two components. The first component is a 10 digit binary number and the second component of the record is a 10 digit ascii number.
2. Use the second component (10 digit ascii) to search a sqlite database with the following schema:
create table tb1 (key1 text(30), key2 integer, primary key(key1, key2));
create index my_index on tb1(key1, key2);
Note: I'm not sure if this is the best schema to use - I just need to be able to search both columns of the table. This utility will search key2 only.
3. for example, the record (from step 1) is a struct consisting of id1 and id2 so, you will use id2 to search column key2 in the sqlite database for a match.
4. if a match is found write the entire record to a binary file else ignore the record and go to the next record.
5. repeat steps 1-4 until the entire binary file is read.
Note: I would also like for the utility to read the sqlite "select" statement and the output file name from a configuration file (i.e. input.cfg) which should be passed into the utility from the comand line prompt (i.e. > program input.cfg).
I have written part of the utility below:
#pragma pack( 1 )
typedef struct _keySafeEntry
#pragma pack( )
int getCnxKey(char * cnxKey);
void logRec(keySafeEntry * keyRec);
keySafeEntry * myRecord;
FILE * fp = fopen("c:/binary_data.dat", "rb");
if (fp == 0)
printf("Could not open file\n");
// while not eof
fread(myRecord, sizeof(*myRecord), 1, fp);
// search sqlite database using
rval = sqlite3_step("select ....");
if (rval == SQLITE_ROW)
const unsigned char *resp = sqlite3_column_text("select ...", 0);
// write record to output file
if (rval != SQLITE_DONE)
// display error message and exit the program
void logRec(keySafeEntry * keyRec)
FILE * fpout;
// if the output file exit delete it
fpout = fopen("c:/out.dat", "wb");
fwrite(keyRec, sizeof(*keyRec), 1, fpout);