2011-01-24 2 views
3

플래시 빌더에 앱을 작성하려고하며 Adobe Air/flashbuilder의 CSV 데이터를 SQLite 데이터베이스로 가져 오는 기능이 필요합니다.CSV 파일의 데이터를 Adobe Air 앱으로 가져 오려면 어떻게해야합니까?

나는 이런 식으로 한 적이 없으며 어디서부터 시작해야할지 완전히 확신하지 못했습니다. 데이터를 다시 삽입하기 전에 데이터를 조작하고 싶습니다. 그래서 정말로 CSV 파일의 데이터를 actionscript에서 조작 할 수있는 배열로 파싱하는 데 필요한 단계 (클래스 및 함수)를 알 필요가 있습니까?

답변

1

로딩을 포함하여 많은 자료에 casalib을 사용합니다. 표준 as3 항목을 사용할 수 있지만 this을 사용하면 훨씬 쉽게 처리 할 수 ​​있습니다. CasaLoader을 살펴보십시오.

당신은 다음 sqlite가 물건을 놀라 울 정도로 쉽게 행/열

를 추출하기 위해 몇 가지 문자열 분할을 사용할 수 있습니다. 이 링크에서보세요 : http://ntt.cc/2008/07/08/sqlite-example-for-adobe-air-working-with-local-sql-databases-with-source-code.html

당신은 MXML 물건을

+1

CSVlib라는 오픈 소스 CSV 해석 작업 스크립트 라이브러리가 있습니다. – Damon

1

[업데이트를 무시할 수 있습니다 : 플래시/액션 스크립트와 달리 내 대답은, HTML/자바 스크립트 AIR를 가정합니다. AS3 쪽에서 더 좋은 답변이있을 수 있습니다 ...]

언제든지 FileStream을 통해 읽고 CSV 파서를 직접 작성하는 저수준 접근 방식을 사용할 수 있습니다. 나는 임의의 CSV를 SQLite에 입력 할 수있는 선재 라이브러리를 찾을 수 있을지는 모르겠다. 그러나 아마도 나는 틀렸다 (나는 보지 않았다).

FileStream 리더로 시작하려는 기본 사항은 비동기 입력시 한 줄을 읽는이 예제 코드와 같습니다. 이 예제는 별도의 프로세스에서 STDOUT을 읽는 것이지만 FileStream에 직접 적용해야합니다.

this.process.addEventListener(air.ProgressEvent.STANDARD_OUTPUT_DATA, function(event) { 
    // call into _stdoutHandler... 
}); 

Foo.prototype._stdoutHandler = function() { 
    var nBytes = this.process.standardOutput.bytesAvailable; 
    var msg = this.process.standardOutput.readUTFBytes(nBytes); 
    // The native process might send us partial lines, due to async IO. 
    // Reconstruct the whole lines. 
    this._sofar += msg; 
    while (true) { 
     var idx = this._sofar.indexOf("\n"); 
     if (idx < 0) 
     break; 
     if (idx > 0) { // skips blank lines 
     var line = this._sofar.substring(0, idx); 
     this._foundLine(line); 
     } 
     if (this._sofar.length > idx + 1) { 
     this._sofar = this._sofar.substring(idx+1); 
     } else { 
     this._sofar = ""; 
     } 
    } 
    var lines = this._sofar.split(/\n/); 
    if (lines.length > 1) { 
     air.trace("programming error: we should have already handled all newlines"); 
    } 
    this._sofar = lines[lines.length - 1]; 
}; 

Foo.prototype._foundLine = function() { 
    // process a single line of input here... 
}; 
관련 문제