Urgent: C Utility Needed to Query a Sqlite Database

Closed - This job posting has been filled and work has been completed.
Web, Mobile & Software Dev Scripts & Utilities Posted 2 years ago

Fixed Price

Delivery by March 4, 2013

$75.00

Budget

Details

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
{
   uint8_t id1[10];
   char    id2[10];
}keySafeEntry;
#pragma pack( )

int getCnxKey(char * cnxKey);
void logRec(keySafeEntry * keyRec);

void main()
{
   printf("start program\n");
   keySafeEntry * myRecord;

   FILE * fp = fopen("c:/binary_data.dat", "rb");

   if (fp == 0)
   {
      printf("Could not open file\n");
   }
   else
   {

      // while not eof

      fread(myRecord, sizeof(*myRecord), 1, fp);

      // search sqlite database using
      sqlite3_reset(database->stmt);  


       rval = sqlite3_step("select ....");

       if (rval == SQLITE_ROW)
       {
          const unsigned char *resp = sqlite3_column_text("select ...", 0);

          // write record to output file
          logRec(myRecord);

       }

      if (rval != SQLITE_DONE)
      {
           // display error message and exit the program
      }

      fclose(fp);
   }

}

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);
   fclose(fpout);
}


About the Client

(5.00) 20 reviews

United States
Alpharetta 04:12 PM

34 Jobs Posted
71% Hire Rate, 1 Open Job

Over $40,000 Total Spent
26 Hires, 1 Active

$20.75/hr Avg Hourly Rate Paid
1,050 Hours

Member Since Aug 25, 2010