Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ckchan
Starting Member
5 Posts |
Posted - 2006-10-30 : 23:17:37
|
hello! i'm new to director mx and it uses SQL query for the database? i was hoping if anyone could help me with the source code as it returns a 'SQL error' upon saving data. thanks in advance. :)-- *** MAIN *** --on getURL me, data if data = "close" then sendSprite("dialog", #beginSprite) if data = "save" then m = _global.theMonth d = _global.theDay y = _global.theYear if sprite("dialog").biking.selected = true then saveType = "B" if sprite("dialog").running.selected = true then saveType = "R" if sprite("dialog").walking.selected = true then saveType = "W" saveLoc = sprite("dialog").location.text saveMiles = sprite("dialog").miles.text saveTime = sprite("dialog").time.text saveNotes = sprite("dialog").notes.text err = _global.myDB.executeSQL("INSERT INTO dataVALUES(?,?,?,?,?,?,?,?)", [m,d,y, saveType, saveLoc, saveMiles, saveTime, saveNotes]) errCode = err.errorMsg if errCode <> 0 then showError(errCode) else displayMonth() end if end ifendon startMovie _global.theYear = _movie.systemDate().year _global.theMonth = _movie.systemDate().month _global.theDay = 0 _global.dataSprites = 10 _global.daySprites = 53 _global.exercisesSprites = 96 _global.myDB = new(xtra "arca") err = _global.myDB.openDB(_movie.path & "exercise") errCode = err.errorMsg if errCode = 604 then makeDB() else if errCode <> 0 then showError(errCode) end ifon makeDB err = _global.myDB.createDB(_movie.path & "exercise") errCode = err.errorMsg if errCode = 0 then --create table err = _global.myDB.executeSQL("CREATE TABLE data(m integer, d integer, y integer, type, location, distance float, time, notes)") errCode = err.errorMsg if errCode <> 0 then showError(errCode) end if else showError(errCode) end ifendon showError errCode errString = _global.myDB.explainError(errCode) _player.alert(errString)endon stopMovie err = _global.myDB.closeDB() errCode = err.errorMsg if errCode <> 0 then showError(errCode)endon displayMonth sendAllSprites(#doClear) sendAllSprites(#clearDate) thisMonth = _global.theMonth thisYear = _global.theYear --number of days in each month daysList = [31,28,31,30,31,30,31,31,30,31,30,31] monthList = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] --show month and year dateString = monthList[thisMonth] && string(thisYear) member("date shadow").text = dateString member("date display").text = dateString --determine number of days in this month and check for leap year days = daysList[thisMonth] if thisMonth = 2 then leapCheck = date(thisYear, 2, 29) if leapCheck.month = 2 then days = 29 end if end if --Now get the day of week the first starts on flashDate = newObject("date") flashDate.setFullYear(thisYear, thisMonth - 1, 1) _global.firstDayOfWeek = integer(flashDate.getDay()) --returns 0-6 dayChannel = _global.daySprites + _global.firstdayofWeek dataChannel = _global.dataSprites + _global.firstDayOfWeek exerciseChannel = _global.exerciseSprites + _global.firstDayOfWeek m = _global.theMonth y = _global.theYear repeat with thisDay = 1 to days sprite(dayChannel).member.text = string(thisDay) sendSprite (dataChannel, #setDate, thisDay) err = _global.myDB.executeSQL("SELECT * FROM data WHERE m = ? AND d = ? and y = ?",[m, thisDay, y]) errCode = err.errorMsg if errCode = 0 then theData = err.rows if theData.count <> 0 then theData = theData[1] theType = theData[4] theLoc = theData[5] theDist = theData[6] theTime = theData[7] theNotes = theData sprite(exerciseChannel).member.text = theType sprite(dataChannel).member.text = theLoc & return & theDist & " " & theTime & return & theNotes end if end if exerciseChannel = exerciseChannel + 1 dataChannel = dataChannel + 1 dayChannel = dayChannel + 1 end repeatend |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-31 : 00:39:15
|
| err = _global.myDB.executeSQL("INSERT INTO dataVALUES(?,?,?,?,?,?,?,?)", [m,d,y, saveType, saveLoc, saveMiles, saveTime, saveNotes])Where are the values to insert? I can only see the column names.Peter LarssonHelsingborg, Sweden |
 |
|
|
ckchan
Starting Member
5 Posts |
Posted - 2006-10-31 : 00:58:35
|
| hello! thank you for replying but i'm only copying from a book, and it says:"by allowing you to use question marks and a list of values, Arca makes the process much easier. Any question marks within the VALUES portion will be replaced with the values given in the list of values. Note the order of data being stored. Recall when you created the table, the field order went: theDate, type, location, distance, time, notes. The order of data in the INSERT command needs to be the same.After the INSERT is complete the returned error list is checked to make sure no error occured. If none has, then the displayMonth method is called, which redraws the calendar. This is done so that the newly entered data appears as soon as Save is pressed. Don't worry; you'll add the code to display the data next."Does this explain what you ask. It is my first time to learn the software, I beg your pardon. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-31 : 01:00:57
|
| err = _global.myDB.executeSQL("INSERT INTO dataVALUES(?,?,?,?,?,?,?,?)", [" & m & "," & d & "," & y & ", " & saveType & ", " & saveLoc & ", " & saveMiles & ", " & saveTime & ", " & saveNotes & "]")Peter LarssonHelsingborg, Sweden |
 |
|
|
ckchan
Starting Member
5 Posts |
Posted - 2006-10-31 : 01:13:35
|
| hi again!copy pasted.. Script error: String does not end correctly |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-31 : 01:20:01
|
| err = _global.myDB.executeSQL("INSERT INTO dataVALUES(?,?,?,?,?,?,?,?)", "[" & m & "," & d & "," & y & ", " & saveType & ", " & saveLoc & ", " & saveMiles & ", " & saveTime & ", " & saveNotes & "]")Peter LarssonHelsingborg, Sweden |
 |
|
|
ckchan
Starting Member
5 Posts |
Posted - 2006-10-31 : 01:22:33
|
| it played! but the error this time is:"Function requires a list argument" |
 |
|
|
ckchan
Starting Member
5 Posts |
Posted - 2006-10-31 : 04:21:23
|
| RESOLVED "dataVALUES" should be data VALUESbut thanks anyhow. ;) |
 |
|
|
|
|
|
|
|