myBackSpace - XOJO/SQLite - Database-First Template Code Generation

If you find yourself working with SQLite and XOJO and would like to try template based “Database-First” approach to XOJO source code generation, then you may want to try myBackSpace.com. The template is hosted by the fantastic folks over at My2ndGeneration.com via their cloud interface.

This could save you some time building those repetitive database access layers in your application and since we generate XOJO source code; it works with all XOJO project types.

myBackSpace.com is 100% free and generates 100% XOJO source code.

Show me.

Hi i was trying your solution and like it… I’m new to xojo

I have only one problem… How to insert new data… I found IsNew option but it does not work…

Editing data is working, but inserting new… How with your code?! There is none in Example do you have one?

It seams this Works… Hope its best way

dim k as new myKorisnici

k.IsNew = true

k.fldIme =“Some first name”
k.fldKorisnikID = 100 (i don’t Know why it did not autoincriment so i added it manualy for test
k.fldKorisnickoIme =“Login user name”
k.fldKorisnikGUID = app.NewGUID
k.fldLozinka = App.Hash(“password”)
k.fldMail = “mail@mail.com
k.fldPrezime = “Surname”
k.fldVerificiran = true

If k.Save = true then
MsgBox(“Saved”)
end if

Hi Andrej,

Glad you found us and are having some success with myBackSpace. We enjoy building it.

Using your code above as a sample. The following line should not be required when adding new rows. It does not cause an issue if it is there.

k.IsNew = true

The auto increment values are populated by the database engine following the save operation. Try the following in your code.

If k.Save = true Then
MsgBox(“Saved”)
//Now k.fldKorisnikID will be populated with the auto number.
End If

We are in the process of building a sample application that is hosted on GitHub that demonstrates the architecture. Right now it is a Web application, but our plans include tasks to build the sample in each of the XOJO project types.

URL: https://github.com/myBackSpace/xojo-mybackspace-orm-web-app-sample

-Daniel

Congrats - and two remarks:

Please be aware that a For Each loop is not guaranteed to happen in the order of the elements in an array. You should change your examples to For i As Integer = 0 To …Ubound. From the docs:

Your code uses a lot of Mes where Selfs would be more appropriate. It is not wrong to use Me, but Me in Xojo is not meant to be the same as Me in VB and VB Net. From the docs:

[quote=103504:@Daniel Pigford]Hi Andrej,

Using your code above as a sample. The following line should not be required when adding new rows. It does not cause an issue if it is there.

k.IsNew = true

The auto increment values are populated by the database engine following the save operation. Try the following in your code.

If k.Save = true Then
MsgBox(“Saved”)
//Now k.fldKorisnikID will be populated with the auto number.
End If

-Daniel[/quote]

Tnx for replay

I tried your way and omiting ID field

dim g as new myUserGroups

g.fldDescription = “Administrator”
g.fldName = “Administrator”

If g.Save = True then
MsgBox(“Saved”)
else
msgbox(“Not Saved”)
end if

And its not saving in DB

with

dim g as new myUserGroups

g.fldId = 1
g.fldDescription = “Administrator”
g.fldName = “Administrator”

If g.Save = True then
MsgBox(“Saved”)
else
msgbox(“Not Saved”)
end if

IS saving

I was doing this with SQLite without autoincrement and with autoincrimet specified in db field creating to see if something is wrong… but the same result, when i add g.fldId = 1 then it Works…

Reading in documentation, when inserting in SQLite db new row, you need to insert with NULL value to work with autoincriment from DB i did not manage to check your generated code if there is maybe a bug that passes some value or something and not null in insert comand

[quote=103504:@Daniel Pigford]Hi Andrej,

URL: https://github.com/myBackSpace/xojo-mybackspace-orm-web-app-sample

-Daniel[/quote]

p.s. i downloaded samples before writning First time, but there is no insert example in there…

Whatever i try, i can’t save in DB (insert) in db…

I made field in table with AUTOINCREMENT, without autoincremen with only INTEGER and Primary KEY commands

if i don’t give to ID field value it wont insert into DB

and if i manage to insert without id it inserts with id 0

So this is table

– Describe USERGROUPS
CREATE TABLE [UserGroups] (
[Id] INTEGER PRIMARY KEY,
[Name] nvarchar COLLATE NOCASE,
[Description] nvarchar COLLATE NOCASE
)

– Describe USERS_IX_GROUP_ID
CREATE INDEX [Users_IX_Group_Id]
ON [Users]
([Group_Id] DESC)

– Describe FKI_USERS_GROUP_ID_USERGROUPS_ID
CREATE TRIGGER [fki_Users_Group_Id_UserGroups_Id] Before Insert ON [Users] BEGIN SELECT RAISE(ROLLBACK, ‘insert on table Users violates foreign key constraint fki_Users_Group_Id_UserGroups_Id’) WHERE NEW.Group_Id IS NOT NULL AND (SELECT Id FROM UserGroups WHERE Id = NEW.Group_Id) IS NULL; END

– Describe FKU_USERS_GROUP_ID_USERGROUPS_ID
CREATE TRIGGER [fku_Users_Group_Id_UserGroups_Id] Before Update ON [Users] BEGIN SELECT RAISE(ROLLBACK, ‘update on table Users violates foreign key constraint fku_Users_Group_Id_UserGroups_Id’) WHERE NEW.Group_Id IS NOT NULL AND (SELECT Id FROM UserGroups WHERE Id = NEW.Group_Id) IS NULL; END

And when i run this in SQLiteman Insert into usergroups values (null, “Test1”, “Test”) it inserts into db and gives it next ID … so i Know autoincrement Works… and DB is ok