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 8084321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:45:30+00:00 2026-06-05T17:45:30+00:00

I am newbie to SQLite and I don’t know how to sort by fields.

  • 0

I am newbie to SQLite and I don’t know how to sort by fields. I searched to use “ORDER BY”, but I cannot do it well. I have a class to implement the SQLite functions as follow:

public class PLSQLiteOpenHelper extends SQLiteOpenHelper{
public String TableNames[];
public String FieldNames[][];
public String FieldTypes[][];
public static String NO_CREATE_TABLES = "no tables";
private String message = "";

public PLSQLiteOpenHelper(Context context, String name, CursorFactory factory, int version, String tableNames[], String fieldNames[][], String fieldTypes[][]) {
    super(context, name, factory, version);
    TableNames = tableNames;
    FieldNames = fieldNames;
    FieldTypes = fieldTypes;
}

@Override
public void onCreate(SQLiteDatabase db) {
    if(TableNames == null){
        message = NO_CREATE_TABLES;
        return;
    }

    for(int i = 0; i < TableNames.length; i++){
        String sql = "CREATE TABLE " + TableNames[i] + "(";
        for(int j = 0; j < FieldNames[i].length; j++)
            sql += FieldNames[i][j] + " " + FieldTypes[i][j] + ",";
        sql = sql.substring(0, sql.length() - 1);
        sql += ")";
        db.execSQL(sql);
    }
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    for(int i = 0; i < TableNames[i].length(); i++){
        String sql = "DROP TABLE IF EXISTS " + TableNames[i];
        db.execSQL(sql);
    }
    onCreate(db);
}

public void execSQL(String sql) throws java.sql.SQLException{
    SQLiteDatabase db = this.getWritableDatabase();
    db.execSQL(sql);
}

public Cursor select(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy){
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy);
    return cursor;
}

public long insert(String table, String fields[], String values[]){
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues cv = new ContentValues();
    for(int i = 0; i < fields.length; i++)
        cv.put(fields[i], values[i]);
    return db.insert(table, null, cv);
}

public int sort(String table, String updateFields[], String orderBy){
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.query(table, updateFields, null, null, null, null, orderBy);

    ContentValues cv = new ContentValues();
    int i = 0;
    while(cursor.moveToNext()){
        cv.putNull(updateFields[i]);
        i++;
    }
    return db.update(table, cv, null, null);
}

public int delete(String table, String where, String[] whereValue){
    SQLiteDatabase db = this.getWritableDatabase();
    return db.delete(table, where, whereValue);
}

public int update(String table, String updateFields[], String updateValues[], String where, String[] whereValue){
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues cv = new ContentValues();
    for(int i = 0; i < updateFields.length; i++)
        cv.put(updateFields[i], updateValues[i]);
    return db.update(table, cv, where, whereValue);
}

public String getMessage(){
    return message;
}

@Override
public synchronized void close(){
    super.close();
}
}

I know that I need to use the “select” & “update” function together, but I don’t know how to call them in order to sort the table by a field name. Anyone can tell me the function call order with the follow information?

Table Names: "t_passwordlist"
Field Names: "f_id", "f_service", "f_user", "f_pwd", "f_lanuch"
Field Types: "INTEGER PRIMARY KEY AUTOINCREMENT", "text", "text", "text", "text"
Order By: "f_service"
  • 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-05T17:45:32+00:00Added an answer on June 5, 2026 at 5:45 pm

    Create an object of your helper class and then call the method this way.

    Cursor cursor = pLSQLiteOpenHelper.select("table_name", new String[] { "f_id", "f_service", "f_user", "f_pwd", "f_lanuch" }, null, null, null, null, "f_service");
    

    Hope this helps.

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

Sidebar

Related Questions

Total newbie here, regarding sqlite, so don't flame too hard :) I have a
Newbie question here but for some reason I cant figure this out. I have
Newbie-Problem: I have a small test-class (TestLibMain.cpp) in c++ an compiled it to a
I was newbie in using sqlite database android. and now I have a problem
Newbie Warning I have a simple but vexing problem trying to disable an NSButton.
Newbie asking for help: I have an array of numbers that needs to be
Newbie question... The objective: I intend to have an HTML text input field as
another iPhone newbie question... I have the following: NSPersistentStoreCoordinator NSManagedObjectContext NSManagedObjectModel Is it possible
I have been using the System.Data.SQLite provider for my application. When I try to
Newbie question. I am trying to use ActiveRecord::Base.connection.execute(..) in a ruby 3.1 app and

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.