Results 1 to 20 of 25

Thread: Load in memory the content of a database

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2010
    Location
    US, Washington State
    Posts
    54
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: Load in memory the content of a database

    Get a database management tool for your database system. Using it you can form queries to the database in an interactive way. Once you discover what queries need to be made to get the results you want then translate those queries to your application. If you're database is SQL Server based then MS has the free "Microsoft SQL Server Management Studio Express", get the version that matches your server (2005, 2008).

    What database system do you use? Someone here can probably point you to a good management tool for your particular system.
    http://en.wikipedia.org/wiki/Compari...database_tools

  2. #2
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: Load in memory the content of a database

    Quote Originally Posted by pkohut View Post
    Get a database management tool for your database system. Using it you can form queries to the database in an interactive way. Once you discover what queries need to be made to get the results you want then translate those queries to your application. If you're database is SQL Server based then MS has the free "Microsoft SQL Server Management Studio Express", get the version that matches your server (2005, 2008).

    What database system do you use? Someone here can probably point you to a good management tool for your particular system.
    http://en.wikipedia.org/wiki/Compari...database_tools
    Hi,
    I already know which query I have to do and this was not my initial question.
    Regards,
    Franco
    Franco Amato

  3. #3
    Join Date
    Dec 2010
    Location
    US, Washington State
    Posts
    54
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: Load in memory the content of a database

    Quote Originally Posted by franco.amato View Post
    Hi,
    I already know which query I have to do and this was not my initial question.
    Regards,
    Franco
    If there is no upper limit to the number of database entries, then "to read in memory the content of the database in 1 shot" is not a solution. It's possible that the current query can be reformed to work more efficient with the db. Playing what if queries in an interactive way can help with the discovery.

    I don't know what your query is or the db structure. From the description it sounds like the query is doing a brute force search. If so, then maybe this simple, far from optimized, approach could be better than the current one. There are iris codes 1 - 3, lets call them x, y, z.
    1) get collection results of everything matching x.
    2) from previous result set, get collection result of everything matching y.
    3) from previous result set, get collection result of everything matching z.
    4) Should have 1 result in collection.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Load in memory the content of a database

    Here is an example that creates an Sqlite database with 100 test rows and a series of queries against it.
    Qt Code:
    1. #include <QtCore>
    2. #include <QtSql>
    3. #include <QDebug>
    4.  
    5. void createTestData()
    6. {
    7. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    8. db.setDatabaseName("test.db");
    9. if (db.open()) {
    10.  
    11. QSqlQuery query;
    12. query.exec("create table irisdata ("
    13. "userid varchar(20), "
    14. "iriscode1 blob, "
    15. "iriscode2 blob, "
    16. "iriscode3 blob, "
    17. "primary key(userid) )");
    18. if (query.prepare( "insert into irisdata ("
    19. "userid, iriscode1, iriscode2, iriscode3) "
    20. "values (?, ?, ?, ?)" )) {
    21. for (int i=0; i<100; ++i) {
    22. QByteArray blobData1(i+1, 'a');
    23. QByteArray blobData2(i+1, 'b');
    24. QByteArray blobData3(i+1, 0x83);
    25. query.bindValue(0, QString("User %1").arg(i));
    26. query.bindValue(1, blobData1);
    27. query.bindValue(2, blobData2);
    28. query.bindValue(3, blobData3);
    29. query.exec();
    30. }
    31. }
    32. }
    33. }
    34.  
    35. void queryTestData(const QByteArray &ba)
    36. {
    37. QSqlDatabase db = QSqlDatabase::database();
    38. QSqlQuery query;
    39. if (query.prepare(
    40. "select userid from irisdata "
    41. "where iriscode1 = ? OR iriscode2 = ? or iriscode3 = ?") ) {
    42. query.bindValue(0, ba);
    43. query.bindValue(1, ba);
    44. query.bindValue(2, ba);
    45. if (query.exec()) {
    46. while (query.next())
    47. qDebug() << "Found" << query.value(0).toString();
    48. }
    49. }
    50. }
    51.  
    52. int main(int argc, char *argv[])
    53. {
    54. QCoreApplication app(argc, argv);
    55.  
    56. createTestData();
    57. queryTestData(QByteArray(3, 'a')); // user 2
    58. queryTestData(QByteArray(5, 'b')); // user 4
    59. queryTestData(QByteArray(10, 0x83)); // user 9
    60. queryTestData(QByteArray(10, 0x00)); // does not exist
    61. }
    To copy to clipboard, switch view to plain text mode 
    Should work against a Mysql or other database also.

  5. #5
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: Load in memory the content of a database

    Quote Originally Posted by wysota View Post
    To be honest such things are not done like that. This is a special case of image classification and if you want to do it fast you should use an algorithm dedicated for it. While searching three scans for ten people is not a big effort, when your database grows, the complexity of the problem grows in a non-linear manner. So basically you should either "pre-teach" your system with a static set of images (for example using neural networks) which then reduces the classification complexity practically to O(1) or use some other kind of clustering & classification heuristics to match the scans. Especially that you will never get two identical scans of the same iris due to changing environmental conditions (such as ambient light) so you will have to work on "features" and not pixel by pixel comparison anyway. I don't see how a database is helpful in any of this unless the matching algorithm is implemented as a stored procedure for it (then it's just a matter of performing a single SELECT query to find the id of the person matching the scan).

    As for what you wrote about VB - the fact that you need one line of code in your program to load all records from the database to memory doesn't mean that internally the engine is not looping over records. So if you write one line of code or four lines of code it doesn't matter as internally the same operation is performed so the one line version is not "faster" than the four line version.
    Hi Wysota.
    I don't know how a neural network can help me. IN the database I don't store iris images but only the extracted encoded iris code.
    Regards,

    Quote Originally Posted by SixDegrees View Post
    If you don't know anything about databases, how do you know if the one you're using is too slow in this case?

    More to the point: why are you trying to code a particular solution if you know nothing about how to implement the solution you've chosen?
    SixDegrees I was part of the development of the iris recognition kernel and now I would implement a demo showing the results of the matching.
    So my 'problem' is looping through the iris codes stored in the database.
    Regards


    Added after 10 minutes:


    Quote Originally Posted by ChrisW67 View Post
    Here is an example that creates an Sqlite database with 100 test rows and a series of queries against it.
    Qt Code:
    1. #include <QtCore>
    2. #include <QtSql>
    3. #include <QDebug>
    4.  
    5. void createTestData()
    6. {
    7. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    8. db.setDatabaseName("test.db");
    9. if (db.open()) {
    10.  
    11. QSqlQuery query;
    12. query.exec("create table irisdata ("
    13. "userid varchar(20), "
    14. "iriscode1 blob, "
    15. "iriscode2 blob, "
    16. "iriscode3 blob, "
    17. "primary key(userid) )");
    18. if (query.prepare( "insert into irisdata ("
    19. "userid, iriscode1, iriscode2, iriscode3) "
    20. "values (?, ?, ?, ?)" )) {
    21. for (int i=0; i<100; ++i) {
    22. QByteArray blobData1(i+1, 'a');
    23. QByteArray blobData2(i+1, 'b');
    24. QByteArray blobData3(i+1, 0x83);
    25. query.bindValue(0, QString("User %1").arg(i));
    26. query.bindValue(1, blobData1);
    27. query.bindValue(2, blobData2);
    28. query.bindValue(3, blobData3);
    29. query.exec();
    30. }
    31. }
    32. }
    33. }
    34.  
    35. void queryTestData(const QByteArray &ba)
    36. {
    37. QSqlDatabase db = QSqlDatabase::database();
    38. QSqlQuery query;
    39. if (query.prepare(
    40. "select userid from irisdata "
    41. "where iriscode1 = ? OR iriscode2 = ? or iriscode3 = ?") ) {
    42. query.bindValue(0, ba);
    43. query.bindValue(1, ba);
    44. query.bindValue(2, ba);
    45. if (query.exec()) {
    46. while (query.next())
    47. qDebug() << "Found" << query.value(0).toString();
    48. }
    49. }
    50. }
    51.  
    52. int main(int argc, char *argv[])
    53. {
    54. QCoreApplication app(argc, argv);
    55.  
    56. createTestData();
    57. queryTestData(QByteArray(3, 'a')); // user 2
    58. queryTestData(QByteArray(5, 'b')); // user 4
    59. queryTestData(QByteArray(10, 0x83)); // user 9
    60. queryTestData(QByteArray(10, 0x00)); // does not exist
    61. }
    To copy to clipboard, switch view to plain text mode 
    Should work against a Mysql or other database also.
    Hi Chris,
    your code is very interesting but the 'queryTestData' will not work because a iris code will never be the same. A matching is performed calculating the hamming distance over 2 iris codes. Something like this:
    Qt Code:
    1. if ( hamming_distance( iris_code1, iris_code2) < threshold )
    2. qDebug() << " MATCH ";
    3. else
    4. qDebug() << " NO MATCH ";
    To copy to clipboard, switch view to plain text mode 

    So I think it's mandatory to scan every code stored in the database.

    Best Regards
    Last edited by franco.amato; 31st December 2010 at 06:47.
    Franco Amato

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Load in memory the content of a database

    Are you calculating the hamming distance between the values in two columns of the same record, or between a candidate iris code and each of three columns in each record? If it is the former then you only ever need do this once and store the result.

    Have you profiled your code to make sure that it is not the hamming distance algorithm that is chewing the time? Don't waste time optimising something that is not the biggest problem.

    It is possible to provide an extension to Sqlite to give it the hamming_distance function it does not currently have. This is will be more efficient than dragging the data through Qt's Sql layers but is obviously another bunch of APIs to learn.

  7. #7
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: Load in memory the content of a database

    Quote Originally Posted by ChrisW67 View Post
    Are you calculating the hamming distance between the values in two columns of the same record, or between a candidate iris code and each of three columns in each record?
    It's between a candidate and each of the three columns in each record.

    If it is the former then you only ever need do this once and store the result.
    I didn't get you.

    Have you profiled your code to make sure that it is not the hamming distance algorithm that is chewing the time? Don't waste time optimising something that is not the biggest problem.
    The matching routine is really fast.
    My initial doubt was if I have to copy all database entry in memory and performing the matching there instead of doing n queries against the database.

    It is possible to provide an extension to Sqlite to give it the hamming_distance function it does not currently have. This is will be more efficient than dragging the data through Qt's Sql layers but is obviously another bunch of APIs to learn.
    Here we're using microsoft sql express 2005.
    Regards
    Franco Amato

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Load in memory the content of a database

    Quote Originally Posted by franco.amato View Post
    Here we're using microsoft sql express 2005.
    I'm sure it can be extended with custom functions as well.

    The first three links from Google:
    http://www.sqlteam.com/article/user-defined-functions
    http://www.sqlteam.com/article/intro...ctions-updated
    http://www.dreamincode.net/forums/to...ions-in-mssql/
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: Load in memory the content of a database

    Quote Originally Posted by wysota View Post
    Thank you very much Wysota, my head is exploting these days trying to find a solution.
    Best Regards
    Franco Amato

  10. #10
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: Load in memory the content of a database

    Quote Originally Posted by wysota View Post
    Wysota hi,
    is possible to run a routine contained in a dll directly in the database? I hope you understood what I mean.
    Best Regards
    Franco Amato

  11. #11
    Join Date
    Dec 2010
    Location
    US, Washington State
    Posts
    54
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: Load in memory the content of a database

    Quote Originally Posted by franco.amato View Post
    Wysota hi,
    is possible to run a routine contained in a dll directly in the database? I hope you understood what I mean.
    Best Regards
    Extended Stored Procedure

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Load in memory the content of a database

    Just a side note - IF the database runs on another host than the device performing the scans there is always a subject of security as I understand this iris scanning is meant to provide security. If you do the matching on a machine different than the one that actually gives the user some "access" then you have to think whether you are not making yourself vulnerable to things such as man-in-the-middle attack, a situation when an intruder substitutes the host with the database server with his own version (e.g. by rerouting you to a different machine) or simply performs a successfull attack against the host that contains the database. Since you have no control over the other host, protection against such attacks is not a trivial task.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Jan 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Load in memory the content of a database

    Quote Originally Posted by wysota View Post
    Just a side note - IF the database runs on another host than the device performing the scans there is always a subject of security as I understand this iris scanning is meant to provide security. If you do the matching on a machine different than the one that actually gives the user some "access" then you have to think whether you are not making yourself vulnerable to things such as man-in-the-middle attack, a situation when an intruder substitutes the host with the database server with his own version (e.g. by rerouting you to a different machine) or simply performs a successfull attack against the host that contains the database. Since you have no control over the other host, protection against such attacks is not a trivial task.
    To this I have to add my 2 pence. If you have to have a connection to an outside source then the best way to get around security issues would be to keep a local copy and only update from the master list nightly. To further muddle the attacker add an additional table to your data set to hold hashes specific to each terminal. If you pull an update and the hashes dont match, and a random sampling doesn't match then something is amiss.

    Local data should be sqlite while external master list can be whatever best fits, though from a safety standpoint I would bet against MS SQL. If you want security don't run the OS and DBMS by the same company. If someone wanted to break in and they knew you used windows server the safe bet would be to assume that said server will also be running MS SQL or Oracle.

    For the scan. Is this a straight scan no additional input or will there be a more traditional card swipe/id key entry along with the scan?

  14. #14
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: Load in memory the content of a database

    Quote Originally Posted by wysota View Post
    Just a side note - IF the database runs on another host than the device performing the scans there is always a subject of security as I understand this iris scanning is meant to provide security. If you do the matching on a machine different than the one that actually gives the user some "access" then you have to think whether you are not making yourself vulnerable to things such as man-in-the-middle attack, a situation when an intruder substitutes the host with the database server with his own version (e.g. by rerouting you to a different machine) or simply performs a successfull attack against the host that contains the database. Since you have no control over the other host, protection against such attacks is not a trivial task.
    Thank you very much Wysota I'll considere it.
    Regarsd
    Franco Amato

  15. #15
    Join Date
    Dec 2010
    Location
    US, Washington State
    Posts
    54
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: Load in memory the content of a database

    Quote Originally Posted by franco.amato View Post
    Hi Wysota.
    I don't know how a neural network can help me. IN the database I don't store iris images but only the extracted encoded iris code.
    Regards,

    SixDegrees I was part of the development of the iris recognition kernel and now I would implement a demo showing the results of the matching.
    So my 'problem' is looping through the iris codes stored in the database.
    Regards

    Hi Chris,
    your code is very interesting but the 'queryTestData' will not work because a iris code will never be the same. A matching is performed calculating the hamming distance over 2 iris codes. Something like this:
    Qt Code:
    1. if ( hamming_distance( iris_code1, iris_code2) < threshold )
    2. qDebug() << " MATCH ";
    3. else
    4. qDebug() << " NO MATCH ";
    To copy to clipboard, switch view to plain text mode 

    So I think it's mandatory to scan every code stored in the database.

    Best Regards
    Based on the information you've provided I'd look into storing a spatial index in the database. Queries could then be very fast. This link might be of use (refer to the excepted answer).
    http://stackoverflow.com/questions/3...mysql-database

    Given the luxury of having a whole spatial index in memory, look into adapting the Kd-tree algorithm to the data set. Iris codes 1 - 3 are treated as X, Y, Z coordinates, distance calculations would use the hammering algorithm. Then nearest neighbor and nearest range queries could be performed.

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Load in memory the content of a database

    Quote Originally Posted by franco.amato View Post
    I don't know how a neural network can help me. IN the database I don't store iris images but only the extracted encoded iris code.
    Based on the features (the "iris code" as you call it) it immediately classifies an unknown feature vector into a pre-learned set of feature sets (iris scans) without the need for looping over each iris record and performing the comparison. Then you don't even have to load the scans from the database or just load one or two to confirm the results of the algorithm.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. how to load images from phone memory
    By trupti in forum Qt Programming
    Replies: 11
    Last Post: 7th January 2011, 11:24
  2. QSqlite, multiple connections to in memory database.
    By adzajac in forum Qt Programming
    Replies: 9
    Last Post: 10th March 2010, 22:35
  3. inserting content in database
    By codeman in forum Qt Programming
    Replies: 2
    Last Post: 3rd June 2009, 16:47
  4. Load textfile content into a textEdit
    By gt.beta2 in forum Newbie
    Replies: 1
    Last Post: 3rd March 2009, 22:57
  5. Load menu from database
    By daica2003 in forum Qt Programming
    Replies: 5
    Last Post: 11th May 2008, 18:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.