Changeset 32
- Timestamp:
- 11/05/07 11:03:50 (10 months ago)
- Files:
-
- dbtest (added)
- dbtest/Makefile (added)
- dbtest/mydbtest.c (added)
- dbtest/testlibpq.c (added)
- vowfs/db.cxx (modified) (1 diff)
- vowfs/db.hxx (modified) (2 diffs)
- vowfs/dir.cxx (modified) (4 diffs)
- vowfs/dir.hxx (modified) (5 diffs)
- vowfs/error.hxx (added)
- vowfs/file.cxx (modified) (5 diffs)
- vowfs/file.hxx (modified) (2 diffs)
- vowfs/vowfs.hxx (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
vowfs/db.cxx
r29 r32 2 2 #include "db.hxx" 3 3 4 namespace VoWFS{ 5 Database::Database(string host, int port, string db_name, string user, string password){ 6 connection = PQsetdbLogin(host.c_str(), 7 /*to_string*/(port), 8 NULL,NULL, 9 db_name.c_str(), 10 user.c_str(), 11 password.c_str()); 12 } 4 using namespace VoWFS; 13 5 14 Database::~Database(){ 15 PQfinish(connection); 16 } 17 }; 6 7 Database::Database(string host, int port, string db_name, string user, string password){ 8 connection = PQsetdbLogin(host.c_str(), 9 /*to_string*/(port), 10 NULL,NULL, 11 db_name.c_str(), 12 user.c_str(), 13 password.c_str()); 14 } 15 16 Database::~Database(){ 17 PQfinish(connection); 18 } 19 20 int Database::getFileId(string file_path){ 21 int split = file_path.find_last_of('/'); 22 23 string directory_name = file_path.substr(0,split); 24 string file_name = file_path.substr(split,file_path.size()); 25 26 // TODO: SQL Command: Get file_id in column 1 27 PQresult *pq_data = PQexec(connection,""); 28 29 // All of the results should have the same file id, take the top one 30 31 int column_number = PQftablecol(pq_data,1); 32 33 return file_id=*(int*)PQgetvalue(pq_data,0,column_number); 34 } 35 36 File Database::getFile(int file_id){ 37 // TODO: SQL Command: Get file stats of the most recent version from file_id 38 PQresult *pq_data = PQexec(connection,""); 39 return File(pq_data); 40 } 41 42 File Database::getFile(int file_id, int revision){ 43 // TODO: SQL Command: Get file stats from file_id and revision 44 PQresult *pq_data = PQexec(connection,""); 45 return File(pq_data); 46 } 47 48 49 50 int Database::getDirId(string dir_name){ 51 52 // TODO: SQL Command: Get dir_id in column 1 53 PQresult *pq_data = PQexec(connection,""); 54 55 // All of the results should have the same file id, take the top one 56 57 int column_number = PQftablecol(pq_data,1); 58 59 return file_id=*(int*)PQgetvalue(pq_data,0,column_number); 60 } 61 62 63 Dir Database::getDir(int dir_id){ 64 // TODO: SQL Command: Get dir stats of the most recent version from dir_id 65 PQresult *pq_data = PQexec(connection,""); 66 return Dir(pq_data); 67 } 68 69 Dir Database::getDir(int dir_id, int revision){ 70 // TODO: SQL Command: Get dir stats from dir_id and revision 71 PQresult *pq_data = PQexec(connection,""); 72 return Dir(pq_data); 73 } 74 75 vowfs/db.hxx
r29 r32 5 5 #include "vowfs.hxx" 6 6 7 /* TODO: Implement all get-er functions 8 * It isn't too difficult, but we 9 * need all of the SQL queries for 10 * them. 11 */ 7 // TODO: Get SQL functions to Implement all get-er functions 12 8 13 9 namespace VoWFS{ … … 26 22 27 23 File getFile(int file_id, int revision); 24 25 string getFileData(int file_id); 26 27 string getFileData(int file_id, int revision); 28 28 29 29 vowfs/dir.cxx
r29 r32 5 5 parent_dir_id = 0; 6 6 directory_path = ""; 7 start_time = 0;8 end_time = 0;7 write_time = 0; 8 modify_time = 0; 9 9 delete_flag = false; 10 10 } … … 17 17 if( PQnfields(pq_data) < NUM_FIELDS ){ 18 18 NUM_FIELDS = 0; 19 // TODO: Throw error19 throw BAD_FIELDS; 20 20 } 21 21 … … 24 24 pq_format.parent_dir_id = PQfnumber(pq_data,"parent_dir_id"); 25 25 pq_format.directory_path = PQfnumber(pq_data,"directory_path"); 26 pq_format. end_time = PQfnumber(pq_data,"end_time");26 pq_format.modify_time = PQfnumber(pq_data,"modify_time"); 27 27 pq_format.delete_flag = PQfnumber(pq_data,"delete_flag"); 28 28 } 29 29 30 if( PQntuples(pq_data) <= row || PQnfields(pq_data) < NUM_FIELDS ){ 31 // TODO: Throw error 32 } 30 if( PQntuples(pq_data) <= row ) throw BAD_ENTRY; 31 if( PQnfields(pq_data) < NUM_FIELDS ) throw BAD_FIELDS; 33 32 34 33 revision_id = *(int*)PQgetvalue(pq_data, row, pq_format.revision_id ); … … 37 36 directory_path = string(PQgetvalue(pq_data, row, pq_format.directory_path )); 38 37 39 // TODO: How does PostgreSQL store times and booleans? Is this correct?40 start_time = *(long*)PQgetvalue(pq_data, row, pq_format.start_time );41 end_time = *(long*)PQgetvalue(pq_data, row, pq_format.end_time );38 // TODO: How does PostgreSQL store times and booleans? Is this correct? 39 write_time = *(long*)PQgetvalue(pq_data, row, pq_format.write_time ); 40 modify_time = *(long*)PQgetvalue(pq_data, row, pq_format.modify_time ); 42 41 delete_flag = *(bool*)PQgetvalue(pq_data, row, pq_format.delete_flag ); 42 43 PQclear(pq_data); 43 44 } 44 45 }; vowfs/dir.hxx
r29 r32 18 18 string directory_path; 19 19 20 long start_time;21 long end_time;20 long write_time; 21 long modify_time; 22 22 23 23 /* As with File's data, when the class is first constructed, … … 34 34 int parent_dir_id; 35 35 int directory_path; 36 int start_time;37 int end_time;36 int write_time; 37 int modify_time; 38 38 }; 39 39 … … 64 64 65 65 int startTime(){ 66 return start_time;66 return write_time; 67 67 } 68 68 69 69 int endTime(){ 70 return end_time;70 return modify_time; 71 71 } 72 72 … … 76 76 77 77 list<File> listFileContents(){ 78 // TODO: What is the Query for Files78 // TODO: What is the Query for Files 79 79 return file_list=db.getFiles(""); 80 80 } … … 82 82 83 83 list<File> listDirContents(){ 84 // TODO: What is the Query for Directories84 // TODO: What is the Query for Directories 85 85 return dir_list=db.getDirs(""); 86 86 } vowfs/file.cxx
r29 r32 2 2 #include "file.hxx" 3 3 4 namespace VoWFS{ 5 File::File(){ 6 revision_id = 0; 4 namespace VoWFS{ File::File(){ revision_id = 0; 7 5 file_id = 0; 8 6 parent_file_id = 0; … … 11 9 file_name = ""; 12 10 directory_path = ""; 13 start_time = 0; 14 end_time = 0; 11 write_time = 0; 15 12 delete_flag = 0; 16 13 } 17 14 18 string File::readData(){19 char *tmp_data// TODO: Get the file data based on the file_id20 }21 22 15 File::File(PQresult *pq_data, int row){ 23 16 if( NUM_FIELDS ){ … … 27 20 if( PQnfields(pq_data) < NUM_FIELDS ){ 28 21 NUM_FIELDS = 0; 29 // TODO: Throw error22 throw BAD_FIELDS; 30 23 } 31 24 … … 37 30 pq_format.file_name = PQfnumber(pq_data,"file_name"); 38 31 pq_format.directory_path = PQfnumber(pq_data,"directory_path"); 39 pq_format.start_time = PQfnumber(pq_data,"start_time"); 40 pq_format.end_time = PQfnumber(pq_data,"end_time"); 32 pq_format.write_time = PQfnumber(pq_data,"write_time"); 41 33 pq_format.create_flag = PQfnumber(pq_data,"create_flag"); 42 34 pq_format.delete_flag = PQfnumber(pq_data,"delete_flag"); 43 35 } 44 36 45 if( PQntuples(pq_data) <= row || PQnfields(pq_data) < NUM_FIELDS ){ 46 // TODO: Throw error 47 } 37 if( PQntuples(pq_data) <= row ) throw BAD_ENTRY; 48 38 39 if( PQnfields(pq_data) < NUM_FIELDS ) throw BAD_FIELDS; 40 41 // Now we initialize the member variables 49 42 revision_id = *(int*)PQgetvalue(pq_data, row, pq_format.revision_id ); 50 43 file_id = *(int*)PQgetvalue(pq_data, row, pq_format.file_id ); … … 55 48 directory_path = string(PQgetvalue(pq_data, row, pq_format.directory_path )); 56 49 57 // TODO: How does PostgreSQL store times and booleans? Is this correct? 58 start_time = *(long*)PQgetvalue(pq_data, row, pq_format.start_time ); 59 end_time = *(long*)PQgetvalue(pq_data, row, pq_format.end_time ); 50 // TODO: How does PostgreSQL store times and booleans? Is this correct? 51 write_time = *(long*)PQgetvalue(pq_data, row, pq_format.write_time ); 60 52 delete_flag = *(bool*)PQgetvalue(pq_data, row, pq_format.delete_flag ); 53 54 PQclear(pq_data); 61 55 } 62 56 63 57 string File::readData(){ 64 char *tmp_data// TODO: Get the file data based on the file_id58 string this_data=db.getFileData(file_id, revision_id); 65 59 66 File new_file=db.getFile(file_id, revision_id +1);60 File new_file=db.getFile(file_id, revision_id+1); 67 61 68 if( new_file ){ 69 // TODO: patch based on new_file.fileData() and tmp_data 70 } 71 else{ 72 data=tmp_data; 73 } 74 return data; 62 if( new_data != "" ) 63 return data=diff.patch(new_file.readData(), this_data); 64 else 65 return data=this_data; 75 66 } 76 67 }; vowfs/file.hxx
r29 r32 25 25 string directory_path; 26 26 27 long start_time; 28 long end_time; 27 long write_time; 29 28 bool delete_flag; 30 29 … … 53 52 int file_name; 54 53 int directory_path; 55 int start_time; 56 int end_time; 54 int write_time; 57 55 int delete_flag; 58 56 }; vowfs/vowfs.hxx
r29 r32 16 16 }; 17 17 18 #include "error.hxx" 18 19 #include "xdelta.hxx" 19 20 #include "db.hxx"
