How to rollback create table with sqlalchemy transaction? (sqlite)

Uncategorized
Question: #!/usr/bin/env python3 import logging import sqlalchemy logging.basicConfig() logging.getLogger('sqlalchemy').setLevel(logging.DEBUG) engine = sqlalchemy.create_engine("sqlite:///test.db") connection = engine.connect() transaction = connection.begin() try:connection.execution_options(autocommit=False).execute("create table test (`id` int NOT NULL);") connection.execution_options(autocommit=False).execute("create table test (`id` int NOT NULL);") transaction.commit() except:transaction.rollback() raise I have this python script. My expectation would be, that database doesn't have table test afterwards, but it does. What am I doing wrong/How can I rollback create table? Answer: Read more
Read More

Aggregate counting logical values

Uncategorized
Question: Hello friend I am not friendly with mongodb aggregation I want is that I have array of object that contains subjects with its score for each question and I am using node js so I want is that full calculation with mongo query if possible that include subject name with its total score and count of attempt and not attempt my Json Array is as bellow { "examId": ObjectId("597367af7d8d3219d88c4341"), "questionId": ObjectId("597368207d8d3219d88c4342"), "questionNo": 1, "subject": "Reasoning Ability", "yourChoice": "A", "correctMark": "1", "attempt": true, "notAttempt": false, } here in object one field is for correct marks subject are different an I want an output like |Subject Name | Total attempts | total not attempts | total score | | A | 5 | 3 | 10 | | B | 10…
Read More

How can I handle FCM when my app is not running?

Uncategorized
Question: I can receive FCM when app is active or background. But can't receive when not running. How can I receive FCM when application state not running? Answer: in didFinishLaunchingWithOptions.There is a parameter launchOptions which contains push notification.Store the data and handle it in firstViewController you open.I did it by writing these lines in appDelegate I used swiftyJson and take userPush in singleton class to 1:guard let pushNotification = launchOptions? [UIApplicationLaunchOptionsKey.remoteNotification] else { return true } print(pushNotification) let data = JSON(pushNotification) UserDataSingleton.sharedInstance.notificationData = data UserDataSingleton.sharedInstance.userPush = 1 Now in my splashViewController I did:override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(true) if (UserDataSingleton.sharedInstance.userPush == 1){ UserDataSingleton.sharedInstance.userPush = 0 let appDelegate = UIApplication.shared.delegate as! AppDelegate appDelegate.handlePushNavigation(userInfo: UserDataSingleton.sharedInstance.notificationData!) } else{ } } handlePushNotification is a func i have written for all 3 cases in…
Read More

PHP MySQL not submitting or working

Uncategorized
Question: I have some PHP and HTML code which should send data from the form to my MySQL database. However, on clicking Submit in the form, the page reloads and nothing happens. No echo or anything. The HTML is in the same file as the PHP file. PHP HTML Note: I know this code is currently subject to SQL injection, and the password is not encrypted. It is temporary starting code in an attempt to get it working first. Answer: You lack the name attribute in the submit button, add name="submit". Read more
Read More

What is the equivalent of this Visual Basic code to c#? [on hold]

Uncategorized
Question: Can you please give me the equivalent codes for c#. This is the VB.NET code:Private Sub Productname() Myquery = "Select name from products where Item_ID = '" & txtsearch.Text & "'" ConnOpen (connstring) With myComm .CommandText = Myquery .Connection = myconn End With With myAdapter .SelectCommand = myComm .Fill(mydata1) End With For i = 0 to mydata1.Rows.Count - 1 With prod. text = (mydata1.Rows(i)("Name")) End With Next End Sub mydata1 as Datatable. i as integer. Myquery as string. myComm as MysqlCommand myAdapter as MysqlAdapter Answer: private void Productname() { Myquery = $"Select name from products where Item_ID = '{txtsearch.Text}'"; ConnOpen(connstring); myComm.CommandText = Myquery myComm.Connection = myconn myAdapter.SelectCommand = myComm myAdapter.Fill(mydata1) for (i = 0; i
Read More

setFetchBatchSize Fetching all the rows in messages Table

Uncategorized
Question: Following is my code snippet. NSSortDescriptor *sortSequence = [[NSSortDescriptor alloc] initWithKey:@"date_added" ascending:YES]; NSArray *sortDescriptors =[NSArray arrayWithObjects:sortSequence,nil]; [fetchRequest setFetchBatchSize:5]; [fetchRequest setSortDescriptors:sortDescriptors]; [NSFetchedResultsController deleteCacheWithName:@“Chats”]; NSFetchedResultsController *theFetchedResultsController =[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext: managedObjectContext sectionNameKeyPath:@"messageSectionKey" cacheName:@"Chats"]; In my listing I want to implement load more functionality. I want to sort based on the key date_added . messageSectionKey is a getter method in the coredata class which will return Yesterday,Today etc based on date_added … But After fetching instead of loading 5, it is loading all the rows in my Message table Answer: I guess to get the 5 objects you should set the fetch limit as 5 [fetchRequest setFetchLimit:5]; To get say 20 records , you pass in the parameter value of numberOfItems = 20, do your working inside a function, its just an…
Read More

Ubuntu VM stuck at 47% boot

ubuntu
Question: I had a power cut and ever since I have been unable to boot an ubuntu server. In VMware it gets to 47% in Powering on Virtual machine then stops, no errors appear, I looked in the log and this is what it says 2017-08-18T14:39:21.682Z| vmx| I120: Vigor_ClientRequestCb: failed to do op=3 on unregistered device 'MKS' (cmd=queryFields) 2017-08-18T14:39:21.683Z| vmx| I120: Vigor_ClientRequestCb: failed to do op=3 on unregistered device 'Tools' (cmd=queryFields) 2017-08-18T14:39:21.683Z| vmx| I120: Vigor_ClientRequestCb: failed to do op=3 on unregistered device 'GuestInfo' (cmd=queryFields) 2017-08-18T14:39:21.684Z| vmx| I120: Vigor_ClientRequestCb: failed to do op=3 on unregistered device 'GuestPeriodic' (cmd=queryFields) 2017-08-18T14:39:21.684Z| vmx| I120: Vigor_ClientRequestCb: failed to do op=3 on unregistered device 'GuestAppMonitor' (cmd=queryFields) 2017-08-18T14:39:21.685Z| vmx| I120: Vigor_ClientRequestCb: failed to do op=3 on unregistered device 'MKS' (cmd=queryFields) 2017-08-18T14:39:21.686Z| vmx| I120: Vigor_ClientRequestCb: failed to do…
Read More