Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8127005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:21:52+00:00 2026-06-06T07:21:52+00:00

Right now, I have my code looking like this: SqlTables.java: // Separate file public

  • 0

Right now, I have my code looking like this:

SqlTables.java:

// Separate file
public enum SqlTables {
    TABLE_1("table_1"),
    .
    .
    .
    TABLE_N("table_n");
    final String name;
    private SqlTables(String name) {
        this.name = name;
    }
}

Table1Columns.java:

// Separate file
public enum Table1Columns {
    ...
}

SqlDatabaseInterface.java:

Cursor c = db.query(SqlTables.TABLE_1.toString(), null...);
final int indexId = c.getColumnIndexOrThrow(
        Table1Columns.ID.toString());
final int indexName = c.getColumnIndexOrThrow(
        Table1Columns.NAME.toString());
while (c.moveToNext()) {
    final String id = c.getString(indexId);
    final String name = c.getString(indexName);
}

I did not find any documentation regarding how Android mapped columns to indices, so while I’ve confirmed that it is based on the order in which the columns were stated in the query, I do not have a guarantee that this will work 100% of the time, or that future updates will keep this behavior. The benefits of using getColumnIndexOrThrow(...) is the guarantee that my indices will always be correct, so long as the columns they reference are included in the query. The downside is that, besides the tedium, it makes my code much harder to read and greatly increases the length of my methods. On the other hand, I could just specify the indices without calling getColumnsIndexOrThrow, and that’d shorten my code, but the lack of documentation makes it feel wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:21:53+00:00Added an answer on June 6, 2026 at 7:21 am

    No, you definitely should not hard code the column index values into your code. If you do, your database will be nearly impossible to manage (since making changes to the table could cause the index values to change).

    From what I can tell, your code is difficult to read because:

    1. You are literring your code with unnecessary calls to toString(). Just get rid of them… they are completely redundant.

    2. You are using the final keyword way too much and its cluttering your code. This should be used as a precaution in situations where you might accidentally change the value of a variable. This is not one of those situations…

    3. You are spreading simple statements across multiple lines. Just use one line and it’ll make it a lot easier to read.

    That said, there is technically nothing wrong with any of the above coding practices. I’m just saying, if you really care about making your code easy to read then you might want to consider them as suggestions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now, I have code that looks something like this: Private Sub ShowReport(ByVal reportName
I have this code right now to get the row value from jquery grid..
Right now, I have this code where $obj_arr maybe contain array and an object.
I wish to make something looking like this: http://img291.imageshack.us/img291/5571/bartablestyling.png (Right now i only have
Right now I have the following code working: @UiHandler(usernameTextBox) void onUsernameTextBoxKeyPress(KeyPressEvent event) { keyPress(event);
Right now i have a line of code, in vb, that calls a text
I have some code right now that executes when a link is clicked. The
I have some code that shows results in a table Right now it will
I have my core web-app code in the header right now in a tag
I have some code that does something like this (Irrelevant bits snipped): void foo(Bitmap

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.