當前位置: 首頁>>代碼示例>>C#>>正文


C# SqliteCommand.ExecuteStatement方法代碼示例

本文整理匯總了C#中Mono.Data.Sqlite.SqliteCommand.ExecuteStatement方法的典型用法代碼示例。如果您正苦於以下問題:C# SqliteCommand.ExecuteStatement方法的具體用法?C# SqliteCommand.ExecuteStatement怎麽用?C# SqliteCommand.ExecuteStatement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.Data.Sqlite.SqliteCommand的用法示例。


在下文中一共展示了SqliteCommand.ExecuteStatement方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ReadpVm

		internal void ReadpVm (IntPtr pVm, int version, SqliteCommand cmd)
		{
			int pN;
			IntPtr pazValue;
			IntPtr pazColName;
			bool first = true;
			
			int[] declmode = null;

			while (true) {
				bool hasdata = cmd.ExecuteStatement(pVm, out pN, out pazValue, out pazColName);
			
				// For the first row, get the column information
				if (first) {
					first = false;
					
					if (version == 3) {
						// A decltype might be null if the type is unknown to sqlite.
						decltypes = new string[pN];
						declmode = new int[pN]; // 1 == integer, 2 == datetime
						for (int i = 0; i < pN; i++) {
							IntPtr decl = Sqlite.sqlite3_column_decltype16 (pVm, i);
							if (decl != IntPtr.Zero) {
								decltypes[i] = Marshal.PtrToStringUni (decl).ToLower(System.Globalization.CultureInfo.InvariantCulture);
								if (decltypes[i] == "int" || decltypes[i] == "integer")
									declmode[i] = 1;
								else if (decltypes[i] == "date" || decltypes[i] == "datetime")
									declmode[i] = 2;
							}
						}
					}
					
					columns = new string[pN];	
					for (int i = 0; i < pN; i++) {
						string colName;
						if (version == 2) {
							IntPtr fieldPtr = Marshal.ReadIntPtr (pazColName, i*IntPtr.Size);
							colName = Sqlite.HeapToString (fieldPtr, ((SqliteConnection)cmd.Connection).Encoding);
						} else {
							colName = Marshal.PtrToStringUni (Sqlite.sqlite3_column_name16 (pVm, i));
						}
						columns[i] = colName;
						column_names_sens [colName] = i;
						column_names_insens [colName] = i;
					}
				}

				if (!hasdata) break;
				
				object[] data_row = new object [pN];
				for (int i = 0; i < pN; i++) {
					if (version == 2) {
						IntPtr fieldPtr = Marshal.ReadIntPtr (pazValue, i*IntPtr.Size);
						data_row[i] = Sqlite.HeapToString (fieldPtr, ((SqliteConnection)cmd.Connection).Encoding);
					} else {
						switch (Sqlite.sqlite3_column_type (pVm, i)) {
							case 1:
								long val = Sqlite.sqlite3_column_int64 (pVm, i);
							
								// If the column was declared as an 'int' or 'integer', let's play
								// nice and return an int (version 3 only).
								if (declmode[i] == 1 && val >= int.MinValue && val <= int.MaxValue)
									data_row[i] = (int)val;
								
								// Or if it was declared a date or datetime, do the reverse of what we
								// do for DateTime parameters.
								else if (declmode[i] == 2)
									data_row[i] = DateTime.FromFileTime(val);
								
								else
									data_row[i] = val;
									
								break;
							case 2:
								data_row[i] = Sqlite.sqlite3_column_double (pVm, i);
								break;
							case 3:
								data_row[i] = Marshal.PtrToStringUni (Sqlite.sqlite3_column_text16 (pVm, i));
								
								// If the column was declared as a 'date' or 'datetime', let's play
								// nice and return a DateTime (version 3 only).
								if (declmode[i] == 2)
									data_row[i] = DateTime.Parse((string)data_row[i]);
								break;
							case 4:
								int blobbytes = Sqlite.sqlite3_column_bytes16 (pVm, i);
								IntPtr blobptr = Sqlite.sqlite3_column_blob (pVm, i);
								byte[] blob = new byte[blobbytes];
								Marshal.Copy (blobptr, blob, 0, blobbytes);
								data_row[i] = blob;
								break;
							case 5:
								data_row[i] = null;
								break;
							default:
								throw new ApplicationException ("FATAL: Unknown sqlite3_column_type");
						}
					}
				}
				
//.........這裏部分代碼省略.........
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:101,代碼來源:SqliteDataReader.cs


注:本文中的Mono.Data.Sqlite.SqliteCommand.ExecuteStatement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。