当我尝试将 SQL UPDATE 与我在 Flex builder 中制作的移动应用程序一起使用时,出现此错误。我试图搜索它并删除参数,但即使这样我也得到了相同的代码。任何帮助将非常感激
SQLError: 'Error #3115: SQL Error.', details:'Mismatch in parameter count. Found 6 in SQL specified and 5 value(s) set in parameters property.
', operation:'execute', detailID:'1004'
at flash.data::SQLStatement/internalExecute()
at flash.data::SQLStatement/execute()
at model::SQLiteDatabase$/updateMember()[/Users/stokhofdavey/Documents/Adobe Flash Builder 4.6/MenuPlannerApplication/src/model/SQLiteDatabase.as:175]
at views::MemberDetailsView/onSaveButtonClicked()[/Users/stokhofdavey/Documents/Adobe Flash Builder 4.6/MenuPlannerApplication/src/views/MemberDetailsView.mxml:25]
at views::MemberDetailsView/___MemberDetailsView_Button3_click()[/Users/stokhofdavey/Documents/Adobe Flash Builder 4.6/MenuPlannerApplication/src/views/MemberDetailsView.mxml:45]
这是 MXML 代码:
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:ns1="*"
title="Member Details">
<fx:Script>
<![CDATA[
import model.Dish;
import model.Member;
import model.SQLiteDatabase;
protected function onHomeButtonClicked(event:MouseEvent):void {
navigator.popView();
}
protected function onSaveButtonClicked():void {
var editNote:Member = new Member();
editNote.FirstName = efirstname.text;
editNote.FamilyName = efamilyname.text;
editNote.Sex = esex.text;
editNote.Age = eage.text;
editNote.Notes = enotes.text;
SQLiteDatabase.updateMember(editNote);
currentState = "Info";
}
]]>
</fx:Script>
<s:states>
<s:State name="Info"/>
<s:State name="Favorites"/>
<s:State name="EInfo"/>
<s:State name="EFavorites"/>
</s:states>
<s:navigationContent>
<s:Button label="Back" click="navigator.popView();"/>
</s:navigationContent>
<s:actionContent>
<s:Button includeIn="Info" label="Edit" click.Info="this.currentState="EInfo""/>
<s:Button includeIn="EInfo" label="Save" click="onSaveButtonClicked()"/>
</s:actionContent>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:VGroup x="245" y="10" width="100%" height="354" gap="0" >
<ns1:TabMemInfoS includeIn="Favorites" width="60" height="40"/>
<ns1:TabMebInfoL includeIn="Info" width="70" height="40"/>
<ns1:TabMemFavoritesS includeIn="Info" width="60" height="40"/>
<ns1:TabMebInfoL includeIn="EInfo" width="70" height="40"/>
<ns1:TabMemFavoritesS includeIn="EInfo" width="60" height="40"/>
<ns1:TabMemInfoS includeIn="EFavorites"/>
<ns1:TabMemFavoritesL includeIn="EFavorites"/>
<ns1:TabMemFavoritesL includeIn="Favorites" width="70" height="40"/>
</s:VGroup>
<s:Label id="FirstName" includeIn="Info" x="87" y="15" width="148" height="29" text="{data.FirstName}" textAlign="center"
verticalAlign="middle"/>
<s:Label id="FamilyName" includeIn="Info" x="87" y="46" width="148" height="29" text="{data.FamilyName}" textAlign="center"
verticalAlign="middle"/>
<s:Label id="Age" includeIn="Info" x="9" y="97" width="70" height="31" text="{data.Age}" textAlign="center"
verticalAlign="middle"/>
<s:Label id="Sex" includeIn="Info" x="87" y="97" width="70" height="31" text="{data.Sex}" textAlign="center"
verticalAlign="middle"/>
<s:Label id="notes" includeIn="Info" x="10" y="150" width="225" height="204" text="{data.Notes}"/>
<s:Group includeIn="EInfo" width="246" height="364">
<s:TextInput id="efirstname" x="83" y="10" width="150" text="{data.FirstName}" />
<s:TextInput id="efamilyname" x="83" y="47" width="150" text="{data.FamilyName}" />
<s:TextInput id="eage" x="108" y="88" width="90" text="{data.Age}" />
<s:TextInput id="esex" x="10" y="88" width="90" text="{data.Sex}" />
<s:TextArea id="enotes" x="9" y="162" width="227" height="192" text="{data.Notes}" />
</s:Group>
</s:View>
和 2 个 .as 文件:SQLiteDatabase
package model
{
import flash.data.SQLConnection;
import flash.data.SQLResult;
import flash.data.SQLStatement;
import flash.events.SQLEvent;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import model.Dish;
import model.Member;
import mx.collections.ArrayCollection;
public class SQLiteDatabase
{
private static var _sqlConnection:SQLConnection;
public static function get sqlConnection():SQLConnection
{
if (_sqlConnection)
return _sqlConnection;
openDatabase(File.desktopDirectory.resolvePath("test.db"));
return _sqlConnection;
}
public static function getNote(id:int):Dish
{
var sql:String = "SELECT id, title, time, message FROM notes WHERE id=?";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.parameters[0] = id;
stmt.execute();
var result:Array = stmt.getResult().data;
if (result && result.length == 1)
return processRow(result[0]);
else
return null;
}
public static function getMYBlist(id:int):Dish
{
var sql:String = "SELECT id, title, time, message FROM notes WHERE id=?";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.parameters[0] = id;
stmt.execute();
var result:Array = stmt.getResult().data;
if (result && result.length == 1)
return processRow(result[0]);
else
return null;
}
public static function notes():ArrayCollection
{
var noteList:ArrayCollection = new ArrayCollection();
var sql:String = "SELECT id, title, time, message FROM notes";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.execute();
var sqlResult:SQLResult = stmt.getResult();
if (sqlResult) {
var result:Array = sqlResult.data;
if (result) {
for (var index:Number = 0; index < result.length; index++) {
noteList.addItem(processRow(result[index]));
}
}
}
return noteList;
}
public static function members():ArrayCollection
{
var noteList:ArrayCollection = new ArrayCollection();
var sql:String = "SELECT FirstName, FamilyName, Sex, Age, Notes FROM Members";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.execute();
var sqlResult:SQLResult = stmt.getResult();
if (sqlResult) {
var result:Array = sqlResult.data;
if (result) {
for (var index:Number = 0; index < result.length; index++) {
noteList.addItem(processRow2(result[index]));
}
}
}
return noteList;
}
public static function addNote(note:Dish):void
{
var sql:String =
"INSERT INTO notes (title, time, message) " +
"VALUES (?,?,?)";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.parameters[0] = note.title;
stmt.parameters[1] = note.time;
stmt.parameters[2] = note.message;
stmt.execute();
}
public static function addMember(note:Member):void
{
var sql:String =
"INSERT INTO notes (FirstName, FamilyName, Age, Sex, Notes) " +
"VALUES (?,?,?,?,?)";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.parameters[0] = note.FirstName;
stmt.parameters[1] = note.FamilyName;
stmt.parameters[2] = note.Age;
stmt.parameters[3] = note.Sex;
stmt.parameters[4] = note.Notes;
stmt.execute();
}
public static function deleteNote(note:Dish):void
{
var sql:String = "DELETE FROM notes WHERE id=?";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.parameters[0] = note.id;
stmt.execute();
}
public static function deleteMember(note:Dish):void
{
var sql:String = "DELETE FROM notes WHERE id=?";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.parameters[0] = note.id;
stmt.execute();
}
public static function updateNote(note:Dish):void
{
var sql:String = "UPDATE notes SET title=?, time=?, message=? WHERE id=?";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.parameters[0] = note.title;
stmt.parameters[1] = note.time;
stmt.parameters[2] = note.message;
stmt.parameters[3] = note.id;
stmt.execute();
}
public static function updateMember(note:Member):void
{
var sql:String = "UPDATE Members SET FirstName=?, FamilyName=?, Sex=?, Age=?, Notes=? WHERE ID=?";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.parameters[0] = note.FirstName;
stmt.parameters[1] = note.FamilyName;
stmt.parameters[2] = note.Sex;
stmt.parameters[3] = note.Age;
stmt.parameters[4] = note.Notes;
stmt.execute();
}
protected static function processRow(o:Object):Dish
{
var note:Dish = new Dish();
note.id = o.id;
note.title = o.title == null ? "" : o.title;
note.time = o.time == null ? "" :o.time;
note.message = o.message == null ? "" : o.message;
return note;
}
protected static function processRow2(o:Object):Member
{
var info:Member = new Member();
info.ID = o.ID;
info.FirstName = o.FirstName == null ? "" : o.FirstName;
info.FamilyName = o.FamilyName == null ? "" : o.FamilyName;
info.Sex = o.Sex == null ? "" : o.Sex;
info.Age = o.Age == null ? "" : o.Age;
info.Notes = o.Notes == null ? "" : o.Notes;
return info;
}
public static function openDatabase(file:File):void
{
var newDB:Boolean = true;
if (file.exists)
newDB = false;
_sqlConnection = new SQLConnection();
_sqlConnection.open(file);
if (newDB)
{
createDatabase();
populateDatabase();
}
}
protected static function createDatabase():void
{
var sql:String =
"CREATE TABLE IF NOT EXISTS notes ( "+
"id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"title VARCHAR(50), " +
"time VARCHAR(50), " +
"message VARCHAR(200))"
"CREATE TABLE IF NOT EXISTS members ( "+
"id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"title VARCHAR(50), " +
"time VARCHAR(50), " +
"message VARCHAR(200))"
;
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.execute();
}
protected static function populateDatabase():void
{
var file:File = File.applicationDirectory.resolvePath("assets/notes.xml");
if (!file.exists) return;
var stream:FileStream = new FileStream();
stream.open(file, FileMode.READ);
var xml:XML = XML(stream.readUTFBytes(stream.bytesAvailable));
stream.close();
for each (var n:XML in xml.note)
{
var note:Dish = new Dish();
note.id = n.id;
note.title = n.title;
note.time = n.time;
note.message = n.message;
addNote(note);
}
}
}
}
和 member.as
package model
{
import mx.collections.ArrayCollection;
import mx.core.IUID;
[Bindable]
public class Member implements IUID
{
public var ID:int;
public var FirstName:String;
public var FamilyName:String;
public var Sex:String;
public var AgeID:int;
public var Notes:String;
public var Fname:String;
public var Famname:String;
public var Age:String;
public function get uid(): String {
return ID.toString();
}
public function set uid(value: String): void {
ID = parseInt(value);
}
}
}