Python psycopg2 not inserting into postgresql table

If don’t want to have to commit each entry to the database, you can add the following line: conn.autocommit = True So your resulting code would be: import psycopg2 try: conn = psycopg2.connect(“dbname=”djangostack” user=”bitnami” host=”localhost” password=’password'”) conn.autocommit = True except: print “Cannot connect to db” cur = conn.cursor() try: cur.execute(“””insert into cnet values (‘r’, ‘s’, … Read more

SQL Populate table with random data

I dont know exactly if this fits the requirement for a “random description”, and it’s not clear if you want to generate the full data: but, for example, this generates 10 records with consecutive ids and random texts: test=# SELECT generate_series(1,10) AS id, md5(random()::text) AS descr; id | descr —-+———————————- 1 | 65c141ee1fdeb269d2e393cb1d3e1c09 2 | … Read more

PHP mysql insert date format

As stated in Date and Time Literals: MySQL recognizes DATE values in these formats: As a string in either ‘YYYY-MM-DD’ or ‘YY-MM-DD’ format. A “relaxed” syntax is permitted: Any punctuation character may be used as the delimiter between date parts. For example, ‘2012-12-31’, ‘2012/12/31’, ‘2012^12^31’, and ‘2012@12@31’ are equivalent. As a string with no delimiters … Read more

Android: Insert text into EditText at current position

Cpt.Ohlund gave me the right hint. I solved it, now, partly with using EditText.getSelectionStart(), but I realized that you can also replace the selected text with the same expression and you don’t need String.subString() for that. int start = Math.max(myEditText.getSelectionStart(), 0); int end = Math.max(myEditText.getSelectionEnd(), 0); myEditText.getText().replace(Math.min(start, end), Math.max(start, end), textToInsert, 0, textToInsert.length()); This works … Read more

How to add a character at a particular index in string in Swift

Swift 3 Use the native Swift approach: var welcome = “hello” welcome.insert(“!”, at: welcome.endIndex) // prints hello! welcome.insert(“!”, at: welcome.startIndex) // prints !hello welcome.insert(“!”, at: welcome.index(before: welcome.endIndex)) // prints hell!o welcome.insert(“!”, at: welcome.index(after: welcome.startIndex)) // prints h!ello welcome.insert(“!”, at: welcome.index(welcome.startIndex, offsetBy: 3)) // prints hel!lo If you are interested in learning more about Strings and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)