Drupal 6 next tid value - drupal-6

I need to find the next tid value that will be created when I create a new term. The term_data table does not show this value as the term with the highest tid can be deleted. It looks like the sequences table held this value in Drupal 5 but where is it held in Drupal 6?
Thanks for your time with this!

What do you need this for? You should be creating the term, then pulling the ID based on the vocabulary ID plus the term, like this -
$term = taxonomy_get_term_by_name('whatever the term is');
$new_term_id = $term->tid;
But to answer your question specifically -
$result = db_query("SHOW TABLE STATUS LIKE 'term_data'");
$row = db_fetch_array($result);
$next_id = $row['Auto_increment'];

Related

Contradicting information on CQL counter type in docs

I have been looking for some information on counters and it seems like there is some rather contradicting info regarding to what you can do with them.
According to the official DataStax Documentation (https://docs.datastax.com/en/cql-oss/3.x/cql/cql_reference/counter_type.html) "You cannot set the value of a counter, which supports two operations: increment and decrement.".
However, if we look into the BATCH CQL documentation (https://docs.datastax.com/en/dse/6.0/cql/cql/cql_reference/cql_commands/cqlBatch.html#cqlBatch__batch-updates), the bottom page example includes setting, adding, and subtracting a counter variable within a batch.
This example is likely also breaking the rule that having a counter in a table should only have counters for the rest of the table.
So what really are the limitations / usability for counters in cassandra DataStax? There does not seem to be a clear definition.
I think it's just a misunderstanding. Those pages do not contradict each other.
The CQL Counter type page correctly states that it is not possible to set the value of a counter column. For example, this is NOT valid:
UPDATE ks.counter_table
SET count = 10
WHERE pk = ?
The only valid operations on a counter column are increment and decrement. Here are some examples:
UPDATE ks.counter_table
SET count = count + 1
WHERE pk = ?
UPDATE ks.counter_table
SET count = count - 1
WHERE pk = ?
In the BATCH command page, the first 2 examples are increment operations:
UPDATE cycling.popular_count
SET popularity = popularity + 1
WHERE id = 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47;
UPDATE cycling.popular_count
SET popularity = popularity + 125
WHERE id = 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47;
The last example is a decrement operation:
UPDATE cycling.popular_count
SET popularity = popularity - 64
WHERE id = 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47;
I can't see how the examples would break the rule about only having counters in a counter table. From the examples, I would infer that the table schema is:
CREATE TABLE cycling.popular_count
id uuid,
popularity counter,
PRIMARY KEY(id)
)
You can have as many non-counter columns in the table as long as they are part of the PRIMARY KEY.
As a side note, it is not correct to refer to the software as either "Cassandra DataStax" or "DataStax Cassandra" so I've updated the title accordingly. DataStax (the company) does not own Cassandra. The more appropriate reference is "Apache Cassandra" or just plain "Cassandra". Cheers!

How to write a query for reordering elements

I'm working on a code that will have a list of items in a specific order and I'd like to reorder them at will. The setup isn't really that important, but to summarize it, it's a node server with MSSQL database.
For the sake of the demonstration lets say we're discussing forum categories that show in a specific order.
Id | OrderNumber | Name
------------------------
1 | 1 | Rules
2 | 3 | Off-topic
5 | 2 | General
8 | 4 | Global
I've already handled the front end that will allow me to reorder them as I like and the problem is what should happen when I press the save button on the database.
Ideally I'd like to send a JavaScript object containing item IDs in the right order to the API endpoint on the server that will execute a stored procedure. Something like:
Data = {
IDs:"5,2,8,1"
}
Is there a way that I can program a that stored procedure that it's only parameter is the list of Ids but that it can go through that list and do something I can only describe as the following pseudo code:
var Order = 1;
foreach ID in Data.IDs
UPDATE Categories SET OrderNum = Order WHERE Id = ID
Order = Order + 1
My biggest problem is that I'm not very experienced with advanced SQL commands, but that's the only part I need help with, I handled everything else already. Thank you for your help.
Example
Declare #IDs varchar(max) = '5,2,8,1'
Update A
set OrderNumber=B.RetSeq
From YourTable A
Join (
Select RetSeq = row_number() over (order by (select null))
,RetVal = B.n.value('(./text())[1]', 'int')
From ( values (cast('<x>' + replace(#IDs,',','</x><x>')+'</x>' as xml) )) A(xmldata)
Cross Apply xmldata.nodes('x') B(n)
) B on A.ID=B.RetVal
Updated Table
Id OrderNumber Name
1 4 Rules
2 2 Off-topic
5 1 General
8 3 Global

MVC 5 Paging a long list (50 000 object), i used listPaged but it takes time to charge list

I has to display a list of books that containes more than 50 000 book.
I want to display paged list where for each page i invoke a method that gives me 20 books.
List< Books > Ebooks = Books.GetLibrary(index);
But using PagedList doesnt match with my want because it creates a subset of the collection of objects given and accesse to each subset with the index. And refering to the definition of its methode, i had to charge the hole list from the begining.
I also followed this article
var EBooks = from b in db.Books select b;
int pageSize = 20;
int pageNumber = (page ?? 1);
return View(Ebooks.ToPagedList(pageNumber, pageSize));
But doing so, i has to invoke (var Books = from b in db.Books select b; ) on each index
**EDIT****
I'm searching for indications to achieve this
List< Books > Ebooks = Books.GetLibrary(index);
and of course i has the number of all the books so i know the number of pages
So i'm searching for indication that leads me to achieve it: for each index, i invoke GetLibrary(index)
any suggestions ?
Have you tried something like:
var pagedBooks = Books.GetLibrary().Skip(pageNumber * pageSize).Take(pageSize);
This assumes a 0-based pageNumber.
If that doesn't work, can you add a new method to the Books class that gets a paged set directly from the data source?
Something like "Books.GetPage(pageNumber, pageSize);" that way you don't get the entire collection every time.
Other than that, you may have to find a way to cache the initial result of Books.GetLibrary() somewhere.

ColdFusion: Object with duplicate values (removing duplicates)

I have a query object (SQL) with some records, the problem is that some of the records contain duplicate values. :( (I can't use DISTINCT in my SQL Query, so how to remove in my object?)
categories[1].id = 1
categories[2].id = 1
categories[3].id = 2
categories[4].id = 3
categories[5].id = 2
Now I want to get a list with 1, 2, 3
Is that possible?
I'm not quite sure why you say you can't use DISTINCT, even given the qualification you offered. It doesn't matter were a query came from (<cfquery>, <cfldap>, <cfdirectory>, built by hand) by the time it's exposed to your CFML code, it's just "a query", so you can definitely use DISTINCT on it:
<cfquery name="distinctCategories" dbtype="query">
SELECT DISTINCT id
FROM categories
</cfquery>

Creating an associative array using a while loop for select list?

I am dynamically generating a selectlist in Drupal and I want to create an associative array to populate the node ID as the value, and the title of the node as the option.
By default, it makes the value for each option the index of the select list. This is no good because the select list is dynamic, meaning the values won't be in the same order.
I used drupal_map_assoc to make the value the same as the option, but I have queries based on the value stored in this field, so if someone updates the value stored, the queries won't match.
<option value="Addison Reserve Country Club Inc.">Addison Reserve Country Club Inc.</option>
I want to replace the value with the Node ID also pulled with the query.
$sql = 'SELECT DISTINCT title, nid FROM {node} WHERE type = \'accounts\' ';
$result = db_query($sql);
while ($row = db_fetch_array($result)) {
$return[] = $row['title'];
//Trying to do something like 'Addison Reserve Country Club' => '2033' - where 2033 is the nid
}
$return = drupal_map_assoc($return);
I think you just want to do this inside the loop:
$return[$row['nid']] = $row['title'];
Based on your comment, you would also want to do an array_flip() right after the loop, but I think your comment may just have it backwards.

Resources