Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

data.cfc 3.0 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  1. // data.cfc
  2. component {
  3. function index(event, rc, prc) {
  4. // Render the index form view
  5. event.setView("data");
  6. }
  7. // Function to create a new student
  8. function createStudent(sname, major, level, byear) {
  9. // Prepare the SQL statement with placeholders
  10. var insertQuery = new query(datasource="task");
  11. var sql = "INSERT INTO student (sname, major, level, byear) VALUES (?, ?, ?, ?)";
  12. insertQuery.setSQL(sql);
  13. var result = insertQuery.execute([sname, major, level, byear]);
  14. // Check for errors
  15. if (result.status != "SUCCESS") {
  16. throw new Error("Error inserting student: " & result.getError());
  17. }
  18. // Close the query
  19. insertQuery.close();
  20. }
  21. // Function to read all students
  22. function getAllStudents() {
  23. var students = [];
  24. var allQuery = new query(datasource="task");
  25. allQuery.setSQL("SELECT * FROM Student");
  26. var result = allQuery.execute();
  27. while (result.next()) {
  28. var student = {
  29. "sid": result.sid,
  30. "sname": result.sname,
  31. "major": result.major,
  32. "level": result.level,
  33. "byear": result.byear
  34. };
  35. arrayAppend(students, student);
  36. }
  37. result.close();
  38. return students;
  39. }
  40. // Query 1: Print all the projects in which a specified student is involved
  41. function getProjectsForStudent(studentID) {
  42. var projects = [];
  43. var projectQuery = new query(datasource="task");
  44. var sql = "SELECT pname FROM Project WHERE pid IN (SELECT pid FROM Assigned WHERE sid = ?)";
  45. projectQuery.setSQL(sql);
  46. var result = projectQuery.execute([studentID]);
  47. while (result.next()) {
  48. arrayAppend(projects, result.pname);
  49. }
  50. result.close();
  51. return projects;
  52. }
  53. // Query 2: Print all the people working on a specified project
  54. function getPeopleForProject(projectID) {
  55. var people = [];
  56. var projectAllQuery = new query(datasource="task");
  57. var sql = "SELECT sname FROM Student WHERE sid IN (SELECT sid FROM Assigned WHERE pid = ?)";
  58. projectAllQuery.setSQL(sql);
  59. var result = projectAllQuery.execute([projectID]);
  60. while (result.next()) {
  61. arrayAppend(people, result.sname);
  62. }
  63. result.close();
  64. return people;
  65. }
  66. // Query 3: Print all the projects supervised by a specified faculty within a specified time range
  67. function getProjectsForFacultyWithinTimeRange(facultyID, startDate, endDate) {
  68. var projects = [];
  69. var facultyQuery = new query(datasource="task");
  70. var sql = "SELECT pname FROM Project WHERE pi = ? AND sdate >= ? AND edate <= ?";
  71. facultyQuery.setSQL(sql);
  72. var result = facultyQuery.execute([facultyID, startDate, endDate]);
  73. while (result.next()) {
  74. arrayAppend(projects, result.pname);
  75. }
  76. result.close();
  77. return projects;
  78. }
  79. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...