2015-01-02 4 views
1

현재 SQLite for windows phone 8.1에는 SQLite 데이터 리더가 포함되어 있지 않지만 SQLite DB에서 데이터를 읽어야합니다. Type을 미리 알지 못하면 테이블 데이터와 스키마가 외부로 변경 (내 신청서 외부).Windows Phone 용 Sqlite 데이터 리더기 8.1

그래서 T를 알 수없는

var connection = new SQLiteConnection(dbName); 
connection.Query<T>("Select * from Table") 

아래로 SQLite는 테이블 데이터를 읽을 수있는 방법은 무엇입니까?

또는 connection.GetTableInfo ("테이블 이름")에서 가져온 열 목록에서 동적으로 T를 만들 수 있습니까?

답변

0

일반 형식이 지정되지 않은 SQL (https://sqlwinrt.codeplex.com/)을 지원하는 Andy Wigley의 SQLiteWinRT 래퍼를 사용할 수 있습니다.

당신은 평범한 오래된 문을 사용할 수 있습니다 :

// Get the file from the install location 
var file = await Package.Current.InstalledLocation.GetFileAsync("cities.db"); 

// Create a new SQLite instance for the file 
var db = new Database(file); 

// Open the database asynchronously 
await db.OpenAsync(SqliteOpenMode.OpenRead); 

// Prepare a SQL statement to be executed 
var statement = awaitdb.PrepareStatementAsync(
    "SELECT rowid, CityName FROM Cities;"); 

// Loop through all the results and add to the collection 
while (awaitstatement.StepAsync()) 
    items.Add(statement.GetIntAt(0) + ": "+ statement.GetTextAt(1)); 

을 또는 당신이 (더 모듈화 제공으로 확실히 더 나은입니다) 준비된 문을 사용할 수 있습니다

// Prepare a SQL statement to be executed with a parameter 
var statement = await db.PrepareStatementAsync(
    “SELECT rowid, CityName FROM Cities WHERE CityName LIKE ?;”); 

// Bind the parameter value to the statement 
statement.BindTextParameterAt(1, “c%”); 

// Loop through all the results and add to the collection 
// Same as above 

당신은 쿼리를 볼 수 있듯이을 객체를 생성하는 데 사용할 수있는 간단한 문자열을 반환합니다. 또는 직접적으로 작업 할 수 있습니다 (기본 객체에 대해 반드시 알 필요는 없다고 언급 했음). 여기

당신이 시작할 수 있어야 또 다른 튜토리얼 : 나는이 라이브러리는 또한 승리 전화 8.1 응용 프로그램에 대해 잘 작동하는지 확실하지 않다 귀하의 제안에 대한 http://blogs.windows.com/buildingapps/2013/05/30/sqlite-winrt-wrapper-for-windows-phone/

+0

감사합니다, 나는 그것을 시도하고 당신을 다시 얻을 것이다 . 다시 한번 감사드립니다. 이 사이트는 "최신 라이브러리 업데이트는 Windows 8 개발 외에도 Windows Phone 8 개발을 지원합니다."라고 알려줍니다. 잘하면 이것이 우리를 위해 일할 것입니다, 나는 이것을 시도하고 다시 당신에게 돌아갈 것입니다. – Swamy

+0

Andy가 WP 8.1 jumpstart 대화에서 예제를 보여 주었기 때문에 작동 할 것이라고 확신합니다.) – Fred

+0

예.이 라이브러리는 라이센스 및 지원에 대해 조금 걱정이되지만, 나는 감사하고 싶었고 이것을 대답으로 받아 들였다. – Swamy