Handling Duplicate Records in SQL

This happens a lot (to me at least 🙂 ) so I decided to make a note here!

Following SQL script will allow you to SELECT duplicate records in a given table.

SELECT * FROM my_table WHERE some_field IN (SELECT some_field FROM my_table GROUP BY some_field HAVING COUNT(some_field) > 1)

This code actually finds all the records in a table named “my_table” which have the same value for a field (or column) named “some_field” in more than 1 records which is specified in the final clause COUNT(some_field) > 1

To delete (remove) duplicate records you only need to change “SELECT *” to “DELETE”.

DELETE FROM my_table WHERE some_field IN (SELECT some_field FROM my_table GROUP BY some_field HAVING COUNT(some_field) > 1)

Add Administrator Level Privileges to Your Qt Program

Include the following in your project’s PRO file to have Administrator level privileges added to your program.

Following should be noted while using this:
1. This will only work if you are using a Microsoft Visual C++ compiler and Windows OS
2. Your OS might ask you for Administrator password or confirmation when you try to run your executable. This depends on how your OS is configured.
3. Qt Creator needs to be started as Administrator in order to run a program (for debugging) that has the following lines in its PRO file.

win32-msvc* {
    CONFIG += embed_manifest_exe
    QMAKE_LFLAGS_WINDOWS += $$quote( /MANIFESTUAC:\"level=\'requireAdministrator\' uiAccess=\'false\'\" )
}


How to build Qt 5.5 Static Libraries using any Microsoft Visual C++ Compiler

Following steps will help you with building Qt 5.5 Static Libraries with any MSVC Compiler. I have used MSVC2010 in this example but it should be the same for any compiler version from 2005 to 2015 (Visual Studio 2005 (8.0), VC++ 14.0)

Note that building Qt like this will remove all dependencies meaning there won’t be any need for MSVC dlls)

Continue reading “How to build Qt 5.5 Static Libraries using any Microsoft Visual C++ Compiler”

Introduction to Support Vector Machines OpenCV 3.0.0 Example (Working version)

Following is the slightly modified version of the example for “Introduction to Support Vector Machines” that is working with OpenCV v.3.0.0 (Current version on OpenCV website only works with version 2.4.X)

I assume that you have installed OpenCV 3.0.0 on your computer successfully and you know how to add library references etc. If you have any questions please put a comment or use the “Contact Me” page.

Continue reading “Introduction to Support Vector Machines OpenCV 3.0.0 Example (Working version)”

Add version information to your executables and libraries in Qt

Executable files have an embedded version information which can be found by checking their properties. It includes version number, comments, company info etc. As developer you sometimes need to leave a scratch on the EXE files you are providing to your customers in order to track what you have and what your customers have.

Continue reading “Add version information to your executables and libraries in Qt”

How to use Windows API in Qt (A simple example)

Qt is a cross-platform framework that encapsulates API across many Operating Systems but one always faces situations in which he/she needs to access and use OS specific capabilities. Windows API is a massive collection of interfaces that allow a programmer to use and include Windows features in their programs.  Below is a simple example on how to use Windows API in Qt.

Let’s say we want to use GetSystemTime function in our Qt program. Searching Google for “GetSystemTime API” you’ll get the API Documentation from MSDN website. Parameters and return type values should be obvious:

Continue reading “How to use Windows API in Qt (A simple example)”

How to convert date formats in SQLite

Date types are handled like a string in SQLite and below is an example of how to change the date format from MM/dd/yyyy to yyyy-MM-dd. With a little modification it can be used for other formats too.

select substr(column, 7, 4)||”-“||substr(column, 1,2)||”-“||substr(column, 4,2) from table