sqlite數(shù)據(jù)庫在使用時(shí)遇到的奇葩問題記錄_第1頁
sqlite數(shù)據(jù)庫在使用時(shí)遇到的奇葩問題記錄_第2頁
sqlite數(shù)據(jù)庫在使用時(shí)遇到的奇葩問題記錄_第3頁
sqlite數(shù)據(jù)庫在使用時(shí)遇到的奇葩問題記錄_第4頁
sqlite數(shù)據(jù)庫在使用時(shí)遇到的奇葩問題記錄_第5頁
已閱讀5頁,還剩6頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、sqlite數(shù)據(jù)庫在使用時(shí)遇到的奇葩問題記錄有時(shí)候做些簡單的項(xiàng)目一般都會(huì)選擇sqlite數(shù)據(jù)庫,優(yōu)點(diǎn)有很多,這里就不詳細(xì)說了。在此主要記錄一些平時(shí)在使用時(shí)遇到的問題及解決方法。希望能對(duì)大家有所幫助。-一:sqlite一直提示 the database file is locked解決:-二:錯(cuò)誤提示-混合模式程序集是針對(duì)v2.0.解決:-三:在IIS中發(fā)布網(wǎng)站程序時(shí),如果操作系統(tǒng)是64位的,有時(shí)候會(huì)出現(xiàn)訪問錯(cuò)誤的問題,這時(shí)可以將應(yīng)用程序高級(jí)設(shè)置中的“啟用32位應(yīng)用程序”設(shè)置項(xiàng)改為True,再測試是否成功。(如果“啟用32位應(yīng)用程序項(xiàng)為True” 時(shí)網(wǎng)站提示下面的錯(cuò)誤黃頁,則可以將該項(xiàng)設(shè)置為Fa

2、lse試試看。2014-5-24 更新:今天在測試一個(gè)網(wǎng)站時(shí),發(fā)現(xiàn)在True的情況下網(wǎng)站報(bào)錯(cuò),則將該項(xiàng)切換為了False,則可以訪問了。至于如何來解釋這種問題,待研究。)這種情況的一種錯(cuò)誤現(xiàn)象是:在IIS中發(fā)布使用sqlite數(shù)據(jù)庫的網(wǎng)站項(xiàng)目時(shí),配置好IIS后訪問,頁面可能就是顯示下面的:這時(shí)就需要你去修改應(yīng)用程序池的模式了:-四:使用sql語句插入當(dāng)前時(shí)間在sqlserver中,如果在操作數(shù)據(jù)時(shí)需要插入當(dāng)前時(shí)間的情況,可以使用 GETDATE()來插入,而在sqlite中則不同:INSERT INTO MWaitPlayList(Msongid,Mtitle,Mauthor,Mtime) V

3、ALUES(songid,title,author,datetime(now, localtime)要用datetime(now,localtime)來插入。項(xiàng)目實(shí)例: #region 將歌曲添加到待播放列表中 / / 將歌曲添加到待播放列表中 / / 歌曲id / 歌曲名 / 歌手 / public static bool XMusicAddtoWaitList(long songid, string songtitle, string songauthor) string sql = INSERT INTO MWaitPlayList(Msongid,Mtitle,Mauthor,Mtim

4、e) VALUES(songid,title,author,datetime(now,localtime); SQLiteParameter parameter = new SQLiteParameter(songid,DbType.Int64), new SQLiteParameter(title,DbType.String,200), new SQLiteParameter(author,DbType.String,200) ; parameter0.Value = songid; parameter1.Value = songtitle; parameter2.Value = songa

5、uthor; int row = ZXSQLiteHelper.ExecuteSql(sql, parameter); if (row 0) return true; else return false; -五. 數(shù)據(jù)庫配置Web.Config或App.Config文件中的設(shè)置: 數(shù)據(jù)庫文件要放在App_Data文件夾中:-六.SQLite中獲取最新添加自增ID,last_insert_rowid()的使用今天在用sqlite數(shù)據(jù)庫時(shí),想要在新插入數(shù)據(jù)的同時(shí)獲取自增的id值,從網(wǎng)上找了找,發(fā)現(xiàn)可以用last_insert_rowid() 這個(gè)函數(shù)來獲取,但是在sql語句中執(zhí)行時(shí)卻一直返回0。于

6、是又在網(wǎng)上找到了一個(gè)相關(guān)的文章,經(jīng)測試可行。遂記錄一下。出現(xiàn)上面所提問題的主要原因是“l(fā)ast_insert_rowid()” 函數(shù)必須要和insert語句一起使用,說的再明白點(diǎn),就是必須是由同一個(gè)“SQLiteConnection” 來操作。修改后的sqliteHelper : / / 執(zhí)行插入語句,并獲取最新的一條數(shù)據(jù)的id / / / / public static long ExecuteGetInsertId(string SQLString, params SQLiteParameter cmdParms) using (SQLiteConnection connection =

7、new SQLiteConnection(connectionString) using (SQLiteCommand cmd = new SQLiteCommand() long result = 0; try PrepareCommand(cmd, connection, null, SQLString, cmdParms); /result = cmd.ExecuteNonQuery(); /查詢 select用executeScalar() ,如果用executeNonQuery返回的永遠(yuǎn)是1. 這里由于肯定能轉(zhuǎn)換為數(shù)字 ,所以可以直接轉(zhuǎn)換 result = Convert.ToInt

8、64(cmd.ExecuteScalar(); (); catch ( E) result = -1; throw new Exception(E.Message); return result; sql語句: string sql = INSERT INTO UMembers(QId,UName,UPwd,UEmail,UPhoto,UTime) VALUES (5,uname,upwd,uemail,uphoto,datetime(now,localtime);SELECT last_insert_rowid() from UMembers; -參考:今天在我的數(shù)據(jù)類中給Add方法完善一下

9、.想要實(shí)現(xiàn)添加之后返回添加的實(shí)體的自增ID,遂想起了select last_insert_rowid(),可是用了之后就是不好使,各種返回0,后來經(jīng)度娘指教,我發(fā)現(xiàn)一句話在同一個(gè)SQLiteConnection中.,原來如此.修改代碼,搞定!我之前是這么寫的DBHelperSQLite.ExecuteSql(sql,parameters);return Convert.ToInt32(DBHelperSQLite.GetSingle(select last_insert_rowid();注意:由于我的DBHelper寫法的原因,這樣的話就變成了兩個(gè)SQLiteConnection改進(jìn)后retu

10、rn DBHelperSQLite.ExecuteSql(sql+ ;select last_insert_rowid();, parameters);DBHelper修改public static int ExecuteSql(string SQLString, List para) using (SQLiteConnection connection = new SQLiteConnection(connectionString) using (SQLiteCommand cmd = new SQLiteCommand(SQLString, connection) try connecti

11、on.Open(); foreach (SQLiteParameter p in para) (p); int rows =0; if(SQLString.IndexOf(insert) != -1) rows = Convert.ToInt32(cmd.ExecuteScalar(); else rows = cmd.ExecuteNonQuery(); return rows; catch (SQLiteException e) connection.Close(); throw e; 注意15行到18行,判斷是否是insert操作.然后執(zhí)行cmd.ExecuteScalar(),而不是c

12、md.ExecuteNonQuery().這樣就實(shí)現(xiàn)在同一個(gè)SQLiteConnection啦!鏈接:SQLite中獲取最新添加自增ID,last_insert_rowid()的使用 - 飯 - 博客園-七. sqlite查詢特定時(shí)間段的數(shù)據(jù)1.查詢某一天的數(shù)據(jù)SELECT Utitle,Uurl,Utime FROM Urls WHERE Uisok=1 AND date(Utime)=date(2014-02-10)2.查詢今天的數(shù)據(jù) (待測試)select time=datetime(now,start of day,+0 day) and time=datetime(now,start

13、 of day,-1 day) and time=datetime(now,start of day,-7 day,weekday 1) AND time=datetime(now, start of month, +0 month, -0 day) and UTime=datetime(now,start of month,-1 month,-0 day) AND Time datetime(now,start of month,+0 month,-1 day) from 表-八.Sqlite分頁數(shù)據(jù)查詢sqlite中 limit 一般的語法格式為:Select * From Person

14、Limit 9 Offset 10;表示從 數(shù)據(jù)庫Person 中 第10條開始 共獲取9條數(shù)據(jù)也可以使用 簡寫形式:Select * From Person Limit 10,9;-查詢相應(yīng)條數(shù)數(shù)據(jù) 相當(dāng)于sql中的 top -0,2 從第幾條開始 共查詢多少條 SELECT Bid,BTitle,BContent,BLink,BImg,BDate FROM XBooks WHERE BDel=0 ORDER BY BDate DESC LIMIT 0,2分頁查詢 string sql2 = string.Format(SELECT Bid,BTitle,BContent,BLink,BImg,BDate FROM XBooks WHERE BDel=0 ORDER BY BDate DESC LIMI

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論