handling errors inside code first migrations - entity-framework-migrations

I have the following inside my Up()
public override void Up()
{
try
{
Sql("drop index [IX_SalesInvoiceLine] on dbo.SalesInvoiceLines");
}
catch (Exception)
{
// ignored
}
string sql = #"CREATE UNIQUE NONCLUSTERED INDEX [IX_SalesInvoiceLine] ON [dbo].[SalesInvoiceLines] ( [SalesInvoice_Id] ASC, [seqNo] ASC) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]";
Sql(sql);
}
When I step through the code in the debugger I can step through each line.
However when I run the migration I get a message
"Cannot drop the index'dbo.SalesInvoiceLines_IXSalesInvoiceLine' ,
because it does not exist or you do not have permission"
Why is this error being thrown?

The Up procedure is feeding commands to the migration to run later.
Thus the try catch is not relevant here.

Related

How to check if a record was updating using Zend Framework's 2 Sql Adapter Class

I'm trying to test to see if an update query was successful with Zend Framework 2. I'm using the getAdapter()->query() methods but I'm unsure of how to actually test to see if anything was returned or if it actually executed. I know it is executing (as I can see the update working via mysql workbench) but I'm not sure on how to actually count or verify. Here is the code I have in place (which I know is wrong but I don't know what else to do):
$update = $this->update->table('stores')
->set(array('number_of_items' => $number))->where(array('store_name' => $this->store_name));
$query = $this->sql->getAdapter()->query($this->sql->buildSqlString($update), Adapter::QUERY_MODE_EXECUTE);
if ($query->count() > 0) {
// insert the items into the items table
$insert = $this->insert->into('items')
->columns(array('store_id', 'price', 'description'))
->values(array($row['store_id'], $price, $item_desc));
$query = $this->sql->getAdapter()->query(
$this->sql->buildSqlString($insert),
Adapter::QUERY_MODE_EXECUTE
);
if ($query->count() > 0) {
return true;
} else {
throw new \Exception("Error adding your item to the items table, please try again.");
}
} else {
// this is the exception being thrown
throw new \Exception("An error occurred while adding your item(s) to the store, please try again");
}
Now I know most likely count() will only work on select queries but I am unsure of how to test to see if the update and insert were successful.
Any help would be appreciated
Thanks
To test if update and insert were successful.
As per your code
try {
$affetedRows = $this->insert->into('items')
->columns(array('store_id', 'price', 'description'))
->values(array($row['store_id'], $price, $item_desc));
}catch (\Exception $e) {
var_dump($e->getMessage());exit; // see if any exaption Or error in query
}
}
var_dump($affetedRows ) // it will return number of affected rows.
Same for delete and update, after successfull execution delete and updateare also returns number of affected rows.
so if there is successfull exceution, you can check success of your query.
Thanks.

Stripe IOS SDK not matching AllResponseFields?

I'm trying to do a simple count check for a customer to see if they need to add a source before moving onto another page. However, my calls to the STPCustomer object's attributes are not matching the information for the full response.
I've tried clearing the customer cache and reloading the customer, but uh... still no match.
Here's a truncated like, essentials code. The class has the STPPaymentContextDelegate attached.
private var customerContext = STPCustomerContext?
private var paymentContext = STPPaymentContext?
func setupStripe() {
self.paymentContext = STPPaymentContext(customerContext: self.customerContext!)
self.paymentContext?.hostViewController = self
self.paymentContext?.delegate = self
self.paymentView = STPPaymentMethodsViewController(configuration: STPPaymentConfiguration.shared(), theme: STPTheme.default(), customerContext: self.customerContext!, delegate: self)
}
func getCustomerSources() {
if let customer = customerContext.retrieveCustomer({ (customer, error) in
if customer != nil {
print(customer.sources.count)
print(customer.sources)
print(customer.allResponseFields)
}
})
}
When I run getCustomerSources() on the test customer, I am expecting:
1
[ba_1Dvf46LrBVaGM6Sq9qIYhOlJ]
AnyHashable("id"): cus_number, AnyHashable("email"): rosa_diaz#gmail.com, AnyHashable("default_source"): ba_1Dvf46LrBVaGM6Sq9qIYhOlJ, AnyHashable("created"): 1548220659, AnyHashable("description"): LiG8WbVhT8SVhta8LdfUuWzOwQn2, AnyHashable("livemode"): 0, AnyHashable("object"): customer, AnyHashable("sources"): {
data = (
{
"bank_name" = "STRIPE TEST BANK";
country = US;
currency = usd;
customer = "cus_EOQzwwGPjzopjS";
fingerprint = 1AQMB9nzeGSGXHst;
id = "ba_1Dvf46LrBVaGM6Sq9qIYhOlJ";
last4 = 6789;
metadata = {
};
object = "bank_account";
"routing_number" = 110000000;
status = verified;
}
);
"has_more" = 0;
object = list;
"total_count" = 1;
url = "/v1/customers/cus_EOQzwwGPjzopjS/sources";
}])
However, instead of my 1 and ba_1Dvf46LrBVaGM6Sq9qIYhOlJ, I am getting 0 and []. But the allResponseFields section is the same.
Any ideas as to why there's a discrepancy between what the STPCustomer object attributes are returning and what the actual response is telling me?
it's hard to say what's going on without knowing more about the error parameter that your callback receives. It sounds like there might be an error parsing the API response, and printing the error passed into your retrieveCustomer block should give you a better idea about what's going on. If the error persists I'd recommend contacting support#stripe.com with details, as they can help directly with iOS app questions!

FireDAC TFDTable CreateTable

I am trying to use the CreateTable() method of FireDAC's TFDTable class to create a table on my MySQL Server.
void __fastcall TFormMain::ButtonCreateTableClick(TObject *Sender)
{
TFDTable *Table = new TFDTable(this);
try
{
Table->Connection = FDConnection;
Table->TableName = "Setting";
Table->Exclusive = true;
//Table->FieldDefs->Add( "SettingCode", ftString, 99 );
//Table->FieldDefs->Add( "SettingValue", ftString, 255 );
TField *Field;
Field = new TStringField( this );
Field->Name = "FieldSettingCode";
Field->FieldName = "SettingCode";
Field->Size = 100;
Field->DataSet = Table;
Field = new TStringField( this );
Field->Name = "FieldSettingValue";
Field->FieldName = "SettingValue";
Field->Size = 255;
Field->DataSet = Table;
// Fires "Table 'Setting' doesn't exist" error
Table->CreateTable( false, TFDPhysCreateTableParts() << tpTable << tpPrimaryKey << tpIndexes );
Table->Open();
Table->Insert();
Table->FieldByName("SettingCode")->Value = "test2";
Table->FieldByName("SettingValue")->Value = "testValue2";
Table->Post();
// Table->CreateDataSet();
}
__finally
{
Table->Free();
}
}
As soon as I call the CreateTable method it throws an error that the table xxxx.Setting does not exist:
Im Projekt DBCreator.exe ist eine Exception der Klasse EMySQLNativeException mit der Meldung '[FireDAC][Phys][MySQL] Table 'setting' already exists' aufgetreten.
So far so good: This error message is correct - but the real fun fact is, that the table has been successfully created and the code has been inserted.
This also happens using SQLite instead of MySQL.
I am using Embarcadero C++ Builder XE10 Seattle.
How should I handle this correctly?
Is there a way to supress this pretty useless error message?
Edit:
It turned out that EMySQLNativeException is only thrown when the debugger is running. So I just clicked the checkbox to ignore these exceptions and everything is good.
Creating databases with TFDTable and CreateTable() works like charm. Unfortunately it is just undocumented at all (like almost everything #Borland/CodeGear/Embarcadero)...
That exception is thrown by the FireDAC engine and is caused by an attempt to create table without checking if already exists. It is internally handled and the engine acts properly, so what you see is a debugger exception message. If you called the CreateTable method with the recreation parameter enabled:
Table->CreateTable( True, TFDPhysCreateTableParts() << tpTable << tpPrimaryKey << tpIndexes );
the table would be first deleted and you would not get the mentioned exception for this reason.

BlackBerry OS 5: PersistentStore.getPersistentObject returns null?

PersistentStore.getPersistentObject returns null?
I am using a random key to retrieve an object form PersistentStore
persist = PersistentStore.getPersistentObject( KEY );
Works fine on the Simulator (OS 5), when i take the signed code to the device (BB OS 5.0 Bold 8900)
For some reason this returns null, without an exception. Subsequently any API I inoke on PersistentStore/persist returns null without an exception even when persist is null.
I am not sure if this is an eclipse debugger thing, but even though the debugger shows that objects are null. Null check applied in the code seems to fail, that means code sees these objects as not null. Pheww!!! how is this possible?
In this code persist shows up as null, so does safetyTable and orderedkeys. However, the null checks in the code fail.
At a later point in the code, when i try to access orderedkeys these are null again!!! Have been grappling with this issue for two days now, any pointers would be very heplful.
persist = PersistentStore.getPersistentObject( KEY );
persistOrderedKeys = PersistentStore.getPersistentObject(KEY_ORDERED_KEYS);
safetyTable = (Hashtable)persist.getContents();
orderedKeys = (Vector)persistOrderedKeys.getContents();
if (safetyTable == null)
{
safetyTable = new Hashtable();
persist.setContents(safetyTable);
persist.commit();
}
if (orderedKeys==null)
{
orderedKeys=new Vector();
if (safetyTable.size() > 0)
{
Enumeration addressKeys = safetyTable.keys();
while(addressKeys.hasMoreElements())
{
orderedKeys.addElement((String)addressKeys.nextElement());
}
}
persistOrderedKeys.setContents(orderedKeys);
persistOrderedKeys.commit();
}

net.rim.device.api.database.DatabaseIOException: File system error (12)

I have created a tab bar which appears when I enter first time in database screen, this code is working fine. But when we go on another tab and again go on database screen tab it throws an exception
net.rim.device.api.database.DatabaseIOException: File system error (12)
I have closed database properly.
This error occurs when you try to open database which already open.
In first tab, you have opened database connection but when you switch another tab then how you close your database connection.
You should close database connection before reopen.
see following link for more details
http://docs.blackberry.com/en/developers/deliverables/29299/Opening_and_closing_databases_1585333_11.jsp
If you still not able to resolve your issue, please paste your database code.
To open database code
public void openDb(){
try{
closeDb();
// Open the database
URI uri = URI.create("Go2Reward.sqlite");
Logger.debug("-----URI-----"+uri);
_db = DatabaseFactory.open(uri);
}catch(Exception e){
Logger.error("--------- in open db====="+e.getMessage()+"----"+e);
}
}
// close database
public void closeDb(){
try{
if(_db != null)
{
Logger.debug("----close db---");
_db.close();
_db = null;
}
}catch(Exception e){
Logger.error(" ---------in close db" , e);
}
}
code to get data from database is as follow
public Vector getCategoryVector() {
Vector categoryVec = new Vector();
try{
openDb();
Statement statement = _db.createStatement("SELECT category FROM CategoriesTable");
statement.prepare();
Cursor cursor = statement.getCursor();
Row row;
while(cursor.next()) {
row = cursor.getRow();
categoryVec.addElement(row.getString(0));
}
cursor.close();
statement.close();
}catch (Exception e) {
Logger.error("---error getCategoryVector---"+e.getMessage());
}finally{
closeDb();
}
return categoryVec;
}
but when i open the database it work fine but within 10 transaction it returns the exception net.rim.device.api.database.DatabaseIOException: File system out of resources

Resources