Voting Results

//get the voter uid var user = client.user; var voteConn = null; // voting db connection // get the connection // name connection for debugging purposes // set server timeout to 10 seconds voteConn = project.appPool.connection("checkVoters",10); if (voteConn == null) { write('Error: Unable to connect to database'); } //update vote var ballot = request.q1; //get current results sql = "SELECT votes.yesvote, votes.novote FROM votes WHERE ((votes.voteskey) = 1)"; //make it an updateable cursor //voteConn.beginTransaction(); //for db's that support updateable cursors like Oracle //var counterCursor = voteConn.cursor(sql,true); // ditto var counterCursor = voteConn.cursor(sql); if (!counterCursor.next()) { write('

No voteing results found matching key 1

'); var err = voteConn.majorErrorCode() + ": " + voteConn.majorErrorMessage(); write('

' + err + '

'); } else { if (ballot == "yes") { counterCursor.yesvote = counterCursor.yesvote + 1 ; sql = "UPDATE votes SET votes.yesvote = "+ counterCursor.yesvote + " WHERE ((votes.voteskey) = 1)"; } if (ballot == "no") { counterCursor.novote = counterCursor.novote + 1; sql = "UPDATE votes SET votes.novote = "+ counterCursor.novote + " WHERE ((votes.voteskey) = 1)"; } // var results = counterCursor.updateRow("votes"); //updateable if db supports updatable cursors // must use pass-through SQL for Access var results = voteConn.execute(sql); if (results > 0) { write('

Error occurred: '); var err = voteConn.majorErrorCode() + ": " + voteConn.majorErrorMessage(); write(err + '

'); } else { write('updated successfully!
'); // voteConn.commitTransaction(); //if db supports transactions } //now update voter so that it shows they have voted sql = "UPDATE voter SET voter.hasvoted = 1 WHERE ((voter.uid='" + user +"'))"; var results = voteConn.execute(sql); if (results > 0) { write('

Error occurred during voter update: '); var err = voteConn.majorErrorCode() + ": " + voteConn.majorErrorMessage(); write(err + '

'); } }

Exit the System; >