Forum > Database
Retrieve Multiple Records as TStringList Array.
(1/1)
nugax:
I created a type:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type TStringListArray = array of TStringList;
I am trying to retrieve a bunch of text(string) fields from a sqlite3 database. I have the return code as below. The issue is, its failing (cant see errors) on the
[
code=pascal]TReturnList[iCnt].Add(Query.FieldByName('mailid').AsString);
[/code]
I cannot figure out why.
Can someone assist - full function below:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- //Get All Mail Array function GetMailFromLocalMailConf(): TStringListArray; var Connect: TSQLite3Connection; Trans: TSQLTransaction; Query: TSQLQuery; db_name: string[100]; sqlhandle: string[255]; TReturnList: TStringListArray; iCnt: integer; begin //Setup SQL db_name := programinfo.cbbsInfo.sLocalMailDB; sqlhandle := 'SELECT mailid, to_id, from_id, subject, date, read, message FROM localmail WHERE to_id = ' + userhandler.recCurrentUser.UserID.ToString; write('SQL' + sqlhandle); //Code to update password from handle Connect := TSQLite3Connection.Create(nil); Query := TSQLQuery.Create(nil); Trans := TSQLTransaction.Create(Connect); Connect.Transaction := Trans; Connect.DatabaseName := db_name; Trans.StartTransaction; // opens Connect, EInOutError if SQLite not installed Query.SQL.Text := sqlhandle; write('here1'); Query.Database := Connect; //Connection for SQL write('here23'); Query.Open; //boolFoundUser := (Query.RecordCount > 0) and (Query.FieldByName('password').AsString <> ''); TReturnList. write('here'); iCnt := 1; repeat TReturnList[iCnt].Add(Query.FieldByName('mailid').AsString); TReturnList[iCnt].Add(Query.FieldByName('to_id').AsString); TReturnList[iCnt].Add(Query.FieldByName('from_id').AsString); TReturnList[iCnt].Add(Query.FieldByName('subject').AsString); TReturnList[iCnt].Add(Query.FieldByName('date').AsString); TReturnList[iCnt].Add(Query.FieldByName('read').AsString); TReturnList[iCnt].Add(Query.FieldByName('message').AsString); iCnt := iCnt + 1; write('Adding'); query.Next; until (iCnt = Query.RecordCount); { while not Query.EOF do begin TReturnList[iCnt].Add(Query.FieldByName('mailid').AsString); TReturnList[iCnt].Add(Query.FieldByName('to_id').AsString); TReturnList[iCnt].Add(Query.FieldByName('from_id').AsString); TReturnList[iCnt].Add(Query.FieldByName('subject').AsString); TReturnList[iCnt].Add(Query.FieldByName('date').AsString); TReturnList[iCnt].Add(Query.FieldByName('read').AsString); TReturnList[iCnt].Add(Query.FieldByName('message').AsString); Write('local + ' + TReturnList[iCnt].ToString); iCnt := iCnt + 1; end; } Query.Close; Query.Free; Connect.Free; exit(TReturnList); end;
nugax:
Excuse the test code, and unfinished area. I was testing..
bytebites:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---TReturnList[iCnt]:=TStringList.create
nugax:
So I changed it to a array of records and it does the exact same thing. Where would you initialize (create) the record?
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type LocalMailRecord = record mailid : string; to_id : string; from_id : string; subject : string; date : string; read : string; message : string; end; type LocalMailArray = array of LocalMailRecord;
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---//Get All Mail Arrayfunction GetMailFromLocalMailConf(): LocalMailArray;var Connect: TSQLite3Connection; Trans: TSQLTransaction; Query: TSQLQuery; db_name: string[100]; sqlhandle: string[255]; MailRecordArray : LocalMailArray; iCnt: integer; begin //Setup SQL db_name := programinfo.cbbsInfo.sLocalMailDB; sqlhandle := 'SELECT mailid, to_id, from_id, subject, date, read, message FROM localmail WHERE to_id = ' + userhandler.recCurrentUser.UserID.ToString; Write('SQL' + sqlhandle); //Code to update password from handle Connect := TSQLite3Connection.Create(nil); Query := TSQLQuery.Create(nil); Trans := TSQLTransaction.Create(Connect); Connect.Transaction := Trans; Connect.DatabaseName := db_name; Trans.StartTransaction; // opens Connect, EInOutError if SQLite not installed Query.SQL.Text := sqlhandle; Write('here1'); Query.Database := Connect; //Connection for SQL Write('here23'); Query.Open; //boolFoundUser := (Query.RecordCount > 0) and (Query.FieldByName('password').AsString <> ''); Write('here'); iCnt := 1; repeat // test := Query.FieldByName('mailid').AsString; // TReturnList[iCnt].create; Write('at least here'); write('test data: ' + Query.FieldByName('subject').AsString); MailRecordArray[iCnt] := LocalMailArray. MailRecordArray[iCnt].mailid := Query.FieldByName('mailid').AsString; // TReturnList[iCnt] := TStringList.Create; // TReturnList[iCnt].Add(test); Write('ahah!'); { TReturnList[iCnt].Add(Query.FieldByName('to_id').AsString); TReturnList[iCnt].Add(Query.FieldByName('from_id').AsString); TReturnList[iCnt].Add(Query.FieldByName('subject').AsString); TReturnList[iCnt].Add(Query.FieldByName('date').AsString); TReturnList[iCnt].Add(Query.FieldByName('read').AsString); TReturnList[iCnt].Add(Query.FieldByName('message').AsString); } iCnt := iCnt + 1; Write('Adding'); query.Next; until (iCnt = Query.RecordCount); { while not Query.EOF do begin TReturnList[iCnt].Add(Query.FieldByName('mailid').AsString); TReturnList[iCnt].Add(Query.FieldByName('to_id').AsString); TReturnList[iCnt].Add(Query.FieldByName('from_id').AsString); TReturnList[iCnt].Add(Query.FieldByName('subject').AsString); TReturnList[iCnt].Add(Query.FieldByName('date').AsString); TReturnList[iCnt].Add(Query.FieldByName('read').AsString); TReturnList[iCnt].Add(Query.FieldByName('message').AsString); Write('local + ' + TReturnList[iCnt].ToString); iCnt := iCnt + 1; end; } Query.Close; Query.Free; Connect.Free; exit(MailRecordArray); //Return Mail Array end;
bytebites:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---SetLength(MailRecordArray,Query.RecordCount)repeat...
Navigation
[0] Message Index