SubSonic Inner join Select problem - subsonic

I have 3 tables and need to select some recoreds,
In 2 table of them I have fileds with same name , and when I try to use Where Expression on these filed I got error message :
If I use TABLENAMe.Columns.COLNAME this error message shows : Ambiguous column name 'FKLoginID'.
and if I use TableNAme.COLColumn.QualifiedName , it has error near created paramter "#[dbo].[Tbl_PersonalInformation].[FKLoginID]0"
How can I query on these tables?
Thanks
SqlQuery q = new Select().From(Tables.TblStockbrokerBroadDirector)
.InnerJoin(TblPersonalInformation.PersonalInfoIDColumn, TblStockbrokerBroadDirector.FKPersonalInfoIDColumn)
.InnerJoin(TblCompanyInformation.BizInfoIDColumn, TblStockbrokerBroadDirector.FKBizInfoIDColumn)
.Where(TblPersonalInformation.FKLoginIDColumn.QualifiedName).IsEqualTo(User.Identity.Name);
CREATE TABLE [dbo].[Tbl_CompanyInformation](
[Code] [bigint] IDENTITY(111111111,1) NOT NULL,
[BizInfoID] [nvarchar](20) NOT NULL,
[BizName] [nvarchar](50) NOT NULL,
[RegisterationNO] [nvarchar](50) NOT NULL,
[RegisterationPlace] [bigint] NOT NULL,
[TypeBiz] [nvarchar](50) NOT NULL,
[DirectManagerCode] [nvarchar](20) NOT NULL,
[FKAddressID] [nvarchar](20) NOT NULL,
[FKLoginID] [nvarchar](20) NOT NULL,
[SabtDate] [nvarchar](50) NOT NULL,
[NewName] [nvarchar](50) NULL,
[OldName] [nvarchar](50) NULL,
[DateTasisAgahi] [nvarchar](50) NOT NULL,
[NOTasisAgahi] [nvarchar](20) NOT NULL,
[NOAsasname] [nvarchar](20) NOT NULL,
[FKStatus] [smallint] NOT NULL CONSTRAINT [DF_Tbl_CompanyInformation_FKStatus] DEFAULT ((0)),
CONSTRAINT [PK_Tbl_CompanyInformation_1] PRIMARY KEY CLUSTERED
(
[Code] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY],
CONSTRAINT [IX_Tbl_Biz] UNIQUE NONCLUSTERED
(
[BizInfoID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY],
CONSTRAINT [IX_Tbl_CompanyRegNoP] UNIQUE NONCLUSTERED
(
[RegisterationNO] ASC,
[RegisterationPlace] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
CREATE TABLE [dbo].[Tbl_PersonalInformation](
[Code] [bigint] IDENTITY(111111111,1) NOT NULL,
[PersonalInfoID] [nvarchar](20) NOT NULL,
[FKLoginID] [nvarchar](20) NULL,
[FirstName] [nvarchar](50) NOT NULL,
[LastName] [nvarchar](150) NOT NULL,
[SSN] [nvarchar](10) NOT NULL,
[NationalCode] [nvarchar](10) NOT NULL,
[CopyNCard] [image] NULL,
[Birthyear] [nvarchar](50) NOT NULL,
[Birthplace] [bigint] NOT NULL,
[FKProvince] [smallint] NOT NULL,
[FKAddressID] [nvarchar](20) NOT NULL,
[Phone] [nvarchar](50) NULL,
[Sex] [bit] NOT NULL CONSTRAINT [DF_Tbl_PersonalInformation_Sex] DEFAULT ((0)),
[FKStatus] [smallint] NULL CONSTRAINT [DF_Tbl_PersonalInformation_FKStatus] DEFAULT ((0)),
CONSTRAINT [PK_Tbl_PersonalInformation_1] PRIMARY KEY CLUSTERED
(
[Code] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY],
CONSTRAINT [IX_Tbl_PersonalInformation] UNIQUE NONCLUSTERED
(
[PersonalInfoID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
CREATE TABLE [dbo].[Tbl_Stockbroker_BroadDirector](
[Code] [bigint] IDENTITY(111111111,1) NOT NULL,
[StockbrokerCode] [nvarchar](20) NOT NULL,
[FKBizInfoID] [nvarchar](20) NOT NULL,
[FKPersonalInfoID] [nvarchar](20) NULL,
[IsStockbroker] [bit] NOT NULL CONSTRAINT [DF_Tbl_Stockbroker_BroadDirector_IsStockbroker] DEFAULT ((0)),
[IsBoardDirector] [bit] NOT NULL CONSTRAINT [DF_Tbl_Stockbroker_BroadDirector_IsBoardDirector] DEFAULT ((0)),
[FKStatus] [smallint] NULL CONSTRAINT [DF_Tbl_Stockbroker_BroadDirector_status] DEFAULT ((0)),
[StockPercent] [float] NULL CONSTRAINT [DF_Tbl_Stockbroker_BroadDirector_StockPercent] DEFAULT ((0)),
[SahamdarHoghoghi] [bit] NULL,
[FkBizinfoIDSahamdar] [nvarchar](20) NULL,
CONSTRAINT [PK_Tbl_Stockbroker_BroadDirector] PRIMARY KEY CLUSTERED
(
[Code] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY],
CONSTRAINT [IX_Tbl_Stockbroker_Code] UNIQUE NONCLUSTERED
(
[StockbrokerCode] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

The following should work:
SqlQuery query = DB.Select().From(Tables.TblStockbrokerBroadDirector)
.InnerJoin(TblPersonalInformation)
.InnerJoin(TblCompanyInformation)
.Where(TblPersonalInformation.Columns.FKLoginIDColumn).IsEqualTo(User.Identity.Name);

Change
.Where(TblPersonalInformation.FKLoginIDColumn.QualifiedName).IsEqualTo(User.Identity.Name);
to
.Where(TblPersonalInformation.FKLoginIDColumn).IsEqualTo(User.Identity.Name);
When you call .QualifiedName you are inadvertently calling Where(string columnName) instead of Where(TableColumn column).
You can verify this by checking the value of q.BuildSqlStatement(). This is very useful for debugging.

Thanks for your answer, but by yor code I got this error message
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 33: .InnerJoin(TblCompanyInformation.BizInfoIDColumn, TblStockbrokerBroadDirector.FKBizInfoIDColumn)
Line 34: .Where(TblPersonalInformation.FKLoginIDColumn).IsEqualTo(User.Identity.Name);
Line 35: Response.Write(q.BuildSqlStatement());
Line 36: q.ExecuteDataSet();
Line 37: }
Source File: E:\MehdiBackup\Visual Studio 2008\Projects\EXtjsUI\EXtjsUI\testi\default.aspx.cs Line: 35
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
SubSonic.ANSISqlGenerator.BuildConstraintSQL(String& constraintOperator, StringBuilder sb, Boolean isFirst, Boolean& expressionIsOpen, Constraint c) +129
SubSonic.ANSISqlGenerator.GenerateWhere() +218
SubSonic.ANSISqlGenerator.BuildSelectStatement() +124
SubSonic.SqlQuery.BuildSqlStatement() +71
IMPermit.testi._default.Page_Load(Object sender, EventArgs e) in E:\MehdiBackup\Visual Studio 2008\Projects\EXtjsUI\EXtjsUI\testi\default.aspx.cs:35
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436

Related

JOOQ Code generation: tinyint to boolean in Gradle plugin

I tried using this configuration for converting TINYINT(1) to BOOLEAN as per this blog in Gradle plugin
https://blog.jooq.org/2019/09/27/how-to-map-mysqls-tinyint1-to-boolean-in-jooq/
database {
name = 'org.jooq.meta.mysql.MySQLDatabase'
inputSchema = 'example'
forcedTypes {
forcedType {
name = "BOOLEAN"
types = "(?i:(TINY|SMALL|MEDIUM|BIG)?INT(UNSIGNED)?\\(1\\))"
}
}
}
It doesn't seem to work. The TINYINT(1) type is still generated as Byte and not Boolean.
In my case, the TINYINT was without "(1)", so worked this way (Gradle Groovy DSL):
forcedTypes {
forcedType {
name = 'BOOLEAN'
includeTypes = '(?i:TINYINT)'
}
}
With TINYINT(1) you can use includeTypes = '(?i:TINYINT(1))', without backslash.

What is the correct code in OR SqLite Android? Code not working

I'm working with Sqlite Database in my app. I want to search a word and return all results that i search from NAME and REGION.
The search is working fine when my code is searching only in NAME but when using OR only with the function LIKE is working.
I tried using OR and || but it is not working.
fun getWords(wordPrefix: String = ""): Cursor {
return if(wordPrefix.isBlank()) {
readableDatabase.query(DatabaseEntryContract.TABLE_NAME, null,
null, null, null, null,
"${DatabaseEntryContract.COLUMN_NAME} ASC")
} else {
readableDatabase.query(DatabaseEntryContract.TABLE_NAME, null,
"${DatabaseEntryContract.COLUMN_NAME} || ${DatabaseEntryContract.COLUMN_REGION} LIKE?", arrayOf("$wordPrefix%"),
null, null,
"${DatabaseEntryContract.COLUMN_NAME} ASC")
}
}
I expect the Output to search in either NAME and REGION. for example if I input A in the search bar.
The results should be show all prefix with A in the NAME and REGION
You could try :-
fun getWords(wordPrefix: String = ""): Cursor {
return if(wordPrefix.isBlank()) {
readableDatabase.query(DatabaseEntryContract.TABLE_NAME, null,
null, null, null, null,
"${DatabaseEntryContract.COLUMN_NAME} ASC")
} else {
readableDatabase.query(DatabaseEntryContract.TABLE_NAME, null,
"${DatabaseEntryContract.COLUMN_NAME} LIKE? OR ${DatabaseEntryContract.COLUMN_REGION} LIKE?",
arrayOf("$wordPrefix%","$wordPrefix%"),
null, null,
"${DatabaseEntryContract.COLUMN_NAME} ASC")
}
}

How to enable grid field in Acumatica - Journal Transactions screen irrespective of status

Below is the code which I have written to enable fields at grid level in Journal Transaction screen but it is not working. I have tried with automation steps but it also doens't work. Could any one help me out here?
protected void Batch_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
Batch row = (Batch)e.Row;
if (row != null)
{
PXUIFieldAttribute.SetReadOnly<GLTran.branchID>(Base.GLTranModuleBatNbr.Cache, null, false);
PXUIFieldAttribute.SetReadOnly<GLTran.accountID>(Base.GLTranModuleBatNbr.Cache, null, false);
PXUIFieldAttribute.SetReadOnly<GLTran.subID>(Base.GLTranModuleBatNbr.Cache, null, false);
PXUIFieldAttribute.SetReadOnly<GLTran.refNbr>(Base.GLTranModuleBatNbr.Cache, null, false);
PXUIFieldAttribute.SetReadOnly<GLTran.qty>(Base.GLTranModuleBatNbr.Cache, null, false);
PXUIFieldAttribute.SetReadOnly<GLTran.uOM>(Base.GLTranModuleBatNbr.Cache, null, false);
PXUIFieldAttribute.SetReadOnly<GLTran.curyDebitAmt>(Base.GLTranModuleBatNbr.Cache, null, false);
PXUIFieldAttribute.SetReadOnly<GLTran.curyCreditAmt>(Base.GLTranModuleBatNbr.Cache, null, false);
}
}

writning the data into the database using xml file in groovy

import groovy.sql.Sql
class come {
static main(args) {
def sql = Sql.newInstance("jdbc:mysql://localhost/test", "root","nayeem","com.mysql.jdbc.Driver")
assert(sql)
sql.execute('drop table if exists customers')
sql.execute(
'''create table customers(
CustomerID bigint(20) not null auto_increment,
CustomerName varchar(50) not null,
ContactName varchar(50) not null,
Address varchar(50) not null,
city varchar(25) not null,
PostalCode bigint(20) not null,
Country varchar(20) not null,
primary key(CustomerID))''')
def i=1
def key1= new XmlSlurper().parse('E:/kha.xml')
assert(key1)
//key1.each{println it}
for (p in { vars -> customers
} ){
println 'Hai'
println("->$i")
def CustomerID=p.CustomerID.text();
println("->$CustomerID")
def CustomerName=p.CustomerName.text();
println("->$CustomerName")
def ContactName=p.ContactName.text();
println("->$ContactName")
def Address=p.Address.text();
println("->$Address")
def array=[] as String
def city=p.city.text();
println("->$city")
def PostalCode=p.PostalCode.text();
println("->$PostalCode")
def Country=p.Country.text();
println("->$Country")
def key2="insert into customers values($CustomerID,$CustomerName,$ContactName,$Address,$city,$PostalCode,$Country)"
sql.execute(key2)
i++
}
def list=sql.rows"select * from customers"
println ''
println '------reading data--------'
println list
}
}
i am getting groovy.lang.MissingPropertyException: No such property: CustomerID for class: come please give me reply

Retrieving data from composite key via astyanax

I am very naive in cassandra & am using astyanax
CREATE TABLE employees (empID int, deptID int, first_name varchar,
last_name varchar, PRIMARY KEY (empID, deptID));
i want to get the values of query:
select * from employees where empID =2 and deptID = 800;
public void read(Integer empID, String deptID) {
OperationResult<ColumnList<String>> result;
try {
columnFamilies = ColumnFamily.newColumnFamily("employees", IntegerSerializer.get(), StringSerializer.get());
result = keyspace.prepareQuery(columnFamilies).getKey(empID).execute();
ColumnList<String> cols = result.getResult();
//Other stuff
}
how should i achieve this
As far as I can find, there isn't a super clean way to do this. You have to do it by executing a cql query and then iterating through the rows. This code is taken from the astynax examples file
public void read(int empId) {
logger.debug("read()");
try {
OperationResult<CqlResult<Integer, String>> result
= keyspace.prepareQuery(EMP_CF)
.withCql(String.format("SELECT * FROM %s WHERE %s=%d;", EMP_CF_NAME, COL_NAME_EMPID, empId))
.execute();
for (Row<Integer, String> row : result.getResult().getRows()) {
logger.debug("row: "+row.getKey()+","+row); // why is rowKey null?
ColumnList<String> cols = row.getColumns();
logger.debug("emp");
logger.debug("- emp id: "+cols.getIntegerValue(COL_NAME_EMPID, null));
logger.debug("- dept: "+cols.getIntegerValue(COL_NAME_DEPTID, null));
logger.debug("- firstName: "+cols.getStringValue(COL_NAME_FIRST_NAME, null));
logger.debug("- lastName: "+cols.getStringValue(COL_NAME_LAST_NAME, null));
}
} catch (ConnectionException e) {
logger.error("failed to read from C*", e);
throw new RuntimeException("failed to read from C*", e);
}
}
You just have to tune the cql query to return what you want. This is a bit frustrating because according to the documentation, you can do
Column<String> result = keyspace.prepareQuery(CF_COUNTER1)
.getKey(rowKey)
.getColumn("Column1")
.execute().getResult();
Long counterValue = result.getLongValue();
However I don't know what rowkey is. I've posted a question about what rowkey can be. Hopefully that will help

Resources