Applications return an error code in which 0 is 'The operation completed successfully' and other values are pre-defined error codes. If your function only returns SUCCESS or FAILURE (like the code snippet), then the closest match to these would be TRUE and FALSE. You could typedef these values as follows:
typedef enum {FAILURE = 0, SUCCESS = !FAILURE} ErrorStatus;
typedef enum {FAILURE = 0, SUCCESS = !FAILURE} ErrorStatus;
To copy to clipboard, switch view to plain text mode
COUNT(*) will retrieve all rows matching your condition (in your case, all rows, as you have no limits placed, so it will become slower over time and not scale well). It will then validate that the rows actually contain data. I'm sure when you created your schema that some fields you used the "NOT NULL" restriction to ensure they had data.
COUNT(1) doesn't care if the rows contain data or not, only that they exist.
Since your code only requires that at least one row exists, you could take it further:
SELECT COUNT(1) FROM tempinvoiceentries LIMIT 1
SELECT COUNT(1) FROM tempinvoiceentries LIMIT 1
To copy to clipboard, switch view to plain text mode
This will always take the same amount of time to execute regardless of how many entries are in your table.
Bookmarks