813 | | uint max_db_val = query.value(0).toInt() + 1; |
814 | | return max(max_db_val, desired_chanid = sourceid * 1000 + 1); |
| 813 | desired_chanid = max((uint)(query.value(0).toInt() + 1), sourceid * 1000); |
| 814 | |
| 815 | query.prepare( |
| 816 | QString("SELECT chanid FROM channel " |
| 817 | "WHERE chanid = '%1'").arg(desired_chanid)); |
| 818 | if (!query.exec() || !query.isActive()) |
| 819 | { |
| 820 | MythContext::DBError("Getting chanid for new channel (3)", query); |
| 821 | return -1; |
| 822 | } |
| 823 | if (query.size() == 0) |
| 824 | return desired_chanid; |
| 825 | |
| 826 | query.prepare("SELECT MAX(chanid) FROM channel"); |
| 827 | if (!query.exec() || !query.isActive()) |
| 828 | { |
| 829 | MythContext::DBError("Getting chanid for new channel (4)", query); |
| 830 | return -1; |
| 831 | } |
| 832 | if (!query.next()) |
| 833 | { |
| 834 | VERBOSE(VB_IMPORTANT, "Can't find largest existing chanid."); |
| 835 | return -1; |
| 836 | } |
| 837 | return query.value(0).toInt() + 1; |