-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
186 additions
and
138 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.msbilgin.sqlkolayexample; | ||
|
||
import java.util.Date; | ||
|
||
public class Book { | ||
public int id; | ||
public String name; | ||
public String author; | ||
public String publishDate; | ||
public double price; | ||
|
||
public Book() { | ||
} | ||
|
||
public Book(String name, String author, String publishDate, double price) { | ||
this.name = name; | ||
this.author = author; | ||
this.publishDate = publishDate; | ||
this.price = price; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
app/src/main/java/com/msbilgin/sqlkolayexample/TableBooks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.msbilgin.sqlkolayexample; | ||
|
||
import android.content.ContentValues; | ||
import android.database.Cursor; | ||
|
||
import com.msbilgin.sqlkolay.Column; | ||
import com.msbilgin.sqlkolay.Table; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class TableBooks extends Table { | ||
private static final String tableName = "BOOKS"; | ||
|
||
@Column(type = Column.Type.INTEGER_AUTOINC, primary = true) | ||
private Column id; | ||
|
||
private Column name; | ||
private Column author; | ||
|
||
@Column(type = Column.Type.NUMBER) | ||
private Column date; | ||
|
||
@Column(type = Column.Type.REAL) | ||
private Column price; | ||
|
||
public TableBooks() { | ||
super(tableName); | ||
} | ||
|
||
public void add(Book book) { | ||
ContentValues values = new ContentValues(); | ||
values.put("name", book.name); | ||
values.put("author", book.author); | ||
values.put("date", book.publishDate); | ||
values.put("price", book.price); | ||
insert(null, values); | ||
} | ||
|
||
public Book getByID(int id) { | ||
Book book = new Book(); | ||
|
||
String sql = String.format("select * from %s where id=%s", tableName, id); | ||
Cursor cursor = getDB().rawQuery(sql, null); | ||
if (cursor.moveToFirst()) { | ||
book.id = cursor.getInt(cursor.getColumnIndex("id")); | ||
book.name = cursor.getString(cursor.getColumnIndex("name")); | ||
book.author = cursor.getString(cursor.getColumnIndex("author")); | ||
book.price = cursor.getDouble(cursor.getColumnIndex("price")); | ||
book.publishDate = cursor.getString(cursor.getColumnIndex("date")); | ||
} | ||
return book; | ||
} | ||
|
||
public List<Book> getByAuthor(String author) { | ||
List<Book> books = new ArrayList<>(); | ||
String sql = "select * from " + tableName + " where author like '%" + author + "%'"; | ||
|
||
Cursor cursor = getDB().rawQuery(sql, null); | ||
if (cursor.moveToFirst()) { | ||
do { | ||
Book book = new Book(); | ||
book.id = cursor.getInt(cursor.getColumnIndex("id")); | ||
book.name = cursor.getString(cursor.getColumnIndex("name")); | ||
book.author = cursor.getString(cursor.getColumnIndex("author")); | ||
book.price = cursor.getDouble(cursor.getColumnIndex("price")); | ||
book.publishDate = cursor.getString(cursor.getColumnIndex("date")); | ||
books.add(book); | ||
} while (cursor.moveToNext()); | ||
} | ||
return books; | ||
} | ||
|
||
public void remove(int id) { | ||
delete("id=" + id, null); | ||
} | ||
} |
57 changes: 0 additions & 57 deletions
57
app/src/main/java/com/msbilgin/sqlkolayexample/TableUser.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.