0

I am trying to post a question on Stack Overflow. I filled out the title, question body, and added five existing tags. I hit "Post your question", and I get "An error occurred submitting your question" red alert.

In the JavaScript console of Chrome I see:

POST http://stackoverflow.com/questions/ask/submit net::ERR_CONNECTION_RESET

In the network tab:

submit    (failed)    xhr    jquery.min.js:4

Maybe there's something wrong in the question body? I managed to post another question. It looks like it has something to do with the content.

This is what failed to submit:


I am trying to write an upsert function that can insert new rows or update existing rows. The catch is that I have a PRIMARY KEY and another UNIQUE column.

Test table:

CREATE TABLE test (
     _id INTEGER PRIMARY KEY,
     name TEXT,
     uniq_field TEXT UNIQUE ON_CONFLICT FAIL)

Test data:

_id | name   | uniq_field
  1 | first  | foo
  2 | second | bar

Now I want to be able to do the following operations:

Inserting new (non-conflicting) row should insert row with _id=3:

upsert(null, 'third','moo');

Inserting a row that conflicts in the UNIQUE field should fail:

upsert(null, 'third','foo'); // foo exists

Updating an existing row with no conflict:

upsert(1, 'FIRST','mew');

Updating an existing row with conflict in the uniq field:

upsert(1, 'FIRST','bar'); // bar exists

This is my current code from MyDbHelper (extends SQLiteOpenHelper):

public long upsert(final Long _id, final String name, final String uniqField) {
    final ContentValues values = new ContentValues();
    if (_id != null && _id != -1) {
        values.put(ItemColumns._ID, _id);
    }
    values.put(ItemColumns.NAME, name);
    values.put(ItemColumns.UNIQ_FIELD, uniqField);

    SQLiteDatabase db = getWritableDatabase();
    // Insert the new row, returning the primary key value of the new row

    // TRIED THIS:
    final long newRowId = db.replaceOrThrow(
            getTableName(),
            null,
            values);

    // AND THIS AS WELL:
    final long newRowId = db.insertWithOnConflict(
            getTableName(),
            null,
            values,
            SQLiteDatabase.CONFLICT_REPLACE);

    return newRowId;
}
12
  • Seems strange that it works on meta though :) - Have you waited and re-tried posting on main since asking this? Mar 14, 2016 at 12:36
  • yes, right now. I even signed off/in again. Though I was trying from the already open tab
    – Gavriel
    Mar 14, 2016 at 12:37
  • and I also tried now from firefox. I had to log in (I think I've never been logged in before in FF) I got the same error messages.
    – Gavriel
    Mar 14, 2016 at 12:42
  • I managed to ask a "test" question: stackoverflow.com/questions/35987931/…
    – Gavriel
    Mar 14, 2016 at 12:46
  • 4
    The error you are seeing suggests a network issue - probably an intermittent one. Try posting over https to rule out injected content.
    – Oded
    Mar 14, 2016 at 12:48
  • But I managed to post another question. It looks like it has something to do with the content IMHO
    – Gavriel
    Mar 14, 2016 at 12:49
  • 1
    I deleted the test question - it is off-topic, after all.
    – Oded
    Mar 14, 2016 at 12:49
  • 1
    Are you posting from work? Could be that the firewalls between you and us are not liking the content. We've seen that before with some SQL questions, so could be a similar issue.
    – Oded
    Mar 14, 2016 at 12:51
  • 1
    I could be imagining this, but I'm fairly sure we've had a post with someone trying to post SQL code and it turned out it was the network filter at their workplace that disagreed with something or other. It did work over https though... Mar 14, 2016 at 12:51
  • I see it went through - did HTTPS sort it?
    – Oded
    Mar 14, 2016 at 12:53
  • https solved it: stackoverflow.com/questions/35988050/…. Yes I'm from work, maybe the firewall thinks I'm trying to post sensitive code. Is there a way to set https to be the default (though I didn't have similar problems in the past year when I asked/answered hundreds of questions)
    – Gavriel
    Mar 14, 2016 at 12:53
  • 2
    HTTPS is still work in progress, though it tends to work ok. There are some areas that aren't yet fully supported (child meta sites for most SE sites). Tools like the HTTPS Everywhere browser extension would do that, but I don't know how granular they are (that is, not sure you can tell them to only turn on for a specific site).
    – Oded
    Mar 14, 2016 at 13:27

0

Browse other questions tagged .