1. Ruslan Zasukhin
  2. Valentina Studio
  3. Четверг, Апрель 13 2017, 07:07 AM
  4.  Подписаться через email
Hi Valentina Developers!

In 7.0 we integrated a JavaScript engine into Valentina Reports - this feature is now available for ALL Valentina products.

In 7.1 we took one more step forward to JavaScript. This time in Valentina Studio. We adding integration of the QT JS engine.

This means huge job to push into JavaScript classes/methods/properties that are related to internal C++ objects of Valentina Studio model.

Thanks to this, we can now write JS scripts directly in Valentina Studio, which can do a lots of different job. For now we put this scripts into Valentina Project.

During last days we have develop a couple of such JS scripts. See below about that.

----
We going to spend many time to develop this feature -- CODE GENERATION in Valentina Studio.

It is obvious that we must be able to do this for all supported languages and IDEs: Xojo, C++, Java, NET, PHP, etc. Note that these JS scripts will be open source, we can develop a library of them. With sure in nearest time we will make this as special Tool in Valentina Studio, because to get real comfort developer must be able specify set of parameters and VStudio should remember them.

We will be happy to hear any ideas about TASKS in your daily job, that can be GENERATED instead.
Комментарий
There are no comments made yet.
Ruslan Zasukhin Ответ принят
The first script (draft of course) can take mySQL / postgreSQL / SQLite / VDB database.
and for the specified table GENERATE CODE for Xojo, with command INSERT / UPDATE / SELECT

Using parameter you can specify if you want to use set of Bind() calls to bind values, or put them into SqlExecute() or SqlSelect() command.

For UPDATE command, script is able recognize PrimaryKey fields of a table, and put them into WHERE part instead of UPDATE SET part.

Bellow are examples of generated code for both these variants:


dim cmd as string = "UPDATE mantis_bug_file_table SET bug_id = ?, title = ?, description = ?, diskfile = ?, filename = ?, folder = ?, filesize = ?, file_type = ?, content = ?, date_added = ?, user_id = ? ) WHERE id = ?"
dim ps as PreparedSQLStatement = db.Prepare( cmd )

ps.BindType( 0, MySQLPreparedStatement.MYSQL_TYPE_LONG ) // bug_id
ps.BindType( 1, MySQLPreparedStatement.MYSQL_TYPE_STRING ) // title
ps.BindType( 2, MySQLPreparedStatement.MYSQL_TYPE_STRING ) // description
ps.BindType( 3, MySQLPreparedStatement.MYSQL_TYPE_STRING ) // diskfile
ps.BindType( 4, MySQLPreparedStatement.MYSQL_TYPE_STRING ) // filename
ps.BindType( 5, MySQLPreparedStatement.MYSQL_TYPE_STRING ) // folder
ps.BindType( 6, MySQLPreparedStatement.MYSQL_TYPE_LONG ) // filesize
ps.BindType( 7, MySQLPreparedStatement.MYSQL_TYPE_STRING ) // file_type
ps.BindType( 8, MySQLPreparedStatement.MYSQL_TYPE_BLOB ) // content
ps.BindType( 9, MySQLPreparedStatement.MYSQL_TYPE_LONG ) // date_added
ps.BindType( 10, MySQLPreparedStatement.MYSQL_TYPE_LONG ) // user_id

// WHERE part binding:
ps.BindType( 11, MySQLPreparedStatement.MYSQL_TYPE_LONG ) // id

ps.Bind( 0, int ) // bug_id
ps.Bind( 1, "" ) // title
ps.Bind( 2, "" ) // description
ps.Bind( 3, "" ) // diskfile
ps.Bind( 4, "" ) // filename
ps.Bind( 5, "" ) // folder
ps.Bind( 6, int ) // filesize
ps.Bind( 7, "" ) // file_type
ps.Bind( 8, blobstr ) // content
ps.Bind( 9, int ) // date_added
ps.Bind( 10, int ) // user_id

// WHERE part binding:
ps.Bind( 11, int ) // id

ps.SQLExecute()




dim cmd as string = "UPDATE mantis_bug_file_table SET bug_id = ?, title = ?, description = ?, diskfile = ?, filename = ?, folder = ?, filesize = ?, file_type = ?, content = ?, date_added = ?, user_id = ? ) WHERE id = ?"
dim ps as PreparedSQLStatement = db.Prepare( cmd )

ps.BindType( 0, MySQLPreparedStatement.MYSQL_TYPE_LONG ) // bug_id
ps.BindType( 1, MySQLPreparedStatement.MYSQL_TYPE_STRING ) // title
ps.BindType( 2, MySQLPreparedStatement.MYSQL_TYPE_STRING ) // description
ps.BindType( 3, MySQLPreparedStatement.MYSQL_TYPE_STRING ) // diskfile
ps.BindType( 4, MySQLPreparedStatement.MYSQL_TYPE_STRING ) // filename
ps.BindType( 5, MySQLPreparedStatement.MYSQL_TYPE_STRING ) // folder
ps.BindType( 6, MySQLPreparedStatement.MYSQL_TYPE_LONG ) // filesize
ps.BindType( 7, MySQLPreparedStatement.MYSQL_TYPE_STRING ) // file_type
ps.BindType( 8, MySQLPreparedStatement.MYSQL_TYPE_BLOB ) // content
ps.BindType( 9, MySQLPreparedStatement.MYSQL_TYPE_LONG ) // date_added
ps.BindType( 10, MySQLPreparedStatement.MYSQL_TYPE_LONG ) // user_id

// WHERE part binding:
ps.BindType( 11, MySQLPreparedStatement.MYSQL_TYPE_LONG ) // id

ps.SQLExecute( int, "", "", "", "", "", int, "", blobstr, int, int, int ) <====== REPLACE place-holders AND remove this comment
Вложения
Комментарий
There are no comments made yet.
Ruslan Zasukhin Ответ принят
This script generates the whole Xojo XML Project for a given database using Class Style of V4RB,
i.e. each table becomes a class, Database object manage each table class, etc.

Generated project can be opened in Xojo IDE for immediate use.

Again, so far this is only a draft to see what we can do with this new feature of Valentina Studio.



<?xml version="1.0" encoding="UTF-8"?>
<RBProject version="2016r4.1" FormatVersion="2" MinIDEVersion="20070100">
<block type="Project" ID="0">
<ProjectSavedInVers>2016.041</ProjectSavedInVers>
<MajorVersion>1</MajorVersion>
<MinorVersion>0</MinorVersion>
<SubVersion>0</SubVersion>
<Release>0</Release>
<NonRelease>0</NonRelease>
<Region></Region>
<ShortVersion></ShortVersion>
<LongVersion></LongVersion>
<InfoVersion></InfoVersion>
<AutoIncVersion>0</AutoIncVersion>
<DefaultViewID>0</DefaultViewID>
<ProjectType>0</ProjectType>
<DefaultLanguage>0</DefaultLanguage>
<CurrentLanguage>0</CurrentLanguage>
<DefaultEncoding>0</DefaultEncoding>
<BuildFlags>6400</BuildFlags>
<UseBuildsFolder>1</UseBuildsFolder>
<WebApp>0</WebApp>
<Icon></Icon>
<MacCreator></MacCreator>
<BuildCarbonMachOName>My Application</BuildCarbonMachOName>
<BundleIdentifier>com.mycompany.MyApplication</BundleIdentifier>
<WinMDICaption></WinMDICaption>
<BuildWinName>My Application.exe</BuildWinName>
<BuildWinMDI>0</BuildWinMDI>
<BuildWinCompanyName></BuildWinCompanyName>
<BuildWinProductName></BuildWinProductName>
<BuildWinInternalName></BuildWinInternalName>
<BuildWinFileDescription></BuildWinFileDescription>
<UseGDIPlus>0</UseGDIPlus>
<BuildLinuxX86Name>MyApplication</BuildLinuxX86Name>
<BuildCarbonExecutableFormat>1</BuildCarbonExecutableFormat>
<DebuggerCommandLine></DebuggerCommandLine>
<OptimizationLevel>0</OptimizationLevel>
<CopyWindowsRedist>0</CopyWindowsRedist>
</block>
<block type="Module" ID="-1">
<ObjName>join_tests</ObjName>
<ObjContainerID>0</ObjContainerID>
<IsClass>1</IsClass>
<Superclass>VDatabase</Superclass>
<ItemFlags>1</ItemFlags>
<IsInterface>0</IsInterface>
<Compatibility></Compatibility>
<Method>
<ItemName>Constructor</ItemName>
<Compatibility></Compatibility>
<Visible>1</Visible>
<ItemSource>
<TextEncoding>134217984</TextEncoding>
<SourceLine>Sub Constructor(inConnection As VConnection)</SourceLine>
<SourceLine>// This is constructor for a Client/Server database.</SourceLine>
<SourceLine></SourceLine>
<SourceLine>// Call the parent constructor</SourceLine>
<SourceLine>Super.Constructor( inConnection )</SourceLine>
<SourceLine></SourceLine>
<SourceLine>ConstructorCommon()</SourceLine>
<SourceLine>End Sub</SourceLine>
</ItemSource>
<TextEncoding>134217984</TextEncoding>
<AliasName></AliasName>
<ItemFlags>0</ItemFlags>
<IsShared>0</IsShared>
<ItemParams>inConnection As VConnection</ItemParams>
<ItemResult></ItemResult>
</Method>
<Method>
<ItemName>Constructor</ItemName>
<Compatibility></Compatibility>
<Visible>1</Visible>
<ItemSource>
<TextEncoding>134217984</TextEncoding>
<SourceLine>Sub Constructor(inStorageType as Integer = 0)</SourceLine>
<SourceLine>// This is constructor for a LOCAL db.</SourceLine>
<SourceLine></SourceLine>
<SourceLine>// Call the parent constructor</SourceLine>
<SourceLine>Super.Constructor( inStorageType )</SourceLine>
<SourceLine></SourceLine>
<SourceLine>ConstructorCommon()</SourceLine>
<SourceLine>End Sub</SourceLine>
</ItemSource>
<TextEncoding>134217984</TextEncoding>
<AliasName></AliasName>
<ItemFlags>0</ItemFlags>
<IsShared>0</IsShared>
<ItemParams>inStorageType as Integer = 0</ItemParams>
<ItemResult></ItemResult>
</Method>
<Method>
<ItemName>ConstructorCommon</ItemName>
<Compatibility></Compatibility>
<Visible>1</Visible>
<ItemSource>
<TextEncoding>134217984</TextEncoding>
<SourceLine>Sub ConstructorCommon()</SourceLine>
<SourceLine>// Common part of DB construction.</SourceLine>
<SourceLine></SourceLine>
<SourceLine>// Create objects FOR EACH Table of this database:</SourceLine>
<SourceLine>mT1 = new tblT1</SourceLine>
<SourceLine>mT2 = new tblT2</SourceLine>
<SourceLine>End Sub</SourceLine>
</ItemSource>
<TextEncoding>134217984</TextEncoding>
<AliasName></AliasName>
<ItemFlags>0</ItemFlags>
<IsShared>0</IsShared>
<ItemParams></ItemParams>
<ItemResult></ItemResult>
</Method>
<Property>
<ItemName>mT1</ItemName>
<Compatibility></Compatibility>
<Visible>1</Visible>
<ItemSource>
<TextEncoding>134217984</TextEncoding>
<SourceLine>mT1 as tblT1</SourceLine>
</ItemSource>
<TextEncoding>134217984</TextEncoding>
<ItemDeclaration>mT1 as tblT1</ItemDeclaration>
<ItemFlags>0</ItemFlags>
<IsShared>0</IsShared>
</Property>
<Property>
<ItemName>mT2</ItemName>
<Compatibility></Compatibility>
<Visible>1</Visible>
<ItemSource>
<TextEncoding>134217984</TextEncoding>
<SourceLine>mT2 as tblT2</SourceLine>
</ItemSource>
<TextEncoding>134217984</TextEncoding>
<ItemDeclaration>mT2 as tblT2</ItemDeclaration>
<ItemFlags>0</ItemFlags>
<IsShared>0</IsShared>
</Property>
</block>
<block type="Module" ID="1">
<ObjName>tblT1</ObjName>
<ObjContainerID>0</ObjContainerID>
<IsClass>1</IsClass>
<Superclass>VTable</Superclass>
<ItemFlags>1</ItemFlags>
<IsInterface>0</IsInterface>
<Compatibility></Compatibility>
<Method>
<ItemName>Constructor</ItemName>
<Compatibility></Compatibility>
<Visible>1</Visible>
<ItemSource>
<TextEncoding>134217984</TextEncoding>
<SourceLine>mf_f1 = new VVarChar( "f1", 2044 )</SourceLine>
<SourceLine>mf_f2 = new VVarChar( "f2", 2044 )</SourceLine>
<SourceLine>End Sub</SourceLine>
</ItemSource>
<TextEncoding>134217984</TextEncoding>
<AliasName></AliasName>
<ItemFlags>0</ItemFlags>
<IsShared>0</IsShared>
<ItemParams></ItemParams>
<ItemResult></ItemResult>
</Method>
<Property>
<ItemName>mf_f1</ItemName>
<Compatibility></Compatibility>
<Visible>1</Visible>
<ItemSource>
<TextEncoding>134217984</TextEncoding>
<SourceLine>mf_f1 as VVarChar</SourceLine>
</ItemSource>
<TextEncoding>134217984</TextEncoding>
<ItemDeclaration>mf_f1 as VVarChar</ItemDeclaration>
<ItemFlags>0</ItemFlags>
<IsShared>0</IsShared>
</Property>
<Property>
<ItemName>mf_f2</ItemName>
<Compatibility></Compatibility>
<Visible>1</Visible>
<ItemSource>
<TextEncoding>134217984</TextEncoding>
<SourceLine>mf_f2 as VVarChar</SourceLine>
</ItemSource>
<TextEncoding>134217984</TextEncoding>
<ItemDeclaration>mf_f2 as VVarChar</ItemDeclaration>
<ItemFlags>0</ItemFlags>
<IsShared>0</IsShared>
</Property>
</block>
<block type="Module" ID="1">
<ObjName>tblT2</ObjName>
<ObjContainerID>0</ObjContainerID>
<IsClass>1</IsClass>
<Superclass>VTable</Superclass>
<ItemFlags>1</ItemFlags>
<IsInterface>0</IsInterface>
<Compatibility></Compatibility>
<Method>
<ItemName>Constructor</ItemName>
<Compatibility></Compatibility>
<Visible>1</Visible>
<ItemSource>
<TextEncoding>134217984</TextEncoding>
<SourceLine>mf_b2 = new VVarChar( "b2", 2044 )</SourceLine>
<SourceLine>End Sub</SourceLine>
</ItemSource>
<TextEncoding>134217984</TextEncoding>
<AliasName></AliasName>
<ItemFlags>0</ItemFlags>
<IsShared>0</IsShared>
<ItemParams></ItemParams>
<ItemResult></ItemResult>
</Method>
<Property>
<ItemName>mf_b2</ItemName>
<Compatibility></Compatibility>
<Visible>1</Visible>
<ItemSource>
<TextEncoding>134217984</TextEncoding>
<SourceLine>mf_b2 as VVarChar</SourceLine>
</ItemSource>
<TextEncoding>134217984</TextEncoding>
<ItemDeclaration>mf_b2 as VVarChar</ItemDeclaration>
<ItemFlags>0</ItemFlags>
<IsShared>0</IsShared>
</Property>
</block>
<block type="Module" ID="1415811071">
<ObjName>App</ObjName>
<ObjContainerID>0</ObjContainerID>
<IsClass>1</IsClass>
<Superclass>Application</Superclass>
<ItemFlags>1</ItemFlags>
<IsInterface>0</IsInterface>
<IsApplicationObject>1</IsApplicationObject>
<Compatibility></Compatibility>
<PropertyVal Name="MenuBar">0</PropertyVal>
<ViewBehavior>
</ViewBehavior>
</block>
<block type="BuildAutomation" ID="35588095">
<ObjName>Build Automation</ObjName>
<ObjContainerID>0</ObjContainerID>
</block>
<block type="BuildStepsList" ID="581324799">
<ObjName>Linux</ObjName>
<ObjContainerID>35588095</ObjContainerID>
</block>
<block type="BuildProjectStep" ID="1256044543">
<ObjName>Build</ObjName>
<ObjContainerID>581324799</ObjContainerID>
</block>
<block type="BuildStepsList" ID="1628166143">
<ObjName>Mac OS X</ObjName>
<ObjContainerID>35588095</ObjContainerID>
</block>
<block type="BuildProjectStep" ID="2082426879">
<ObjName>Build</ObjName>
<ObjContainerID>1628166143</ObjContainerID>
</block>
<block type="BuildStepsList" ID="480573439">
<ObjName>Windows</ObjName>
<ObjContainerID>35588095</ObjContainerID>
</block>
<block type="BuildProjectStep" ID="853768191">
<ObjName>Build</ObjName>
<ObjContainerID>480573439</ObjContainerID>
</block>
<block type="UIState" ID="0">
<StudioWindowState>
<EditBounds><Rect left="0" top="23" width="1676" height="841"/></EditBounds>
<WindowMaximized>0</WindowMaximized>
<Editors>
<EditorCount>1</EditorCount>
<Editor>
<EditorIndex>0</EditorIndex>
<EditorLocation></EditorLocation>
<EditorPath></EditorPath>
<EditorPath></EditorPath>
</Editor>
<SelectedTab>0</SelectedTab>
</Editors>
</StudioWindowState>
</block>
</RBProject>
Вложения
Комментарий
There are no comments made yet.
Ruslan Zasukhin Ответ принят
This is picture of docs about our own classes that was added into JS
Вложения
Комментарий
There are no comments made yet.
Ruslan Zasukhin Ответ принят
One more script for Xojo:
* it takes e.g. mySQL with N tables and produce Xojo project with MODULE,
which have CreateSchema() method, which calls set of other methods that do job.

We have used Mantis bug-tracker database to generate Xojo project, which is able create the same db on mySQL server.
Few mouse clicks - and you have a lots of generated code :-)
Вложения
Комментарий
There are no comments made yet.
Ruslan Zasukhin Ответ принят
Next step for JavaScript in Valentina Studio: MORE and MORE QT classes exposed into JS!

You can see on picture list of QT classes we already have expose into JS,
thanks to this JS-writer can produce easy enough own dialogs and windows!

Example of JS code that create dialog to choose one of opened DB:

// @return STRING - db name
function Dialog_ChooseOpenDb()
{
var d = new QDialog( 'Select Table' );
var items = new QListWidget();
var ok = new QPushButton( 'OK' );
var cancel = new QPushButton( 'Cancel' );

var bl = new QHBoxLayout();
bl.addStretch( 1 );
bl.addWidget( ok );
bl.addWidget( cancel );

var l = new QVBoxLayout();
l.addWidget( items, 1 );
l.addLayout( bl, 1 );

d.layout = l;

// FILL DIALOG:
items.addItems( GetArrayOfOpenDbNames() );
ok.Enabled = false;

// CONNECT SIGNALS:
items.itemSelectionChanged = function() { ok.enabled = (items.selectedItems().length > 0); }
items.itemDoubleClicked = function() { if( ok.enabled ) d.accept(); }
ok.clicked = function() { d.accept(); }
cancel.clicked = function() { d.reject(); }

// EXECUTE DIALOG:
var name = '';
if( d.exec() )
name = items.selectedItems()[ 0 ].text;

return name;
}

Dialog_ChooseOpenDb();
Вложения
Комментарий
There are no comments made yet.
Ruslan Zasukhin Ответ принят
We keep improve JS-feature in Valentina Studio:

- more QT classes integrated into JS
- better Find-Replace dialog into Script Editor,
- etc

You can see latest commits that will be available in 7.1b2
Вложения
Комментарий
There are no comments made yet.
Ruslan Zasukhin Ответ принят
We have ship 7.1 release, so you guys can play with JS feature yourself.
and you can check this project with Code Generation scripts.

We have made special WIKI page, where you can find/download this project file, and some additional notes.
Комментарий
There are no comments made yet.
Andrej Škvorc Ответ принят
HI

I think you have bug in scripts, atleast gen_xojo_proj_vbd_class_style ...

I was looking why it always gives error Table.Compatibility Syntax Error

Then after i downloaded one of your examples i notices script creates module with properties for tables and for constructor and constructorcommon, and also for each table its created as module also

In your example those are Classes...

When can we expect updated scripts? With some real examples...

For me as a begginer is hard to work with valentina (i think for others to) when we dont have real examples and when scripts like this that should help generate errors...

Also you coud expand turtorial for Class Way on Xojo... cose this way of creating tables is not covered there... It would be greate if you could make more turtorials and examples (like how to populate list box with class way or drop box or just select one value from database etc... etc...)

Greetings from Croatia :)
Комментарий
Hi Andrej,
Let me first of all show some info to you.

* Please check this article on our WIKI
http://valentina-db.com/docs/dokuwiki/v7/doku.php?id=valentina:articles:coding_style

* About Getting Started with VDB, please make a separate post.

* we have about 70 Examples in V4RB. You have see them?

* Class way is attractive from one side, but I'd use it only for simple cases. It not gives you SQL power.
  1. Ruslan Zasukhin
  2. около 2 лет назад
There are no comments made yet.
Ruslan Zasukhin Ответ принят
Hi Andrej,

Well, JS-based Code Generator was experimental feature for us, to see how it works. We will try to found bug and fix it.

Scripts we keep in .vsp file, so its easy send that if urgent.
Except that, we do quite often hot-fix builds.
Комментарий
There are no comments made yet.
Ruslan Zasukhin Ответ принят
For history: currently, docs about this and project can be found in WIKI, see link below:
Ссылки
  1. https://valentina-db.com/dokuwiki/doku.php?id=valentina:products:vstudio:examples:scripts:js
Комментарий
There are no comments made yet.
  • Страница :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.

Categories

Announcements & News
  1. 0 subcategories
Valentina Studio
  1. 2 subcategories
Valentina Server
  1. 4 subcategories
Valentina Database ADK
  1. 0 subcategories
Valentina Reports ADK
  1. 0 subcategories
Other Discussions
  1. 0 subcategories
BETA Testing
  1. 0 subcategories
Education & Research
  1. 0 subcategories
Omegabundle
  1. 0 subcategories