Ecere SDK/eC Forums http://ecere.org/community/ Print view |
|
Fetch all recordset from ODBC http://ecere.org/community/viewtopic.php?f=1&t=341 |
Page 1 of 2 |
Author: | samsam598 [ Wed Dec 05, 2012 3:09 am ] |
Post subject: | Fetch all recordset from ODBC |
Greetings! I am writing an ODBC wrapper class to read and write with MS Access Database file.Below function is to retrieve all record set from query.However it turned out it does not work properly.I think the main problem is I did something wrong with Array<String*> and dynamic array of array of char(*).Could you please figure me out the proper way to do so?Thanks. Code: Select all
|
Author: | jerome [ Wed Dec 05, 2012 3:32 am ] |
Post subject: | Re: Fetch all recordset from ODBC |
Hi Sam! You know it would be great if you could write an ODBC driver for EDA, using our existing drivers as examples... Juan Sanchez started the work on the Oracle driver earlier this year (sdk/eda/drivers). This would really be the proper way so that we can easily import for an ODBC database into EDA and vice-versa Also you could use the eC active records and DB schema syntax. Do you have access to IRC (#ecere on irc.freenode.net) ? This code seems a bit complex and I don't have a way to test so it would be easier to help you out there. -Jerome |
Author: | samsam598 [ Wed Dec 05, 2012 4:41 am ] |
Post subject: | Re: Fetch all recordset from ODBC |
Hi Jerome, Thanks for the reply.I hope I can implemented in an eC way using the EDA technology but I am sorry I can't fully understand it at this moment.At the very first step I just tried to write a simple but workable wrapper to test the basic coding needed,like dynamic array etc,and trying to make it recognize Chinese character record properly.Next step I will study and try to re-implement with EDA technology. Attached please find the GUI version of the test case.It can run but it will crash when tring to retreive the recordset. Regards, Sam |
Author: | jerome [ Wed Dec 05, 2012 5:04 am ] |
Post subject: | Re: Fetch all recordset from ODBC |
Hi Sam, I don't have any ODBC connection to test with though... Could you explain in more details what is going on what you think is the problem? |
Author: | jerome [ Wed Dec 05, 2012 5:07 am ] |
Post subject: | Re: Fetch all recordset from ODBC |
Ah, I just noticed. I don't think Array<String *> will work. There is a bug http://ecere.com/mantis/view.php?id=770 (Basically, at the moment template parameters must be either a basic data type e.g. int or an eC class/struct/enum/union. Pointers and 'C' style types (e.g. 'struct Bla' or typedefs) are not yet supported.) |
Author: | jerome [ Wed Dec 05, 2012 5:08 am ] |
Post subject: | Re: Fetch all recordset from ODBC |
You can work around it by making a class that contains a String * Or you could do Array<Array<String>> |
Author: | samsam598 [ Wed Dec 05, 2012 9:02 pm ] |
Post subject: | Re: Fetch all recordset from ODBC |
Hi Jerome, My main problem is not knowing exactly how to write a function which return an array of array of String,the data is from a SQL record set,and the 2 dimensional array should properly deal with Chinese character.Below is the pseudo code: Code: Select all
|
Author: | jerome [ Wed Dec 05, 2012 9:35 pm ] |
Post subject: | Re: Fetch all recordset from ODBC |
Hi Sam, The ODBC SQLGetData with SQL_C_WCHAR is going to return you strings encoded in UTF-16. You can use UTF16toUTF8 or UTF16toUTF8Buffer to convert those UTF-16 strings into UTF8 strings which the Ecere API expects. As for the storage itself, you could use String ** and allocate it as such: Code: Select all
String * array = new String[numRows * numCols]; and refer to each as array[j * numCols + i]; Or you could use the Array<Array<String>>: Code: Select all
Regards, Jerome |
Author: | samsam598 [ Wed Dec 05, 2012 10:09 pm ] |
Post subject: | Re: Fetch all recordset from ODBC |
Jerome, Sorry we don't know the total NumRows until reach the end of the loop(but we know numCols before the loop): Code: Select all
|
Author: | jerome [ Thu Dec 06, 2012 12:27 am ] |
Post subject: | Re: Fetch all recordset from ODBC |
Well you could certainly count the number of rows beforehand, SQL lets you do SELECT COUNT(*)... But if you don't you can use the dynamic Array class and just use Add() to increase the size of each row. If you use just the pointer then you need to re-allocate the memory for the pointer (renew in eC: array = renew array String *[newRowCount]). -Jerome |
All times are UTC-05:00 | Page 1 of 2 |
Powered by phpBB® Forum Software © phpBB Limited |