use of android.database.SQLException in project cardslib by gabrielemariotti.
the class CardCursorProvider method insert.
@Override
public Uri insert(Uri uri, ContentValues values) {
Log.d(TAG, "insert(uri=" + uri + ", values=" + values.toString() + ")");
// Open a read / write database to support the transaction.
SQLiteDatabase db = myOpenHelper.getWritableDatabase();
// To add empty rows to your database by passing in an empty Content Values
// object, you must use the null column hack parameter to specify the name of
// the column that can be set to null.
String nullColumnHack = null;
long id = -1;
if (uriMatcher.match(uri) == CardCursor_ALLROWS) {
// Insert the values into the table
id = db.insert(CardCursorSQLiteOpenHelper.Tables.CardCursor, nullColumnHack, values);
}
if (id > -1) {
// Construct and return the URI of the newly inserted row.
// Equals to Uri.parse(BASE_PATH + "/" + id);
Uri insertedId = ContentUris.withAppendedId(uri, id);
// Notify any observers of the change in the data set.
getContext().getContentResolver().notifyChange(insertedId, null);
return insertedId;
} else
throw new SQLException("Problem while inserting into uri: " + uri);
}
use of android.database.SQLException in project WordPress-Android by wordpress-mobile.
the class WPLegacyMigrationUtils method hasSelfHostedSiteToMigrate.
public static boolean hasSelfHostedSiteToMigrate(Context context) {
try {
SQLiteDatabase db = context.openOrCreateDatabase(DEPRECATED_DATABASE_NAME, 0, null);
String[] fields = new String[] { "username", "password", "url", "homeURL", "blogId", "api_blogid" };
// To exclude the jetpack sites we need to check for empty password
String byString = String.format("dotcomFlag=0 AND NOT(dotcomFlag=0 AND password='%s')", encryptPassword(""));
Cursor c = db.query(DEPRECATED_BLOGS_TABLE, fields, byString, null, null, null, null);
int numRows = c.getCount();
c.moveToFirst();
for (int i = 0; i < numRows; i++) {
long apiBlogId = StringUtils.stringToLong(c.getString(5));
if (apiBlogId > 0) {
// If the api_blogid field is set, that's probably a Jetpack site that is not connected to the main
// account, so we want to skip it.
c.moveToNext();
continue;
}
c.close();
return true;
}
c.close();
return false;
} catch (SQLException e) {
return false;
}
}
use of android.database.SQLException in project WordPress-Android by wordpress-mobile.
the class WPLegacyMigrationUtils method getDraftsFromDeprecatedDB.
static List<PostModel> getDraftsFromDeprecatedDB(Context context, SiteStore siteStore) {
List<PostModel> postList = new ArrayList<>();
try {
SQLiteDatabase db = context.openOrCreateDatabase(DEPRECATED_DATABASE_NAME, 0, null);
String byString = "localDraft=1 OR isLocalChange=1";
Cursor c = db.query(DEPRECATED_POSTS_TABLE, null, byString, null, null, null, null);
int numRows = c.getCount();
c.moveToFirst();
for (int i = 0; i < numRows; i++) {
PostModel postModel = new PostModel();
Cursor siteCursor = db.query(DEPRECATED_BLOGS_TABLE, new String[] { "dotcomFlag", "blogId", "url", "api_blogid" }, String.format("id=%s", c.getInt(c.getColumnIndex("blogID"))), null, null, null, null);
if (siteCursor.getCount() > 0) {
siteCursor.moveToFirst();
boolean dotcomFlag = siteCursor.getInt(0) == 1;
int blogId = siteCursor.getInt(1);
String xmlrpcUrl = siteCursor.getString(2);
long apiBlogId = StringUtils.stringToLong(siteCursor.getString(3));
int migratedSiteLocalId;
if (dotcomFlag) {
// WP.com site - identify it by WP.com site ID
migratedSiteLocalId = siteStore.getLocalIdForRemoteSiteId(blogId);
} else if (apiBlogId > 0) {
// Jetpack site - identify it by WP.com site ID
migratedSiteLocalId = siteStore.getLocalIdForRemoteSiteId(apiBlogId);
} else {
// Self-hosted site - identify it by its self-hosted site ID and XML-RPC URL
migratedSiteLocalId = siteStore.getLocalIdForSelfHostedSiteIdAndXmlRpcUrl(blogId, xmlrpcUrl);
}
postModel.setLocalSiteId(migratedSiteLocalId);
siteCursor.close();
} else {
AppLog.d(T.DB, "Couldn't find site corresponding to draft in deprecated DB! " + "Site local id " + c.getInt(c.getColumnIndex("blogID")) + " - Post title: " + c.getString(c.getColumnIndex("title")));
c.moveToNext();
siteCursor.close();
continue;
}
postModel.setIsLocalDraft(SqlUtils.sqlToBool(c.getInt(c.getColumnIndex("localDraft"))));
postModel.setIsLocallyChanged(SqlUtils.sqlToBool(c.getInt(c.getColumnIndex("isLocalChange"))));
String postId = c.getString(c.getColumnIndex("postid"));
if (!TextUtils.isEmpty(postId)) {
postModel.setRemotePostId(StringUtils.stringToLong(postId));
}
postModel.setTitle(StringUtils.unescapeHTML(c.getString(c.getColumnIndex("title"))));
String descriptionText = c.getString(c.getColumnIndex("description"));
String moreText = c.getString(c.getColumnIndex("mt_text_more"));
if (TextUtils.isEmpty(moreText)) {
postModel.setContent(descriptionText);
} else {
postModel.setContent(descriptionText + "\n<!--more-->\n" + moreText);
}
long dateCreated = c.getLong(c.getColumnIndex("date_created_gmt"));
if (dateCreated > 0) {
postModel.setDateCreated(DateTimeUtils.iso8601UTCFromTimestamp(dateCreated / 1000));
}
long dateLocallyChanged = c.getLong(c.getColumnIndex("dateLastUpdated"));
if (dateLocallyChanged > 0) {
postModel.setDateLocallyChanged(DateTimeUtils.iso8601UTCFromTimestamp(dateLocallyChanged / 1000));
}
postModel.setExcerpt(c.getString(c.getColumnIndex("mt_excerpt")));
postModel.setFeaturedImageId(c.getLong(c.getColumnIndex("wp_post_thumbnail")));
postModel.setLink(c.getString(c.getColumnIndex("link")));
postModel.setTagNames(c.getString(c.getColumnIndex("mt_keywords")));
postModel.setStatus(c.getString(c.getColumnIndex("post_status")));
postModel.setPassword(c.getString(c.getColumnIndex("wp_password")));
postModel.setPostFormat(c.getString(c.getColumnIndex("wp_post_format")));
postModel.setIsPage(SqlUtils.sqlToBool(c.getInt(c.getColumnIndex("isPage"))));
int latColumnIndex = c.getColumnIndex("latitude");
int lngColumnIndex = c.getColumnIndex("longitude");
if (!c.isNull(latColumnIndex) && !c.isNull(lngColumnIndex)) {
postModel.setLocation(c.getDouble(latColumnIndex), c.getDouble(lngColumnIndex));
}
postModel.setCustomFields(c.getString(c.getColumnIndex("custom_fields")));
postList.add(postModel);
c.moveToNext();
}
c.close();
} catch (SQLException e) {
// DB doesn't exist
}
return postList;
}
use of android.database.SQLException in project XobotOS by xamarin.
the class SMSDispatcher method processMessagePart.
/**
* If this is the last part send the parts out to the application, otherwise
* the part is stored for later processing. Handles both 3GPP concatenated messages
* as well as 3GPP2 format WAP push messages processed by
* {@link com.android.internal.telephony.cdma.CdmaSMSDispatcher#processCdmaWapPdu}.
*
* @param pdu the message PDU, or the datagram portion of a CDMA WDP datagram segment
* @param address the originating address
* @param referenceNumber distinguishes concatenated messages from the same sender
* @param sequenceNumber the order of this segment in the message
* (starting at 0 for CDMA WDP datagrams and 1 for concatenated messages).
* @param messageCount the number of segments in the message
* @param timestamp the service center timestamp in millis
* @param destPort the destination port for the message, or -1 for no destination port
* @param isCdmaWapPush true if pdu is a CDMA WDP datagram segment and not an SM PDU
*
* @return a result code from {@link Telephony.Sms.Intents}, or
* {@link Activity#RESULT_OK} if the message has been broadcast
* to applications
*/
protected int processMessagePart(byte[] pdu, String address, int referenceNumber, int sequenceNumber, int messageCount, long timestamp, int destPort, boolean isCdmaWapPush) {
byte[][] pdus = null;
Cursor cursor = null;
try {
// used by several query selection arguments
String refNumber = Integer.toString(referenceNumber);
String seqNumber = Integer.toString(sequenceNumber);
// Check for duplicate message segment
cursor = mResolver.query(mRawUri, PDU_PROJECTION, "address=? AND reference_number=? AND sequence=?", new String[] { address, refNumber, seqNumber }, null);
// moveToNext() returns false if no duplicates were found
if (cursor.moveToNext()) {
Log.w(TAG, "Discarding duplicate message segment from address=" + address + " refNumber=" + refNumber + " seqNumber=" + seqNumber);
String oldPduString = cursor.getString(PDU_COLUMN);
byte[] oldPdu = HexDump.hexStringToByteArray(oldPduString);
if (!Arrays.equals(oldPdu, pdu)) {
Log.e(TAG, "Warning: dup message segment PDU of length " + pdu.length + " is different from existing PDU of length " + oldPdu.length);
}
return Intents.RESULT_SMS_HANDLED;
}
cursor.close();
// not a dup, query for all other segments of this concatenated message
String where = "address=? AND reference_number=?";
String[] whereArgs = new String[] { address, refNumber };
cursor = mResolver.query(mRawUri, PDU_SEQUENCE_PORT_PROJECTION, where, whereArgs, null);
int cursorCount = cursor.getCount();
if (cursorCount != messageCount - 1) {
// We don't have all the parts yet, store this one away
ContentValues values = new ContentValues();
values.put("date", timestamp);
values.put("pdu", HexDump.toHexString(pdu));
values.put("address", address);
values.put("reference_number", referenceNumber);
values.put("count", messageCount);
values.put("sequence", sequenceNumber);
if (destPort != -1) {
values.put("destination_port", destPort);
}
mResolver.insert(mRawUri, values);
return Intents.RESULT_SMS_HANDLED;
}
// All the parts are in place, deal with them
pdus = new byte[messageCount][];
for (int i = 0; i < cursorCount; i++) {
cursor.moveToNext();
int cursorSequence = cursor.getInt(SEQUENCE_COLUMN);
// GSM sequence numbers start at 1; CDMA WDP datagram sequence numbers start at 0
if (!isCdmaWapPush) {
cursorSequence--;
}
pdus[cursorSequence] = HexDump.hexStringToByteArray(cursor.getString(PDU_COLUMN));
// It's not a bad idea to prefer the port from the first segment for 3GPP as well.
if (cursorSequence == 0 && !cursor.isNull(DESTINATION_PORT_COLUMN)) {
destPort = cursor.getInt(DESTINATION_PORT_COLUMN);
}
}
// GSM sequence numbers start at 1; CDMA WDP datagram sequence numbers start at 0
if (isCdmaWapPush) {
pdus[sequenceNumber] = pdu;
} else {
pdus[sequenceNumber - 1] = pdu;
}
// Remove the parts from the database
mResolver.delete(mRawUri, where, whereArgs);
} catch (SQLException e) {
Log.e(TAG, "Can't access multipart SMS database", e);
return Intents.RESULT_SMS_GENERIC_ERROR;
} finally {
if (cursor != null)
cursor.close();
}
// Special handling for CDMA WDP datagrams
if (isCdmaWapPush) {
// Build up the data stream
ByteArrayOutputStream output = new ByteArrayOutputStream();
for (int i = 0; i < messageCount; i++) {
// reassemble the (WSP-)pdu
output.write(pdus[i], 0, pdus[i].length);
}
byte[] datagram = output.toByteArray();
// Dispatch the PDU to applications
if (destPort == SmsHeader.PORT_WAP_PUSH) {
// Handle the PUSH
return mWapPush.dispatchWapPdu(datagram);
} else {
pdus = new byte[1][];
pdus[0] = datagram;
// The messages were sent to any other WAP port
dispatchPortAddressedPdus(pdus, destPort);
return Activity.RESULT_OK;
}
}
// Dispatch the PDUs to applications
if (destPort != -1) {
if (destPort == SmsHeader.PORT_WAP_PUSH) {
// Build up the data stream
ByteArrayOutputStream output = new ByteArrayOutputStream();
for (int i = 0; i < messageCount; i++) {
SmsMessage msg = SmsMessage.createFromPdu(pdus[i], getFormat());
byte[] data = msg.getUserData();
output.write(data, 0, data.length);
}
// Handle the PUSH
return mWapPush.dispatchWapPdu(output.toByteArray());
} else {
// The messages were sent to a port, so concoct a URI for it
dispatchPortAddressedPdus(pdus, destPort);
}
} else {
// The messages were not sent to a port
dispatchPdus(pdus);
}
return Activity.RESULT_OK;
}
use of android.database.SQLException in project XobotOS by xamarin.
the class CDMAPhone method updateCurrentCarrierInProvider.
/**
* Sets the "current" field in the telephony provider according to the
* build-time operator numeric property
*
* @return true for success; false otherwise.
*/
boolean updateCurrentCarrierInProvider(String operatorNumeric) {
if (!TextUtils.isEmpty(operatorNumeric)) {
try {
Uri uri = Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "current");
ContentValues map = new ContentValues();
map.put(Telephony.Carriers.NUMERIC, operatorNumeric);
log("updateCurrentCarrierInProvider from system: numeric=" + operatorNumeric);
getContext().getContentResolver().insert(uri, map);
// Updates MCC MNC device configuration information
MccTable.updateMccMncConfiguration(this, operatorNumeric);
return true;
} catch (SQLException e) {
Log.e(LOG_TAG, "Can't store current operator", e);
}
}
return false;
}
Aggregations