|
22 | 22 | public class OrmaDatabase |
23 | 23 | { |
24 | 24 | private static final String TAG = "sorm.OrmaDatabase"; |
25 | | - public static final String OrmaDatabaseVersion = "1.0.1"; |
| 25 | + public static final String OrmaDatabaseVersion = "1.0.2"; |
26 | 26 |
|
27 | 27 | final static boolean ORMA_TRACE = false; // set "false" for release builds |
28 | 28 | final static boolean ORMA_LONG_RUNNING_TRACE = false; // set "false" for release builds |
@@ -768,6 +768,83 @@ public static String run_query_for_single_result(String sql_query) |
768 | 768 | return text_result; |
769 | 769 | } |
770 | 770 |
|
| 771 | + public static long run_query_for_single_result_l(String sql_query) |
| 772 | + { |
| 773 | + long long_result = 0L; |
| 774 | + |
| 775 | + orma_global_sqlfreehand_lock.lock(); |
| 776 | + try |
| 777 | + { |
| 778 | + Statement statement = null; |
| 779 | + try |
| 780 | + { |
| 781 | + statement = sqldb.createStatement(); |
| 782 | + statement.setQueryTimeout(10); // set timeout to x sec. |
| 783 | + } |
| 784 | + catch (Exception e) |
| 785 | + { |
| 786 | + Log.i(TAG, "ERR:QSLL:001:" + e.getMessage()); |
| 787 | + } |
| 788 | + |
| 789 | + try |
| 790 | + { |
| 791 | + if (ORMA_TRACE) |
| 792 | + { |
| 793 | + Log.i(TAG, "sql=" + sql_query); |
| 794 | + } |
| 795 | + ResultSet rs = statement.executeQuery(sql_query); |
| 796 | + if (rs.next()) |
| 797 | + { |
| 798 | + long_result = rs.getLong(1); |
| 799 | + } |
| 800 | + rs.close(); |
| 801 | + } |
| 802 | + catch (Exception e) |
| 803 | + { |
| 804 | + Log.i(TAG, "ERR:QSLL:002:" + e.getMessage()); |
| 805 | + } |
| 806 | + |
| 807 | + try |
| 808 | + { |
| 809 | + statement.close(); |
| 810 | + } |
| 811 | + catch (Exception e) |
| 812 | + { |
| 813 | + Log.i(TAG, "ERR:QSLL:003:" + e.getMessage()); |
| 814 | + } |
| 815 | + } |
| 816 | + catch (Exception e) |
| 817 | + { |
| 818 | + Log.i(TAG, "ERR:QSLL:004:" + e.getMessage()); |
| 819 | + } |
| 820 | + finally |
| 821 | + { |
| 822 | + orma_global_sqlfreehand_lock.unlock(); |
| 823 | + } |
| 824 | + |
| 825 | + return long_result; |
| 826 | + } |
| 827 | + |
| 828 | + public static String now_datetime_utc() |
| 829 | + { |
| 830 | + return run_query_for_single_result("select datetime('now')"); |
| 831 | + } |
| 832 | + |
| 833 | + public static String now_datetime_localtime() |
| 834 | + { |
| 835 | + return run_query_for_single_result("select datetime('now','localtime')"); |
| 836 | + } |
| 837 | + |
| 838 | + public static long now_unixepoch_utc() |
| 839 | + { |
| 840 | + return run_query_for_single_result_l("select unixepoch('now')"); |
| 841 | + } |
| 842 | + |
| 843 | + public static long now_unixepoch_localtime() |
| 844 | + { |
| 845 | + return run_query_for_single_result_l("select unixepoch('now','localtime')"); |
| 846 | + } |
| 847 | + |
771 | 848 | public static boolean set_bindvars_where(final PreparedStatement statement, |
772 | 849 | final int bind_where_count, |
773 | 850 | final List<OrmaBindvar> bind_where_vars) |
|
0 commit comments