FMDB, Swift 3, executeUpdate - compiler build failed - compilation

I'm using FMDB with Swift 3.
Everything worked fine on Swift 2 but after making the Swift upgrade I'm getting:
"Command failed due to signal: Killed: 9"
After investigating the cause of it I've found that doing "executeUpdate" with about 24 arguments in the ArgumentsArray cause the compiler to be very slow and finally return compilation error.
When decreasing the number of arguments in the array to 20, the compiler build is still slow but succeed to finish successfully.
Any idea why/help will be welcome... !
Here is my code:
(Build succeed but uncommenting the 4 lines below will make the compilation build failed. Any other 4 lines will have same result of course)
func insertLocalization(_ localization: Localization) -> Bool {
print ("Insert Localization: \(localization.localization_object_id!)#\(localization.spot_object_id!)#\(localization.language_code!)")
sharedInstance.database!.open()
let isInserted = sharedInstance.database!.executeUpdate(
"INSERT INTO localizations (" +
"localization_object_id, " +
"spot_object_id, " +
"language_code, " +
"current_location_enabled, " +
"spot_title, " +
"spot_desc, " +
"local_assistant_phone, " +
"orientation_360_enabled, " +
"direction_n_title, " +
"direction_n_desc, " +
"direction_ne_title, " +
"direction_ne_desc, " +
"direction_e_title, " +
"direction_e_desc," +
"direction_se_title, " +
"direction_se_desc, " +
"direction_s_title, " +
"direction_s_desc, " +
"direction_sw_title, " +
"direction_sw_desc, " +
"direction_w_title, " +
"direction_w_desc, " +
"direction_nw_title, " +
"direction_nw_desc) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
withArgumentsIn: [
// localization.localization_object_id!,
// localization.spot_object_id!,
// localization.language_code!,
// localization.current_location_enabled!,
localization.spot_title!,
localization.spot_desc!,
localization.local_assistant_phone!,
localization.orientation_360_enabled!,
localization.direction_n_title!,
localization.direction_n_desc!,
localization.direction_ne_title!,
localization.direction_ne_desc!,
localization.direction_e_title!,
localization.direction_e_desc!,
localization.direction_se_title!,
localization.direction_se_desc!,
localization.direction_s_title!,
localization.direction_s_desc!,
localization.direction_sw_title!,
localization.direction_sw_desc!,
localization.direction_w_title!,
localization.direction_w_desc!,
localization.direction_nw_title!,
localization.direction_nw_desc!
])
sharedInstance.database!.close()
return isInserted
}
Thanks!

This code compiles without incident for me in Xcode 8.0 (8A218a). But if this isn't working for you, I'd suggest splitting the line up, for example
let values = [localization.localization_object_id!, ..., localization.direction_nw_desc!]
let isInserted = sharedInstance.database!.executeUpdate(
"INSERT INTO localizations (...) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
withArgumentsIn: values)

Related

How to call custom insert Query using JPA in Spring Boot

I am trying to call custom insert Query using JPA in Spring Boot.
#Repository
public interface eosRepo extends JpaRepository<EosthirdpartylabelsRequest, Long> {
#Modifying
#Query(
value =
"INSERT INTO public.documents_zpl(\\r\\n\" +\r\n" +
" \" loc_id, order_nbr, sub_order_nbr, carton_id, doc_payload, dt_ent, tm_ent, program_ent, dt_chg, tm_chg, program_chg)\\r\\n\"\r\n" +
" + \" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?",
nativeQuery = true)
void insertData(Integer locID, Integer OrderNum,Integer SubOrderNum,Integer CartonId,String CarrierLabel);
}
How can I call this query in Controller.
First use:
#Autowired
eosRepo eosRepo;
in your controller and then call insertData.
In controller firstly do this
#Autowired
private eosRepo object_name;
and then you can call this method
object_name.insertData
And put ')' in your query which you have forgot.
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?", you are forgot to give ')' and also call repo from controller use
#Autowired
private eosRepo theEosRepo;

CREATE LINKED TABLE not working with PreparedStatement

I'm trying to run the following PreparedStatement:
final PreparedStatement ps = conn.prepareStatement("CREATE LINKED TABLE IF NOT EXISTS " + linkedName + "(?, ?, ?, ?, 'ROADS', ?)");
But when the debugger runs over the previous line I get the error:
Syntax error in SQL statement "CREATE LINKED TABLE IF NOT EXISTS
ROAD_TABLE_LINKED(?,[*] ?, ?, ?, 'ROADS', ?)"; expected "string";
SQL statement: CREATE LINKED TABLE IF NOT EXISTS
ROAD_TABLE_LINKED(?, ?, ?, ?, 'ROADS', ?) [42001-199]
Is it not possible to used PreparedStatement with CREATE LINKED TABLE?
Edit: It works fine if I use a normal statement and insert the parameters.
Unfortunately, you cannot use parameters (?) in DDL commands in H2. You need to replace them with string literals.
Statement s = connection.createStatement();
s.execute("CREATE LINKED TABLE IF NOT EXISTS \""
+ linkedName.replaceAll("\"", "\"\"")
+ "\"('', '"
+ url.replaceAll("'", "''")
+ "', '"
+ user.replaceAll("'", "''")
+ "', '"
+ password.replaceAll("'", "''")
+ "', '"
+ schema.replaceAll("'", "''")
+ "', '"
+ table.replaceAll("'", "''")
+ "')");

Two wherehas in a Laravel Eloquent query

I have the following query, simplified below.
$property = Property::whereHas('features', function ($q1) use ($features) {
$q1->where(function ($sub) use ($features) {
$sub->whereIn('features.FeatureID', $features);
});
$q1->groupBy('PropertyID');
$q1->having('count(*)', '=', count($features));
})
->whereHas('Week', function ($q) use ($nights) {
$q->where(function ($sub) use ($nights) {
$sub->whereIn('priceAvailDate', $nights);
});
$q->groupBy('PropertyID');
$q->having('count(*)', '=', count($nights));
})
->get();
If I take one whereHas out, I get the expected collection returned. If I take the other out I get the expected result.It is when they are together I have nothing returned. I assume it is down to having two count(*). I know I have data where both whereHas is true.
SQL output is
select * from `tblproperties` where (select count(*) from `features` inner
join `propertyfeatures` on `features`.`featureid` =
`propertyfeatures`.`FeatureID` where `propertyfeatures`.`PropertyID` =
`tblproperties`.`PropertyID` and (`features`.`FeatureID` in (?)) group by
`PropertyID` having `count(*)` = ?) >= 1 and (select count(*) from
`tblpriceavail` where `tblpriceavail`.`propertyID` = `tblproperties`.`PropertyID`
and (`priceAvailDate` in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)) group by
`PropertyID` having `count(*)` = ?) >= 1
Fixed, although not 100% sure why. Using havingRaw instead of having worked.
i.e. changing the $q->having('count(*)', '=', count($nights));
to $q->havingRaw('count(*) = ' . count($nights));

Inconsistent datatypes: expected DATE got NUMBER - when inserting into DB

I'm trying to insert a row in a DB table and I keep getting
ORA-00932: inconsistent datatypes: expected DATE got NUMBER
I don't know why this is happening since all dates are SYSDATE
String insertNewAlarmStat =
"insert into alarmes (id_alarm, alarm_key, id_notif, sever, urgency, date_hour_start, date_hour_modif, date_hour_end, " +
"state, state_rec, date_hour_rec, id_user_rec, id_system_rec, " +
"type, cause, " +
"num_events, id_entity_g, type_entity_g, " +
"desc_entity_g, problem, " +
"time_urg_act, max_urg_act, time_end, time_arq, lim, rec_oblig, dn, num_events_ps, id_alarm_o, id_notif_o, text_ad, domain, date_hour_reg) " +
"values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SYSDATE, SYSDATE, SYSDATE, SYSDATE, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SYSDATE)";
PreparedStatement prpstmt = null ;
try {
prpstmt = conn.prepareStatement(insertNewAlarmStat);
prpstmt.setInt(1, randomNumberGenerator());
prpstmt.setString(2, UUID.randomUUID().toString());
prpstmt.setString(3, UUID.randomUUID().toString());
prpstmt.setInt(4, randomNumberGenerator());
prpstmt.setInt(5, 8);
prpstmt.setInt(6, 8524);
prpstmt.setString(7, UUID.randomUUID().toString());
prpstmt.setString(8, UUID.randomUUID().toString());
prpstmt.setString(9, UUID.randomUUID().toString());
prpstmt.setString(10, UUID.randomUUID().toString());
prpstmt.setString(11, "KABOOM");
prpstmt.setInt(12, 8);
prpstmt.setInt(13, 43);
prpstmt.setString(14, UUID.randomUUID().toString());
prpstmt.setString(15, UUID.randomUUID().toString());
prpstmt.setString(16, UUID.randomUUID().toString());
prpstmt.setString(17, UUID.randomUUID().toString());
prpstmt.setInt(18, 2);
prpstmt.setInt(19, 224);
prpstmt.setInt(20, 2);
prpstmt.setInt(21, 224);
prpstmt.setInt(22, 2);
prpstmt.setInt(23, 224);
prpstmt.setInt(24, 2);
prpstmt.setString(25, UUID.randomUUID().toString());
prpstmt.setString(26, UUID.randomUUID().toString());
prpstmt.setString(27, UUID.randomUUID().toString());
prpstmt.setInt(28, 2);
prpstmt.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I've tryed this way and I've tryed to remove the SYSDATE's and add some:
prpstmt.setDate(number, getCurrentDate()); //getCurrent date returns sql.Date
However, the error is the same
I've been debugging for some time now and I can't seem to find the problem, what am I missing?
Check the position of your columns compared to the values you are sending for datatype agreement.

VB6, RDO AND QUERYSTRING

I'm creating a query string as follows ...
gSql = "{ CALL MYSP( ?, ?, ?, ?, ?, ?, {resultset 10, RECORD_OUTPUT} ) }"
the {resultset 1000, RECORD_OUTPUT} is copied it from Microsoft's MSDN
The error displayed after I compile is:
identifier \'RECORD_OUTPUT\' must be declared
What should the {resultset 1000, RECORD_OUTPUT} actually be ?
At this position, The Stored Procedure will return refcursor back to VB6.

Resources