I am trying to create a SQLite custom function that will accept the entire row as its argument. An example query would be:
SELECT * FROM some_table ORDER BY custom_rank_function(<entire row>)
However, I'm unsure for the syntax to pass in the entire row. I tried using * but this passes each column value as a separate argument, which results in many arguments as my table has 15 fields. Is there any way to pass some kind of "row pointer" and then pull field values from this row pointer?
Thanks.
There is no syntax for this, because the SQLite API does not have any mechanism for this.
Related
I am trying to create an if function and if true execute one query if false execute another query, but I keep on having a 'Array Literal was missing values for one or more rows' error, the funtion goes like this:
=ARRAYFORMULA({"Cases";IF(H2="SFDC",QUERY(OPTION1),QUERY(OPTION2))})
Any ideia why, is there any other way to construct a conditional like this?
Thanks in Advance.
You need to make sure that our output as the same number of columns. For example, in your equation, you have one column of data (the header "Cases"). Because of this, the result of your IF statement must also have only one column of data.
One way to fix this is to define some extra empty columns. For example:
=ARRAYFORMULA({"Cases","","";IF(H2="SFDC",QUERY({1,2,3},"select *"),QUERY({4,5,6},"select *"))})
I added two more columns after Cases, therefore allowing my resulting query to properly expand.
I managed to solve the issue, I was not specifying the header at the end of the query which was generating a conflict.
Thanks to all.
This error is produced When two arrays have different numbers of columns, in you case make sure the length of array in QUERY(OPTION1) is the same length as
the one in QUERY(OPTION2).
use this formula to check array length.
for QUERY(OPTION1)
=COUNTA(SPLIT(QUERY(OPTION1),"/"))
and this for QUERY(OPTION2)
=COUNTA(SPLIT(QUERY(OPTION2),"/"))
Replace it with your formula of course.
Reference/test sheet: https://docs.google.com/spreadsheets/d/1fp6ZTBtgb5E0J9GKOqh8Ae47OzY1smec5ha9BfUfAsY/edit?usp=sharing
I have a Google Sheets document with one sheet (calculator) that pulls some values from another sheet (database). database is organized by two columns: make, and model. I use some weird data validation and helper columns to make dropdowns in calculator. Then I use filter() to pull the matching value from database.
This all works fine but it will be a calculator that gets reused and the data discarded, so I need only a finite number of rows in calculator (10-20). For this, it would be super nice to be able to select the whole row and hit delete to clear the calculation without destroying all the formulas. Ideally, the filter() would happen inside an arrayformula() in a hidden and protected top row to allow the rows to be easily cleared.
For some reason though, I can't get that to work. vlookup() is not an option because I need to match two keys.
On another note, it would be nice to not need the helper columns B:J and the data validation unique to each row. This is workable though as I only need a few rows. In the actual version I hide and protect B:J and there are many more columns there.
I know you said Vlookup() wouldn't work because you need to match on two keys, I think that vlookup() will help in this situation. Try this formula...
=arrayformula(Vlookup(A3:A&K3:K,{database!A$2:A&database!B$2:B,database!C$2:C},2,False))
The concept here is to put those two matches you need into one unique key. So we use the curly brackets {} to build an array within the formula and combine those two lookup fields in your 'database' sheet. So the columns of A and B become concatenated into one element, and the second part of that array is the column C which you need.
To lookup then just combines your A&K columns similarly, so it can lookup that combined element. The rest of the vlookup follows as normal. I.e. we look up this concatenation against that one and when it matches it returns the second column of the array we built, in this case database!C.
I don't think I'm clear on your columns B:J, so I'm not sure if this helps you with that as well.
You can't get rid of the helper column approach, as long as you want the calculator to use drop down selection for the model. Data validation for dropdowns requires either a list of values, ie. static, so no good, or a range of cells.
What you might want to do is to put those cells in a totally separate tab, eg. DataValidation, and then hide that tab. Your Calculator sheet will then be cleaner, with no hidden columns. Column K will use for data validation the "hidden" values, formerly columns B:J, that are now built off in the DataValidation tab.
See attached image file:
Assuming the data is loaded from SQL Server, GridView includes 5 columns as shown above, cells Search of textbox where you find out quickly (due to its use on the image for illustration), in his cell this search textbox enter any value in the column that has (according to this column 5), the GridView grid lines present value of the lookup value, usually looking to have a value equal to 1 column with which to look.
If you use fast search method does not need to specify one column before it, how to write this quickly find how to load into the GridView ?
I'm not entirely sure I understand your question but if your looking for a fast way to search the contents of a datagridview you can bind the SQL result to a bindingsource, use the bindingsource as the datagridviews data source and then set the binding sources filter to "dataproperty LIKE '%" + textBox1.Text + "%';"
Refer to: https://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource(v=vs.110).aspx
Sorry if this isn't what you're asking for!
In an SQLite table in my app, I need to have a column with row numbers going 1,2,3,4,5 (or to be able to get a row number for every row). Now I delete rows and add rows all the time, so I cant just put a number every time I add a new row, because when rows are deleted, the numbering will get messed up. So is there a way to get the row number, or create a special column that will act as row numbering? If so, how?
If you want this to be reset every time you add and delete rows, should this really be a column in your table?
For example, if you just want to be able to select the 20th row from the table, you can use the LIMIT and OFFSET clauses of SQL to select a particular row, e.g., to retrieve the 20th row from my news table, I could do:
SELECT * FROM news LIMIT 1 OFFSET 19;
Alternatively, if you really want a column with this row number information, you could just add a new INTEGER column type and then write an Objective C method to update the values for that column, and invoke that method any time you delete or insert rows in your result set.
There are a number of ways of solving your problem. You have to explain what you're trying to accomplish for us to help you out. The typical AUTOINCREMENT answer is what we generally use for table keys, but it sounds like you don't want this to be the key of your table, but rather something else.
If you use ROWID which is an auto-incrementing number, you can compute row numbers by selecting all of your data, ordered by ROWID and then using their index in the returned results as their row number. If you have some data model class you're creating, you could pass that in to its initializer.
If that won't do what you want, then how about adding some more details about what you're trying to do. Are you sure you need a row number?
You don't want to go changing all the existing records in your database when you delete rows that make "holes" in your row-umber scheme.
SQLite already supports what you want, with the ROWID. When you make a select query, just specify it to sort on ROWID, and all your returned records will be sorted in their proper order, and you can iterate over them in their order.
See this page: http://www.sqlite.org/autoinc.html
FWIW, there are certainly places where you should prefer direct SQLite over Core Data. However, those are rare cases. In general, reach for Core Data first, and fall back to SQLite only when CD does not serve your needs.
Just use an autoincrement primary key for the table. then there is always a unique identifier you can access a record.
I am creating the columns of a datagrid dynamically at run time and I need to allocate the sort compare function to those columns based on the data type of that column, is there a way I can pass some argument to that compare function which could tell the function what type of column is it going to operate on?
Thanks.
This link was helpful:
Flex: question about the sortCompareFunction of the DataGridColumn
But, in my case it didnt work because the solumns are getting generated dynamically and fieldName was not getting properly filled up (it was picking the last fieldName from code)...therefore I declared a global string (local to the class) and set it to the column name on headerRelease event of the datagrid (event class would be DataGridEvent and event.dataField would give the column name (which was dynamic in my case). You can use this column inside the sortcompare function to calculate the sorting logic based on column.