Example usage for android.database.sqlite SQLiteDatabase insert

List of usage examples for android.database.sqlite SQLiteDatabase insert

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteDatabase insert.

Prototype

public long insert(String table, String nullColumnHack, ContentValues values) 

Source Link

Document

Convenience method for inserting a row into the database.

Usage

From source file:Main.java

private static void insertGymPlan(SQLiteDatabase db, String machineName, String machineSteps,
        int machineImageId) {
    ContentValues gymPlanValues = new ContentValues();
    gymPlanValues.put("MACHINE_NAME", machineName);
    gymPlanValues.put("EXCERCISE_STEPS", machineSteps);
    gymPlanValues.put("MACHINE_IMAGE_ID", machineImageId);
    db.insert("GYMPLAN", null, gymPlanValues);
}

From source file:Main.java

/**********************************************************************************************
 *
 *       Helper method to insert items into the individual muscle group tables of the database
 *
 *********************************************************************************************/
private static void insertLift(SQLiteDatabase db, String name, String description, String searchLink,
        String image_id, String muscleGroup) {
    ContentValues lift = new ContentValues();
    lift.put("NAME", name);
    lift.put("DESCRIPTION", description);
    lift.put("SEARCH_LINK", searchLink);
    lift.put("IMAGE_RESOURCE_ID", image_id);
    db.insert(muscleGroup, null, lift);
}

From source file:Main.java

public static void insertCompany(SQLiteDatabase db, String name, String email, String password, String phone,
        String address) {/*  www.  j  ava  2 s  .  co  m*/
    ContentValues companyValues = new ContentValues();
    companyValues.put("NAME", name);
    companyValues.put("EMAIL", email);
    companyValues.put("PASSWORD", password);
    companyValues.put("PHONE", phone);
    companyValues.put("ADDRESS", address);
    companyValues.put("ACTIVO", "ACTIVO");

    db.insert("COMPANY", null, companyValues);
}

From source file:Main.java

public static void insert(SQLiteDatabase db, String title, String pubdate, String itemDetail, String link,
        String firstImgUrl, String sectionTitle) {
    ContentValues values = new ContentValues();
    values.put("title", title);
    values.put("pubdate", pubdate);
    values.put("item_detail", itemDetail);
    values.put("link", link);
    values.put("first_img_url", firstImgUrl);
    values.put("table_name", sectionTitle);
    db.insert("favorite_item", null, values);
    db.close();/*from   w w  w .  ja v a 2  s.  c o m*/
}

From source file:Main.java

public static void insertEstablishment(SQLiteDatabase db, String name, String email, String password,
        String phone, String address, String waste) {
    ContentValues establishmentValues = new ContentValues();
    establishmentValues.put("NAME", name);
    establishmentValues.put("EMAIL", email);
    establishmentValues.put("PASSWORD", password);
    establishmentValues.put("PHONE", phone);
    establishmentValues.put("ADDRESS", address);
    establishmentValues.put("WASTE", waste);
    establishmentValues.put("ACTIVO", "ACTIVO");
    db.insert("ESTABLISHMENT", null, establishmentValues);
}

From source file:Main.java

private static void insertDepartment(SQLiteDatabase db, String name, double coordinateX, double coordinateY,
        String city, String address, String[] telephoneNumbers, String workingHours) {
    ContentValues valuesDepartment = new ContentValues();
    valuesDepartment.put("NAME", name);
    valuesDepartment.put("COORDINATE_X", coordinateX);
    valuesDepartment.put("COORDINATE_Y", coordinateY);
    valuesDepartment.put("CITY", city);
    valuesDepartment.put("ADDRESS", address);
    valuesDepartment.put("WORKING_HOURS", workingHours);
    long idInsertedDepartment = db.insert("DEPARTMENT", null, valuesDepartment);
    for (String number : telephoneNumbers) {
        ContentValues valuesNumbers = new ContentValues();
        valuesNumbers.put("DEPARTMENT_ID", idInsertedDepartment);
        valuesNumbers.put("TELEPHONE", number);
        db.insert("TELEPHONE", null, valuesNumbers);
    }//from   ww  w. j  a v a  2  s .co  m
}

From source file:Main.java

public static void insertContainer(SQLiteDatabase db, String nameContainer, String latlong,
        String establishmentName, String companyName, String estado, String activo, String waste) {
    ContentValues containerValues = new ContentValues();
    containerValues.put("NAME_CONTAINER", nameContainer);
    containerValues.put("LATLONG", latlong);
    containerValues.put("ESTABLISHMENT", establishmentName);
    containerValues.put("COMPANY", companyName);
    containerValues.put("ESTADO", estado);
    containerValues.put("ACTIVO", activo);
    containerValues.put("WASTE", waste);
    db.insert("CONTAINER", null, containerValues);
}

From source file:org.thinschema.dataaccess.JSONAdapter.java

/**
 * Fill a table with data from a JSON. The JSON must contain an array of
 * JSON named 'rows', where each JSON represents one row (or record)
 * in the database.//from  w w  w  . j a  v a 2 s .  c om
 *
 * @param sqLiteDatabase SQLiteDatabase instance.
 * @param dbSchema       Database schema.
 * @param tableName      Table name.
 * @param jsonData       JSONObject
 * @return true if insertion is successful.
 */
public static boolean fill(SQLiteDatabase sqLiteDatabase, DBSchema dbSchema, String tableName,
        JSONObject jsonData) {
    boolean success = true;
    JSONArray data = jsonData.optJSONArray("rows");

    sqLiteDatabase.beginTransaction();
    try {
        if (data != null && data.length() > 0) {
            for (int i = 0, size = data.length(); i < size; ++i) {
                JSONObject row = data.optJSONObject(i);
                ContentValues cv = toContentValues(row, dbSchema, tableName);
                if (sqLiteDatabase.insert(tableName, null, cv) == -1) {
                    success = false;
                    break;
                }
            }
        }

        if (success) {
            sqLiteDatabase.setTransactionSuccessful();
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        sqLiteDatabase.endTransaction();
    }
    return success;
}

From source file:Main.java

private static void insertDisease(SQLiteDatabase db, String diseaseName, String diseaseSymptoms,
        String diseaseOverview, String diseaseExpectations, String diseaseRiskFactors, String diseaseTreatment,
        String diseaseSelfCare, String diseaseMAdeWorseBy) {
    ContentValues diseaseValues = new ContentValues();
    diseaseValues.put("NAME", diseaseName);
    diseaseValues.put("SYMPTOMS", diseaseSymptoms);
    diseaseValues.put("OVERVIEW", diseaseOverview);
    diseaseValues.put("EXPECTATIONS", diseaseExpectations);
    diseaseValues.put("RISKFACTORS", diseaseRiskFactors);
    diseaseValues.put("TREATMENT", diseaseTreatment);
    diseaseValues.put("SELFCARE", diseaseSelfCare);
    diseaseValues.put("MADEWORSEBY", diseaseMAdeWorseBy);
    db.insert("DISEASE", null, diseaseValues);
}

From source file:net.zionsoft.obadiah.model.translations.TranslationHelper.java

public static void saveBookNames(SQLiteDatabase db, JSONObject booksInfoObject) throws Exception {
    final String translationShortName = booksInfoObject.getString("shortName");
    final ContentValues bookNamesValues = new ContentValues(3);
    bookNamesValues.put(DatabaseHelper.COLUMN_TRANSLATION_SHORT_NAME, translationShortName);
    final JSONArray booksArray = booksInfoObject.getJSONArray("books");
    for (int i = 0; i < Bible.getBookCount(); ++i) {
        bookNamesValues.put(DatabaseHelper.COLUMN_BOOK_INDEX, i);

        final String bookName = booksArray.getString(i);
        if (TextUtils.isEmpty(bookName))
            throw new Exception("Illegal books.json file: " + translationShortName);
        bookNamesValues.put(DatabaseHelper.COLUMN_BOOK_NAME, bookName);

        db.insert(DatabaseHelper.TABLE_BOOK_NAMES, null, bookNamesValues);
    }/*  w  w w. j ava  2s  .  co m*/
}