Thanks Anm, but I'm looking for something diferent, i want to create a
class like this(I got it from android example):
public class base extends ContentProvider {
private static final String TAG = "Base";
private static final String DATABASE_NAME = "base.db";
private static final int DATABASE_VERSION = 2;
private static final String POINTS_TABLE_NAME = "points";
// private static final String CITY_TABLE_NAME = "city";
// private static final String CATEGORY_TABLE_NAME = "category";
private static HashMap<String, String> sNotesProjectionMap;
private static final int POINTS = 1;
private static final int POINT_ID = 2;
private static final UriMatcher sUriMatcher;
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + POINTS_TABLE_NAME + " ("
+ Points._ID + " INTEGER PRIMARY KEY,"
+ Points.NOMBRE + " TEXT,"
+ Points.DESCRIPCION + " TEXT,"
+ Points.DIRECCION + " TEXT,"
+ Points.ALTITUD + " TEXT,"
+ Points.ID_CAT + " TEXT,"
+ Points.ID_CIUDAD + " TEXT,"
+ Points.LATITUD + " TEXT,"
+ Points.LONGUITUD + " TEXT,"
+ Points.URL + " TEXT,"
+ Points.TELEFONO + " TEXT"
+ ");");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion
+ " to "
+ newVersion + ", which will destroy all old
data");
db.execSQL("DROP TABLE IF EXISTS notes");
onCreate(db);
}
}
private DatabaseHelper mOpenHelper;
@Override
public boolean onCreate() {
mOpenHelper = new DatabaseHelper(getContext());
return true;
}
@Override
public Cursor query(Uri uri, String[] projection, String
selection, String[] selectionArgs,
String sortOrder) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
switch (sUriMatcher.match(uri)) {
case POINTS:
qb.setTables(POINTS_TABLE_NAME);
qb.setProjectionMap(sNotesProjectionMap);
break;
case POINT_ID:
qb.setTables(POINTS_TABLE_NAME);
qb.setProjectionMap(sNotesProjectionMap);
qb.appendWhere(Points._ID + "=" +
uri.getPathSegments().get(1));
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
// If no sort order is specified use the default
String orderBy;
if (TextUtils.isEmpty(sortOrder)) {
orderBy = tablas.Points.DEFAULT_SORT_ORDER;
} else {
orderBy = sortOrder;
}
// Get the database and run the query
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
Cursor c = qb.query(db, projection, selection, selectionArgs,
null, null, orderBy);
// Tell the cursor what uri to watch, so it knows when its
source data changes
c.setNotificationUri(getContext().getContentResolver(), uri);
return c;
}
@Override
public String getType(Uri uri) {
switch (sUriMatcher.match(uri)) {
case POINTS:
// return Notes.CONTENT_TYPE;
case POINT_ID:
// return Notes.CONTENT_ITEM_TYPE;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
}
@Override
public Uri insert(Uri uri, ContentValues initialValues) {
// Validate the requested uri
if (sUriMatcher.match(uri) != POINTS) {
throw new IllegalArgumentException("Unknown URI " + uri);
}
ContentValues values;
if (initialValues != null) {
values = new ContentValues(initialValues);
} else {
values = new ContentValues();
}
Long now = Long.valueOf(System.currentTimeMillis());
/*
// Make sure that the fields are all set
if (values.containsKey(NotePad.Notes.CREATED_DATE) == false) {
values.put(NotePad.Notes.CREATED_DATE, now);
}
if (values.containsKey(NotePad.Notes.MODIFIED_DATE) == false)
{
values.put(NotePad.Notes.MODIFIED_DATE, now);
}
if (values.containsKey(NotePad.Notes.TITLE) == false) {
Resources r = Resources.getSystem();
values.put(NotePad.Notes.TITLE,
r.getString(android.R.string.untitled));
}
if (values.containsKey(NotePad.Notes.NOTE) == false) {
values.put(NotePad.Notes.NOTE, "");
} */
values.put(tablas.Points.NOMBRE, "Pizza Hut");
values.put(tablas.Points.DIRECCION, "Remigio Crespo");
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
long rowId = db.insert(POINTS_TABLE_NAME, null, values);
if (rowId > 0) {
Uri noteUri =
ContentUris.withAppendedId(tablas.Points.CONTENT_URI, rowId);
getContext().getContentResolver().notifyChange(noteUri,
null);
return noteUri;
}
throw new SQLException("Failed to insert row into " + uri);
}
@Override
public int delete(Uri arg0, String arg1, String[] arg2) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
// TODO Auto-generated method stub
return 0;
}
static {
sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
sUriMatcher.addURI(tablas.AUTHORITY, "notes", POINTS);
sUriMatcher.addURI(tablas.AUTHORITY, "notes/#", POINT_ID);
sNotesProjectionMap = new HashMap<String, String>();
sNotesProjectionMap.put(Points._ID, Points._ID);
sNotesProjectionMap.put(Points.NOMBRE, Points.NOMBRE);
sNotesProjectionMap.put(Points.DIRECCION, Points.DIRECCION);
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---