GithubHelp home page GithubHelp logo

jrvansuita / sqlitehelper Goto Github PK

View Code? Open in Web Editor NEW
58.0 7.0 17.0 109 KB

πŸ—„ This project comes in handy when you want to write a sql statement easily and smarter.

License: MIT License

Java 100.00%
sqlitehelper sql android sqlite sqlite3 sqlite-database query update delete insert

sqlitehelper's Introduction

Buy Me a Coffee at ko-fi.com

Release Android Arsenal

SQLiteHelper

This Parser comes in handy when you want to write a sql statement easily and smarter.

#Porpouse

Make things easy when you need to write a sql statment for Android SQLite.

Usage

Step 1. Add the JitPack repository to your build file:

allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
	}
}

Step 2. Add the dependency

dependencies {
        compile 'com.github.jrvansuita:SQLiteHelper:v1.0.0'
}

Samples

You can take a look at the sample app located on this project.

Implementation

Select

Working with columns.
SqlParser.query()
   .col("A")
   .col("B")
   .col("C", "NICK")
   .col("ALIAS","D", "NICK")
   .cols("E", "F", "G")
   .sum("H").count()
   .max("I")
   .table("YOUR_TABLE", "T")
   .build();

Output: SELECT A, B, C AS NICK, ALIAS.D AS NICK, E, F, G, SUM(H), COUNT(*), MAX(I) FROM YOUR_TABLE T

More than one table.
 SqlParser.query()
    .col("P", "NAME", "PRODUCT_NAME")
    .col("C", "NAME", "COLOR_NAME")
    .table("PRODUCT", "P")
    .table("COLOR", "C")
    .equal("P", "IDCOLOR", "C","ID")
    .build();

Output: SELECT P.NAME AS PRODUCT_NAME, C.NAME AS COLOR_NAME FROM PRODUCT P, COLOR C WHERE P.IDCOLOR = C.ID

Exists or not exists.
    SqlParser.query()
       .table("TABLE", "T")
       .exists(Sql.query().table("XTABLE", "XT").equal("XT", "FIELD", "T","FIELD").build())
       .notExists(Sql.query().table("YTABLE", "YT").equal("YT", "FIELD", "T","FIELD").build())
       .build();

Output: SELECT * FROM TABLE T WHERE EXISTS (SELECT * FROM XTABLE XT WHERE XT.FIELD = T.FIELD) NOT EXISTS (SELECT * FROM YTABLE YT WHERE YT.FIELD = T.FIELD)

Greater, smaller, equal, trim.
  SqlParser.query()
     .table("TABLE")
     .greater("THE_COLUMN" , 9)
     .and()
     .smallerEqual("THE_COLUMN", 40)
     .or()
     .equalTrim("TEST", " RAW ")
     .like("TEST2", "%fox%")
     .build();

Output: SELECT * FROM TABLE WHERE THE_COLUMN > 9 AND THE_COLUMN <= 40 OR TRIM(TEST) = 'RAW'

Delete.

 SqlParser.delete("TABLE").smallerEqual("COL", 0).build();     

Output: DELETE FROM TABLE WHERE COL <= 0

Insert.

  SqlParser.insert("TABLE")
     .col("A", 1)
     .col("B", "TEST")
     .build();

Output: INSERT INTO TABLE(A,B) VALUES(1,'TEST');

Create.

 SqlParser.create("TABLE")
            .pk("ID")
            .num("CODE")
            .num("TYPE")
            .flo("PRICE")
            .flo("QUANTITY")
            .build();

Output: CREATE TABLE TABLE (ID INTEGER PRIMARY KEY,CODE INTEGER,TYPE INTEGER,PRICE FLOAT,QUANTITY FLOAT);

Cursor.

 Cursor cp = SqlParser.cursor(yourCursor);

    if (cp.binded()) 
        Product product = new Product(cp.num("ID")
                                    , cp.num("CODE")
                                    , cp.flo("STOCK")
                                    , cp.flo("")
                                    , cp.str("NAME"));

ContentValues.

 SqlParser.content().add("NAME", "John")
	          .add("CITY", "New York")
    		  .add("STATE", "New Jersey");

Update

    ContentValues cv =  SqlParser.content().add("NAME", "John")
	          .add("CITY", "New York")
    		  .add("STATE", "New Jersey").get();

     yourDb.update(tableName, cv, rowId + " = ?", new String[]{String.valueOf(yourId)});
Instagram Github Google Play Store E-mail

sqlitehelper's People

Contributors

etemplar avatar jrvansuita avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sqlitehelper's Issues

Modify the "Android Arsenal" Description

for now you have

Please, change the SQLiteParser project to this project. I sumitted the SQLiteParser project last week, but I had some problems with maven and I had to move the project to another repository.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.