Please answer the following programing question Consider the

Please answer the following programing question. Consider the following schema:Veterinarians (vid: integer, eLevel); Examine (vid: integer,did: integer, fee: integer); Dogs (did: integer, age: integer); The eLevel is meant to be an experience rating level; it is in the range: [1, 10]. Fee is in the range: [25, 125], age is in the range: [8, 11] Heap files corresponding to instances of the above relations are VFile (for Veterinarians), EFile (for Examine) and DFile (for Dogs); on each line of the heap file, the attributes are listed in the abovecorresponding schema order.

You are to write a C/C++ program to find the answer to the following query:

SELECT D.age, COUNT(*), AVG(X.fee), AVG(V.eLevel)

FROM Dogs D, Exmaine X,Veterinarians V

WHERE D.did=X.did AND X.vid=V.vid

GROUP BY D.age

You are expected to implement an efficient join algorithm as part of your solution to this problem.However, you must assume that main memory is limited, and it is not possible to read all of the relations into main memory at once; furthermore, your solution must be capable of processing files of unbounded (unknown) size. Your program is to use VFile, DFile and EFile as input to the program.

Solution

#include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>

static int printCallback(void *data, int argc, char **argv, char **azColName){
int i;
fprintf(stderr, \"%s: \", (const char*)data);
for(i=0; i<argc; i++){
printf(\"%d %d &f %f\ \", argv[i],argv[2],argv[3],argv[4]);
}
printf(\"\ \");
return 0;
}

int main(int argc, char* argv[])
{
sqlite3 *db;
char *zErrMsg = 0;
int res;
char *sql;
const char* data = \"Callback method calling\";

/* Opening database */
res = sqlite3_open(\"test.db\", &db);
if( res ){
fprintf(stderr, \"unable to open database: %s\ \", sqlite3_errmsg(db));
return(0);
}else{
fprintf(stderr, \"Opened database successfully\ \");
}

// preparing SQL statement
sql = \"SELECT D.age, COUNT(*), AVG(X.fee), AVG(V.eLevel) FROM Dogs D, Exmaine X,Veterinarians V WHERE D.did=X.did AND X.vid=V.vid GROUP BY D.age\";

// executing sql statement
res = sqlite3_exec(db, sql, printCallback, (void*)data, &zErrMsg);
if( res != SQLITE_OK ){
fprintf(stderr, \"SQL error: %s\ \", zErrMsg);
sqlite3_free(zErrMsg);
}else{
fprintf(stdout, \"QUERY run successfully\ \");
}
sqlite3_close(db);
return 0;
}

Please answer the following programing question. Consider the following schema:Veterinarians (vid: integer, eLevel); Examine (vid: integer,did: integer, fee: in
Please answer the following programing question. Consider the following schema:Veterinarians (vid: integer, eLevel); Examine (vid: integer,did: integer, fee: in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site