My code is this
Profile.update_all(["is_active = ?, name = ?, geo_lat = ?, geo_long = ?, radius = ?, search_option = ?", 1, params[:profile_name],'null','null','null','st'])
but it assign
geo_lat=0
and
geo_long=0
In my database structure default value is null for both
and i want to assign null
please help me
The issue here are string 'null'.
Try the following:
Profile.update_all(["is_active = ?, name = ?, geo_lat = ?, geo_long = ?, radius = ?, search_option = ?", 1, params[:profile_name], nil, nil, nil, 'st'])
Also check your migration to see if default is not set to string 'null'.
Related
Probably a simple answer to this one but I can't find the answer online :(
I am currently migrating to MySQL database but I am having problems transfering my stored procedures from my dataset in Visual Studio. The SQL query in my dataset did not force me to name all the parameters however, MySQL gives a syntax error when I use ? instead of naming and declaring every single parameter.
SQL query in dataset of Visual Studio:
UPDATE tblConfigurations
SET DEUnit_ID_UnitName = ?, DEUnit_ID_UnitType = ?, DEUnit_ID_UnitLevel = ?, DEUnit_Aut_NumberOfMastercards = ?, DEUnit_Aut_MasterCardId1 = ?, DEUnit_Aut_MasterCardId2 = ?,
DEUnit_Aut_MasterCardId3 = ?, DEUnit_Aut_MasterCardId4 = ?, DEUnit_Aut_MasterCardId5 = ?, DEUnit_Aut_MasterCardId6 = ?, DEUnit_Aut_MasterCardId7 = ?, DEUnit_Aut_MasterCardId8 = ?,
DEUnit_Lck_SeperatedAntennas = ?, DEUnit_AF_SilentAlarmActivation = ?, DEUnit_AF_AlarmInputConnection = ?, DEUnit_NW_Address = ?, DEUnit_KD_KeyboardOrientation = ?,
DEUnit_KD_SpecialAcousticConfirmation = ?, DEUnit_KD_KeyClickSound = ?, DEUnit_KD_LedColors = ?, DEUnit_ReservedValue1 = ?, DEUnit_ReservedValue2 = ?, DEUnit_ReservedValue4 = ?,
DEUnit_ReservedValue7 = ?, DEUnit_ReservedValue8 = ?, DEUnit_ReservedValue9 = ?, DEUnit_ReservedValue10 = ?, DEUnit_ReservedValue11 = ?, DEUnit_ReservedValue12 = ?, DEUnit_ReservedValue13 = ?,
DEUnit_ReservedValue14 = ?, DEUnit_ReservedValue15 = ?, DEUnit_ReservedValue22 = ?, DEUnit_ReservedValue27 = ?
WHERE (config_ID = ?)
You can use the ? placeholders only if you use the PREPARE and EXECUTE syntax. Read https://dev.mysql.com/doc/refman/8.0/en/sql-prepared-statements.html for details.
But even if you do use PREPARE & EXECUTE, you would still have to name the variables as you pass them to EXECUTE.
In a stored procedure, you can use variables instead of using placeholders.
CREATE PROCEDURE citycount (IN country CHAR(3), OUT cities INT)
BEGIN
SELECT COUNT(*) INTO cities FROM world.city
WHERE CountryCode = country;
END
In that example, country is a procedure input parameter. You can use it directly in an SQL statement (in this case SELECT, but it works for UPDATE too).
Make sure your parameter names are not the same as any column in the table you query, because that creates an ambiguity.
I set up an Apps Script program and it needs to save data to database. However, it is not working.
I have tried to use the code from Google Apps Script Documentation but I can't see how to skip the autoIncrementing field named ID and its the primary key as well.
I have used code below.
var connectionName = 'frms-db:us-central1:****';
var user = 'rj-**';
var userPwd = 'fEwnj*LAAj3****';
var db = 'CCW_CLR';
var dbUrl = 'jdbc:google:mysql://' + connectionName + '/' + db;
var conn = Jdbc.getCloudSqlConnection(dbUrl, user, userPwd);
var stmt2 = conn.prepareStatement('INSERT INTO tblPreInterview '
+ '(ID, Timestamp, Email, Section4, Section5, Section6, Section7, Pages12_13, MinorsAtHome, FirearmsStoreage, ReferenceType1, ReferenceName1, ReferencePhone1, ReferenceType2, ReferenceName2, ReferencePhone2, ReferenceEmail2, '
+ 'ReferenceType3, ReferenceName3, ReferencePhone3, ReferenceEmail3, DeptConditions, NoGuarantee, ServicePolicy, NoRefunds, PenaltyPerjury, Authorization) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '
+ '?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
stmt2.setString(2, new Date());
stmt2.setString(3, data.email);
stmt2.setString(4, data.section4);
stmt2.setString(5, data.section5);
stmt2.setString(6, data.section6);
stmt2.setString(7, data.section8);
stmt2.setString(8, data.pages1213);
stmt2.setString(9, data.minors);
stmt2.setString(10, data.storefirearm);
stmt2.setString(11, data.reftype1);
stmt2.setString(12, data.refcon1);
stmt2.setString(13, data.refphone1);
stmt2.setString(14, data.refemail1);
stmt2.setString(15, data.reftype2);
stmt2.setString(16, data.refcon2);
stmt2.setString(17, data.refphone2);
stmt2.setString(18, data.refemail2);
stmt2.setString(19, data.reftype3);
stmt2.setString(20, data.refcon3);
stmt2.setString(21, data.refemail3);
stmt2.setString(22, data.deptcondition);
stmt2.setString(23, data.review_agree1);
stmt2.setString(24, data.review_agree2);
stmt2.setString(25, data.review_agree3);
stmt2.setString(26, data.review_agree4);
stmt2.setString(27, data.review_agree5);
stmt2.setString(28, data.signature);
stmt2.execute();
I expect to add data to my SQL database.
If the column is auto_incremented, you do not need to provide a value for it. MySQL automatically assigns a new number when you perform an insert where no value is given for that column.
So you should just not specify this column in your insert, ie change:
var stmt2 = conn.prepareStatement(
'INSERT INTO tblPreInterview '
+ '(ID, Timestamp, Email, Section4, Section5, Section6, ...
To:
'INSERT INTO tblPreInterview '
+ '(Timestamp, Email, Section4, Section5, Section6, ...
Accordingly you should remove the first parameter.
I am using this code:
$image = mysqli_real_escape_string($dbc, $res[3][$i]);
Where $res[3][$i] is a url.
Then I store $image in a Mysql DB. But when I retrieve it, it's all messed up with the special characters... (my DB is in utf8).
How can I store a url in mysql and get it back exactly as it was?
Thanks
Actually I am using prepared statement:
$image = mysqli_real_escape_string($dbc, $res[3][$i]);
$md5_of_title = md5($title);
//$query = "INSERT IGNORE INTO scrap (date, journal, section, title, href, teaser, image, md5_of_title) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
$query = "INSERT INTO scrap (date, journal, section, title, href, teaser, image, md5_of_title) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = mysqli_prepare($dbc, $query);
/*i Integers;
d Doubles;
b Blobs;
s Everything Else;*/
mysqli_stmt_bind_param($stmt, "ssssssss", date('Y-m-d H:i:s'), $name, $section, $title, $href, $teaser, $image, $md5_of_title);
mysqli_stmt_execute($stmt);
I want to insert rows to mysql database with an jsp code, but I can´t.
Here is my jsp code without the html form:
<%
String login = request.getParameter("login");
String password = request.getParameter("password");
String full_name = request.getParameter("full_name");
String ulevel = request.getParameter("ulevel");
String team_id = request.getParameter("team_id");
Connection connection = null;
PreparedStatement pstatement = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
int updateQuery = 0;
if(login!=null && password!=null && full_name!=null && ulevel!=null && team_id!=null){
if(login!="" && password!="" && full_name!="" && ulevel!="" && team_id!="") {
try {
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/android","root","root");
String queryString = "INSERT INTO users(user_id,login,password,full_name,ulevel,team_id) VALUES (null, ?, ?, ?, ?, ?)";
pstatement = connection.prepareStatement(queryString);
pstatement.setString(2, login);
pstatement.setString(3, password);
pstatement.setString(4, full_name);
pstatement.setString(5, ulevel);
pstatement.setString(6, team_id);
updateQuery = pstatement.executeUpdate();
if (updateQuery != 0) { %>
When I press SUBMIT, the webpage shows me this:
type Status report message descriptionThe requested resource () is
not available.
p.s.: column user_id is set to autoincrement in mysql table, so I use null.
But I dont know, that´s the right way...
I run the code from netbeans 7.0.1
since ID is auto-incremented, get rid of it from the list, preparedstatement is looking for index 1 on its parameters.
String queryString = "INSERT INTO users(login,password,full_name,ulevel,team_id) VALUES (?, ?, ?, ?, ?)";
pstatement = connection.prepareStatement(queryString);
pstatement.setString(1, login);
pstatement.setString(2, password);
pstatement.setString(3, full_name);
pstatement.setString(4, ulevel);
pstatement.setString(5, team_id);
this one below is not tested
just start you parameter with 1 because there are only 5 parameters to be defined.
String queryString = "INSERT INTO users(user_id,login,password,full_name,ulevel,team_id) VALUES (null, ?, ?, ?, ?, ?)";
pstatement = connection.prepareStatement(queryString);
pstatement.setString(1, login);
pstatement.setString(2, password);
pstatement.setString(3, full_name);
pstatement.setString(4, ulevel);
pstatement.setString(5, team_id);
I found the problem. The error was in html form, at attribute action, where i had an source file, which i never had before. :/
String queryString = "INSERT INTO users(user_id,login,password,full_name,ulevel,team_id) VALUES (?, ?, ?, ?, ?)";
You should not use anything not even null for query!
I keep getting an incorrect string value error in my Rake Task when I go to insert into my DB for one specific record. I tried converting it to UTF8 after reading several posts here on it but still have not resolved the issue (no guarantee I did that right). Any thoughts on what else it could be? Anything I left out?
MySQL Server Community 5.5
Conversion Code:
ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
#summary = ic.iconv(bug.summary << ' ')[0..-2]
Create Code:
JiraBug.create(
:issue => bug.key,
:summary => #summary,
:reporter_name => reporter_name,
:assignee_name => assignee_name,
:weight => weight, :issue_created => issue_created,
:issue_updated => issue_updated,
:jira_it_division_id => #it_division_id,
:jira_project_id => #project_id,
:jira_priority_id => #priority_id,
:jira_status_id => #status_id,
:jira_originating_phase_id => #originating_phase_id,
:jira_detection_phase_id => #detection_phase_id,
:jira_version_id => #version_id,
:jira_version_name => #version_name,
:death_burrito_application_id => #jira_id
)
Offending String:
"Instance Blueprints → aa-test-kim → Module/Domain Objects - there is
a drop down title \"ID [REMOVEME]\". I don't think the 'removeme'
belongs."
Error
Mysql::Error: Incorrect string value: '\xE2\x86\x92 aa...' for column
'summary' at row 1: INSERT INTO jira_bugs (assignee_name,
created_at, death_burrito_application_id, issue,
issue_created, issue_updated, jira_detection_phase_id,
jira_it_division_id, jira_originating_phase_id,
jira_priority_id, jira_project_id, jira_status_id,
jira_version_id, jira_version_name, reporter_name, summary,
updated_at, weight) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?) [1m[35m (1.0ms)[0m ROLLBACK Mysql::Error:
Incorrect string value: '\xE2\x86\x92 aa...' for column 'summary' at
row 1: INSERT INTO jira_bugs (assignee_name, created_at,
death_burrito_application_id, issue, issue_created,
issue_updated, jira_detection_phase_id, jira_it_division_id,
jira_originating_phase_id, jira_priority_id, jira_project_id,
jira_status_id, jira_version_id, jira_version_name,
reporter_name, summary, updated_at, weight) VALUES (?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
I wound up doing a record specific hack for right now.
#summary = bug.summary.gsub(/→/,'>')
Not the greatest solution but until I find a better way this will have to do