SQLiteHelper


Source link: https://github.com/jrvansuita/SQLiteHelper

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)
}
);
 

Resources

Celebrate more with this lightweight confetti particle system 🎊 Create realistic confetti by implementing this easy to use library.

A library for draggable boardview.

Kloud is a Kotlin implementation of a new architecture idea that I named cloud, it's based on system communication without any type of instance reference or static properties, in a robust, simple and reactive way.

It is a debugging tool for measuring simple network traffic.

A simple cache for android.

Time picker for Android to type in a time.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes