Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
joypan1 committed Mar 15, 2024
2 parents 836fe26 + c1bc640 commit 070624b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 35 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const db = new Dexie("Team Tracking App");
//trap was in there twice throwing errors so I removed the last one of them (2nd to last entry)

db.version(2).stores({
teams: "++id, teamname, globalid, teamnumber, teamschool, alliancescore, moreinfo, startingpos, Leaveszone, scores1amp, scores1speaker, picksup, scores2amp, scores2speaker, preferredScoringMethod, preferredIntakeMethod, prefintake, spotlight, trap, alone, hangsWithAnother, attemptsSpotlight, coop",
db.version(3).stores({
teams: "++indexid, teamname, globalid, teamnumber, teamschool, alliancescore, moreinfo, startingpos, Leaveszone, scores1amp, scores1speaker, picksup, scores2amp, scores2speaker, preferredScoringMethod, preferredIntakeMethod, prefintake, spotlight, trap, alone, hangsWithAnother, attemptsSpotlight, coop",
matches: "++id, rank, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, otherinfo"
});
// Version numbers must be changed whenever database objects (schema) are edited? See "Modify Schema" in https://dexie.org/docs/Tutorial/Understanding-the-basics
Expand Down
6 changes: 3 additions & 3 deletions pages/matchinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ plusBtn7.addEventListener('click', function() {
// DATABASE ---------------------------------------------------------------

const db = new Dexie("Team Tracking App");
db.version(2).stores({
teams: "++id, teamname, globalid, teamnumber, teamschool, alliancescore, moreinfo, startingpos, Leaveszone, scores1amp, scores1speaker, picksup, scores2amp, scores2speaker, preferredScoringMethod, preferredIntakeMethod, prefintake, spotlight, trap, alone, hangsWithAnother, attemptsSpotlight, coop",
matches: "++id, rank, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, otherinfo"
db.version(3).stores({
teams: "++indexid, teamname, globalid, teamnumber, teamschool, alliancescore, moreinfo, startingpos, Leaveszone, scores1amp, scores1speaker, picksup, scores2amp, scores2speaker, preferredScoringMethod, preferredIntakeMethod, prefintake, spotlight, trap, alone, hangsWithAnother, attemptsSpotlight, coop",
matches: "++indexid, rank, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, otherinfo"
});
// Version numbers must be changed whenever database objects (schema) are edited? See "Modify Schema" in https://dexie.org/docs/Tutorial/Understanding-the-basics
// db = database
Expand Down
18 changes: 15 additions & 3 deletions pages/teamdetails.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
// Global Dexie database initialization
const db = new Dexie("Team Tracking App");
db.version(2).stores({
teams: "++id, teamname, globalid, teamnumber, teamschool, alliancescore, moreinfo, startingpos, Leaveszone, scores1amp, scores1speaker, picksup, scores2amp, scores2speaker, preferredScoringMethod, preferredIntakeMethod, prefintake, spotlight, trap, alone, hangsWithAnother, attemptsSpotlight, coop",
matches: "++id, rank, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, otherinfo"
db.version(3).stores({
teams: "++indexid, teamname, globalid, teamnumber, teamschool, alliancescore, moreinfo, startingpos, Leaveszone, scores1amp, scores1speaker, picksup, scores2amp, scores2speaker, preferredScoringMethod, preferredIntakeMethod, prefintake, spotlight, trap, alone, hangsWithAnother, attemptsSpotlight, coop",
matches: "++indexid, rank, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, otherinfo"
});





//i CHANGED ID TO INDEXID AS ID WAS CONFLICTING WITH THE AUTO INCREMENTED ID IN THE TABLE ON THE SQL SERVER ***********************






// Version numbers must be changed whenever database objects (schema) are edited? See "Modify Schema" in https://dexie.org/docs/Tutorial/Understanding-the-basics


Expand Down
66 changes: 39 additions & 27 deletions php/db.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<?php

/*
TODO:
Add check to see if team globalid exists and update instead of insert
Add check that the team data being updated is more recent then the data in the database
FOR THE SYNC FUNCTION
Add check to make sure we are not syncing duplicate data (timestamps everywhere) back to the ipads or whatever
Add check to make sure we are not syncing old data back to the . . .
*/

header('Content-Type: application/json');

// Decode the received JSON data
Expand All @@ -13,34 +25,34 @@
'connection' => ''
];

try {
// Connection using PDO
$conn = new PDO("sqlsrv:server = tcp:scounting7127.database.windows.net,1433; Database = scouting7127", "CloudSAcaf36d4a", "3P&tLBL7Xc7L6R5p");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$response['connection'] = 'Connected to database successfully';

// Assuming $data is an array of teams
foreach ($data as $team) {
$columns = array_keys($team);
$placeholders = array_map(function($value) { return '?'; }, $team);
$sql = "INSERT INTO teams (" . implode(", ", $columns) . ") VALUES (" . implode(", ", $placeholders) . ")";
// try {
// // Connection using PDO
// $conn = new PDO("sqlsrv:server = tcp:scounting7127.database.windows.net,1433; Database = scouting_7127", "CloudSAcaf36d4a", "3HKEkfjD3Q@!S#r9"); //CloudSAcaf36d4a
// $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// $response['connection'] = 'Connected to database successfully';

// // Assuming $data is an array of teams
// foreach ($data as $team) {
// $columns = array_keys($team);
// $placeholders = array_map(function($value) { return '?'; }, $team);
// $sql = "INSERT INTO teams (" . implode(", ", $columns) . ") VALUES (" . implode(", ", $placeholders) . ")";

$stmt = $conn->prepare($sql);
if ($stmt->execute(array_values($team))) {
$response['success'] = true;
$response['data'][] = 'Inserted: ' . json_encode($sql);
} else {
$response['debug'] = true;
$response['data'][] = 'Inserted: ' . json_encode($sql);
}
}
} catch (PDOException $e) {
$response['debug'] = 'Error connecting to SQL Server.';
$response['data'] = $e->getMessage();
} catch (Exception $e) {
$response['debug'] = 'An error occurred.';
$response['data'] = $e->getMessage();
}
// $stmt = $conn->prepare($sql);
// if ($stmt->execute(array_values($team))) {
// $response['success'] = true;
// $response['data'][] = 'Inserted: ' . json_encode($sql);
// } else {
// $response['debug'] = true;
// $response['data'][] = 'Inserted: ' . json_encode($sql);
// }
// }
// } catch (PDOException $e) {
// $response['debug'] = 'Error connecting to SQL Server.';
// $response['data'] = $e->getMessage();
// } catch (Exception $e) {
// $response['debug'] = 'An error occurred.';
// $response['data'] = $e->getMessage();
// }

echo json_encode($response);
?>

0 comments on commit 070624b

Please sign in to comment.