Solved

update query to SQLite database

Posted on 2006-11-27
14
233 Views
Last Modified: 2012-08-14
I'm trying to do an update query from a Zinc textfield component to SQLite database.  The following won't work.  Any idea what I need to adjust?


on(release)
{
var val = _parent.myDB.runQuery("UPDATE preferences SET typenum = \""+thisfield.text+"\" WHERE id = 1;");

}
0
Comment
Question by:COwebmaster
  • 7
  • 7
14 Comments
 
LVL 11

Expert Comment

by:ch2
Comment Utility
Well did never use that class but as i know a bit of sqlite and mysql. Did you open a connection to the database?

I searched a bit and got to this link: http://www.thecodezone.com/downloads/sqlite.html

So try like this

// Connect
var id:Boolean = _parent.myDB.connect("my.db");
// Check connection
if (id) {
      trace("connected");
      var stat:Boolean = _parent.myDB.runQuery("UPDATE preferences SET typenum = \""+thisfield.text+"\" WHERE id = 1;");
      if (stat) {
            // Check if inserted
            trace("Record inserted");
      } else {
            trace("Record not inserted");
      }
} else {
      trace("Record not connected");
}
_parent.myDB.close;
0
 

Author Comment

by:COwebmaster
Comment Utility
Thanks but the issue is that it inserts the string "+thisfield.text+" instead of the value inside that textfield which is a number or anything else the end user enters.  Not sure how to handle that on an update query.
0
 
LVL 11

Expert Comment

by:ch2
Comment Utility
Try this.

_parent.myDB.runQuery("UPDATE preferences SET typenum = '"+thisfield.text+"' WHERE id = 1;");
0
 
LVL 11

Expert Comment

by:ch2
Comment Utility
or also try this.

_parent.myDB.runQuery("UPDATE preferences SET typenum = "+chr(34)+thisfield.text+chr(34)+" WHERE id = 1;");
0
 

Author Comment

by:COwebmaster
Comment Utility
Ok, let me try those..
0
 
LVL 11

Expert Comment

by:ch2
Comment Utility
If the above dosen't work also try this and post here the trace.

var sql = "UPDATE preferences SET typenum = '"+thisfield.text+"' WHERE id = 1;";
trace (sql)
_parent.myDB.runQuery(sql);
0
 

Author Comment

by:COwebmaster
Comment Utility
Ok, I tried the first solution:

_parent.myDB.runQuery("UPDATE preferences SET typenum = '"+thisfield.text+"' WHERE id = 1;");

and it inserted undefined
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:COwebmaster
Comment Utility
Ok, I also tried:

_parent.myDB.runQuery("UPDATE preferences SET typenum = "+chr(34)+thisfield.text+chr(34)+" WHERE id = 1;");

and that didn't update anything.
0
 

Author Comment

by:COwebmaster
Comment Utility
The trace on the above is:

UPDATE preferences SET typenum = 'undefined' WHERE id = 1;
0
 
LVL 11

Expert Comment

by:ch2
Comment Utility
ok so that is correct.

This is the right one:

_parent.myDB.runQuery("UPDATE preferences SET typenum = '"+thisfield.text+"' WHERE id = 1;");

but now your problem is the textfield because it's unefined or empty. Where is the textfield located?
0
 

Author Comment

by:COwebmaster
Comment Utility
The textfield is located on the _root with the button to update.  Both are flash components.
0
 
LVL 11

Accepted Solution

by:
ch2 earned 500 total points
Comment Utility
so try like this.

_parent.myDB.runQuery("UPDATE preferences SET typenum = '"+_root.thisfield.text+"' WHERE id = 1;");
0
 

Author Comment

by:COwebmaster
Comment Utility
YES!!!!!!

_root didn't get referneced.  

Thanks ch2!
0
 
LVL 11

Expert Comment

by:ch2
Comment Utility
nice it worked for you!

Thanks for the points.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now