Exploring SQL Components with JavaScript

Here is the code I am currently using:

//This function handles all games and their attributes
function handleGames(){
    sql.query('SELECT id FROM games', function (err, rows){
        if(err){
            console.log(String(err).error.bgWhite);
        } else {
            for(var i = 0; i < rows.length; i++) {

                var timeNow = new Date().getTime();

                //Game Expiration
                //0 = Open | 4 = Expired | 5 = Generic Error

                //Generic error --> Expired
                if(rows[i]["status"] == 5){
                    sql.query('UPDATE games SET status = 4 WHERE id = "' + rows[i]["id"] + '"', function (err, rows){
                        if(err) console.log(String(err).error.bgWhite);
                        console.log(("Updating status for game " + rows[i]["id"] + " to 4").info.bgWhite);
                    });
                }

                //Set game status to expired if it has lasted more than 5 minutes (300s)
                if(((rows[i]["starttime"] + 300) >= timeNow) && (rows[i]["status"] == 0)){
                    sql.query('UPDATE games SET status = 4 WHERE id = "' + rows[i]["id"] + '"', function (err, rows){
                        if(err) console.log(String(err).error.bgWhite);
                    });
                }
            };
        }
    });
}

Using this data:

https://i.stack.imgur.com/1NWxm.png

This program is designed for Node and aims to update the status of any game that has been active for 5 minutes (300s), but there seems to be an issue with how the keys are accessed. The game status remains unchanged.

JSON Version


SQL Export:

-- phpMyAdmin SQL Dump
...
... (rest of the SQL export content)
...

Answer №1

Calculate the time duration in seconds by using

((new Date()).getTime()-starttime)/1000
. Feel free to share your code on an online JavaScript editor like Plunker! Are you here?

INSERT INTO `games` (`id`, `starttime`, `status`, `ct_name`, `ct_avatar`, `ct_steamid`, `ct_bet`, `t_name`, `t_avatar`, `t_steamid`, `t_bet`) VALUES 
(3, 1461862619, 0, 'Robinlemon > CSGOVoid.net', 'steamcdn-a.akamaihd.net/…', 76561198065346589, 3, 'Yuuta', 'cdn.akamai.steamstatic.com/…', 76561198052096214, 3);

This data is included in your SQL dump! It inserts an entity with ID (using AUTO_INCREMENT) as 3!! For subsequent inserts, AUTO_INCREMENT will be set as 4!!!

If you wish to change that, you can delete the row from the table and reset the AUTO_INCREMENT counter.

ALTER TABLE tablename AUTO_INCREMENT = 1

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"In Typescript, receiving the error message "Attempting to call an expression that is not callable" can be resolved

I am in the process of creating a function that matches React's useState signature: declare function useState<S>( initialState: S | (() => S), ): [S, React.Dispatch<React.SetStateAction<S>>]; Below is an excerpt from the functi ...

Instructions for selecting a checkbox using boolean values

According to the HTML specification, you should use the checked attribute in the <input type="checkbox"> tag to indicate that it is checked. However, I only have a boolean value of either true or false. Unfortunately, I am unable to manipulate the b ...

Encountering build:web failure within npm script due to TypeScript

Our project is utilizing the expo-cli as a local dependency in order to execute build:web from an npm script without requiring the global installation of expo-cli. However, when we run npm run build:web, we encounter the following exception. To isolate th ...

Incorporate image into Vue.js form along with other information

I have been successfully sending the content of multiple fields in a form to the Database. Now I am looking to add an additional field for uploading images/files and including it with the other form fields, but I am unsure about how to accomplish this task ...

Exploring methods to detect when a PHP page has been printed using the 'ctrl+p' shortcut and then subsequently updating

Hey there! I'm currently managing a php website that functions as an accounting system. Within this system, there are receipts, invoices, and other forms of documentation in use. However, I've encountered a problem with the main table in my myS ...

Passing multiple parameters in URL for APIs using Next.js

Is there a way to pass multiple parameters and retrieve results from the next.js API? I found the documentation very helpful, you can check it out here /api/posts/[postId].js The above setup works fine, but I want to know if it's possible to pass an ...

What is the process for designating and incorporating a particular version of an npm package from GitLab Package Registry into my project?

My project is currently hosted on GitLab, and I have successfully published an npm package to the self-hosted Community Edition of the GitLab Package Registry. However, I am now faced with the challenge of integrating a specific version of that package in ...

What is the process for adding pictures and information to a MySQL database through PHP?

I'm encountering an issue when trying to save data to the database. My connection details and SQL insert query are correct, and the image is successfully uploading to the folder. However, I can't figure out why the data, along with the image, isn ...

Is Docker refusing to generate an image name during the build process? Have you tried running the 'docker scan' command?

FROM node WORKDIR /app COPY . /app RUN npm install EXPOSE 80 CMD ["node", "server.js"] This dockerfile is based on a tutorial I recently watched. However, when I try to build it with the command: docker build . I get the following output: [+] Buildi ...

Retrieve telephone number prefix from Cookies using React

Being able to retrieve the ISO code of a country is possible using this method: import Cookies from 'js-cookie'; const iso = Cookies.get('CK_ISO_CODE'); console.log(iso); // -> 'us' I am curious if there is a method to obt ...

When it comes to the CSS `:visited` pseudo-class, I have

I'm having trouble changing the color of the anchor tag and blurring the image after visiting the link. Despite my CSS code, only the color is changing and the image remains unchanged. Here's my CSS code: <style> .image123{ paddin ...

What is the best way to deliver HTML and JavaScript content using Node.js from virtual memory?

Situation I'm currently developing an in-browser HTML/JS editor, utilizing memory-fs (virtual memory) with Webpack and webpack-html-plugin to package the files created by users in the editor. Storing the files in virtual memory helps avoid I/O operat ...

What is the reason behind having to restart the npm server each time?

When first learning Reactjs with VSCode, there was no need to restart the server after making modifications. However, now I find that I must restart the server every time I make a change in order for those changes to be applied. ...

Intermittent TCP socket writing in NodeJS (coffeescript)

I'm facing difficulties in setting up a basic server using the net module in nodejs. The server should keep each TCP socket open once connected, read data from the socket, and then reply/write back to the socket after receiving each line of text. Alt ...

Encountering difficulties installing socket.io using npm on Centos 6.4

Currently in the process of setting up socket.io via npm on a fresh Centos 6.4 (running on a virtual machine). (using root access temporarily for testing purposes) [root@localhost lib]# npm cache clean [root@localhost lib]# npm install socket.io npm http ...

The browser has blocked access to XMLHttpRequest from a specific origin due to the absence of the 'Access-Control-Allow-Origin' header in the requested resource

After developing an Asp.Net Core 3.1 API and deploying it on the server through IIS, everything worked fine when sending GET/POST requests from Postman or a browser. However, I encountered an error with the following code: $.ajax({ type: 'GET' ...

Utilizing JSON data for efficient React component rendering

As a newcomer to React, I am currently in the process of constructing a dashboard that showcases data from three different sensors. The information regarding these sensors is stored in a single JSON file where each sensor has its own ID and name. This JSON ...

Running a Mongoimport command within a JavaScript/Node.js script

Is there a node.js/javascript library available that allows for the use of mongoimport within code? From what I understand, mongoimport is similar to an .exe file that needs to be executed before being able to utilize its text input environment. Is it fe ...

Learn the process of uploading an image to Firebase storage from the server side

I'm working on implementing an upload feature that utilizes Firebase storage on the server side. Here is the upload function on the server side: const functions = require("firebase-functions"); const admin = require("firebase-admin&quo ...

NPM - Modify a module by forking it, make necessary code changes, and submit a pull

When trying to make changes to a specific npm package and create a PR, the author instructed me to do so from a particular branch. I was able to update the url and branch in the package.json file, allowing me to load the specific branch as an npm module an ...