Giter VIP home page Giter VIP logo

android-db's Introduction

Examples of using the DB objects (from an activity)

// First let's find out if they exist
UsersDB db = new UsersDB(this);
db.open();
ContentValues v = db.fetchOne(UsersDB.KEY_CODE+" = ? AND "+UsersDB.KEY_BUSINESS+" = ?", new String[]{userCode, mCode});

// We need to create a new local record
long user_id;
if(v.size() == 0) {
	HashMap<String,String> values = new HashMap<String,String>();
	values.put(UsersDB.KEY_BUSINESS, mCode);
	values.put(UsersDB.KEY_CODE, userCode);
	values.put(UsersDB.KEY_USED, "1");
	user_id = db.create(values);
} else {
	user_id = v.getAsLong(UsersDB.KEY_ROWID);
	used = v.getAsInteger(UsersDB.KEY_USED);
	used++;
	v.put(UsersDB.KEY_USED, used);
	db.update(v.getAsInteger(UsersDB.KEY_ROWID), v);
}

Cursor res = db.fetch(UsersDB.KEY_BUSINESS+" = 1");
if(res != null) {
	while(!res.isAfterLast()) {
		String code = res.getString(res.getColumnIndex(UsersDB.KEY_CODE));
		int used = res.getInt(res.getColumnIndex(UsersDB.KEY_USED));
		
		// Do something

		res.moveToNext();
	}
	res.close();
}

db.truncate();

db.delete(user_id);

db.close();

android-db's People

Contributors

methodin avatar

Watchers

 avatar  avatar

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.