Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Amine Laadhari
@aminelaadhari
Me neither but the compiler was raising an error. For string properties we have to explicitly choose the type of assingement (assign, copy or retain) I think
I used copy just to make it work, not sure about it though
Sam Bosley
@sbosley
huh! didn't know. thanks for the heads up. copy should be fine, and actually it's probably a good idea in case the caller passes in an NSMutableString on the iOS side
I wonder if that's a new thing in Xcode 9 that they introduced to guard against exactly that kind of bug. I'll definitely get those changes into our 4.0 branch
Amine Laadhari
@aminelaadhari
Concerning not an instance of Collection: I tried using a forced ArrayList. I had the issue. What's is strange is we have the issue only with xcode 9 and not 8
Sam Bosley
@sbosley
yeah that's definitely weird. I'll be curious to see if we can reproduce the issue when compiling with j2objc from the command line outside of xcode
all Lists should also be Collections though, since List extends Collection. I'll probably need to examine the translated code and do some debug stepping to track down the problem
if you would like to debug on your own before I can look at it on monday, you could add some logging to InCollectionCriterion to make sure it's adding your argument as a collection, and also add some logging to the private findCollectionArgs method in CompiledArgumentResolver to see if that is in turn finding your collection args.
Amine Laadhari
@aminelaadhari
sure I will do that
thanks!
Sam Bosley
@sbosley
if the logging doesn't reveal anything interesting about whether or not things are collections, I could be way off in my guess :) but based on the exception that's what it seems like. findCollectionArgs looks through the argument list for anything that's a collection, and adds it to the collectionArgs field in CompiledArgumentResolver. line 94 in that class extracts them: Collection<?> values = collectionArgs.get(index);, but the exception indicates the list is empty. it'll be illuminating to understand why it's empty
I'm sure your list has arguments, but it seems like the list of lists that we keep internally isn't being populated, and that's what's throwing the exception
@aminelaadhari I just came across this: https://groups.google.com/forum/#!topic/j2objc-discuss/avy79pz1XxU/discussion. not sure if its the same issue, but it sounds similar to what you're experiencing
Amine Laadhari
@aminelaadhari
ah yes, I will check it
Sam Bosley
@sbosley
they're looking at isAssignableFrom instead of instanceof, but I bet the two are pretty similar. could be the same issue under the hood, and they also reported that the issue started when switching from xcode 8 to 9
notable comment: "I'm seeing this too, with our use of translated gson. In our case java.util.Collection.isAssignableFrom(java.util.List) returns false"
the general conclusion of that thread seems to be that it's probably a swift compiler bug (are you using swift in your project)? the thread also suggests some workarounds that you could experiment with
Amine Laadhari
@aminelaadhari
yes we are using swift
I will try the workaround now
Sam Bosley
@sbosley
cool, then yeah this could definitely be the same issue. let me know if the workarounds mentioned in that thread help you at all!
Amine Laadhari
@aminelaadhari
The workaround fixes the issue :)
WizzCad
@WizzCad
Hi everyone ! I'm interested by SquiDB for a cross platform dev and would like to know if a ModelSpec class can extends another class that contains common fields used by many tables like ids, creation and update dates and creation and update authors. I need these fields in almost all my tables (around 30 in total) and would like to avoid the copy paste :) I have tried to extend class but generator don't take it in count and didn't find anything in code about that point... Thanks !
Sam Bosley
@sbosley
hey @WizzCad, great question. unfortunately we don't have first class support for that at the moment -- it's been on my radar to add to 4.0 for a long time, but I've sadly had very little time for active development lately. I would suggest the following as a workaround -- if it's always the same collection of columns that you're wanting to use in all your models, you could create a code generation plugin for those columns at compile time and add them into the code generator's internal representation of the model spec so they all get picked up and generated. you might even be able to make a code generation plugin to scan a superclass of a model spec (which is what we'd eventually do when adding first-class support for this), although it would be a bit more complicated and require slightly deeper knowledge of the java annotation processing APIs. there is some documentation you can find on writing code generation plugins here: https://github.com/yahoo/squidb/wiki/Taking-control-of-code-generation. I also rewrote the entire code generator on our dev_4.0 branch some time ago with a much improved plugin API based on square's javapoet, so if you'd like to use the cutting edge you might have an easier time with creating your own codegen hooks, although it's not as well documented as the 3.0 version. either way, happy to offer more detailed assistance if that sounds like an approach you're open to!
MFlisar
@MFlisar
Is there some way to safely deprecate database fields that are not used anymore? E.g. I have a field that's called "name" and then I upgrade my table to have a field called "firstname" and "secondname" and I deprecate the "name" field. I don't remove it from the table as there is no way to delete a column from sql without creating a new table and copying everything over, deleting the original table and renaming the copy. I want to keep the field in my specs file and want that the compiler throws a build exception if I ever again declare a field with the database name "name". Is something like this supported? Any security mechanism I can use to avoid creating new fields that may exist in some version of my app to avoid conflicts because of this?
Sam Bosley
@sbosley

@MFlisar you can mark fields in your model spec with @Deprecated. this will have the following effects:
1) the column will no longer be included in any newly created tables (but as you say will still exist in existing ones)
2) no getter or setter will be generated in the model for the column
3) a corresponding @Deprecated property for the column will still be generated in the model spec, to assist in writing database migrations using that column

validation to protect you from reintroducing the column name later isn't part of this -- I can definitely imagine a scenario where users might want to repurpose or undeprecate a column using e.g. a different type, so I would be hesitant to have forbidding that be the default. but you could easily implement such validation yourself using a code generation plugin that scans your list of regular and deprecated properties to look for any name duplications

MFlisar
@MFlisar

Of course it would be nice to only optionally makr a field name as unusable like @Deprecated(reuseageAllow = false) or similar. Actually, because of different column type this would be nice. Consider having a column used with an int value, then you deprecate it and half a year later you introduce a new column with the same name but a string value. Tests won't show you any errors, you make a new release and get crashes because of missmatching column types.

In this case it would be nice to get an information that the column name may already exist on some users device so that I can change @Deprecated(reuseageAllow = false) to @Deprecatedand make sure that I write the correct migration code - in this case I would have to delete the old column via a temp intermediate table.

Currently I prefer using following alternative solution that solves this problem over using @Deprecated:

// renaming the field and use the old olumn name
// to make sure to get duplication errors in generated code if the name is reused
@ColumnSpec(name = "name")
String _deprecated1;

Just because this way I get an exception in database creation because of duplicate field names. So testing my app in the emulator will immediately show me that I have a problem...

Still I would prefer an annotation processor exception instead, it should check if a field name and a deprecated field name with reuseageAllow = false exists and throw a generation error... Imho, this would be very nice and would help improving safety...

WizzCad
@WizzCad
@sbosley Thanks for quick your answer ! I'll check that :)
Sam Bosley
@sbosley
@MFlisar good points. of course, @Deprecated(reusageAllow = false) would require a custom @Deprecated annotation that would shadow the default Java one which might not be great, but we could name it something else. although, you might have convinced me -- disallowing reusing a name as the default might not be so bad, because you could always get around it by simply removing the deprecated column altogether and fully replacing it with your new one. you'd have to be careful with your migrations in such a case, but you could do it. as I mentioned I haven't had time for much active development lately, but we've been introducing a lot more compile time code validation in the 4.0 dev branch so I could look into adding it there, and as I mentioned a simple code generation plugin would also definitely work
MFlisar
@MFlisar
The name was just a quick idea, it's not good I know. I personally don't mind what the default behaviour is (although my personal opinion is safety first, so the build should fail by default if you ask me) as long as I get the possibility to do what I want. Thanks for considering this feature.
ujagarsingh
@ujagarsingh
Hi, @MFlisar thanks for reply. i am using squidb and now i want use procedure in squidb. so how can i do
Sam Bosley
@sbosley
@ujagarsingh what exactly do you mean by "use a procedure"? do you mean a SQL query?
ujagarsingh
@ujagarsingh
i mean stored procedure. just like mysql
exapmle-> CREATE PROCEDURE new_procedure ()
BEGIN
select * from user
END
Sam Bosley
@sbosley
I'm actually not familiar with MySQL stored procedures. squidb is a SQLite library and as such only supports SQLite features; I don't believe that SQLite has such a concept
however, you can define methods in java to do whatever read/write operations you want
ujagarsingh
@ujagarsingh
Thank You so much for Information .
Sam Bosley
@sbosley
so by way of your example, you'd define:
public SquidCursor<User> getUsers() {
    return mySquidDatabase.query(User.class, Query.select()); // Equivalent to select * from users
}
or, to parameterize things:
public SquidCursor<User> getUsers(int minimumAge) {
    // Equivalent to select * from users where users.age >= minimumAge
    return mySquidDatabase.query(User.class, Query.select().where(User.AGE.gte(minimumAge)));
}
pretty much you just define java methods with whatever parameters you need, and convert that into queries or transactions that you can execute on an instance of SquidDatabase
ujagarsingh
@ujagarsingh
can i pass this function in query. when i want to run my query. just like 'call getusers()'.
Sam Bosley
@sbosley
not in the way you're thinking of. SQLite just has no concept of stored procedures in the way you're describing (I'm trying to read about them in parallel right now)
you can use subqueries or views to refer to other queries at the SQL level
or you can define java methods for common tasks at the application level
maybe if you give me a more concrete example of the task you're trying to accomplish I can help with other suggestions
ujagarsingh
@ujagarsingh
thank you so much @sbosley for helped us. i give you task detail if i have some problem and not resolved as your suggestion.
Sam Bosley
@sbosley
:+1: sounds good!
John L. Jegutanis
@erasmospunk
Hello. I am using a shared "core" library that is shared between android and ios.
I wanted to include the squidb + annotations without the squidb-android in the core library and include it in the android project.
Unfortunately I get errors that go away if I add all the related squidb dependencies to the android project and remove everything from the core library.
Is there a way around it?
Sam Bosley
@sbosley
Hi @erasmospunk, what you describes sounds like the right concept of setup, so you might need to share more details of the specific error you're seeing. but generally yes, you should create a core library that depends on squidb and squidb-annotations. then your android code depends on core and squidb-android, and your iOS code depends on core and squidb-ios.
without having any further details this is just a wild guess, but did you declare the dependencies in code using api instead of implementation? I believe that only dependencies declared with api will become part of the public api of a shared module
bhavdipb
@bhavdipb

Hi Everyone,,

I am facing one issue and not able to configure squidb with sample project also