Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
C-Database/CPlusCode
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
237 lines (108 sloc)
3.92 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <sstream> | |
#include <SQLAPI.h> | |
//SQLAPI.h library api is a C++ library for accessing multiple SQL databases. This library is from https://www.geeksforgeeks.org/database-connectivity-using-cc/ | |
//It has been used to connection to a SQL Server and run SELECT statements to return data. | |
using namespace std; | |
void CreateMenu(void) | |
//Display user menus | |
{ | |
cout << "Options available:" << endl; | |
cout << "1. Find Course" << endl; | |
cout << "2. Find Room" << endl; | |
cout << "3. Find Lecturer" << endl; | |
cout << "9. Exit" << endl; | |
cout << "Enter option 1 or 2 or 3:"; | |
} | |
bool FindCourse(void) | |
{ | |
string CourseName; | |
SACommand cmdLocal; | |
cout << "Enter Course Name" << endl; | |
cin >> CourseName; | |
cmdLocal.setCommandText("SELECT * FROM Course WHERE CourseName = :1"); | |
cmdLocal.Param(1).setAsString() = CourseName; | |
cmdLcoal.Execute(); | |
while (cmdLcoal.FetchNext()) | |
{ | |
printf("CourseName: %s", cmdLcoal.Field("CourseCode").asString()); | |
printf("CourseName: %s", cmdLcoal.Field("CourseName").asString()); | |
printf("CourseName: %s", cmdLcoal.Field("CourseDesciption").asString()); | |
} | |
connect.Commit(); | |
CreateMenu(); | |
return true; | |
} | |
bool FindRoom(void) | |
{ | |
string RoomNumber; | |
SACommand cmdLocal; | |
cout << "Enter Room Number:" << endl; | |
cin >> RoomNumber; | |
cmdLocal.setCommandText("SELECT r.*, rt.* FROM Rooms r INNER JOIN RoomType rt ON r.RoomType = rt.RoomTypeID WHERE r.RoomNumber = :1"); | |
cmdLocal.Param(1).setAsString() = RoomNumber; | |
cmdLocal.Execute(); | |
while (cmdLcoal.FetchNext()) | |
{ | |
printf("CourseName: %s", cmdLcoal.Field("RoomNumber").asString()); | |
printf("CourseName: %s", cmdLcoal.Field("RoomName").asString()); | |
printf("CourseName: %s", cmdLcoal.Field("RoomTypeName").asString()); | |
printf("CourseName: %s", cmdLcoal.Field("BuildingName").asString()); | |
} | |
connect.Commit(); | |
CreateMenu(); | |
return true; | |
} | |
bool FindLecturer(void) | |
{ | |
string Lecturer; | |
cout << "Enter Lecturer Surname:" << endl; | |
cin >> Lecturer; | |
cmdLocal.setCommandText("SELECT FirstName, LastName, EmailAddress, ContactPhone FROM Lecturers WHERE LastName = :1"); | |
cmdLocal.Param(1).setAsString() = Lecturer; | |
cmdLocal.Execute(); | |
while (cmdLcoal.FetchNext()) | |
{ | |
printf("CourseName: %s", cmdLcoal.Field("FirstName").asString()); | |
printf("CourseName: %s", cmdLcoal.Field("LastName").asString()); | |
printf("CourseName: %s", cmdLcoal.Field("EmailAddress").asString()); | |
printf("CourseName: %s", cmdLcoal.Field("ContactPhone").asString()); | |
} | |
connect.Commit(); | |
CreateMenu(); | |
return true; | |
} | |
int main(int argc, char* argv[]) | |
{ | |
string option; | |
bool loopprompt = true; | |
SAConnection connect; | |
connect.Connect("TimeTable", "sa", "sa", SA_SQLServer_Client); | |
//Display options to the user to select | |
CreateMenu(); | |
while (loopprompt) | |
{ | |
cin >> option; | |
switch (stoi(option)) | |
{ | |
case 1: | |
FindCourse(); | |
break; | |
case 2: | |
FindRoom(); | |
break; | |
case 3: | |
FindLecturer(); | |
break; | |
case 9: | |
cout << "Exit" << endl; | |
connect.Disconnect(); | |
loopprompt = false; | |
default: | |
if (loopprompt) | |
cout << "Choose option 1-3 or 9" << endl; | |
break; | |
} | |
} | |
} |